<commit_before>/*
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

package com.facebook.imagepipeline.memory;

public class BitmapCounterProvider {
  private static final long KB = 1024;
  private static final long MB = 1024 * KB;

  /**
   * Our Bitmaps live in ashmem, meaning that they are pinned in Android's shared native memory.
   *
   * <p> Therefore, we are not constrained by the max heap size of the dalvik heap, but we want to
   * make sure we don't use too much memory on low end devices, so that we don't force other
   * background process to be killed.
   */
  public static final int MAX_BITMAP_TOTAL_SIZE = getMaxSizeHardCap();
  public static final int MAX_BITMAP_COUNT = 384;

  private static BitmapCounter sBitmapCounter;

  private static int getMaxSizeHardCap() {
    final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE);
    if (maxMemory > 16 * MB) {
      return maxMemory / 4 * 3;
    } else {
      return maxMemory / 2;
    }
  }

  public static BitmapCounter get() {
    if (sBitmapCounter == null) {
      sBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_TOTAL_SIZE);
    }
    return sBitmapCounter;
  }
}<commit_msg>Make BitmapCounterProvider.get() ThreadSafe<commit_after>/*
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

package com.facebook.imagepipeline.memory;

import com.facebook.infer.annotation.ThreadSafe;

public class BitmapCounterProvider {
  private static final long KB = 1024;
  private static final long MB = 1024 * KB;

  /**
   * Our Bitmaps live in ashmem, meaning that they are pinned in Android's shared native memory.
   *
   * <p> Therefore, we are not constrained by the max heap size of the dalvik heap, but we want to
   * make sure we don't use too much memory on low end devices, so that we don't force other
   * background process to be killed.
   */
  public static final int MAX_BITMAP_TOTAL_SIZE = getMaxSizeHardCap();
  public static final int MAX_BITMAP_COUNT = 384;

  private static volatile BitmapCounter sBitmapCounter;

  private static int getMaxSizeHardCap() {
    final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE);
    if (maxMemory > 16 * MB) {
      return maxMemory / 4 * 3;
    } else {
      return maxMemory / 2;
    }
  }

  @ThreadSafe
  public static BitmapCounter get() {
    if (sBitmapCounter == null) {
      synchronized (BitmapCounterProvider.class) {
        if (sBitmapCounter == null) {
         sBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_TOTAL_SIZE);
        }
      }
    }
    return sBitmapCounter;
  }
}
{'fraction_non_alphanumeric': 0.07655502392344497, 'fraction_numerical': 0.012759170653907496, 'mean_word_length': 3.3737796373779636, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4744729', 'n_tokens_mistral': 951, 'n_tokens_neox': 873, 'n_words': 359}