src/hotspot/share/gc/cms/allocationStats.hpp
author coleenp
Wed, 14 Mar 2018 07:27:19 -0400
changeset 49392 2956d0ece7a9
parent 48157 7c4d43c26352
child 53244 9807daeb47c4
permissions -rw-r--r--
8199282: Remove ValueObj class for allocation subclassing for gc code Reviewed-by: stefank, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 48157
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
    25
#ifndef SHARE_VM_GC_CMS_ALLOCATIONSTATS_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
    26
#define SHARE_VM_GC_CMS_ALLOCATIONSTATS_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
    28
#include "gc/shared/gcUtil.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    29
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
    31
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 48157
diff changeset
    33
class AllocationStats {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // A duration threshold (in ms) used to filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // possibly unreliable samples.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  static float _threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // We measure the demand between the end of the previous sweep and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // beginning of this sweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  //   Count(end_last_sweep) - Count(start_this_sweep)
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    41
  //     + split_births(between) - split_deaths(between)
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    42
  // The above number divided by the time since the end of the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // previous sweep gives us a time rate of demand for blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // of this size. We compute a padded average of this rate as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // our current estimate for the time rate of demand for blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // of this size. Similarly, we keep a padded average for the time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // between sweeps. Our current estimate for demand for blocks of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // this size is then simply computed as the product of these two
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // estimates.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  AdaptivePaddedAverage _demand_rate_estimate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 19974
diff changeset
    52
  ssize_t     _desired;          // Demand estimate computed as described above
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    53
  ssize_t     _coal_desired;     // desired +/- small-percent for tuning coalescing
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 19974
diff changeset
    55
  ssize_t     _surplus;          // count - (desired +/- small-percent),
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 19974
diff changeset
    56
                                 // used to tune splitting in best fit
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    57
  ssize_t     _bfr_surp;         // surplus at start of current sweep
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    58
  ssize_t     _prev_sweep;       // count from end of previous sweep
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    59
  ssize_t     _before_sweep;     // count from before current sweep
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    60
  ssize_t     _coal_births;      // additional chunks from coalescing
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    61
  ssize_t     _coal_deaths;      // loss from coalescing
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    62
  ssize_t     _split_births;     // additional chunks from splitting
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    63
  ssize_t     _split_deaths;     // loss from splitting
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    64
  size_t      _returned_bytes;   // number of bytes returned to list.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
 public:
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
    66
  void initialize(bool split_birth = false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  AllocationStats() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    71
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // The rate estimate is in blocks per second.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  void compute_desired(size_t count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                       float inter_sweep_current,
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    75
                       float inter_sweep_estimate,
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    76
                       float intra_sweep_estimate) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // If the latest inter-sweep time is below our granularity
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    // of measurement, we may call in here with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    // inter_sweep_current == 0. However, even for suitably small
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    // but non-zero inter-sweep durations, we may not trust the accuracy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    // of accumulated data, since it has not been "integrated"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    // (read "low-pass-filtered") long enough, and would be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // vulnerable to noisy glitches. In such cases, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // ignore the current sample and use currently available
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // historical estimates.
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    86
    assert(prev_sweep() + split_births() + coal_births()        // "Total Production Stock"
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    87
           >= split_deaths() + coal_deaths() + (ssize_t)count, // "Current stock + depletion"
9998
f5cb52083a7c 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 9183
diff changeset
    88
           "Conservation Principle");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if (inter_sweep_current > _threshold) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    90
      ssize_t demand = prev_sweep() - (ssize_t)count + split_births() + coal_births()
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
    91
                       - split_deaths() - coal_deaths();
9998
f5cb52083a7c 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 9183
diff changeset
    92
      assert(demand >= 0,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    93
             "Demand (" SSIZE_FORMAT ") should be non-negative for "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    94
             PTR_FORMAT " (size=" SIZE_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    95
             demand, p2i(this), count);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    96
      // Defensive: adjust for imprecision in event counting
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    97
      if (demand < 0) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    98
        demand = 0;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    99
      }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   100
      float old_rate = _demand_rate_estimate.padded_average();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      float rate = ((float)demand)/inter_sweep_current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      _demand_rate_estimate.sample(rate);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   103
      float new_rate = _demand_rate_estimate.padded_average();
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   104
      ssize_t old_desired = _desired;
8101
1778246610fa 6999988: CMS: Increased fragmentation leading to promotion failure after CR#6631166 got implemented
ysr
parents: 7397
diff changeset
   105
      float delta_ise = (CMSExtrapolateSweep ? intra_sweep_estimate : 0.0);
1778246610fa 6999988: CMS: Increased fragmentation leading to promotion failure after CR#6631166 got implemented
ysr
parents: 7397
diff changeset
   106
      _desired = (ssize_t)(new_rate * (inter_sweep_estimate + delta_ise));
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   107
      log_trace(gc, freelist)("demand: " SSIZE_FORMAT ", old_rate: %f, current_rate: %f, "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   108
                              "new_rate: %f, old_desired: " SSIZE_FORMAT ", new_desired: " SSIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   109
                              demand, old_rate, rate, new_rate, old_desired, _desired);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  ssize_t desired() const { return _desired; }
185
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   114
  void set_desired(ssize_t v) { _desired = v; }
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   115
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   116
  ssize_t coal_desired() const { return _coal_desired; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   117
  void set_coal_desired(ssize_t v) { _coal_desired = v; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  ssize_t surplus() const { return _surplus; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void set_surplus(ssize_t v) { _surplus = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void increment_surplus() { _surplus++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void decrement_surplus() { _surplus--; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   124
  ssize_t bfr_surp() const { return _bfr_surp; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   125
  void set_bfr_surp(ssize_t v) { _bfr_surp = v; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   126
  ssize_t prev_sweep() const { return _prev_sweep; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   127
  void set_prev_sweep(ssize_t v) { _prev_sweep = v; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   128
  ssize_t before_sweep() const { return _before_sweep; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   129
  void set_before_sweep(ssize_t v) { _before_sweep = v; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   131
  ssize_t coal_births() const { return _coal_births; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   132
  void set_coal_births(ssize_t v) { _coal_births = v; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   133
  void increment_coal_births() { _coal_births++; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   135
  ssize_t coal_deaths() const { return _coal_deaths; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   136
  void set_coal_deaths(ssize_t v) { _coal_deaths = v; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   137
  void increment_coal_deaths() { _coal_deaths++; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   139
  ssize_t split_births() const { return _split_births; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   140
  void set_split_births(ssize_t v) { _split_births = v; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   141
  void increment_split_births() { _split_births++; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   143
  ssize_t split_deaths() const { return _split_deaths; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   144
  void set_split_deaths(ssize_t v) { _split_deaths = v; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   145
  void increment_split_deaths() { _split_deaths++; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  NOT_PRODUCT(
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   148
    size_t returned_bytes() const { return _returned_bytes; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9998
diff changeset
   149
    void set_returned_bytes(size_t v) { _returned_bytes = v; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   152
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
   153
#endif // SHARE_VM_GC_CMS_ALLOCATIONSTATS_HPP