1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/shared/ageTable.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,118 @@ 1.4 +/* 1.5 + * Copyright 1997-2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +/* Copyright 1992 Sun Microsystems, Inc. and Stanford University. 1.29 + See the LICENSE file for license information. */ 1.30 + 1.31 +# include "incls/_precompiled.incl" 1.32 +# include "incls/_ageTable.cpp.incl" 1.33 + 1.34 +ageTable::ageTable(bool global) { 1.35 + 1.36 + clear(); 1.37 + 1.38 + if (UsePerfData && global) { 1.39 + 1.40 + ResourceMark rm; 1.41 + EXCEPTION_MARK; 1.42 + 1.43 + const char* agetable_ns = "generation.0.agetable"; 1.44 + const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes"); 1.45 + 1.46 + for(int age = 0; age < table_size; age ++) { 1.47 + char age_name[10]; 1.48 + jio_snprintf(age_name, sizeof(age_name), "%2.2d", age); 1.49 + const char* cname = PerfDataManager::counter_name(bytes_ns, age_name); 1.50 + _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname, 1.51 + PerfData::U_Bytes, 1.52 + CHECK); 1.53 + } 1.54 + 1.55 + const char* cname = PerfDataManager::counter_name(agetable_ns, "size"); 1.56 + PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, 1.57 + table_size, CHECK); 1.58 + } 1.59 +} 1.60 + 1.61 +void ageTable::clear() { 1.62 + for (size_t* p = sizes; p < sizes + table_size; ++p) { 1.63 + *p = 0; 1.64 + } 1.65 +} 1.66 + 1.67 +void ageTable::merge(ageTable* subTable) { 1.68 + for (int i = 0; i < table_size; i++) { 1.69 + sizes[i]+= subTable->sizes[i]; 1.70 + } 1.71 +} 1.72 + 1.73 +int ageTable::compute_tenuring_threshold(size_t survivor_capacity) { 1.74 + size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100); 1.75 + size_t total = 0; 1.76 + int age = 1; 1.77 + assert(sizes[0] == 0, "no objects with age zero should be recorded"); 1.78 + while (age < table_size) { 1.79 + total += sizes[age]; 1.80 + // check if including objects of age 'age' made us pass the desired 1.81 + // size, if so 'age' is the new threshold 1.82 + if (total > desired_survivor_size) break; 1.83 + age++; 1.84 + } 1.85 + int result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold; 1.86 + 1.87 + if (PrintTenuringDistribution || UsePerfData) { 1.88 + 1.89 + if (PrintTenuringDistribution) { 1.90 + gclog_or_tty->cr(); 1.91 + gclog_or_tty->print_cr("Desired survivor size %ld bytes, new threshold %d (max %d)", 1.92 + desired_survivor_size*oopSize, result, MaxTenuringThreshold); 1.93 + } 1.94 + 1.95 + total = 0; 1.96 + age = 1; 1.97 + while (age < table_size) { 1.98 + total += sizes[age]; 1.99 + if (sizes[age] > 0) { 1.100 + if (PrintTenuringDistribution) { 1.101 + gclog_or_tty->print_cr("- age %3d: %10ld bytes, %10ld total", 1.102 + age, sizes[age]*oopSize, total*oopSize); 1.103 + } 1.104 + } 1.105 + if (UsePerfData) { 1.106 + _perf_sizes[age]->set_value(sizes[age]*oopSize); 1.107 + } 1.108 + age++; 1.109 + } 1.110 + if (UsePerfData) { 1.111 + SharedHeap* sh = SharedHeap::heap(); 1.112 + CollectorPolicy* policy = sh->collector_policy(); 1.113 + GCPolicyCounters* gc_counters = policy->counters(); 1.114 + gc_counters->tenuring_threshold()->set_value(result); 1.115 + gc_counters->desired_survivor_size()->set_value( 1.116 + desired_survivor_size*oopSize); 1.117 + } 1.118 + } 1.119 + 1.120 + return result; 1.121 +}