| 1 | /* |
| 2 | * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "precompiled.hpp" |
| 26 | #include "jvm.h" |
| 27 | #include "gc/shared/ageTable.inline.hpp" |
| 28 | #include "gc/shared/ageTableTracer.hpp" |
| 29 | #include "gc/shared/collectedHeap.hpp" |
| 30 | #include "memory/resourceArea.hpp" |
| 31 | #include "logging/log.hpp" |
| 32 | #include "oops/oop.inline.hpp" |
| 33 | #include "utilities/copy.hpp" |
| 34 | |
| 35 | /* Copyright (c) 1992, 2016, Oracle and/or its affiliates, and Stanford University. |
| 36 | See the LICENSE file for license information. */ |
| 37 | |
| 38 | AgeTable::AgeTable(bool global) { |
| 39 | |
| 40 | clear(); |
| 41 | |
| 42 | if (UsePerfData && global) { |
| 43 | |
| 44 | ResourceMark rm; |
| 45 | EXCEPTION_MARK; |
| 46 | |
| 47 | const char* agetable_ns = "generation.0.agetable" ; |
| 48 | const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes" ); |
| 49 | |
| 50 | for(int age = 0; age < table_size; age ++) { |
| 51 | char age_name[10]; |
| 52 | jio_snprintf(age_name, sizeof(age_name), "%2.2d" , age); |
| 53 | const char* cname = PerfDataManager::counter_name(bytes_ns, age_name); |
| 54 | _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname, |
| 55 | PerfData::U_Bytes, |
| 56 | CHECK); |
| 57 | } |
| 58 | |
| 59 | const char* cname = PerfDataManager::counter_name(agetable_ns, "size" ); |
| 60 | PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, |
| 61 | table_size, CHECK); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void AgeTable::clear() { |
| 66 | for (size_t* p = sizes; p < sizes + table_size; ++p) { |
| 67 | *p = 0; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void AgeTable::merge(AgeTable* subTable) { |
| 72 | for (int i = 0; i < table_size; i++) { |
| 73 | sizes[i]+= subTable->sizes[i]; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | uint AgeTable::compute_tenuring_threshold(size_t desired_survivor_size) { |
| 78 | uint result; |
| 79 | |
| 80 | if (AlwaysTenure || NeverTenure) { |
| 81 | assert(MaxTenuringThreshold == 0 || MaxTenuringThreshold == markOopDesc::max_age + 1, |
| 82 | "MaxTenuringThreshold should be 0 or markOopDesc::max_age + 1, but is " UINTX_FORMAT, MaxTenuringThreshold); |
| 83 | result = MaxTenuringThreshold; |
| 84 | } else { |
| 85 | size_t total = 0; |
| 86 | uint age = 1; |
| 87 | assert(sizes[0] == 0, "no objects with age zero should be recorded" ); |
| 88 | while (age < table_size) { |
| 89 | total += sizes[age]; |
| 90 | // check if including objects of age 'age' made us pass the desired |
| 91 | // size, if so 'age' is the new threshold |
| 92 | if (total > desired_survivor_size) break; |
| 93 | age++; |
| 94 | } |
| 95 | result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | log_debug(gc, age)("Desired survivor size " SIZE_FORMAT " bytes, new threshold " UINTX_FORMAT " (max threshold " UINTX_FORMAT ")" , |
| 100 | desired_survivor_size * oopSize, (uintx) result, MaxTenuringThreshold); |
| 101 | |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | void AgeTable::print_age_table(uint tenuring_threshold) { |
| 106 | if (log_is_enabled(Trace, gc, age) || UsePerfData || AgeTableTracer::is_tenuring_distribution_event_enabled()) { |
| 107 | log_trace(gc, age)("Age table with threshold %u (max threshold " UINTX_FORMAT ")" , |
| 108 | tenuring_threshold, MaxTenuringThreshold); |
| 109 | |
| 110 | size_t total = 0; |
| 111 | uint age = 1; |
| 112 | while (age < table_size) { |
| 113 | size_t wordSize = sizes[age]; |
| 114 | total += wordSize; |
| 115 | if (wordSize > 0) { |
| 116 | log_trace(gc, age)("- age %3u: " SIZE_FORMAT_W(10) " bytes, " SIZE_FORMAT_W(10) " total" , |
| 117 | age, wordSize * oopSize, total * oopSize); |
| 118 | } |
| 119 | AgeTableTracer::send_tenuring_distribution_event(age, wordSize * oopSize); |
| 120 | if (UsePerfData) { |
| 121 | _perf_sizes[age]->set_value(wordSize * oopSize); |
| 122 | } |
| 123 | age++; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | |