src/hotspot/share/gc/g1/g1YoungGenSizer.cpp
author eosterlund
Mon, 26 Feb 2018 09:34:12 +0100
changeset 49164 7e958a8ebcd3
parent 47216 71c04702a3d5
child 51332 c25572739e7c
permissions -rw-r--r--
8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy Reviewed-by: stefank, coleenp, kvn, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     1
/*
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     4
 *
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     8
 *
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    13
 * accompanied this code).
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    14
 *
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    18
 *
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    21
 * questions.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    22
 *
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    23
 */
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    24
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    25
#include "precompiled.hpp"
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    26
#include "gc/g1/g1YoungGenSizer.hpp"
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    27
#include "gc/g1/heapRegion.hpp"
37493
5da80e1490de 8154051: Change G1YoungGenSizer to use UL log_warning instead of warning
sjohanss
parents: 37041
diff changeset
    28
#include "logging/log.hpp"
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    29
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    30
G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true),
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    31
        _min_desired_young_length(0), _max_desired_young_length(0) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    32
  if (FLAG_IS_CMDLINE(NewRatio)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    33
    if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
37493
5da80e1490de 8154051: Change G1YoungGenSizer to use UL log_warning instead of warning
sjohanss
parents: 37041
diff changeset
    34
      log_warning(gc, ergo)("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    35
    } else {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    36
      _sizer_kind = SizerNewRatio;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    37
      _adaptive_size = false;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    38
      return;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    39
    }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    40
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    41
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    42
  if (NewSize > MaxNewSize) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    43
    if (FLAG_IS_CMDLINE(MaxNewSize)) {
37493
5da80e1490de 8154051: Change G1YoungGenSizer to use UL log_warning instead of warning
sjohanss
parents: 37041
diff changeset
    44
      log_warning(gc, ergo)("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
5da80e1490de 8154051: Change G1YoungGenSizer to use UL log_warning instead of warning
sjohanss
parents: 37041
diff changeset
    45
                            "A new max generation size of " SIZE_FORMAT "k will be used.",
5da80e1490de 8154051: Change G1YoungGenSizer to use UL log_warning instead of warning
sjohanss
parents: 37041
diff changeset
    46
                            NewSize/K, MaxNewSize/K, NewSize/K);
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    47
    }
39961
49fb257108d6 8024137: Flags should be set using the proper macro
jwilhelm
parents: 38652
diff changeset
    48
    FLAG_SET_ERGO(size_t, MaxNewSize, NewSize);
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    49
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    50
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    51
  if (FLAG_IS_CMDLINE(NewSize)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    52
    _min_desired_young_length = MAX2((uint) (NewSize / HeapRegion::GrainBytes),
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    53
                                     1U);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    54
    if (FLAG_IS_CMDLINE(MaxNewSize)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    55
      _max_desired_young_length =
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    56
                             MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    57
                                  1U);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    58
      _sizer_kind = SizerMaxAndNewSize;
38652
ba8be1a71dec 8156028: G1YoungGenSizer _adaptive_size not correct when setting NewSize and MaxNewSize to the same value
sjohanss
parents: 37985
diff changeset
    59
      _adaptive_size = _min_desired_young_length != _max_desired_young_length;
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    60
    } else {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    61
      _sizer_kind = SizerNewSizeOnly;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    62
    }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    63
  } else if (FLAG_IS_CMDLINE(MaxNewSize)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    64
    _max_desired_young_length =
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    65
                             MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    66
                                  1U);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    67
    _sizer_kind = SizerMaxNewSizeOnly;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    68
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    69
}
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    70
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    71
uint G1YoungGenSizer::calculate_default_min_length(uint new_number_of_heap_regions) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    72
  uint default_value = (new_number_of_heap_regions * G1NewSizePercent) / 100;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    73
  return MAX2(1U, default_value);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    74
}
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    75
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    76
uint G1YoungGenSizer::calculate_default_max_length(uint new_number_of_heap_regions) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    77
  uint default_value = (new_number_of_heap_regions * G1MaxNewSizePercent) / 100;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    78
  return MAX2(1U, default_value);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    79
}
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    80
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    81
void G1YoungGenSizer::recalculate_min_max_young_length(uint number_of_heap_regions, uint* min_young_length, uint* max_young_length) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    82
  assert(number_of_heap_regions > 0, "Heap must be initialized");
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    83
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    84
  switch (_sizer_kind) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    85
    case SizerDefaults:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    86
      *min_young_length = calculate_default_min_length(number_of_heap_regions);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    87
      *max_young_length = calculate_default_max_length(number_of_heap_regions);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    88
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    89
    case SizerNewSizeOnly:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    90
      *max_young_length = calculate_default_max_length(number_of_heap_regions);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    91
      *max_young_length = MAX2(*min_young_length, *max_young_length);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    92
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    93
    case SizerMaxNewSizeOnly:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    94
      *min_young_length = calculate_default_min_length(number_of_heap_regions);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    95
      *min_young_length = MIN2(*min_young_length, *max_young_length);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    96
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    97
    case SizerMaxAndNewSize:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    98
      // Do nothing. Values set on the command line, don't update them at runtime.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    99
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   100
    case SizerNewRatio:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   101
      *min_young_length = number_of_heap_regions / (NewRatio + 1);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   102
      *max_young_length = *min_young_length;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   103
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   104
    default:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   105
      ShouldNotReachHere();
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   106
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   107
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   108
  assert(*min_young_length <= *max_young_length, "Invalid min/max young gen size values");
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   109
}
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   110
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   111
void G1YoungGenSizer::adjust_max_new_size(uint number_of_heap_regions) {
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   112
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   113
  // We need to pass the desired values because recalculation may not update these
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   114
  // values in some cases.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   115
  uint temp = _min_desired_young_length;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   116
  uint result = _max_desired_young_length;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   117
  recalculate_min_max_young_length(number_of_heap_regions, &temp, &result);
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   118
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   119
  size_t max_young_size = result * HeapRegion::GrainBytes;
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   120
  if (max_young_size != MaxNewSize) {
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   121
    FLAG_SET_ERGO(size_t, MaxNewSize, max_young_size);
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   122
  }
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   123
}
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   124
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   125
void G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   126
  recalculate_min_max_young_length(new_number_of_heap_regions, &_min_desired_young_length,
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   127
          &_max_desired_young_length);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   128
}