annotate src/share/vm/memory/classify.cpp @ 3302:2a3da7eaf4a6

7036747: 7017009 reappeared, problem with ElfStringTable Summary: Created new "new" operator for CHeapObj that allows malloc to fail without causing fatal error. Also replaced "HeapAllocate" with "os::malloc" in decoder code to allow decoder to handle low memory scenario. Reviewed-by: coleenp, dholmes
author zgu
date Wed, 27 Apr 2011 09:09:57 -0400
parents 1d1603768966
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2177
diff changeset
2 * Copyright (c) 2003, 2011, 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: 1142
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1142
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: 1142
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 "memory/classify.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 const char* ClassifyObjectClosure::object_type_name[number_object_types] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 "unknown",
a61af66fc99e Initial load
duke
parents:
diff changeset
32 "instance",
a61af66fc99e Initial load
duke
parents:
diff changeset
33 "instanceRef",
a61af66fc99e Initial load
duke
parents:
diff changeset
34 "objArray",
a61af66fc99e Initial load
duke
parents:
diff changeset
35 "symbol",
a61af66fc99e Initial load
duke
parents:
diff changeset
36 "klass",
a61af66fc99e Initial load
duke
parents:
diff changeset
37 "instanceKlass",
a61af66fc99e Initial load
duke
parents:
diff changeset
38 "method",
a61af66fc99e Initial load
duke
parents:
diff changeset
39 "constMethod",
a61af66fc99e Initial load
duke
parents:
diff changeset
40 "methodData",
a61af66fc99e Initial load
duke
parents:
diff changeset
41 "constantPool",
a61af66fc99e Initial load
duke
parents:
diff changeset
42 "constantPoolCache",
a61af66fc99e Initial load
duke
parents:
diff changeset
43 "typeArray",
a61af66fc99e Initial load
duke
parents:
diff changeset
44 "compiledICHolder"
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 object_type ClassifyObjectClosure::classify_object(oop obj, bool count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 object_type type = unknown_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 Klass* k = obj->blueprint();
a61af66fc99e Initial load
duke
parents:
diff changeset
52
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 0
diff changeset
53 if (k->as_klassOop() == SystemDictionary::Object_klass()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54 tty->print_cr("Found the class!");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 k->set_alloc_count(k->alloc_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 if (obj->is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if (k->oop_is_instanceRef()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 type = instanceRef_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 type = instance_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else if (obj->is_typeArray()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 type = typeArray_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else if (obj->is_objArray()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 type = objArray_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 } else if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 Klass* k = ((klassOop)obj)->klass_part();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (k->oop_is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 type = instanceKlass_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 type = klass_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 } else if (obj->is_method()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 type = method_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 } else if (obj->is_constMethod()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 type = constMethod_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 } else if (obj->is_methodData()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 } else if (obj->is_constantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 type = constantPool_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 } else if (obj->is_constantPoolCache()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 type = constantPoolCache_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 } else if (obj->is_compiledICHolder()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 type = compiledICHolder_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 assert(type != unknown_type, "found object of unknown type.");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return type;
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 void ClassifyObjectClosure::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 for (int i = 0; i < number_object_types; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 object_count[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 object_size[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 total_object_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 total_object_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
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 ClassifyObjectClosure::do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int i = classify_object(obj, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 ++object_count[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
112 ++total_object_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 size_t size = obj->size() * HeapWordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 object_size[i] += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 total_object_size += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 size_t ClassifyObjectClosure::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int num_objects = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 size_t size_objects = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 for (int i = 0; i < number_object_types; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (object_count[i] != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 tty->print_cr("%8d %-22s (%8d bytes, %5.2f bytes/object)",
a61af66fc99e Initial load
duke
parents:
diff changeset
125 object_count[i], object_type_name[i], object_size[i],
a61af66fc99e Initial load
duke
parents:
diff changeset
126 (float)object_size[i]/(float)object_count[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 num_objects += object_count[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
129 size_objects += object_size[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 assert(num_objects == total_object_count, "Object count mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(size_objects == total_object_size, "Object size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 tty->print_cr(" Total: %d objects, %d bytes", total_object_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
135 total_object_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return total_object_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 void ClassifyInstanceKlassClosure::do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 int type = classify_object(obj, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (type == instanceKlass_type || type == klass_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 Klass* k = ((klassOop)obj)->klass_part();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (k->alloc_count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (k->name() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (obj == Universe::klassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 name = "_klassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
151 } else if (obj == Universe::arrayKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 name = "_arrayKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
153 } else if (obj == Universe::objArrayKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 name = "_objArrayKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
155 } else if (obj == Universe::typeArrayKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 name = "_typeArrayKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
157 } else if (obj == Universe::instanceKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 name = "_instanceKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
159 } else if (obj == Universe::methodKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 name = "_methodKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
161 } else if (obj == Universe::constMethodKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 name = "_constMethodKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
163 } else if (obj == Universe::constantPoolKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 name = "_constantPoolKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
165 } else if (obj == Universe::constantPoolCacheKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 name = "_constantPoolCacheKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
167 } else if (obj == Universe::compiledICHolderKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 name = "_compiledICHolderKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
169 } else if (obj == Universe::systemObjArrayKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 name = "_systemObjArrayKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
171 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 name = "[unnamed]";
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 name = k->external_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 tty->print_cr("% 8d instances of %s", k->alloc_count(), name);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 total_instances += k->alloc_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 void ClassifyInstanceKlassClosure::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 tty->print_cr(" Total instances: %d.", total_instances);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 void ClassifyInstanceKlassClosure::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 total_instances = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }