hotspot/src/share/vm/gc/shared/ageTable.cpp
author david
Tue, 29 Sep 2015 11:02:08 +0200
changeset 33105 294e48b4f704
parent 32736 755024a84282
child 35061 be6025ebffea
permissions -rw-r--r--
8080775: Better argument formatting for assert() and friends Reviewed-by: kbarrett, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
     2
 * Copyright (c) 1997, 2015, 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"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    26
#include "gc/shared/ageTable.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    27
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    28
#include "gc/shared/collectorPolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    29
#include "gc/shared/gcPolicyCounters.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/copy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    33
/* Copyright (c) 1992, 2015, Oracle and/or its affiliates, and Stanford University.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
   See the LICENSE file for license information. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
ageTable::ageTable(bool global) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  if (UsePerfData && global) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    const char* agetable_ns = "generation.0.agetable";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    for(int age = 0; age < table_size; age ++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      char age_name[10];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      jio_snprintf(age_name, sizeof(age_name), "%2.2d", age);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      const char* cname = PerfDataManager::counter_name(bytes_ns, age_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
      _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                                                          PerfData::U_Bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                                                          CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    const char* cname = PerfDataManager::counter_name(agetable_ns, "size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                                     table_size, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
void ageTable::clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  for (size_t* p = sizes; p < sizes + table_size; ++p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    *p = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
void ageTable::merge(ageTable* subTable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  for (int i = 0; i < table_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    sizes[i]+= subTable->sizes[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
30147
af9a41999c6e 8076314: Remove the static instance variable SharedHeap:: _sh
brutisso
parents: 25351
diff changeset
    75
uint ageTable::compute_tenuring_threshold(size_t survivor_capacity, GCPolicyCounters* gc_counters) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100);
23506
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    77
  uint result;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    78
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    79
  if (AlwaysTenure || NeverTenure) {
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    80
    assert(MaxTenuringThreshold == 0 || MaxTenuringThreshold == markOopDesc::max_age + 1,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32736
diff changeset
    81
           "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
    82
    result = MaxTenuringThreshold;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    83
  } else {
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    84
    size_t total = 0;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    85
    uint age = 1;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    86
    assert(sizes[0] == 0, "no objects with age zero should be recorded");
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    87
    while (age < table_size) {
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    88
      total += sizes[age];
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    89
      // check if including objects of age 'age' made us pass the desired
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    90
      // size, if so 'age' is the new threshold
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    91
      if (total > desired_survivor_size) break;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    92
      age++;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    93
    }
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
    94
    result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  if (PrintTenuringDistribution || UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    if (PrintTenuringDistribution) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      gclog_or_tty->cr();
23506
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
   101
      gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold "
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
   102
        UINTX_FORMAT " (max threshold " UINTX_FORMAT ")",
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23506
diff changeset
   103
        desired_survivor_size*oopSize, (uintx) result, MaxTenuringThreshold);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
23506
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
   106
    size_t total = 0;
9b98355e9060 6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency
tamao
parents: 15228
diff changeset
   107
    uint age = 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    while (age < table_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      total += sizes[age];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      if (sizes[age] > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        if (PrintTenuringDistribution) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23506
diff changeset
   112
          gclog_or_tty->print_cr("- age %3u: " SIZE_FORMAT_W(10) " bytes, " SIZE_FORMAT_W(10) " total",
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23506
diff changeset
   113
                                        age,    sizes[age]*oopSize,          total*oopSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
        _perf_sizes[age]->set_value(sizes[age]*oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      age++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      gc_counters->tenuring_threshold()->set_value(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      gc_counters->desired_survivor_size()->set_value(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
        desired_survivor_size*oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}