annotate src/share/vm/memory/classify.cpp @ 453:c96030fff130

6684579: SoftReference processing can be made more efficient Summary: For current soft-ref clearing policies, we can decide at marking time if a soft-reference will definitely not be cleared, postponing the decision of whether it will definitely be cleared to the final reference processing phase. This can be especially beneficial in the case of concurrent collectors where the marking is usually concurrent but reference processing is usually not. Reviewed-by: jmasa
author ysr
date Thu, 20 Nov 2008 16:56:09 -0800
parents a61af66fc99e
children 4ce7240d622c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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/_classify.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 const char* ClassifyObjectClosure::object_type_name[number_object_types] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 "unknown",
a61af66fc99e Initial load
duke
parents:
diff changeset
31 "instance",
a61af66fc99e Initial load
duke
parents:
diff changeset
32 "instanceRef",
a61af66fc99e Initial load
duke
parents:
diff changeset
33 "objArray",
a61af66fc99e Initial load
duke
parents:
diff changeset
34 "symbol",
a61af66fc99e Initial load
duke
parents:
diff changeset
35 "klass",
a61af66fc99e Initial load
duke
parents:
diff changeset
36 "instanceKlass",
a61af66fc99e Initial load
duke
parents:
diff changeset
37 "method",
a61af66fc99e Initial load
duke
parents:
diff changeset
38 "constMethod",
a61af66fc99e Initial load
duke
parents:
diff changeset
39 "methodData",
a61af66fc99e Initial load
duke
parents:
diff changeset
40 "constantPool",
a61af66fc99e Initial load
duke
parents:
diff changeset
41 "constantPoolCache",
a61af66fc99e Initial load
duke
parents:
diff changeset
42 "typeArray",
a61af66fc99e Initial load
duke
parents:
diff changeset
43 "compiledICHolder"
a61af66fc99e Initial load
duke
parents:
diff changeset
44 };
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 object_type ClassifyObjectClosure::classify_object(oop obj, bool count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 object_type type = unknown_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 Klass* k = obj->blueprint();
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 if (k->as_klassOop() == SystemDictionary::object_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 tty->print_cr("Found the class!");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 if (count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 k->set_alloc_count(k->alloc_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 if (obj->is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 if (k->oop_is_instanceRef()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 type = instanceRef_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 type = instance_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 } else if (obj->is_typeArray()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 type = typeArray_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 } else if (obj->is_objArray()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 type = objArray_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 } else if (obj->is_symbol()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 type = symbol_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 } else if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 Klass* k = ((klassOop)obj)->klass_part();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 if (k->oop_is_instance()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 type = instanceKlass_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 type = klass_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } else if (obj->is_method()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 type = method_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 } else if (obj->is_constMethod()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 type = constMethod_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 } else if (obj->is_methodData()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 } else if (obj->is_constantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 type = constantPool_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 } else if (obj->is_constantPoolCache()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 type = constantPoolCache_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 } else if (obj->is_compiledICHolder()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 type = compiledICHolder_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 assert(type != unknown_type, "found object of unknown type.");
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return type;
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 ClassifyObjectClosure::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 for (int i = 0; i < number_object_types; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 object_count[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 object_size[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 total_object_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 total_object_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 void ClassifyObjectClosure::do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int i = classify_object(obj, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 ++object_count[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
113 ++total_object_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 size_t size = obj->size() * HeapWordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 object_size[i] += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 total_object_size += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 size_t ClassifyObjectClosure::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int num_objects = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 size_t size_objects = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 for (int i = 0; i < number_object_types; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (object_count[i] != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 tty->print_cr("%8d %-22s (%8d bytes, %5.2f bytes/object)",
a61af66fc99e Initial load
duke
parents:
diff changeset
126 object_count[i], object_type_name[i], object_size[i],
a61af66fc99e Initial load
duke
parents:
diff changeset
127 (float)object_size[i]/(float)object_count[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 num_objects += object_count[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
130 size_objects += object_size[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(num_objects == total_object_count, "Object count mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(size_objects == total_object_size, "Object size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 tty->print_cr(" Total: %d objects, %d bytes", total_object_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
136 total_object_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return total_object_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 void ClassifyInstanceKlassClosure::do_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 int type = classify_object(obj, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (type == instanceKlass_type || type == klass_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 Klass* k = ((klassOop)obj)->klass_part();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (k->alloc_count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (k->name() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (obj == Universe::klassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 name = "_klassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
152 } else if (obj == Universe::arrayKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 name = "_arrayKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
154 } else if (obj == Universe::objArrayKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 name = "_objArrayKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
156 } else if (obj == Universe::typeArrayKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 name = "_typeArrayKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
158 } else if (obj == Universe::instanceKlassKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 name = "_instanceKlassKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else if (obj == Universe::symbolKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 name = "_symbolKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
162 } else if (obj == Universe::methodKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 name = "_methodKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
164 } else if (obj == Universe::constMethodKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 name = "_constMethodKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } else if (obj == Universe::constantPoolKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 name = "_constantPoolKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
168 } else if (obj == Universe::constantPoolCacheKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 name = "_constantPoolCacheKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
170 } else if (obj == Universe::compiledICHolderKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 name = "_compiledICHolderKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } else if (obj == Universe::systemObjArrayKlassObj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 name = "_systemObjArrayKlassObj";
a61af66fc99e Initial load
duke
parents:
diff changeset
174 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 name = "[unnamed]";
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 name = k->external_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 tty->print_cr("% 8d instances of %s", k->alloc_count(), name);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 total_instances += k->alloc_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 void ClassifyInstanceKlassClosure::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 tty->print_cr(" Total instances: %d.", total_instances);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 void ClassifyInstanceKlassClosure::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 total_instances = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }