annotate agent/src/share/classes/sun/jvm/hotspot/memory/SystemDictionary.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 60b728ec77c1
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 2001-2005 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 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;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static sun.jvm.hotspot.types.OopField javaSystemLoaderField;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private static int nofBuckets;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static sun.jvm.hotspot.types.OopField objectKlassField;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private static sun.jvm.hotspot.types.OopField classLoaderKlassField;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private static sun.jvm.hotspot.types.OopField stringKlassField;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private static sun.jvm.hotspot.types.OopField systemKlassField;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private static sun.jvm.hotspot.types.OopField threadKlassField;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private static sun.jvm.hotspot.types.OopField threadGroupKlassField;
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 nofBuckets = db.lookupIntConstant("SystemDictionary::_nof_buckets").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 objectKlassField = type.getOopField("_object_klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
67 classLoaderKlassField = type.getOopField("_classloader_klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
68 stringKlassField = type.getOopField("_string_klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
69 systemKlassField = type.getOopField("_system_klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 threadKlassField = type.getOopField("_thread_klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
71 threadGroupKlassField = type.getOopField("_threadGroup_klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public Dictionary dictionary() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Address tmp = dictionaryField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 public Dictionary sharedDictionary() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 Address tmp = sharedDictionaryField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp);
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 PlaceholderTable placeholders() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Address tmp = placeholdersField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return (PlaceholderTable) VMObjectFactory.newObject(PlaceholderTable.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 LoaderConstraintTable constraints() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 Address tmp = placeholdersField.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return (LoaderConstraintTable) VMObjectFactory.newObject(LoaderConstraintTable.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 // few well known classes -- not all are added here.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // add more if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public static InstanceKlass getThreadKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return (InstanceKlass) newOop(threadKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public static InstanceKlass getThreadGroupKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return (InstanceKlass) newOop(threadGroupKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public static InstanceKlass getObjectKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return (InstanceKlass) newOop(objectKlassField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public static InstanceKlass getStringKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return (InstanceKlass) newOop(stringKlassField.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 getClassLoaderKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return (InstanceKlass) newOop(classLoaderKlassField.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 getSystemKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return (InstanceKlass) newOop(systemKlassField.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 InstanceKlass getAbstractOwnableSynchronizerKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return (InstanceKlass) find("java/util/concurrent/locks/AbstractOwnableSynchronizer",
a61af66fc99e Initial load
duke
parents:
diff changeset
122 null, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public static Oop javaSystemLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return newOop(javaSystemLoaderField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public static int getNumOfBuckets() {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return nofBuckets;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 private static Oop newOop(OopHandle handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 /** Lookup an already loaded class. If not found null is returned. */
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public Klass find(String className, Oop classLoader, Oop protectionDomain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 Symbol sym = VM.getVM().getSymbolTable().probe(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (sym == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return find(sym, classLoader, protectionDomain);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 /** Lookup an already loaded class. If not found null is returned. */
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public Klass find(Symbol className, Oop classLoader, Oop protectionDomain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 Dictionary dict = dictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 long hash = dict.computeHash(className, classLoader);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 int index = dict.hashToIndex(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return dict.find(index, hash, className, classLoader, protectionDomain);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 /** Interface for iterating through all classes in dictionary */
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public static interface ClassVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 public void visit(Klass k);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 /** Interface for iterating through all classes and their class
a61af66fc99e Initial load
duke
parents:
diff changeset
158 loaders in dictionary */
a61af66fc99e Initial load
duke
parents:
diff changeset
159 public static interface ClassAndLoaderVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 public void visit(Klass k, Oop loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 /** Iterate over all klasses - including object, primitive
a61af66fc99e Initial load
duke
parents:
diff changeset
164 array klasses */
a61af66fc99e Initial load
duke
parents:
diff changeset
165 public void allClassesDo(final ClassVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 ClassVisitor visitor = new ClassVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public void visit(Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 for (Klass l = k; l != null; l = l.arrayKlassOrNull()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 v.visit(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 };
a61af66fc99e Initial load
duke
parents:
diff changeset
173 classesDo(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 VM.getVM().getUniverse().basicTypeClassesDo(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 /** Iterate over all klasses in dictionary; just the classes from
a61af66fc99e Initial load
duke
parents:
diff changeset
178 declaring class loaders */
a61af66fc99e Initial load
duke
parents:
diff changeset
179 public void classesDo(ClassVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 dictionary().classesDo(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 /** All classes, and their class loaders */
a61af66fc99e Initial load
duke
parents:
diff changeset
184 public void classesDo(ClassAndLoaderVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 dictionary().classesDo(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 /** All array classes of primitive type, and their class loaders */
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public void primArrayClassesDo(ClassAndLoaderVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 placeholders().primArrayClassesDo(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }