src/hotspot/share/gc/shared/ageTable.cpp
author stefank
Fri, 24 Nov 2017 15:48:01 +0100
changeset 48116 8a5e8cd321d9
parent 47765 b7c7428eaab9
child 54678 93f09ca4a7f8
permissions -rw-r--r--
8191861: Move and refactor hSpaceCounters Reviewed-by: pliden, ehelin, rkennke
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 40914
diff changeset
     2
 * Copyright (c) 1997, 2017, 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: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
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: 2105
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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 35492
diff changeset
    27
#include "gc/shared/ageTable.inline.hpp"
36097
c830c234e056 8009538: [Event Request] Want events for tenuring distribution
david
parents: 35862
diff changeset
    28
#include "gc/shared/ageTableTracer.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    29
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    30
#include "gc/shared/collectorPolicy.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/resourceArea.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    32
#include "logging/log.hpp"
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 35492
diff changeset
    33
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/copy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 35492
diff changeset
    36
/* Copyright (c) 1992, 2016, Oracle and/or its affiliates, and Stanford University.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
   See the LICENSE file for license information. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    39
AgeTable::AgeTable(bool global) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  if (UsePerfData && global) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    const char* agetable_ns = "generation.0.agetable";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    for(int age = 0; age < table_size; age ++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
      char age_name[10];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      jio_snprintf(age_name, sizeof(age_name), "%2.2d", age);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      const char* cname = PerfDataManager::counter_name(bytes_ns, age_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                                                          PerfData::U_Bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
                                                          CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    const char* cname = PerfDataManager::counter_name(agetable_ns, "size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                                     table_size, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    66
void AgeTable::clear() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  for (size_t* p = sizes; p < sizes + table_size; ++p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    *p = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    72
void AgeTable::merge(AgeTable* subTable) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  for (int i = 0; i < table_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    sizes[i]+= subTable->sizes[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
    78
uint AgeTable::compute_tenuring_threshold(size_t desired_survivor_size) {
23506
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    79
  uint result;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    80
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    81
  if (AlwaysTenure || NeverTenure) {
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    82
    assert(MaxTenuringThreshold == 0 || MaxTenuringThreshold == markOopDesc::max_age + 1,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32736
diff changeset
    83
           "MaxTenuringThreshold should be 0 or markOopDesc::max_age + 1, but is " UINTX_FORMAT, MaxTenuringThreshold);
23506
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    84
    result = MaxTenuringThreshold;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    85
  } else {
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    86
    size_t total = 0;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    87
    uint age = 1;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    88
    assert(sizes[0] == 0, "no objects with age zero should be recorded");
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    89
    while (age < table_size) {
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    90
      total += sizes[age];
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    91
      // check if including objects of age 'age' made us pass the desired
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    92
      // size, if so 'age' is the new threshold
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    93
      if (total > desired_survivor_size) break;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    94
      age++;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    95
    }
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    96
    result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   100
  log_debug(gc, age)("Desired survivor size " SIZE_FORMAT " bytes, new threshold " UINTX_FORMAT " (max threshold " UINTX_FORMAT ")",
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   101
                     desired_survivor_size * oopSize, (uintx) result, MaxTenuringThreshold);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   102
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   103
  return result;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   104
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   106
void AgeTable::print_age_table(uint tenuring_threshold) {
36097
c830c234e056 8009538: [Event Request] Want events for tenuring distribution
david
parents: 35862
diff changeset
   107
  if (log_is_enabled(Trace, gc, age) || UsePerfData || AgeTableTracer::is_tenuring_distribution_event_enabled()) {
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   108
    log_trace(gc, age)("Age table with threshold %u (max threshold " UINTX_FORMAT ")",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   109
                       tenuring_threshold, MaxTenuringThreshold);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   110
23506
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
   111
    size_t total = 0;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
   112
    uint age = 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    while (age < table_size) {
36097
c830c234e056 8009538: [Event Request] Want events for tenuring distribution
david
parents: 35862
diff changeset
   114
      size_t wordSize = sizes[age];
c830c234e056 8009538: [Event Request] Want events for tenuring distribution
david
parents: 35862
diff changeset
   115
      total += wordSize;
c830c234e056 8009538: [Event Request] Want events for tenuring distribution
david
parents: 35862
diff changeset
   116
      if (wordSize > 0) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   117
        log_trace(gc, age)("- age %3u: " SIZE_FORMAT_W(10) " bytes, " SIZE_FORMAT_W(10) " total",
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   118
                            age, wordSize * oopSize, total * oopSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      }
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   120
      AgeTableTracer::send_tenuring_distribution_event(age, wordSize * oopSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      if (UsePerfData) {
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   122
        _perf_sizes[age]->set_value(wordSize * oopSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      age++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents: 36097
diff changeset
   127
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128