src/hotspot/share/gc/g1/g1YoungGenSizer.cpp
author tschatzl
Fri, 29 Nov 2019 10:20:17 +0100
changeset 59321 5775e4825e58
parent 58980 47c20fc6a517
permissions -rw-r--r--
8233998: New young regions registered too early in collection set Reviewed-by: sangheki, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
     1
/*
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 53116
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
37041
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"
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54466
diff changeset
    26
#include "gc/g1/g1Arguments.hpp"
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
    27
#include "gc/g1/g1HeterogeneousHeapYoungGenSizer.hpp"
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    28
#include "gc/g1/g1YoungGenSizer.hpp"
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    29
#include "gc/g1/heapRegion.hpp"
37493
5da80e1490de 8154051: Change G1YoungGenSizer to use UL log_warning instead of warning
sjohanss
parents: 37041
diff changeset
    30
#include "logging/log.hpp"
58980
47c20fc6a517 8189737: Make HeapRegion not derive from Space
tschatzl
parents: 54983
diff changeset
    31
#include "runtime/globals_extension.hpp"
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    32
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    33
G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults),
54466
58751415d5f8 8222105: Add "use_" prefix to G1Policy::adaptive_young_list_length
tschatzl
parents: 53987
diff changeset
    34
  _use_adaptive_sizing(true), _min_desired_young_length(0), _max_desired_young_length(0) {
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    35
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    36
  if (FLAG_IS_CMDLINE(NewRatio)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    37
    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
    38
      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
    39
    } else {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    40
      _sizer_kind = SizerNewRatio;
54466
58751415d5f8 8222105: Add "use_" prefix to G1Policy::adaptive_young_list_length
tschatzl
parents: 53987
diff changeset
    41
      _use_adaptive_sizing = false;
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    42
      return;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    43
    }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    44
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    45
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    46
  if (NewSize > MaxNewSize) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    47
    if (FLAG_IS_CMDLINE(MaxNewSize)) {
37493
5da80e1490de 8154051: Change G1YoungGenSizer to use UL log_warning instead of warning
sjohanss
parents: 37041
diff changeset
    48
      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
    49
                            "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
    50
                            NewSize/K, MaxNewSize/K, NewSize/K);
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    51
    }
54983
81becad91321 8224203: Remove need to specify type when using FLAG_SET macros
stefank
parents: 54678
diff changeset
    52
    FLAG_SET_ERGO(MaxNewSize, NewSize);
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    53
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    54
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    55
  if (FLAG_IS_CMDLINE(NewSize)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    56
    _min_desired_young_length = MAX2((uint) (NewSize / 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
    if (FLAG_IS_CMDLINE(MaxNewSize)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    59
      _max_desired_young_length =
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    60
                             MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    61
                                  1U);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    62
      _sizer_kind = SizerMaxAndNewSize;
54466
58751415d5f8 8222105: Add "use_" prefix to G1Policy::adaptive_young_list_length
tschatzl
parents: 53987
diff changeset
    63
      _use_adaptive_sizing = _min_desired_young_length != _max_desired_young_length;
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    64
    } else {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    65
      _sizer_kind = SizerNewSizeOnly;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    66
    }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    67
  } else if (FLAG_IS_CMDLINE(MaxNewSize)) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    68
    _max_desired_young_length =
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    69
                             MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    70
                                  1U);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    71
    _sizer_kind = SizerMaxNewSizeOnly;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    72
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    73
}
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
uint G1YoungGenSizer::calculate_default_min_length(uint new_number_of_heap_regions) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    76
  uint default_value = (new_number_of_heap_regions * G1NewSizePercent) / 100;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    77
  return MAX2(1U, default_value);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    78
}
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
uint G1YoungGenSizer::calculate_default_max_length(uint new_number_of_heap_regions) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    81
  uint default_value = (new_number_of_heap_regions * G1MaxNewSizePercent) / 100;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    82
  return MAX2(1U, default_value);
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
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    85
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
    86
  assert(number_of_heap_regions > 0, "Heap must be initialized");
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    87
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    88
  switch (_sizer_kind) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    89
    case SizerDefaults:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    90
      *min_young_length = calculate_default_min_length(number_of_heap_regions);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    91
      *max_young_length = calculate_default_max_length(number_of_heap_regions);
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 SizerNewSizeOnly:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    94
      *max_young_length = calculate_default_max_length(number_of_heap_regions);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    95
      *max_young_length = MAX2(*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 SizerMaxNewSizeOnly:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    98
      *min_young_length = calculate_default_min_length(number_of_heap_regions);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
    99
      *min_young_length = MIN2(*min_young_length, *max_young_length);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   100
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   101
    case SizerMaxAndNewSize:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   102
      // 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
   103
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   104
    case SizerNewRatio:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   105
      *min_young_length = number_of_heap_regions / (NewRatio + 1);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   106
      *max_young_length = *min_young_length;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   107
      break;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   108
    default:
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   109
      ShouldNotReachHere();
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   110
  }
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   111
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   112
  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
   113
}
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   114
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   115
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
   116
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   117
  // 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
   118
  // values in some cases.
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   119
  uint temp = _min_desired_young_length;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   120
  uint result = _max_desired_young_length;
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   121
  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
   122
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   123
  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
   124
  if (max_young_size != MaxNewSize) {
54983
81becad91321 8224203: Remove need to specify type when using FLAG_SET macros
stefank
parents: 54678
diff changeset
   125
    FLAG_SET_ERGO(MaxNewSize, max_young_size);
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37493
diff changeset
   126
  }
37041
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   127
}
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   128
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   129
void G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   130
  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
   131
          &_max_desired_young_length);
803d638420d5 8151365: Move G1YoungGenSizer to a separate file
ehelin
parents:
diff changeset
   132
}
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   133
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54466
diff changeset
   134
G1YoungGenSizer* G1YoungGenSizer::create_gen_sizer() {
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 54466
diff changeset
   135
  if (G1Arguments::is_heterogeneous_heap()) {
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   136
    return new G1HeterogeneousHeapYoungGenSizer();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   137
  } else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   138
    return new G1YoungGenSizer();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   139
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   140
}