annotate src/share/vm/interpreter/bytecodeHistogram.cpp @ 1721:413ad0331a0c

6977924: Changes for 6975078 produce build error with certain gcc versions Summary: The changes introduced for 6975078 assign badHeapOopVal to the _allocation field in the ResourceObj class. In 32 bit linux builds with certain versions of gcc this assignment will be flagged as an error while compiling allocation.cpp. In 32 bit builds the constant value badHeapOopVal (which is cast to an intptr_t) is negative. The _allocation field is typed as an unsigned intptr_t and gcc catches this as an error. Reviewed-by: jcoomes, ysr, phh
author johnc
date Wed, 18 Aug 2010 10:59:06 -0700
parents c18cbe5936b8
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 1997, 2000, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_bytecodeHistogram.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // ------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Implementation of BytecodeCounter
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 int BytecodeCounter::_counter_value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 jlong BytecodeCounter::_reset_time = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 void BytecodeCounter::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 _counter_value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 _reset_time = os::elapsed_counter();
a61af66fc99e Initial load
duke
parents:
diff changeset
41 }
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 double BytecodeCounter::elapsed_time() {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 return (double)(os::elapsed_counter() - _reset_time) / (double)os::elapsed_frequency();
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 double BytecodeCounter::frequency() {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return (double)counter_value() / elapsed_time();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 void BytecodeCounter::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 tty->print_cr(
a61af66fc99e Initial load
duke
parents:
diff changeset
56 "%d bytecodes executed in %.1fs (%.3fMHz)",
a61af66fc99e Initial load
duke
parents:
diff changeset
57 counter_value(),
a61af66fc99e Initial load
duke
parents:
diff changeset
58 elapsed_time(),
a61af66fc99e Initial load
duke
parents:
diff changeset
59 frequency() / 1000000.0
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
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Helper class for sorting
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 class HistoEntry: public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
68 int _index;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 int _count;
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
72 HistoEntry(int index, int count) { _index = index; _count = count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 int index() const { return _index; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int count() const { return _count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 static int compare(HistoEntry** x, HistoEntry** y) { return (*x)->count() - (*y)->count(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 };
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 static GrowableArray<HistoEntry*>* sorted_array(int* array, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 GrowableArray<HistoEntry*>* a = new GrowableArray<HistoEntry*>(length);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int i = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 while (i-- > 0) a->append(new HistoEntry(i, array[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
86 a->sort(HistoEntry::compare);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return a;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 static int total_count(GrowableArray<HistoEntry*>* profile) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 int sum = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 int i = profile->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 while (i-- > 0) sum += profile->at(i)->count();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return sum;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 static const char* name_for(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return Bytecodes::is_defined(i) ? Bytecodes::name(Bytecodes::cast(i)) : "xxxunusedxxx";
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Implementation of BytecodeHistogram
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int BytecodeHistogram::_counters[Bytecodes::number_of_codes];
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 void BytecodeHistogram::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int i = Bytecodes::number_of_codes;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 while (i-- > 0) _counters[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 void BytecodeHistogram::print(float cutoff) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 GrowableArray<HistoEntry*>* profile = sorted_array(_counters, Bytecodes::number_of_codes);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // print profile
a61af66fc99e Initial load
duke
parents:
diff changeset
119 int tot = total_count(profile);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int abs_sum = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789
a61af66fc99e Initial load
duke
parents:
diff changeset
122 tty->print_cr("Histogram of %d executed bytecodes:", tot);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 tty->print_cr(" absolute relative code name");
a61af66fc99e Initial load
duke
parents:
diff changeset
125 tty->print_cr("----------------------------------------------------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 int i = profile->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 while (i-- > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 HistoEntry* e = profile->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 int abs = e->count();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 float rel = abs * 100.0F / tot;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (cutoff <= rel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 tty->print_cr("%10d %7.2f%% %02x %s", abs, rel, e->index(), name_for(e->index()));
a61af66fc99e Initial load
duke
parents:
diff changeset
133 abs_sum += abs;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 tty->print_cr("----------------------------------------------------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
137 float rel_sum = abs_sum * 100.0F / tot;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 tty->print_cr("%10d %7.2f%% (cutoff = %.2f%%)", abs_sum, rel_sum, cutoff);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Implementation of BytecodePairHistogram
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 int BytecodePairHistogram::_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 int BytecodePairHistogram::_counters[BytecodePairHistogram::number_of_pairs];
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 void BytecodePairHistogram::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 _index = Bytecodes::_nop << log2_number_of_codes;
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 int i = number_of_pairs;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 while (i-- > 0) _counters[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void BytecodePairHistogram::print(float cutoff) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 GrowableArray<HistoEntry*>* profile = sorted_array(_counters, number_of_pairs);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // print profile
a61af66fc99e Initial load
duke
parents:
diff changeset
161 int tot = total_count(profile);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 int abs_sum = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789
a61af66fc99e Initial load
duke
parents:
diff changeset
164 tty->print_cr("Histogram of %d executed bytecode pairs:", tot);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 tty->print_cr(" absolute relative codes 1st bytecode 2nd bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
167 tty->print_cr("----------------------------------------------------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 int i = profile->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
169 while (i-- > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 HistoEntry* e = profile->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 int abs = e->count();
a61af66fc99e Initial load
duke
parents:
diff changeset
172 float rel = abs * 100.0F / tot;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 if (cutoff <= rel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 int c1 = e->index() % number_of_codes;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 int c2 = e->index() / number_of_codes;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 tty->print_cr("%10d %6.3f%% %02x %02x %-19s %s", abs, rel, c1, c2, name_for(c1), name_for(c2));
a61af66fc99e Initial load
duke
parents:
diff changeset
177 abs_sum += abs;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 tty->print_cr("----------------------------------------------------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
181 float rel_sum = abs_sum * 100.0F / tot;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 tty->print_cr("%10d %6.3f%% (cutoff = %.3f%%)", abs_sum, rel_sum, cutoff);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 #endif