annotate src/share/vm/runtime/aprofiler.cpp @ 6972:bd7a7ce2e264

6830717: replay of compilations would help with debugging Summary: When java process crashed in compiler thread, repeat the compilation process will help finding root cause. This is done with using SA dump application class data and replay data from core dump, then use debug version of jvm to recompile the problematic java method. Reviewed-by: kvn, twisti, sspitsyn Contributed-by: yumin.qi@oracle.com
author minqi
date Mon, 12 Nov 2012 14:03:53 -0800
parents da91efe96a93
children 203f64878aab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "gc_interface/collectedHeap.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "memory/space.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "oops/oop.inline2.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/aprofiler.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 bool AllocationProfiler::_active = false;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
36 GrowableArray<Klass*>* AllocationProfiler::_print_array = NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 class AllocProfClosure : public ObjectClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 void do_object(oop obj) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
42 Klass* k = obj->klass();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
43 k->set_alloc_count(k->alloc_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 k->set_alloc_size(k->alloc_size() + obj->size());
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46 };
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 void AllocationProfiler::iterate_since_last_gc() {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 if (is_active()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 AllocProfClosure blk;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 GenCollectedHeap* heap = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
53 heap->object_iterate_since_last_GC(&blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 void AllocationProfiler::engage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _active = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 void AllocationProfiler::disengage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 _active = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
68 void AllocationProfiler::add_class_to_array(Klass* k) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _print_array->append(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
73 void AllocationProfiler::add_classes_to_array(Klass* k) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // Iterate over klass and all array klasses for klass
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
75 k->with_array_klasses_do(&AllocationProfiler::add_class_to_array);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
79 int AllocationProfiler::compare_classes(Klass** k1, Klass** k2) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Sort by total allocation size
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
81 return (*k2)->alloc_size() - (*k1)->alloc_size();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int AllocationProfiler::average(size_t alloc_size, int alloc_count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return (int) ((double) (alloc_size * BytesPerWord) / MAX2(alloc_count, 1) + 0.5);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 void AllocationProfiler::sort_and_print_array(size_t cutoff) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _print_array->sort(&AllocationProfiler::compare_classes);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 tty->print_cr("________________Size"
a61af66fc99e Initial load
duke
parents:
diff changeset
93 "__Instances"
a61af66fc99e Initial load
duke
parents:
diff changeset
94 "__Average"
a61af66fc99e Initial load
duke
parents:
diff changeset
95 "__Class________________");
a61af66fc99e Initial load
duke
parents:
diff changeset
96 size_t total_alloc_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 int total_alloc_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 for (int index = 0; index < _print_array->length(); index++) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
99 Klass* k = _print_array->at(index);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
100 size_t alloc_size = k->alloc_size();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (alloc_size > cutoff) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
102 int alloc_count = k->alloc_count();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 #ifdef PRODUCT
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
104 const char* name = k->external_name();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
105 #else
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
106 const char* name = k->internal_name();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
107 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
108 tty->print_cr("%20u %10u %8u %s",
a61af66fc99e Initial load
duke
parents:
diff changeset
109 alloc_size * BytesPerWord,
a61af66fc99e Initial load
duke
parents:
diff changeset
110 alloc_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
111 average(alloc_size, alloc_count),
a61af66fc99e Initial load
duke
parents:
diff changeset
112 name);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 total_alloc_size += alloc_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 total_alloc_count += alloc_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
116 k->set_alloc_count(0);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
117 k->set_alloc_size(0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 tty->print_cr("%20u %10u %8u --total--",
a61af66fc99e Initial load
duke
parents:
diff changeset
120 total_alloc_size * BytesPerWord,
a61af66fc99e Initial load
duke
parents:
diff changeset
121 total_alloc_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
122 average(total_alloc_size, total_alloc_count));
a61af66fc99e Initial load
duke
parents:
diff changeset
123 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 void AllocationProfiler::print(size_t cutoff) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 assert(!is_active(), "AllocationProfiler cannot be active while printing profile");
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 tty->print_cr("Allocation profile (sizes in bytes, cutoff = %ld bytes):", cutoff * BytesPerWord);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Print regular instance klasses and basic type array klasses
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
136 _print_array = new GrowableArray<Klass*>(SystemDictionary::number_of_classes()*2);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
137 SystemDictionary::classes_do(&add_classes_to_array);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Universe::basic_type_classes_do(&add_classes_to_array);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 sort_and_print_array(cutoff);
a61af66fc99e Initial load
duke
parents:
diff changeset
140
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
141 // This used to print metadata in the permgen but since there isn't a permgen
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1972
diff changeset
142 // anymore, it is not yet implemented.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }