Path: blob/master/src/hotspot/share/gc/shared/ageTable.cpp
40957 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jvm.h"26#include "gc/shared/ageTable.inline.hpp"27#include "gc/shared/ageTableTracer.hpp"28#include "gc/shared/collectedHeap.hpp"29#include "gc/shared/gc_globals.hpp"30#include "memory/resourceArea.hpp"31#include "runtime/perfData.hpp"32#include "logging/log.hpp"33#include "oops/oop.inline.hpp"34#include "utilities/copy.hpp"3536/* Copyright (c) 1992, 2021, Oracle and/or its affiliates, and Stanford University.37See the LICENSE file for license information. */3839AgeTable::AgeTable(bool global) {4041clear();4243if (UsePerfData && global) {4445ResourceMark rm;46EXCEPTION_MARK;4748const char* agetable_ns = "generation.0.agetable";49const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes");5051for(int age = 0; age < table_size; age ++) {52char age_name[10];53jio_snprintf(age_name, sizeof(age_name), "%2.2d", age);54const char* cname = PerfDataManager::counter_name(bytes_ns, age_name);55_perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname,56PerfData::U_Bytes,57CHECK);58}5960const char* cname = PerfDataManager::counter_name(agetable_ns, "size");61PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,62table_size, CHECK);63}64}6566void AgeTable::clear() {67for (size_t* p = sizes; p < sizes + table_size; ++p) {68*p = 0;69}70}7172void AgeTable::merge(AgeTable* subTable) {73for (int i = 0; i < table_size; i++) {74sizes[i]+= subTable->sizes[i];75}76}7778uint AgeTable::compute_tenuring_threshold(size_t desired_survivor_size) {79uint result;8081if (AlwaysTenure || NeverTenure) {82assert(MaxTenuringThreshold == 0 || MaxTenuringThreshold == markWord::max_age + 1,83"MaxTenuringThreshold should be 0 or markWord::max_age + 1, but is " UINTX_FORMAT, MaxTenuringThreshold);84result = MaxTenuringThreshold;85} else {86size_t total = 0;87uint age = 1;88assert(sizes[0] == 0, "no objects with age zero should be recorded");89while (age < table_size) {90total += sizes[age];91// check if including objects of age 'age' made us pass the desired92// size, if so 'age' is the new threshold93if (total > desired_survivor_size) break;94age++;95}96result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;97}9899100log_debug(gc, age)("Desired survivor size " SIZE_FORMAT " bytes, new threshold " UINTX_FORMAT " (max threshold " UINTX_FORMAT ")",101desired_survivor_size * oopSize, (uintx) result, MaxTenuringThreshold);102103return result;104}105106void AgeTable::print_age_table(uint tenuring_threshold) {107if (log_is_enabled(Trace, gc, age) || UsePerfData || AgeTableTracer::is_tenuring_distribution_event_enabled()) {108log_trace(gc, age)("Age table with threshold %u (max threshold " UINTX_FORMAT ")",109tenuring_threshold, MaxTenuringThreshold);110111size_t total = 0;112uint age = 1;113while (age < table_size) {114size_t wordSize = sizes[age];115total += wordSize;116if (wordSize > 0) {117log_trace(gc, age)("- age %3u: " SIZE_FORMAT_W(10) " bytes, " SIZE_FORMAT_W(10) " total",118age, wordSize * oopSize, total * oopSize);119}120AgeTableTracer::send_tenuring_distribution_event(age, wordSize * oopSize);121if (UsePerfData) {122_perf_sizes[age]->set_value(wordSize * oopSize);123}124age++;125}126}127}128129130131