Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shared/ageTable.cpp
38920 views
/*1* Copyright (c) 1997, 2014, 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 "gc_implementation/shared/ageTable.hpp"26#include "gc_implementation/shared/ageTableTracer.hpp"27#include "gc_implementation/shared/gcPolicyCounters.hpp"28#include "memory/collectorPolicy.hpp"29#include "memory/resourceArea.hpp"30#include "memory/sharedHeap.hpp"31#include "utilities/copy.hpp"3233/* Copyright (c) 1992-2009 Oracle and/or its affiliates, and Stanford University.34See the LICENSE file for license information. */3536ageTable::ageTable(bool global) {3738clear();3940if (UsePerfData && global) {4142ResourceMark rm;43EXCEPTION_MARK;4445const char* agetable_ns = "generation.0.agetable";46const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes");4748for(int age = 0; age < table_size; age ++) {49char age_name[10];50jio_snprintf(age_name, sizeof(age_name), "%2.2d", age);51const char* cname = PerfDataManager::counter_name(bytes_ns, age_name);52_perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname,53PerfData::U_Bytes,54CHECK);55}5657const char* cname = PerfDataManager::counter_name(agetable_ns, "size");58PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,59table_size, CHECK);60}61}6263void ageTable::clear() {64for (size_t* p = sizes; p < sizes + table_size; ++p) {65*p = 0;66}67}6869void ageTable::merge(ageTable* subTable) {70for (int i = 0; i < table_size; i++) {71sizes[i]+= subTable->sizes[i];72}73}7475void ageTable::merge_par(ageTable* subTable) {76for (int i = 0; i < table_size; i++) {77Atomic::add_ptr(subTable->sizes[i], &sizes[i]);78}79}8081uint ageTable::compute_tenuring_threshold(size_t survivor_capacity, GCTracer &tracer) {82size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100);83size_t total = 0;84uint age = 1;85assert(sizes[0] == 0, "no objects with age zero should be recorded");86while (age < table_size) {87total += sizes[age];88// check if including objects of age 'age' made us pass the desired89// size, if so 'age' is the new threshold90if (total > desired_survivor_size) break;91age++;92}93uint result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;9495if (PrintTenuringDistribution || UsePerfData || AgeTableTracer::is_tenuring_distribution_event_enabled()) {9697if (PrintTenuringDistribution) {98gclog_or_tty->cr();99gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold %u (max %u)",100desired_survivor_size*oopSize, result, (int) MaxTenuringThreshold);101}102103total = 0;104age = 1;105while (age < table_size) {106total += sizes[age];107if (sizes[age] > 0) {108if (PrintTenuringDistribution) {109gclog_or_tty->print_cr("- age %3u: " SIZE_FORMAT_W(10) " bytes, " SIZE_FORMAT_W(10) " total",110age, sizes[age]*oopSize, total*oopSize);111}112}113AgeTableTracer::send_tenuring_distribution_event(age, wordSize * oopSize, tracer);114if (UsePerfData) {115_perf_sizes[age]->set_value(sizes[age]*oopSize);116}117age++;118}119if (UsePerfData) {120SharedHeap* sh = SharedHeap::heap();121CollectorPolicy* policy = sh->collector_policy();122GCPolicyCounters* gc_counters = policy->counters();123gc_counters->tenuring_threshold()->set_value(result);124gc_counters->desired_survivor_size()->set_value(125desired_survivor_size*oopSize);126}127}128129return result;130}131132133