1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/shared/ageTable.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,129 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/shared/ageTable.hpp" 1.30 +#include "gc_implementation/shared/gcPolicyCounters.hpp" 1.31 +#include "memory/collectorPolicy.hpp" 1.32 +#include "memory/resourceArea.hpp" 1.33 +#include "memory/sharedHeap.hpp" 1.34 +#include "utilities/copy.hpp" 1.35 + 1.36 +/* Copyright (c) 1992-2009 Oracle and/or its affiliates, and Stanford University. 1.37 + See the LICENSE file for license information. */ 1.38 + 1.39 +ageTable::ageTable(bool global) { 1.40 + 1.41 + clear(); 1.42 + 1.43 + if (UsePerfData && global) { 1.44 + 1.45 + ResourceMark rm; 1.46 + EXCEPTION_MARK; 1.47 + 1.48 + const char* agetable_ns = "generation.0.agetable"; 1.49 + const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes"); 1.50 + 1.51 + for(int age = 0; age < table_size; age ++) { 1.52 + char age_name[10]; 1.53 + jio_snprintf(age_name, sizeof(age_name), "%2.2d", age); 1.54 + const char* cname = PerfDataManager::counter_name(bytes_ns, age_name); 1.55 + _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname, 1.56 + PerfData::U_Bytes, 1.57 + CHECK); 1.58 + } 1.59 + 1.60 + const char* cname = PerfDataManager::counter_name(agetable_ns, "size"); 1.61 + PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, 1.62 + table_size, CHECK); 1.63 + } 1.64 +} 1.65 + 1.66 +void ageTable::clear() { 1.67 + for (size_t* p = sizes; p < sizes + table_size; ++p) { 1.68 + *p = 0; 1.69 + } 1.70 +} 1.71 + 1.72 +void ageTable::merge(ageTable* subTable) { 1.73 + for (int i = 0; i < table_size; i++) { 1.74 + sizes[i]+= subTable->sizes[i]; 1.75 + } 1.76 +} 1.77 + 1.78 +void ageTable::merge_par(ageTable* subTable) { 1.79 + for (int i = 0; i < table_size; i++) { 1.80 + Atomic::add_ptr(subTable->sizes[i], &sizes[i]); 1.81 + } 1.82 +} 1.83 + 1.84 +uint ageTable::compute_tenuring_threshold(size_t survivor_capacity) { 1.85 + size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100); 1.86 + size_t total = 0; 1.87 + uint age = 1; 1.88 + assert(sizes[0] == 0, "no objects with age zero should be recorded"); 1.89 + while (age < table_size) { 1.90 + total += sizes[age]; 1.91 + // check if including objects of age 'age' made us pass the desired 1.92 + // size, if so 'age' is the new threshold 1.93 + if (total > desired_survivor_size) break; 1.94 + age++; 1.95 + } 1.96 + uint result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold; 1.97 + 1.98 + if (PrintTenuringDistribution || UsePerfData) { 1.99 + 1.100 + if (PrintTenuringDistribution) { 1.101 + gclog_or_tty->cr(); 1.102 + gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold %u (max %u)", 1.103 + desired_survivor_size*oopSize, result, (int) MaxTenuringThreshold); 1.104 + } 1.105 + 1.106 + total = 0; 1.107 + age = 1; 1.108 + while (age < table_size) { 1.109 + total += sizes[age]; 1.110 + if (sizes[age] > 0) { 1.111 + if (PrintTenuringDistribution) { 1.112 + gclog_or_tty->print_cr("- age %3u: " SIZE_FORMAT_W(10) " bytes, " SIZE_FORMAT_W(10) " total", 1.113 + age, sizes[age]*oopSize, total*oopSize); 1.114 + } 1.115 + } 1.116 + if (UsePerfData) { 1.117 + _perf_sizes[age]->set_value(sizes[age]*oopSize); 1.118 + } 1.119 + age++; 1.120 + } 1.121 + if (UsePerfData) { 1.122 + SharedHeap* sh = SharedHeap::heap(); 1.123 + CollectorPolicy* policy = sh->collector_policy(); 1.124 + GCPolicyCounters* gc_counters = policy->counters(); 1.125 + gc_counters->tenuring_threshold()->set_value(result); 1.126 + gc_counters->desired_survivor_size()->set_value( 1.127 + desired_survivor_size*oopSize); 1.128 + } 1.129 + } 1.130 + 1.131 + return result; 1.132 +}