1 /* 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 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 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 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.classfile.*; 30 import sun.jvm.hotspot.oops.*; 31 import sun.jvm.hotspot.runtime.*; 32 import sun.jvm.hotspot.types.*; 33 34 public class SystemDictionary { 35 private static AddressField sharedDictionaryField; 36 private static sun.jvm.hotspot.types.OopField javaSystemLoaderField; 37 38 private static AddressField objectKlassField; 39 private static AddressField classLoaderKlassField; 40 private static AddressField stringKlassField; 41 private static AddressField systemKlassField; 42 private static AddressField threadKlassField; 43 private static AddressField threadGroupKlassField; 44 private static AddressField methodHandleKlassField; 45 46 static { 47 VM.registerVMInitializedObserver(new Observer() { 48 public void update(Observable o, Object data) { 49 initialize(VM.getVM().getTypeDataBase()); 50 } 51 }); 52 } 53 54 private static synchronized void initialize(TypeDataBase db) { 55 Type type = db.lookupType("SystemDictionary"); 56 57 sharedDictionaryField = type.getAddressField("_shared_dictionary"); 58 javaSystemLoaderField = type.getOopField("_java_system_loader"); 59 60 objectKlassField = type.getAddressField(WK_KLASS("Object_klass")); 61 classLoaderKlassField = type.getAddressField(WK_KLASS("ClassLoader_klass")); 62 stringKlassField = type.getAddressField(WK_KLASS("String_klass")); 63 systemKlassField = type.getAddressField(WK_KLASS("System_klass")); 64 threadKlassField = type.getAddressField(WK_KLASS("Thread_klass")); 65 threadGroupKlassField = type.getAddressField(WK_KLASS("ThreadGroup_klass")); 66 methodHandleKlassField = type.getAddressField(WK_KLASS("MethodHandle_klass")); 67 } 68 69 // This WK functions must follow the definitions in systemDictionary.hpp: 70 private static String WK_KLASS(String name) { 71 //#define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)] 72 return ("_well_known_klasses[SystemDictionary::"+WK_KLASS_ENUM_NAME(name)+"]"); 73 } 74 private static String WK_KLASS_ENUM_NAME(String kname) { 75 //#define WK_KLASS_ENUM_NAME(kname) kname##_knum 76 return (kname+"_knum"); 77 } 78 79 public Dictionary sharedDictionary() { 80 Address tmp = sharedDictionaryField.getValue(); 81 return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp); 82 } 83 84 // few well known classes -- not all are added here. 85 // add more if needed. 86 public static InstanceKlass getThreadKlass() { 87 return (InstanceKlass)Metadata.instantiateWrapperFor(threadKlassField.getValue()); 88 } 89 90 public static InstanceKlass getThreadGroupKlass() { 91 return (InstanceKlass)Metadata.instantiateWrapperFor(threadGroupKlassField.getValue()); 92 } 93 94 public static InstanceKlass getObjectKlass() { 95 return (InstanceKlass)Metadata.instantiateWrapperFor(objectKlassField.getValue()); 96 } 97 98 public static InstanceKlass getStringKlass() { 99 return (InstanceKlass)Metadata.instantiateWrapperFor(stringKlassField.getValue()); 100 } 101 102 public static InstanceKlass getClassLoaderKlass() { 103 return (InstanceKlass)Metadata.instantiateWrapperFor(classLoaderKlassField.getValue()); 104 } 105 106 public static InstanceKlass getSystemKlass() { 107 return (InstanceKlass)Metadata.instantiateWrapperFor(systemKlassField.getValue()); 108 } 109 110 public static InstanceKlass getMethodHandleKlass() { 111 return (InstanceKlass)Metadata.instantiateWrapperFor(methodHandleKlassField.getValue()); 112 } 113 114 public InstanceKlass getAbstractOwnableSynchronizerKlass() { 115 ClassLoaderDataGraph cldg = VM.getVM().getClassLoaderDataGraph(); 116 return (InstanceKlass) cldg.find("java/util/concurrent/locks/AbstractOwnableSynchronizer"); 117 } 118 119 public static Oop javaSystemLoader() { 120 return newOop(javaSystemLoaderField.getValue()); 121 } 122 123 private static Oop newOop(OopHandle handle) { 124 return VM.getVM().getObjectHeap().newOop(handle); 125 } 126 }