hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/SystemDictionary.java
author never
Wed, 06 Jan 2010 14:22:39 -0800
changeset 4571 80b553bddc26
parent 670 ddf3e9583f2f
child 5547 f4b087cbb361
permissions -rw-r--r--
6914300: ciEnv should export all well known classes Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 394
diff changeset
     2
 * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.memory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
public class SystemDictionary {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  private static AddressField dictionaryField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  private static AddressField sharedDictionaryField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  private static AddressField placeholdersField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  private static AddressField loaderConstraintTableField;
394
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    38
  private static sun.jvm.hotspot.types.OopField javaSystemLoaderField;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  private static int nofBuckets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
394
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    41
  private static sun.jvm.hotspot.types.OopField objectKlassField;
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    42
  private static sun.jvm.hotspot.types.OopField classLoaderKlassField;
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    43
  private static sun.jvm.hotspot.types.OopField stringKlassField;
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    44
  private static sun.jvm.hotspot.types.OopField systemKlassField;
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    45
  private static sun.jvm.hotspot.types.OopField threadKlassField;
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    46
  private static sun.jvm.hotspot.types.OopField threadGroupKlassField;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    Type type = db.lookupType("SystemDictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    dictionaryField = type.getAddressField("_dictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    sharedDictionaryField = type.getAddressField("_shared_dictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    placeholdersField = type.getAddressField("_placeholders");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    loaderConstraintTableField = type.getAddressField("_loader_constraints");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    javaSystemLoaderField = type.getOopField("_java_system_loader");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    nofBuckets = db.lookupIntConstant("SystemDictionary::_nof_buckets").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 670
diff changeset
    66
    objectKlassField = type.getOopField(WK_KLASS("Object_klass"));
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 670
diff changeset
    67
    classLoaderKlassField = type.getOopField(WK_KLASS("ClassLoader_klass"));
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 670
diff changeset
    68
    stringKlassField = type.getOopField(WK_KLASS("String_klass"));
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 670
diff changeset
    69
    systemKlassField = type.getOopField(WK_KLASS("System_klass"));
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 670
diff changeset
    70
    threadKlassField = type.getOopField(WK_KLASS("Thread_klass"));
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 670
diff changeset
    71
    threadGroupKlassField = type.getOopField(WK_KLASS("ThreadGroup_klass"));
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 1
diff changeset
    72
  }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 1
diff changeset
    73
394
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    74
  // This WK functions must follow the definitions in systemDictionary.hpp:
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    75
  private static String WK_KLASS(String name) {
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    76
      //#define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    77
      return ("_well_known_klasses[SystemDictionary::"+WK_KLASS_ENUM_NAME(name)+"]");
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    78
  }
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    79
  private static String WK_KLASS_ENUM_NAME(String kname) {
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    80
      //#define WK_KLASS_ENUM_NAME(kname)    kname##_knum
c33507c3ac75 6701024: SAJDI functionality is broken
jrose
parents: 379
diff changeset
    81
      return (kname+"_knum");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  public Dictionary dictionary() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    Address tmp = dictionaryField.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  public Dictionary sharedDictionary() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    Address tmp = sharedDictionaryField.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return (Dictionary) VMObjectFactory.newObject(Dictionary.class, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  public PlaceholderTable placeholders() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    Address tmp = placeholdersField.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    return (PlaceholderTable) VMObjectFactory.newObject(PlaceholderTable.class, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  public LoaderConstraintTable constraints() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    Address tmp = placeholdersField.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    return (LoaderConstraintTable) VMObjectFactory.newObject(LoaderConstraintTable.class, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // few well known classes -- not all are added here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // add more if needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public static InstanceKlass getThreadKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return (InstanceKlass) newOop(threadKlassField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  public static InstanceKlass getThreadGroupKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    return (InstanceKlass) newOop(threadGroupKlassField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  public static InstanceKlass getObjectKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    return (InstanceKlass) newOop(objectKlassField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  public static InstanceKlass getStringKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    return (InstanceKlass) newOop(stringKlassField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  public static InstanceKlass getClassLoaderKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    return (InstanceKlass) newOop(classLoaderKlassField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  public static InstanceKlass getSystemKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    return (InstanceKlass) newOop(systemKlassField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  public InstanceKlass getAbstractOwnableSynchronizerKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    return (InstanceKlass) find("java/util/concurrent/locks/AbstractOwnableSynchronizer",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
                                null, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  public static Oop javaSystemLoader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    return newOop(javaSystemLoaderField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  public static int getNumOfBuckets() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    return nofBuckets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  private static Oop newOop(OopHandle handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    return VM.getVM().getObjectHeap().newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  /** Lookup an already loaded class. If not found null is returned. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  public Klass find(String className, Oop classLoader, Oop protectionDomain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    Symbol sym = VM.getVM().getSymbolTable().probe(className);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    if (sym == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return find(sym, classLoader, protectionDomain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  /** Lookup an already loaded class. If not found null is returned. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  public Klass find(Symbol className, Oop classLoader, Oop protectionDomain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    Dictionary dict = dictionary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    long hash = dict.computeHash(className, classLoader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    int index = dict.hashToIndex(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    return dict.find(index, hash, className, classLoader, protectionDomain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  /** Interface for iterating through all classes in dictionary */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  public static interface ClassVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    public void visit(Klass k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  /** Interface for iterating through all classes and their class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      loaders in dictionary */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  public static interface ClassAndLoaderVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    public void visit(Klass k, Oop loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  /** Iterate over all klasses - including object, primitive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      array klasses */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  public void allClassesDo(final ClassVisitor v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    ClassVisitor visitor = new ClassVisitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      public void visit(Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        for (Klass l = k; l != null; l = l.arrayKlassOrNull()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
          v.visit(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    classesDo(visitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    VM.getVM().getUniverse().basicTypeClassesDo(visitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  /** Iterate over all klasses in dictionary; just the classes from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      declaring class loaders */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  public void classesDo(ClassVisitor v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    dictionary().classesDo(v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  /** All classes, and their class loaders */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  public void classesDo(ClassAndLoaderVisitor v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    dictionary().classesDo(v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  /** All array classes of primitive type, and their class loaders */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  public void primArrayClassesDo(ClassAndLoaderVisitor v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    placeholders().primArrayClassesDo(v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}