< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java

Print this page

  60   // ClassState constants
  61   private static int CLASS_STATE_ALLOCATED;
  62   private static int CLASS_STATE_LOADED;
  63   private static int CLASS_STATE_LINKED;
  64   private static int CLASS_STATE_BEING_INITIALIZED;
  65   private static int CLASS_STATE_FULLY_INITIALIZED;
  66   private static int CLASS_STATE_INITIALIZATION_ERROR;
  67 
  68   // _misc_flags constants
  69   private static int MISC_REWRITTEN;
  70   private static int MISC_HAS_NONSTATIC_FIELDS;
  71   private static int MISC_SHOULD_VERIFY_CLASS;
  72   private static int MISC_IS_CONTENDED;
  73   private static int MISC_HAS_NONSTATIC_CONCRETE_METHODS;
  74   private static int MISC_DECLARES_NONSTATIC_CONCRETE_METHODS;
  75   private static int MISC_HAS_BEEN_REDEFINED;
  76   private static int MISC_IS_SCRATCH_CLASS;
  77   private static int MISC_IS_SHARED_BOOT_CLASS;
  78   private static int MISC_IS_SHARED_PLATFORM_CLASS;
  79   private static int MISC_IS_SHARED_APP_CLASS;


  80 
  81   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
  82     Type type            = db.lookupType("InstanceKlass");
  83     arrayKlasses         = new MetadataField(type.getAddressField("_array_klasses"), 0);
  84     methods              = type.getAddressField("_methods");
  85     defaultMethods       = type.getAddressField("_default_methods");
  86     methodOrdering       = type.getAddressField("_method_ordering");
  87     localInterfaces      = type.getAddressField("_local_interfaces");
  88     transitiveInterfaces = type.getAddressField("_transitive_interfaces");
  89     fields               = type.getAddressField("_fields");
  90     javaFieldsCount      = new CIntField(type.getCIntegerField("_java_fields_count"), 0);
  91     constants            = new MetadataField(type.getAddressField("_constants"), 0);
  92     sourceDebugExtension = type.getAddressField("_source_debug_extension");
  93     innerClasses         = type.getAddressField("_inner_classes");
  94     nonstaticFieldSize   = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
  95     staticFieldSize      = new CIntField(type.getCIntegerField("_static_field_size"), 0);
  96     staticOopFieldCount  = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
  97     nonstaticOopMapSize  = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
  98     isMarkedDependent    = new CIntField(type.getCIntegerField("_is_marked_dependent"), 0);
  99     initState            = new CIntField(type.getCIntegerField("_init_state"), 0);

 117 
 118     // read ClassState constants
 119     CLASS_STATE_ALLOCATED = db.lookupIntConstant("InstanceKlass::allocated").intValue();
 120     CLASS_STATE_LOADED = db.lookupIntConstant("InstanceKlass::loaded").intValue();
 121     CLASS_STATE_LINKED = db.lookupIntConstant("InstanceKlass::linked").intValue();
 122     CLASS_STATE_BEING_INITIALIZED = db.lookupIntConstant("InstanceKlass::being_initialized").intValue();
 123     CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("InstanceKlass::fully_initialized").intValue();
 124     CLASS_STATE_INITIALIZATION_ERROR = db.lookupIntConstant("InstanceKlass::initialization_error").intValue();
 125 
 126     MISC_REWRITTEN                    = db.lookupIntConstant("InstanceKlass::_misc_rewritten").intValue();
 127     MISC_HAS_NONSTATIC_FIELDS         = db.lookupIntConstant("InstanceKlass::_misc_has_nonstatic_fields").intValue();
 128     MISC_SHOULD_VERIFY_CLASS          = db.lookupIntConstant("InstanceKlass::_misc_should_verify_class").intValue();
 129     MISC_IS_CONTENDED                 = db.lookupIntConstant("InstanceKlass::_misc_is_contended").intValue();
 130     MISC_HAS_NONSTATIC_CONCRETE_METHODS      = db.lookupIntConstant("InstanceKlass::_misc_has_nonstatic_concrete_methods").intValue();
 131     MISC_DECLARES_NONSTATIC_CONCRETE_METHODS = db.lookupIntConstant("InstanceKlass::_misc_declares_nonstatic_concrete_methods").intValue();
 132     MISC_HAS_BEEN_REDEFINED           = db.lookupIntConstant("InstanceKlass::_misc_has_been_redefined").intValue();
 133     MISC_IS_SCRATCH_CLASS             = db.lookupIntConstant("InstanceKlass::_misc_is_scratch_class").intValue();
 134     MISC_IS_SHARED_BOOT_CLASS         = db.lookupIntConstant("InstanceKlass::_misc_is_shared_boot_class").intValue();
 135     MISC_IS_SHARED_PLATFORM_CLASS     = db.lookupIntConstant("InstanceKlass::_misc_is_shared_platform_class").intValue();
 136     MISC_IS_SHARED_APP_CLASS          = db.lookupIntConstant("InstanceKlass::_misc_is_shared_app_class").intValue();


 137   }
 138 
 139   public InstanceKlass(Address addr) {
 140     super(addr);
 141 
 142     // If the class hasn't yet reached the "loaded" init state, then don't go any further
 143     // or we'll run into problems trying to look at fields that are not yet setup.
 144     // Attempted lookups of this InstanceKlass via ClassLoaderDataGraph, ClassLoaderData,
 145     // and Dictionary will all refuse to return it. The main purpose of allowing this
 146     // InstanceKlass to initialize is so ClassLoaderData.getKlasses() will succeed, allowing
 147     // ClassLoaderData.classesDo() to iterate over all Klasses (skipping those that are
 148     // not yet fully loaded).
 149     if (!isLoaded()) {
 150         return;
 151     }
 152 
 153     if (getJavaFieldsCount() != getAllFieldsCount()) {
 154       // Exercise the injected field logic
 155       for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) {
 156         getFieldName(i);

 551                      // exclude anonymous classes.
 552                      return (innerNameIndex != 0);
 553                   }
 554                }
 555             } else {
 556                Symbol outerName = getConstants().getKlassNameAt(ooff);
 557 
 558                // include only if current class is outer class.
 559                if (outerName.equals(myname) && innerName.equals(sym)) {
 560                   return true;
 561                }
 562            }
 563          }
 564        } // for inner classes
 565        return false;
 566     } else {
 567        return false;
 568     }
 569   }
 570 








 571   public boolean implementsInterface(Klass k) {
 572     if (Assert.ASSERTS_ENABLED) {
 573       Assert.that(k.isInterface(), "should not reach here");
 574     }
 575     KlassArray interfaces =  getTransitiveInterfaces();
 576     final int len = interfaces.length();
 577     for (int i = 0; i < len; i++) {
 578       if (interfaces.getAt(i).equals(k)) return true;
 579     }
 580     return false;
 581   }
 582 
 583   boolean computeSubtypeOf(Klass k) {
 584     if (k.isInterface()) {
 585       return implementsInterface(k);
 586     } else {
 587       return super.computeSubtypeOf(k);
 588     }
 589   }
 590 

  60   // ClassState constants
  61   private static int CLASS_STATE_ALLOCATED;
  62   private static int CLASS_STATE_LOADED;
  63   private static int CLASS_STATE_LINKED;
  64   private static int CLASS_STATE_BEING_INITIALIZED;
  65   private static int CLASS_STATE_FULLY_INITIALIZED;
  66   private static int CLASS_STATE_INITIALIZATION_ERROR;
  67 
  68   // _misc_flags constants
  69   private static int MISC_REWRITTEN;
  70   private static int MISC_HAS_NONSTATIC_FIELDS;
  71   private static int MISC_SHOULD_VERIFY_CLASS;
  72   private static int MISC_IS_CONTENDED;
  73   private static int MISC_HAS_NONSTATIC_CONCRETE_METHODS;
  74   private static int MISC_DECLARES_NONSTATIC_CONCRETE_METHODS;
  75   private static int MISC_HAS_BEEN_REDEFINED;
  76   private static int MISC_IS_SCRATCH_CLASS;
  77   private static int MISC_IS_SHARED_BOOT_CLASS;
  78   private static int MISC_IS_SHARED_PLATFORM_CLASS;
  79   private static int MISC_IS_SHARED_APP_CLASS;
  80   private static int MISC_HAS_INJECTED_PRIMITIVEOBJECT;
  81   private static int MISC_HAS_INJECTED_IDENTITYOBJECT;
  82 
  83   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
  84     Type type            = db.lookupType("InstanceKlass");
  85     arrayKlasses         = new MetadataField(type.getAddressField("_array_klasses"), 0);
  86     methods              = type.getAddressField("_methods");
  87     defaultMethods       = type.getAddressField("_default_methods");
  88     methodOrdering       = type.getAddressField("_method_ordering");
  89     localInterfaces      = type.getAddressField("_local_interfaces");
  90     transitiveInterfaces = type.getAddressField("_transitive_interfaces");
  91     fields               = type.getAddressField("_fields");
  92     javaFieldsCount      = new CIntField(type.getCIntegerField("_java_fields_count"), 0);
  93     constants            = new MetadataField(type.getAddressField("_constants"), 0);
  94     sourceDebugExtension = type.getAddressField("_source_debug_extension");
  95     innerClasses         = type.getAddressField("_inner_classes");
  96     nonstaticFieldSize   = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
  97     staticFieldSize      = new CIntField(type.getCIntegerField("_static_field_size"), 0);
  98     staticOopFieldCount  = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
  99     nonstaticOopMapSize  = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
 100     isMarkedDependent    = new CIntField(type.getCIntegerField("_is_marked_dependent"), 0);
 101     initState            = new CIntField(type.getCIntegerField("_init_state"), 0);

 119 
 120     // read ClassState constants
 121     CLASS_STATE_ALLOCATED = db.lookupIntConstant("InstanceKlass::allocated").intValue();
 122     CLASS_STATE_LOADED = db.lookupIntConstant("InstanceKlass::loaded").intValue();
 123     CLASS_STATE_LINKED = db.lookupIntConstant("InstanceKlass::linked").intValue();
 124     CLASS_STATE_BEING_INITIALIZED = db.lookupIntConstant("InstanceKlass::being_initialized").intValue();
 125     CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("InstanceKlass::fully_initialized").intValue();
 126     CLASS_STATE_INITIALIZATION_ERROR = db.lookupIntConstant("InstanceKlass::initialization_error").intValue();
 127 
 128     MISC_REWRITTEN                    = db.lookupIntConstant("InstanceKlass::_misc_rewritten").intValue();
 129     MISC_HAS_NONSTATIC_FIELDS         = db.lookupIntConstant("InstanceKlass::_misc_has_nonstatic_fields").intValue();
 130     MISC_SHOULD_VERIFY_CLASS          = db.lookupIntConstant("InstanceKlass::_misc_should_verify_class").intValue();
 131     MISC_IS_CONTENDED                 = db.lookupIntConstant("InstanceKlass::_misc_is_contended").intValue();
 132     MISC_HAS_NONSTATIC_CONCRETE_METHODS      = db.lookupIntConstant("InstanceKlass::_misc_has_nonstatic_concrete_methods").intValue();
 133     MISC_DECLARES_NONSTATIC_CONCRETE_METHODS = db.lookupIntConstant("InstanceKlass::_misc_declares_nonstatic_concrete_methods").intValue();
 134     MISC_HAS_BEEN_REDEFINED           = db.lookupIntConstant("InstanceKlass::_misc_has_been_redefined").intValue();
 135     MISC_IS_SCRATCH_CLASS             = db.lookupIntConstant("InstanceKlass::_misc_is_scratch_class").intValue();
 136     MISC_IS_SHARED_BOOT_CLASS         = db.lookupIntConstant("InstanceKlass::_misc_is_shared_boot_class").intValue();
 137     MISC_IS_SHARED_PLATFORM_CLASS     = db.lookupIntConstant("InstanceKlass::_misc_is_shared_platform_class").intValue();
 138     MISC_IS_SHARED_APP_CLASS          = db.lookupIntConstant("InstanceKlass::_misc_is_shared_app_class").intValue();
 139     MISC_HAS_INJECTED_PRIMITIVEOBJECT = db.lookupIntConstant("InstanceKlass::_misc_has_injected_primitiveObject").intValue();
 140     MISC_HAS_INJECTED_IDENTITYOBJECT  = db.lookupIntConstant("InstanceKlass::_misc_has_injected_identityObject").intValue();
 141   }
 142 
 143   public InstanceKlass(Address addr) {
 144     super(addr);
 145 
 146     // If the class hasn't yet reached the "loaded" init state, then don't go any further
 147     // or we'll run into problems trying to look at fields that are not yet setup.
 148     // Attempted lookups of this InstanceKlass via ClassLoaderDataGraph, ClassLoaderData,
 149     // and Dictionary will all refuse to return it. The main purpose of allowing this
 150     // InstanceKlass to initialize is so ClassLoaderData.getKlasses() will succeed, allowing
 151     // ClassLoaderData.classesDo() to iterate over all Klasses (skipping those that are
 152     // not yet fully loaded).
 153     if (!isLoaded()) {
 154         return;
 155     }
 156 
 157     if (getJavaFieldsCount() != getAllFieldsCount()) {
 158       // Exercise the injected field logic
 159       for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) {
 160         getFieldName(i);

 555                      // exclude anonymous classes.
 556                      return (innerNameIndex != 0);
 557                   }
 558                }
 559             } else {
 560                Symbol outerName = getConstants().getKlassNameAt(ooff);
 561 
 562                // include only if current class is outer class.
 563                if (outerName.equals(myname) && innerName.equals(sym)) {
 564                   return true;
 565                }
 566            }
 567          }
 568        } // for inner classes
 569        return false;
 570     } else {
 571        return false;
 572     }
 573   }
 574 
 575   public boolean hasInjectedIdentityObject() {
 576     return (getMiscFlags() & MISC_HAS_INJECTED_IDENTITYOBJECT) != 0;
 577   }
 578 
 579   public boolean hasInjectedPrimitiveObject() {
 580     return (getMiscFlags() & MISC_HAS_INJECTED_PRIMITIVEOBJECT) != 0;
 581   }
 582 
 583   public boolean implementsInterface(Klass k) {
 584     if (Assert.ASSERTS_ENABLED) {
 585       Assert.that(k.isInterface(), "should not reach here");
 586     }
 587     KlassArray interfaces =  getTransitiveInterfaces();
 588     final int len = interfaces.length();
 589     for (int i = 0; i < len; i++) {
 590       if (interfaces.getAt(i).equals(k)) return true;
 591     }
 592     return false;
 593   }
 594 
 595   boolean computeSubtypeOf(Klass k) {
 596     if (k.isInterface()) {
 597       return implementsInterface(k);
 598     } else {
 599       return super.computeSubtypeOf(k);
 600     }
 601   }
 602 
< prev index next >