<commit_before>/*
 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#include "precompiled.hpp"
#include "gc_implementation/shared/adaptiveSizePolicy.hpp"
#include "gc_implementation/shared/gcPolicyCounters.hpp"
#include "gc_implementation/shared/vmGCOperations.hpp"
#include "memory/cardTableRS.hpp"
#include "memory/collectorPolicy.hpp"
#include "memory/gcLocker.inline.hpp"
#include "memory/genCollectedHeap.hpp"
#include "memory/generationSpec.hpp"
#include "memory/space.hpp"
#include "memory/universe.hpp"
#include "runtime/arguments.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/java.hpp"
#include "runtime/thread.inline.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/macros.hpp"
#if INCLUDE_ALL_GCS
#include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
#include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp"
#endif // INCLUDE_ALL_GCS

// CollectorPolicy methods.

// Align down. If the aligning result in 0, return 'alignment'.
static size_t restricted_align_down(size_t size, size_t alignment) {
  return MAX2(alignment, align_size_down_(size, alignment));
}

void CollectorPolicy::initialize_flags() {
  assert(max_alignment() >= min_alignment(),
      err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT,
          max_alignment(), min_alignment()));
  assert(max_alignment() % min_alignment() == 0,
      err_msg("max_alignment: " SIZE_FORMAT " not aligned by min_alignment: " SIZE_FORMAT,
          max_alignment(), min_alignment()));

  if (MaxHeapSize < InitialHeapSize) {
    vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified");
  }

  if (!is_size_aligned(MaxMetaspaceSize, max_alignment())) {
    FLAG_SET_ERGO(uintx, MaxMetaspaceSize,
        restricted_align_down(MaxMetaspaceSize, max_alignment()));
  }

  if (MetaspaceSize > MaxMetaspaceSize) {
    FLAG_SET_ERGO(uintx, MetaspaceSize, MaxMetaspaceSize);
  }

  if (!is_size_aligned(MetaspaceSize, min_alignment())) {
    FLAG_SET_ERGO(uintx, MetaspaceSize,
        restricted_align_down(MetaspaceSize, min_alignment()));
  }

  assert(MetaspaceSize <= MaxMetaspaceSize, "Must be");

  MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, min_alignment());
  MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, min_alignment());

  MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment());

  assert(MetaspaceSize    % min_alignment() == 0, "metapace alignment");
  assert(MaxMetaspaceSize % max_alignment() == 0, "maximum metaspace alignment");
  if (MetaspaceSize < 256*K) {
    vm_exit_during_initialization("Too small initial Metaspace size");
  }
}

void CollectorPolicy::initialize_size_info() {
  // User inputs from -mx and ms must be aligned
  set_min_heap_byte_size(align_size_up(Arguments::min_heap_size(), min_alignment()));
  set_initial_heap_byte_size(align_size_up(InitialHeapSize, min_alignment()));<commit_msg>8025313: MetaspaceMemoryPool incorrectly reports undefined size for max Reviewed-by: stefank, tschatzl<commit_after>/*
 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#include "precompiled.hpp"
#include "gc_implementation/shared/adaptiveSizePolicy.hpp"
#include "gc_implementation/shared/gcPolicyCounters.hpp"
#include "gc_implementation/shared/vmGCOperations.hpp"
#include "memory/cardTableRS.hpp"
#include "memory/collectorPolicy.hpp"
#include "memory/gcLocker.inline.hpp"
#include "memory/genCollectedHeap.hpp"
#include "memory/generationSpec.hpp"
#include "memory/space.hpp"
#include "memory/universe.hpp"
#include "runtime/arguments.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/java.hpp"
#include "runtime/thread.inline.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/macros.hpp"
#if INCLUDE_ALL_GCS
#include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
#include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp"
#endif // INCLUDE_ALL_GCS

// CollectorPolicy methods.

// Align down. If the aligning result in 0, return 'alignment'.
static size_t restricted_align_down(size_t size, size_t alignment) {
  return MAX2(alignment, align_size_down_(size, alignment));
}

void CollectorPolicy::initialize_flags() {
  assert(max_alignment() >= min_alignment(),
      err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT,
          max_alignment(), min_alignment()));
  assert(max_alignment() % min_alignment() == 0,
      err_msg("max_alignment: " SIZE_FORMAT " not aligned by min_alignment: " SIZE_FORMAT,
          max_alignment(), min_alignment()));

  if (MaxHeapSize < InitialHeapSize) {
    vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified");
  }

  // Do not use FLAG_SET_ERGO to update MaxMetaspaceSize, since this will
  // override if MaxMetaspaceSize was set on the command line or not.
  // This information is needed later to conform to the specification of the
  // java.lang.management.MemoryUsage API.
  //
  // Ideally, we would be able to set the default value of MaxMetaspaceSize in
  // globals.hpp to the aligned value, but this is not possible, since the
  // alignment depends on other flags being parsed.
  MaxMetaspaceSize = restricted_align_down(MaxMetaspaceSize, max_alignment());

  if (MetaspaceSize > MaxMetaspaceSize) {
    MetaspaceSize = MaxMetaspaceSize;
  }

  MetaspaceSize = restricted_align_down(MetaspaceSize, min_alignment());

  assert(MetaspaceSize <= MaxMetaspaceSize, "Must be");

  MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, min_alignment());
  MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, min_alignment());

  MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment());

  assert(MetaspaceSize    % min_alignment() == 0, "metapace alignment");
  assert(MaxMetaspaceSize % max_alignment() == 0, "maximum metaspace alignment");
  if (MetaspaceSize < 256*K) {
    vm_exit_during_initialization("Too small initial Metaspace size");
  }
}

void CollectorPolicy::initialize_size_info() {
  // User inputs from -mx and ms must be aligned
  set_min_heap_byte_size(align_size_up(Arguments::min_heap_size(), min_alignment()));
  set_initial_heap_byte_size(align_size_up(InitialHeapSize, min_alignment()));
{'fraction_non_alphanumeric': 0.09538534728829685, 'fraction_numerical': 0.009871550903901046, 'mean_word_length': 5.351208459214502, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3939894', 'n_tokens_mistral': 2651, 'n_tokens_neox': 2471, 'n_words': 731}