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