Tue, 09 Oct 2012 10:09:34 -0700
7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 28 | #include "memory/resourceArea.hpp" |
stefank@2314 | 29 | #include "memory/space.hpp" |
stefank@2314 | 30 | #include "oops/oop.inline.hpp" |
stefank@2314 | 31 | #include "oops/oop.inline2.hpp" |
stefank@2314 | 32 | #include "runtime/aprofiler.hpp" |
duke@435 | 33 | |
duke@435 | 34 | |
duke@435 | 35 | bool AllocationProfiler::_active = false; |
coleenp@4037 | 36 | GrowableArray<Klass*>* AllocationProfiler::_print_array = NULL; |
duke@435 | 37 | |
duke@435 | 38 | |
duke@435 | 39 | class AllocProfClosure : public ObjectClosure { |
duke@435 | 40 | public: |
duke@435 | 41 | void do_object(oop obj) { |
coleenp@4037 | 42 | Klass* k = obj->klass(); |
duke@435 | 43 | k->set_alloc_count(k->alloc_count() + 1); |
duke@435 | 44 | k->set_alloc_size(k->alloc_size() + obj->size()); |
duke@435 | 45 | } |
duke@435 | 46 | }; |
duke@435 | 47 | |
duke@435 | 48 | |
duke@435 | 49 | void AllocationProfiler::iterate_since_last_gc() { |
duke@435 | 50 | if (is_active()) { |
duke@435 | 51 | AllocProfClosure blk; |
duke@435 | 52 | GenCollectedHeap* heap = GenCollectedHeap::heap(); |
duke@435 | 53 | heap->object_iterate_since_last_GC(&blk); |
duke@435 | 54 | } |
duke@435 | 55 | } |
duke@435 | 56 | |
duke@435 | 57 | |
duke@435 | 58 | void AllocationProfiler::engage() { |
duke@435 | 59 | _active = true; |
duke@435 | 60 | } |
duke@435 | 61 | |
duke@435 | 62 | |
duke@435 | 63 | void AllocationProfiler::disengage() { |
duke@435 | 64 | _active = false; |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | |
coleenp@4037 | 68 | void AllocationProfiler::add_class_to_array(Klass* k) { |
duke@435 | 69 | _print_array->append(k); |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | |
coleenp@4037 | 73 | void AllocationProfiler::add_classes_to_array(Klass* k) { |
duke@435 | 74 | // Iterate over klass and all array klasses for klass |
coleenp@4037 | 75 | k->with_array_klasses_do(&AllocationProfiler::add_class_to_array); |
duke@435 | 76 | } |
duke@435 | 77 | |
duke@435 | 78 | |
coleenp@4037 | 79 | int AllocationProfiler::compare_classes(Klass** k1, Klass** k2) { |
duke@435 | 80 | // Sort by total allocation size |
coleenp@4037 | 81 | return (*k2)->alloc_size() - (*k1)->alloc_size(); |
duke@435 | 82 | } |
duke@435 | 83 | |
duke@435 | 84 | |
duke@435 | 85 | int AllocationProfiler::average(size_t alloc_size, int alloc_count) { |
duke@435 | 86 | return (int) ((double) (alloc_size * BytesPerWord) / MAX2(alloc_count, 1) + 0.5); |
duke@435 | 87 | } |
duke@435 | 88 | |
duke@435 | 89 | |
duke@435 | 90 | void AllocationProfiler::sort_and_print_array(size_t cutoff) { |
duke@435 | 91 | _print_array->sort(&AllocationProfiler::compare_classes); |
duke@435 | 92 | tty->print_cr("________________Size" |
duke@435 | 93 | "__Instances" |
duke@435 | 94 | "__Average" |
duke@435 | 95 | "__Class________________"); |
duke@435 | 96 | size_t total_alloc_size = 0; |
duke@435 | 97 | int total_alloc_count = 0; |
duke@435 | 98 | for (int index = 0; index < _print_array->length(); index++) { |
coleenp@4037 | 99 | Klass* k = _print_array->at(index); |
coleenp@4037 | 100 | size_t alloc_size = k->alloc_size(); |
duke@435 | 101 | if (alloc_size > cutoff) { |
coleenp@4037 | 102 | int alloc_count = k->alloc_count(); |
duke@435 | 103 | #ifdef PRODUCT |
coleenp@4037 | 104 | const char* name = k->external_name(); |
duke@435 | 105 | #else |
coleenp@4037 | 106 | const char* name = k->internal_name(); |
duke@435 | 107 | #endif |
duke@435 | 108 | tty->print_cr("%20u %10u %8u %s", |
duke@435 | 109 | alloc_size * BytesPerWord, |
duke@435 | 110 | alloc_count, |
duke@435 | 111 | average(alloc_size, alloc_count), |
duke@435 | 112 | name); |
duke@435 | 113 | total_alloc_size += alloc_size; |
duke@435 | 114 | total_alloc_count += alloc_count; |
duke@435 | 115 | } |
coleenp@4037 | 116 | k->set_alloc_count(0); |
coleenp@4037 | 117 | k->set_alloc_size(0); |
duke@435 | 118 | } |
duke@435 | 119 | tty->print_cr("%20u %10u %8u --total--", |
duke@435 | 120 | total_alloc_size * BytesPerWord, |
duke@435 | 121 | total_alloc_count, |
duke@435 | 122 | average(total_alloc_size, total_alloc_count)); |
duke@435 | 123 | tty->cr(); |
duke@435 | 124 | } |
duke@435 | 125 | |
duke@435 | 126 | |
duke@435 | 127 | void AllocationProfiler::print(size_t cutoff) { |
duke@435 | 128 | ResourceMark rm; |
duke@435 | 129 | assert(!is_active(), "AllocationProfiler cannot be active while printing profile"); |
duke@435 | 130 | |
duke@435 | 131 | tty->cr(); |
duke@435 | 132 | tty->print_cr("Allocation profile (sizes in bytes, cutoff = %ld bytes):", cutoff * BytesPerWord); |
duke@435 | 133 | tty->cr(); |
duke@435 | 134 | |
duke@435 | 135 | // Print regular instance klasses and basic type array klasses |
coleenp@4037 | 136 | _print_array = new GrowableArray<Klass*>(SystemDictionary::number_of_classes()*2); |
duke@435 | 137 | SystemDictionary::classes_do(&add_classes_to_array); |
duke@435 | 138 | Universe::basic_type_classes_do(&add_classes_to_array); |
duke@435 | 139 | sort_and_print_array(cutoff); |
duke@435 | 140 | |
coleenp@4037 | 141 | // This used to print metadata in the permgen but since there isn't a permgen |
coleenp@4037 | 142 | // anymore, it is not yet implemented. |
duke@435 | 143 | } |