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