1 /* 2 * Copyright (c) 1997, 2009, 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 /* Copyright (c) 1992-2009 Oracle and/or its affiliates, and Stanford University. 26 See the LICENSE file for license information. */ 27 28 # include "incls/_precompiled.incl" 29 # include "incls/_ageTable.cpp.incl" 30 31 ageTable::ageTable(bool global) { 32 33 clear(); 34 35 if (UsePerfData && global) { 36 37 ResourceMark rm; 38 EXCEPTION_MARK; 39 40 const char* agetable_ns = "generation.0.agetable"; 41 const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes"); 42 43 for(int age = 0; age < table_size; age ++) { 44 char age_name[10]; 45 jio_snprintf(age_name, sizeof(age_name), "%2.2d", age); 46 const char* cname = PerfDataManager::counter_name(bytes_ns, age_name); 47 _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname, 48 PerfData::U_Bytes, 49 CHECK); 50 } 51 52 const char* cname = PerfDataManager::counter_name(agetable_ns, "size"); 53 PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, 54 table_size, CHECK); 55 } 56 } 57 58 void ageTable::clear() { 59 for (size_t* p = sizes; p < sizes + table_size; ++p) { 60 *p = 0; 61 } 62 } 63 64 void ageTable::merge(ageTable* subTable) { 65 for (int i = 0; i < table_size; i++) { 66 sizes[i]+= subTable->sizes[i]; 67 } 68 } 69 70 void ageTable::merge_par(ageTable* subTable) { 71 for (int i = 0; i < table_size; i++) { 72 Atomic::add_ptr(subTable->sizes[i], &sizes[i]); 73 } 74 } 75 76 int ageTable::compute_tenuring_threshold(size_t survivor_capacity) { 77 size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100); 78 size_t total = 0; 79 int age = 1; 80 assert(sizes[0] == 0, "no objects with age zero should be recorded"); 81 while (age < table_size) { 82 total += sizes[age]; 83 // check if including objects of age 'age' made us pass the desired 84 // size, if so 'age' is the new threshold 85 if (total > desired_survivor_size) break; 86 age++; 87 } 88 int result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold; 89 90 if (PrintTenuringDistribution || UsePerfData) { 91 92 if (PrintTenuringDistribution) { 93 gclog_or_tty->cr(); 94 gclog_or_tty->print_cr("Desired survivor size %ld bytes, new threshold %d (max %d)", 95 desired_survivor_size*oopSize, result, MaxTenuringThreshold); 96 } 97 98 total = 0; 99 age = 1; 100 while (age < table_size) { 101 total += sizes[age]; 102 if (sizes[age] > 0) { 103 if (PrintTenuringDistribution) { 104 gclog_or_tty->print_cr("- age %3d: %10ld bytes, %10ld total", 105 age, sizes[age]*oopSize, total*oopSize); 106 } 107 } 108 if (UsePerfData) { 109 _perf_sizes[age]->set_value(sizes[age]*oopSize); 110 } 111 age++; 112 } 113 if (UsePerfData) { 114 SharedHeap* sh = SharedHeap::heap(); 115 CollectorPolicy* policy = sh->collector_policy(); 116 GCPolicyCounters* gc_counters = policy->counters(); 117 gc_counters->tenuring_threshold()->set_value(result); 118 gc_counters->desired_survivor_size()->set_value( 119 desired_survivor_size*oopSize); 120 } 121 } 122 123 return result; 124 }