src/hotspot/share/gc/parallel/heterogeneousGenerationSizer.cpp
branchniosocketimpl-branch
changeset 57347 16c087c9103e
parent 57344 8b621b0d921c
parent 54696 0907dce4b90e
child 57353 ddfb12ab18e1
equal deleted inserted replaced
57344:8b621b0d921c 57347:16c087c9103e
     1 /*
       
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #include "precompiled.hpp"
       
    26 #include "gc/parallel/heterogeneousGenerationSizer.hpp"
       
    27 #include "gc/shared/collectorPolicy.hpp"
       
    28 #include "logging/log.hpp"
       
    29 #include "runtime/globals_extension.hpp"
       
    30 #include "runtime/os.hpp"
       
    31 #include "utilities/align.hpp"
       
    32 #include "utilities/formatBuffer.hpp"
       
    33 #include "utilities/globalDefinitions.hpp"
       
    34 
       
    35 const double HeterogeneousGenerationSizer::MaxRamFractionForYoung = 0.8;
       
    36 
       
    37 // Check the available dram memory to limit NewSize and MaxNewSize before
       
    38 // calling base class initialize_flags().
       
    39 void HeterogeneousGenerationSizer::initialize_flags() {
       
    40   FormatBuffer<100> calc_str("");
       
    41 
       
    42   julong phys_mem;
       
    43   // If MaxRam is specified, we use that as maximum physical memory available.
       
    44   if (FLAG_IS_DEFAULT(MaxRAM)) {
       
    45     phys_mem = os::physical_memory();
       
    46     calc_str.append("Physical_Memory");
       
    47   } else {
       
    48     phys_mem = (julong)MaxRAM;
       
    49     calc_str.append("MaxRAM");
       
    50   }
       
    51 
       
    52   julong reasonable_max = phys_mem;
       
    53 
       
    54   // If either MaxRAMFraction or MaxRAMPercentage is specified, we use them to calculate
       
    55   // reasonable max size of young generation.
       
    56   if (!FLAG_IS_DEFAULT(MaxRAMFraction)) {
       
    57     reasonable_max = (julong)(phys_mem / MaxRAMFraction);
       
    58     calc_str.append(" / MaxRAMFraction");
       
    59   } else if (!FLAG_IS_DEFAULT(MaxRAMPercentage)) {
       
    60     reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100);
       
    61     calc_str.append(" * MaxRAMPercentage / 100");
       
    62   } else {
       
    63     // We use our own fraction to calculate max size of young generation.
       
    64     reasonable_max = phys_mem * MaxRamFractionForYoung;
       
    65     calc_str.append(" * %0.2f", MaxRamFractionForYoung);
       
    66   }
       
    67   reasonable_max = align_up(reasonable_max, _gen_alignment);
       
    68 
       
    69   if (MaxNewSize > reasonable_max) {
       
    70     if (FLAG_IS_CMDLINE(MaxNewSize)) {
       
    71       log_warning(gc, ergo)("Setting MaxNewSize to " SIZE_FORMAT " based on dram available (calculation = align(%s))",
       
    72                             (size_t)reasonable_max, calc_str.buffer());
       
    73     } else {
       
    74       log_info(gc, ergo)("Setting MaxNewSize to " SIZE_FORMAT " based on dram available (calculation = align(%s)). "
       
    75                          "Dram usage can be lowered by setting MaxNewSize to a lower value", (size_t)reasonable_max, calc_str.buffer());
       
    76     }
       
    77     MaxNewSize = reasonable_max;
       
    78   }
       
    79   if (NewSize > reasonable_max) {
       
    80     if (FLAG_IS_CMDLINE(NewSize)) {
       
    81       log_warning(gc, ergo)("Setting NewSize to " SIZE_FORMAT " based on dram available (calculation = align(%s))",
       
    82                             (size_t)reasonable_max, calc_str.buffer());
       
    83     }
       
    84     NewSize = reasonable_max;
       
    85   }
       
    86 
       
    87   // After setting new size flags, call base class initialize_flags()
       
    88   GenerationSizer::initialize_flags();
       
    89 }
       
    90 
       
    91 bool HeterogeneousGenerationSizer::is_hetero_heap() const {
       
    92   return true;
       
    93 }
       
    94 
       
    95 size_t HeterogeneousGenerationSizer::heap_reserved_size_bytes() const {
       
    96   if (UseAdaptiveGCBoundary) {
       
    97     // This is the size that young gen can grow to, when UseAdaptiveGCBoundary is true.
       
    98     size_t max_yg_size = _max_heap_byte_size - _min_old_size;
       
    99     // This is the size that old gen can grow to, when UseAdaptiveGCBoundary is true.
       
   100     size_t max_old_size = _max_heap_byte_size - _min_young_size;
       
   101 
       
   102     return max_yg_size + max_old_size;
       
   103   } else {
       
   104     return _max_heap_byte_size;
       
   105   }
       
   106 }