hotspot/src/share/vm/gc/g1/g1EvacStats.cpp
author kbarrett
Tue, 30 Aug 2016 23:48:16 -0400
changeset 40892 330a02d935ad
parent 37997 db6541410dfb
child 46290 3c4c1591507d
permissions -rw-r--r--
8156500: Move Reference pending list into VM to prevent deadlocks Summary: Move reference pending list and locking into VM Reviewed-by: coleenp, dholmes, dcubed, mchung, plevart Contributed-by: kim.barrett@oracle.com, per.liden@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     1
/*
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     4
 *
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     8
 *
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    14
 *
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    18
 *
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    21
 * questions.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    22
 *
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    23
 */
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    24
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    25
#include "precompiled.hpp"
34230
b9c64b7c06c9 8141570: Fix Zero interpreter build for --disable-precompiled-headers
coleenp
parents: 33605
diff changeset
    26
#include "memory/allocation.inline.hpp"
37997
db6541410dfb 8154280: Zero build fails with undeclared G1LastPLABAverageOccupancy
coleenp
parents: 37068
diff changeset
    27
#include "gc/g1/g1_globals.hpp"
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    28
#include "gc/g1/g1EvacStats.hpp"
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    29
#include "gc/shared/gcId.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    30
#include "logging/log.hpp"
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    31
#include "trace/tracing.hpp"
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    32
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    33
void G1EvacStats::log_plab_allocation() {
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    34
  PLABStats::log_plab_allocation();
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    35
  log_debug(gc, plab)("%s other allocation: "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    36
                      "region end waste: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    37
                      "regions filled: %u, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    38
                      "direct allocated: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    39
                      "failure used: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    40
                      "failure wasted: " SIZE_FORMAT "B",
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    41
                      _description,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    42
                      _region_end_waste * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    43
                      _regions_filled,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    44
                      _direct_allocated * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    45
                      _failure_used * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    46
                      _failure_waste * HeapWordSize);
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    47
}
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    48
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    49
void G1EvacStats::adjust_desired_plab_sz() {
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    50
  log_plab_allocation();
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
    51
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    52
  if (!ResizePLAB) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    53
    // Clear accumulators for next round.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    54
    reset();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    55
    return;
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    56
  }
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    57
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    58
  assert(is_object_aligned(max_size()) && min_size() <= max_size(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    59
         "PLAB clipping computation may be incorrect");
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
    60
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    61
  if (_allocated == 0) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    62
    assert((_unused == 0),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    63
           "Inconsistency in PLAB stats: "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    64
           "_allocated: " SIZE_FORMAT ", "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    65
           "_wasted: " SIZE_FORMAT ", "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    66
           "_region_end_waste: " SIZE_FORMAT ", "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    67
           "_unused: " SIZE_FORMAT ", "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    68
           "_used  : " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    69
           _allocated, _wasted, _region_end_waste, _unused, used());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    70
    _allocated = 1;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    71
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    72
  // The size of the PLAB caps the amount of space that can be wasted at the
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    73
  // end of the collection. In the worst case the last PLAB could be completely
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    74
  // empty.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    75
  // This allows us to calculate the new PLAB size to achieve the
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    76
  // TargetPLABWastePct given the latest memory usage and that the last buffer
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    77
  // will be G1LastPLABAverageOccupancy full.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    78
  //
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    79
  // E.g. assume that if in the current GC 100 words were allocated and a
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    80
  // TargetPLABWastePct of 10 had been set.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    81
  //
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    82
  // So we could waste up to 10 words to meet that percentage. Given that we
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    83
  // also assume that that buffer is typically half-full, the new desired PLAB
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    84
  // size is set to 20 words.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    85
  //
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    86
  // The amount of allocation performed should be independent of the number of
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    87
  // threads, so should the maximum waste we can spend in total. So if
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    88
  // we used n threads to allocate, each of them can spend maximum waste/n words in
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    89
  // a first rough approximation. The number of threads only comes into play later
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    90
  // when actually retrieving the actual desired PLAB size.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    91
  //
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    92
  // After calculating this optimal PLAB size the algorithm applies the usual
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    93
  // exponential decaying average over this value to guess the next PLAB size.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    94
  //
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    95
  // We account region end waste fully to PLAB allocation (in the calculation of
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    96
  // what we consider as "used_for_waste_calculation" below). This is not
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    97
  // completely fair, but is a conservative assumption because PLABs may be sized
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    98
  // flexibly while we cannot adjust inline allocations.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
    99
  // Allocation during GC will try to minimize region end waste so this impact
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   100
  // should be minimal.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   101
  //
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   102
  // We need to cover overflow when calculating the amount of space actually used
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   103
  // by objects in PLABs when subtracting the region end waste.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   104
  // Region end waste may be higher than actual allocation. This may occur if many
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   105
  // threads do not allocate anything but a few rather large objects. In this
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   106
  // degenerate case the PLAB size would simply quickly tend to minimum PLAB size,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   107
  // which is an okay reaction.
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   108
  size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0;
32602
27d046027824 8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents: 32379
diff changeset
   109
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   110
  size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   111
  size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   112
  // Take historical weighted average
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   113
  _filter.sample(cur_plab_sz);
37068
fd8357c31be4 8150952: Net PLAB size is clipped to max PLAB size as a whole, not on a per thread basis
tschatzl
parents: 36390
diff changeset
   114
  _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34230
diff changeset
   115
37068
fd8357c31be4 8150952: Net PLAB size is clipped to max PLAB size as a whole, not on a per thread basis
tschatzl
parents: 36390
diff changeset
   116
  log_sizing(cur_plab_sz, _desired_net_plab_sz);
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
   117
  // Clear accumulators for next round.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
   118
  reset();
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
   119
}
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff changeset
   120
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   121
G1EvacStats::G1EvacStats(const char* description, size_t desired_plab_sz_, unsigned wt) :
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   122
  PLABStats(description, desired_plab_sz_, wt),
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   123
  _region_end_waste(0),
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   124
  _regions_filled(0),
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   125
  _direct_allocated(0),
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   126
  _failure_used(0),
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   127
  _failure_waste(0) {
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   128
}
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   129
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   130
34230
b9c64b7c06c9 8141570: Fix Zero interpreter build for --disable-precompiled-headers
coleenp
parents: 33605
diff changeset
   131
G1EvacStats::~G1EvacStats() { }