annotate agent/src/share/classes/sun/jvm/hotspot/memory/SystemDictionary.java @ 4864:b2cd0ee8f778

7114376: Make system dictionary hashtable bucket array size configurable Summary: 7u4 new experimental flag -XX:PredictedClassLoadedCount=# Reviewed-by: dholmes, phh, dcubed
author acorn
date Mon, 30 Jan 2012 23:27:30 -0500
parents 7588156f5cf9
children da91efe96a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
4864
b2cd0ee8f778 7114376: Make system dictionary hashtable bucket array size configurable
acorn
parents: 3908
diff changeset
2 * Copyright (c) 2001, 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: 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.memory;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class SystemDictionary {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static AddressField dictionaryField;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static AddressField sharedDictionaryField;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static AddressField placeholdersField;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static AddressField loaderConstraintTableField;
147
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
38 private static sun.jvm.hotspot.types.OopField javaSystemLoaderField;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39
147
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
40 private static sun.jvm.hotspot.types.OopField objectKlassField;
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
41 private static sun.jvm.hotspot.types.OopField classLoaderKlassField;
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
42 private static sun.jvm.hotspot.types.OopField stringKlassField;
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
43 private static sun.jvm.hotspot.types.OopField systemKlassField;
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
44 private static sun.jvm.hotspot.types.OopField threadKlassField;
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
45 private static sun.jvm.hotspot.types.OopField threadGroupKlassField;
3908
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 2042
diff changeset
46 private static sun.jvm.hotspot.types.OopField methodHandleKlassField;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 initialize(VM.getVM().getTypeDataBase());
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 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 Type type = db.lookupType("SystemDictionary");
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 dictionaryField = type.getAddressField("_dictionary");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 sharedDictionaryField = type.getAddressField("_shared_dictionary");
a61af66fc99e Initial load
duke
parents:
diff changeset
61 placeholdersField = type.getAddressField("_placeholders");
a61af66fc99e Initial load
duke
parents:
diff changeset
62 loaderConstraintTableField = type.getAddressField("_loader_constraints");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 javaSystemLoaderField = type.getOopField("_java_system_loader");
a61af66fc99e Initial load
duke
parents:
diff changeset
64
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 196
diff changeset
65 objectKlassField = type.getOopField(WK_KLASS("Object_klass"));
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 196
diff changeset
66 classLoaderKlassField = type.getOopField(WK_KLASS("ClassLoader_klass"));
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 196
diff changeset
67 stringKlassField = type.getOopField(WK_KLASS("String_klass"));
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 196
diff changeset
68 systemKlassField = type.getOopField(WK_KLASS("System_klass"));
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 196
diff changeset
69 threadKlassField = type.getOopField(WK_KLASS("Thread_klass"));
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 196
diff changeset
70 threadGroupKlassField = type.getOopField(WK_KLASS("ThreadGroup_klass"));
3908
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 2042
diff changeset
71 methodHandleKlassField = type.getOopField(WK_KLASS("MethodHandle_klass"));
132
60b728ec77c1 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 0
diff changeset
72 }
60b728ec77c1 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 0
diff changeset
73
147
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
74 // This WK functions must follow the definitions in systemDictionary.hpp:
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
75 private static String WK_KLASS(String name) {
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
76 //#define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
77 return ("_well_known_klasses[SystemDictionary::"+WK_KLASS_ENUM_NAME(name)+"]");
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
78 }
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
79 private static String WK_KLASS_ENUM_NAME(String kname) {
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
80 //#define WK_KLASS_ENUM_NAME(kname) kname##_knum
83c868b757c0 6701024: SAJDI functionality is broken
jrose
parents: 132
diff changeset
81 return (kname+"_knum");
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 public Dictionary dictionary() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Address tmp = dictionaryField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public Dictionary sharedDictionary() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 Address tmp = sharedDictionaryField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 public PlaceholderTable placeholders() {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 Address tmp = placeholdersField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return (PlaceholderTable) VMObjectFactory.newObject(PlaceholderTable.class, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public LoaderConstraintTable constraints() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 Address tmp = placeholdersField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return (LoaderConstraintTable) VMObjectFactory.newObject(LoaderConstraintTable.class, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // few well known classes -- not all are added here.
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // add more if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public static InstanceKlass getThreadKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return (InstanceKlass) newOop(threadKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public static InstanceKlass getThreadGroupKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return (InstanceKlass) newOop(threadGroupKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public static InstanceKlass getObjectKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return (InstanceKlass) newOop(objectKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public static InstanceKlass getStringKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return (InstanceKlass) newOop(stringKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public static InstanceKlass getClassLoaderKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return (InstanceKlass) newOop(classLoaderKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public static InstanceKlass getSystemKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return (InstanceKlass) newOop(systemKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
3908
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 2042
diff changeset
130 public static InstanceKlass getMethodHandleKlass() {
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 2042
diff changeset
131 return (InstanceKlass) newOop(methodHandleKlassField.getValue());
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 2042
diff changeset
132 }
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 2042
diff changeset
133
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134 public InstanceKlass getAbstractOwnableSynchronizerKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return (InstanceKlass) find("java/util/concurrent/locks/AbstractOwnableSynchronizer",
a61af66fc99e Initial load
duke
parents:
diff changeset
136 null, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 public static Oop javaSystemLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return newOop(javaSystemLoaderField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 private static Oop newOop(OopHandle handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 /** Lookup an already loaded class. If not found null is returned. */
a61af66fc99e Initial load
duke
parents:
diff changeset
148 public Klass find(String className, Oop classLoader, Oop protectionDomain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 Symbol sym = VM.getVM().getSymbolTable().probe(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (sym == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return find(sym, classLoader, protectionDomain);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 /** Lookup an already loaded class. If not found null is returned. */
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public Klass find(Symbol className, Oop classLoader, Oop protectionDomain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 Dictionary dict = dictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
157 long hash = dict.computeHash(className, classLoader);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 int index = dict.hashToIndex(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return dict.find(index, hash, className, classLoader, protectionDomain);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 /** Interface for iterating through all classes in dictionary */
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public static interface ClassVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 public void visit(Klass k);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 /** Interface for iterating through all classes and their class
a61af66fc99e Initial load
duke
parents:
diff changeset
168 loaders in dictionary */
a61af66fc99e Initial load
duke
parents:
diff changeset
169 public static interface ClassAndLoaderVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 public void visit(Klass k, Oop loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 /** Iterate over all klasses - including object, primitive
a61af66fc99e Initial load
duke
parents:
diff changeset
174 array klasses */
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public void allClassesDo(final ClassVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 ClassVisitor visitor = new ClassVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public void visit(Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 for (Klass l = k; l != null; l = l.arrayKlassOrNull()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 v.visit(l);
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 classesDo(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 VM.getVM().getUniverse().basicTypeClassesDo(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 /** Iterate over all klasses in dictionary; just the classes from
a61af66fc99e Initial load
duke
parents:
diff changeset
188 declaring class loaders */
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public void classesDo(ClassVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 dictionary().classesDo(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 /** All classes, and their class loaders */
a61af66fc99e Initial load
duke
parents:
diff changeset
194 public void classesDo(ClassAndLoaderVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 dictionary().classesDo(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 /** All array classes of primitive type, and their class loaders */
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public void primArrayClassesDo(ClassAndLoaderVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 placeholders().primArrayClassesDo(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }