Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/memory/SystemDictionary.java @ 3945:8ed53447f690
Merge
author | iveresov |
---|---|
date | Thu, 15 Sep 2011 12:44:09 -0700 |
parents | 7588156f5cf9 |
children | b2cd0ee8f778 |
rev | line source |
---|---|
0 | 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 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
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 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.memory; | |
26 | |
27 import java.util.*; | |
28 import sun.jvm.hotspot.debugger.*; | |
29 import sun.jvm.hotspot.oops.*; | |
30 import sun.jvm.hotspot.runtime.*; | |
31 import sun.jvm.hotspot.types.*; | |
32 | |
33 public class SystemDictionary { | |
34 private static AddressField dictionaryField; | |
35 private static AddressField sharedDictionaryField; | |
36 private static AddressField placeholdersField; | |
37 private static AddressField loaderConstraintTableField; | |
147 | 38 private static sun.jvm.hotspot.types.OopField javaSystemLoaderField; |
0 | 39 private static int nofBuckets; |
40 | |
147 | 41 private static sun.jvm.hotspot.types.OopField objectKlassField; |
42 private static sun.jvm.hotspot.types.OopField classLoaderKlassField; | |
43 private static sun.jvm.hotspot.types.OopField stringKlassField; | |
44 private static sun.jvm.hotspot.types.OopField systemKlassField; | |
45 private static sun.jvm.hotspot.types.OopField threadKlassField; | |
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 | 48 |
49 static { | |
50 VM.registerVMInitializedObserver(new Observer() { | |
51 public void update(Observable o, Object data) { | |
52 initialize(VM.getVM().getTypeDataBase()); | |
53 } | |
54 }); | |
55 } | |
56 | |
57 private static synchronized void initialize(TypeDataBase db) { | |
58 Type type = db.lookupType("SystemDictionary"); | |
59 | |
60 dictionaryField = type.getAddressField("_dictionary"); | |
61 sharedDictionaryField = type.getAddressField("_shared_dictionary"); | |
62 placeholdersField = type.getAddressField("_placeholders"); | |
63 loaderConstraintTableField = type.getAddressField("_loader_constraints"); | |
64 javaSystemLoaderField = type.getOopField("_java_system_loader"); | |
65 nofBuckets = db.lookupIntConstant("SystemDictionary::_nof_buckets").intValue(); | |
66 | |
1142 | 67 objectKlassField = type.getOopField(WK_KLASS("Object_klass")); |
68 classLoaderKlassField = type.getOopField(WK_KLASS("ClassLoader_klass")); | |
69 stringKlassField = type.getOopField(WK_KLASS("String_klass")); | |
70 systemKlassField = type.getOopField(WK_KLASS("System_klass")); | |
71 threadKlassField = type.getOopField(WK_KLASS("Thread_klass")); | |
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 | 76 // This WK functions must follow the definitions in systemDictionary.hpp: |
77 private static String WK_KLASS(String name) { | |
78 //#define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)] | |
79 return ("_well_known_klasses[SystemDictionary::"+WK_KLASS_ENUM_NAME(name)+"]"); | |
80 } | |
81 private static String WK_KLASS_ENUM_NAME(String kname) { | |
82 //#define WK_KLASS_ENUM_NAME(kname) kname##_knum | |
83 return (kname+"_knum"); | |
0 | 84 } |
85 | |
86 public Dictionary dictionary() { | |
87 Address tmp = dictionaryField.getValue(); | |
88 return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp); | |
89 } | |
90 | |
91 public Dictionary sharedDictionary() { | |
92 Address tmp = sharedDictionaryField.getValue(); | |
93 return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp); | |
94 } | |
95 | |
96 public PlaceholderTable placeholders() { | |
97 Address tmp = placeholdersField.getValue(); | |
98 return (PlaceholderTable) VMObjectFactory.newObject(PlaceholderTable.class, tmp); | |
99 } | |
100 | |
101 public LoaderConstraintTable constraints() { | |
102 Address tmp = placeholdersField.getValue(); | |
103 return (LoaderConstraintTable) VMObjectFactory.newObject(LoaderConstraintTable.class, tmp); | |
104 } | |
105 | |
106 // few well known classes -- not all are added here. | |
107 // add more if needed. | |
108 public static InstanceKlass getThreadKlass() { | |
109 return (InstanceKlass) newOop(threadKlassField.getValue()); | |
110 } | |
111 | |
112 public static InstanceKlass getThreadGroupKlass() { | |
113 return (InstanceKlass) newOop(threadGroupKlassField.getValue()); | |
114 } | |
115 | |
116 public static InstanceKlass getObjectKlass() { | |
117 return (InstanceKlass) newOop(objectKlassField.getValue()); | |
118 } | |
119 | |
120 public static InstanceKlass getStringKlass() { | |
121 return (InstanceKlass) newOop(stringKlassField.getValue()); | |
122 } | |
123 | |
124 public static InstanceKlass getClassLoaderKlass() { | |
125 return (InstanceKlass) newOop(classLoaderKlassField.getValue()); | |
126 } | |
127 | |
128 public static InstanceKlass getSystemKlass() { | |
129 return (InstanceKlass) newOop(systemKlassField.getValue()); | |
130 } | |
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 | 136 public InstanceKlass getAbstractOwnableSynchronizerKlass() { |
137 return (InstanceKlass) find("java/util/concurrent/locks/AbstractOwnableSynchronizer", | |
138 null, null); | |
139 } | |
140 | |
141 public static Oop javaSystemLoader() { | |
142 return newOop(javaSystemLoaderField.getValue()); | |
143 } | |
144 | |
145 public static int getNumOfBuckets() { | |
146 return nofBuckets; | |
147 } | |
148 | |
149 private static Oop newOop(OopHandle handle) { | |
150 return VM.getVM().getObjectHeap().newOop(handle); | |
151 } | |
152 | |
153 /** Lookup an already loaded class. If not found null is returned. */ | |
154 public Klass find(String className, Oop classLoader, Oop protectionDomain) { | |
155 Symbol sym = VM.getVM().getSymbolTable().probe(className); | |
156 if (sym == null) return null; | |
157 return find(sym, classLoader, protectionDomain); | |
158 } | |
159 | |
160 /** Lookup an already loaded class. If not found null is returned. */ | |
161 public Klass find(Symbol className, Oop classLoader, Oop protectionDomain) { | |
162 Dictionary dict = dictionary(); | |
163 long hash = dict.computeHash(className, classLoader); | |
164 int index = dict.hashToIndex(hash); | |
165 return dict.find(index, hash, className, classLoader, protectionDomain); | |
166 } | |
167 | |
168 /** Interface for iterating through all classes in dictionary */ | |
169 public static interface ClassVisitor { | |
170 public void visit(Klass k); | |
171 } | |
172 | |
173 /** Interface for iterating through all classes and their class | |
174 loaders in dictionary */ | |
175 public static interface ClassAndLoaderVisitor { | |
176 public void visit(Klass k, Oop loader); | |
177 } | |
178 | |
179 /** Iterate over all klasses - including object, primitive | |
180 array klasses */ | |
181 public void allClassesDo(final ClassVisitor v) { | |
182 ClassVisitor visitor = new ClassVisitor() { | |
183 public void visit(Klass k) { | |
184 for (Klass l = k; l != null; l = l.arrayKlassOrNull()) { | |
185 v.visit(l); | |
186 } | |
187 } | |
188 }; | |
189 classesDo(visitor); | |
190 VM.getVM().getUniverse().basicTypeClassesDo(visitor); | |
191 } | |
192 | |
193 /** Iterate over all klasses in dictionary; just the classes from | |
194 declaring class loaders */ | |
195 public void classesDo(ClassVisitor v) { | |
196 dictionary().classesDo(v); | |
197 } | |
198 | |
199 /** All classes, and their class loaders */ | |
200 public void classesDo(ClassAndLoaderVisitor v) { | |
201 dictionary().classesDo(v); | |
202 } | |
203 | |
204 /** All array classes of primitive type, and their class loaders */ | |
205 public void primArrayClassesDo(ClassAndLoaderVisitor v) { | |
206 placeholders().primArrayClassesDo(v); | |
207 } | |
208 } |