Sat, 10 Sep 2011 00:11:04 -0700
7088020: SEGV in JNIHandleBlock::release_block
Reviewed-by: kvn, twisti
duke@435 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 1997, 2010, 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/permGen.hpp" |
stefank@2314 | 29 | #include "memory/resourceArea.hpp" |
stefank@2314 | 30 | #include "memory/space.hpp" |
stefank@2314 | 31 | #include "oops/oop.inline.hpp" |
stefank@2314 | 32 | #include "oops/oop.inline2.hpp" |
stefank@2314 | 33 | #include "runtime/aprofiler.hpp" |
duke@435 | 34 | |
duke@435 | 35 | |
duke@435 | 36 | bool AllocationProfiler::_active = false; |
duke@435 | 37 | GrowableArray<klassOop>* AllocationProfiler::_print_array = NULL; |
duke@435 | 38 | |
duke@435 | 39 | |
duke@435 | 40 | class AllocProfClosure : public ObjectClosure { |
duke@435 | 41 | public: |
duke@435 | 42 | void do_object(oop obj) { |
duke@435 | 43 | Klass* k = obj->blueprint(); |
duke@435 | 44 | k->set_alloc_count(k->alloc_count() + 1); |
duke@435 | 45 | k->set_alloc_size(k->alloc_size() + obj->size()); |
duke@435 | 46 | } |
duke@435 | 47 | }; |
duke@435 | 48 | |
duke@435 | 49 | |
duke@435 | 50 | #ifndef PRODUCT |
duke@435 | 51 | |
duke@435 | 52 | class AllocProfResetClosure : public ObjectClosure { |
duke@435 | 53 | public: |
duke@435 | 54 | void do_object(oop obj) { |
duke@435 | 55 | if (obj->is_klass()) { |
duke@435 | 56 | Klass* k = Klass::cast(klassOop(obj)); |
duke@435 | 57 | k->set_alloc_count(0); |
duke@435 | 58 | k->set_alloc_size(0); |
duke@435 | 59 | } |
duke@435 | 60 | } |
duke@435 | 61 | }; |
duke@435 | 62 | |
duke@435 | 63 | #endif |
duke@435 | 64 | |
duke@435 | 65 | |
duke@435 | 66 | void AllocationProfiler::iterate_since_last_gc() { |
duke@435 | 67 | if (is_active()) { |
duke@435 | 68 | AllocProfClosure blk; |
duke@435 | 69 | GenCollectedHeap* heap = GenCollectedHeap::heap(); |
duke@435 | 70 | heap->object_iterate_since_last_GC(&blk); |
duke@435 | 71 | } |
duke@435 | 72 | } |
duke@435 | 73 | |
duke@435 | 74 | |
duke@435 | 75 | void AllocationProfiler::engage() { |
duke@435 | 76 | _active = true; |
duke@435 | 77 | } |
duke@435 | 78 | |
duke@435 | 79 | |
duke@435 | 80 | void AllocationProfiler::disengage() { |
duke@435 | 81 | _active = false; |
duke@435 | 82 | } |
duke@435 | 83 | |
duke@435 | 84 | |
duke@435 | 85 | void AllocationProfiler::add_class_to_array(klassOop k) { |
duke@435 | 86 | _print_array->append(k); |
duke@435 | 87 | } |
duke@435 | 88 | |
duke@435 | 89 | |
duke@435 | 90 | void AllocationProfiler::add_classes_to_array(klassOop k) { |
duke@435 | 91 | // Iterate over klass and all array klasses for klass |
duke@435 | 92 | k->klass_part()->with_array_klasses_do(&AllocationProfiler::add_class_to_array); |
duke@435 | 93 | } |
duke@435 | 94 | |
duke@435 | 95 | |
duke@435 | 96 | int AllocationProfiler::compare_classes(klassOop* k1, klassOop* k2) { |
duke@435 | 97 | // Sort by total allocation size |
duke@435 | 98 | return (*k2)->klass_part()->alloc_size() - (*k1)->klass_part()->alloc_size(); |
duke@435 | 99 | } |
duke@435 | 100 | |
duke@435 | 101 | |
duke@435 | 102 | int AllocationProfiler::average(size_t alloc_size, int alloc_count) { |
duke@435 | 103 | return (int) ((double) (alloc_size * BytesPerWord) / MAX2(alloc_count, 1) + 0.5); |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | |
duke@435 | 107 | void AllocationProfiler::sort_and_print_array(size_t cutoff) { |
duke@435 | 108 | _print_array->sort(&AllocationProfiler::compare_classes); |
duke@435 | 109 | tty->print_cr("________________Size" |
duke@435 | 110 | "__Instances" |
duke@435 | 111 | "__Average" |
duke@435 | 112 | "__Class________________"); |
duke@435 | 113 | size_t total_alloc_size = 0; |
duke@435 | 114 | int total_alloc_count = 0; |
duke@435 | 115 | for (int index = 0; index < _print_array->length(); index++) { |
duke@435 | 116 | klassOop k = _print_array->at(index); |
duke@435 | 117 | size_t alloc_size = k->klass_part()->alloc_size(); |
duke@435 | 118 | if (alloc_size > cutoff) { |
duke@435 | 119 | int alloc_count = k->klass_part()->alloc_count(); |
duke@435 | 120 | #ifdef PRODUCT |
duke@435 | 121 | const char* name = k->klass_part()->external_name(); |
duke@435 | 122 | #else |
duke@435 | 123 | const char* name = k->klass_part()->internal_name(); |
duke@435 | 124 | #endif |
duke@435 | 125 | tty->print_cr("%20u %10u %8u %s", |
duke@435 | 126 | alloc_size * BytesPerWord, |
duke@435 | 127 | alloc_count, |
duke@435 | 128 | average(alloc_size, alloc_count), |
duke@435 | 129 | name); |
duke@435 | 130 | total_alloc_size += alloc_size; |
duke@435 | 131 | total_alloc_count += alloc_count; |
duke@435 | 132 | } |
duke@435 | 133 | } |
duke@435 | 134 | tty->print_cr("%20u %10u %8u --total--", |
duke@435 | 135 | total_alloc_size * BytesPerWord, |
duke@435 | 136 | total_alloc_count, |
duke@435 | 137 | average(total_alloc_size, total_alloc_count)); |
duke@435 | 138 | tty->cr(); |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | |
duke@435 | 142 | void AllocationProfiler::print(size_t cutoff) { |
duke@435 | 143 | ResourceMark rm; |
duke@435 | 144 | assert(!is_active(), "AllocationProfiler cannot be active while printing profile"); |
duke@435 | 145 | |
duke@435 | 146 | tty->cr(); |
duke@435 | 147 | tty->print_cr("Allocation profile (sizes in bytes, cutoff = %ld bytes):", cutoff * BytesPerWord); |
duke@435 | 148 | tty->cr(); |
duke@435 | 149 | |
duke@435 | 150 | // Print regular instance klasses and basic type array klasses |
duke@435 | 151 | _print_array = new GrowableArray<klassOop>(SystemDictionary::number_of_classes()*2); |
duke@435 | 152 | SystemDictionary::classes_do(&add_classes_to_array); |
duke@435 | 153 | Universe::basic_type_classes_do(&add_classes_to_array); |
duke@435 | 154 | sort_and_print_array(cutoff); |
duke@435 | 155 | |
duke@435 | 156 | #ifndef PRODUCT |
duke@435 | 157 | tty->print_cr("Allocation profile for system classes (sizes in bytes, cutoff = %d bytes):", cutoff * BytesPerWord); |
duke@435 | 158 | tty->cr(); |
duke@435 | 159 | |
duke@435 | 160 | // Print system klasses (methods, symbols, constant pools, etc.) |
duke@435 | 161 | _print_array = new GrowableArray<klassOop>(64); |
duke@435 | 162 | Universe::system_classes_do(&add_classes_to_array); |
duke@435 | 163 | sort_and_print_array(cutoff); |
duke@435 | 164 | |
duke@435 | 165 | tty->print_cr("Permanent generation dump (sizes in bytes, cutoff = %d bytes):", cutoff * BytesPerWord); |
duke@435 | 166 | tty->cr(); |
duke@435 | 167 | |
duke@435 | 168 | AllocProfResetClosure resetblk; |
duke@435 | 169 | Universe::heap()->permanent_object_iterate(&resetblk); |
duke@435 | 170 | AllocProfClosure blk; |
duke@435 | 171 | Universe::heap()->permanent_object_iterate(&blk); |
duke@435 | 172 | |
duke@435 | 173 | _print_array = new GrowableArray<klassOop>(SystemDictionary::number_of_classes()*2); |
duke@435 | 174 | SystemDictionary::classes_do(&add_classes_to_array); |
duke@435 | 175 | Universe::basic_type_classes_do(&add_classes_to_array); |
duke@435 | 176 | Universe::system_classes_do(&add_classes_to_array); |
duke@435 | 177 | sort_and_print_array(cutoff); |
duke@435 | 178 | #endif |
duke@435 | 179 | } |