annotate agent/src/share/classes/sun/jvm/hotspot/memory/SystemDictionary.java @ 3908:7588156f5cf9

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