hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java
author jiangli
Thu, 29 Mar 2012 22:18:56 -0400
changeset 12369 48fd3da4025c
parent 12231 6a9cfc59a18a
child 12772 d317e5e08194
permissions -rw-r--r--
7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass. Summary: Change implementor to embedded instanceKlass field. Reviewed-by: sspitsyn, minqi, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12369
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 12231
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    21
 * questions.
1
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.oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// An InstanceKlass is the VM level representation of a Java class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
public class InstanceKlass extends Klass {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // field offset constants
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    47
  private static int ACCESS_FLAGS_OFFSET;
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    48
  private static int NAME_INDEX_OFFSET;
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    49
  private static int SIGNATURE_INDEX_OFFSET;
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    50
  private static int INITVAL_INDEX_OFFSET;
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    51
  private static int LOW_OFFSET;
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    52
  private static int HIGH_OFFSET;
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    53
  private static int GENERIC_SIGNATURE_INDEX_OFFSET;
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
    54
  private static int FIELD_SLOTS;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // ClassState constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  private static int CLASS_STATE_UNPARSABLE_BY_GC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private static int CLASS_STATE_ALLOCATED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  private static int CLASS_STATE_LOADED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  private static int CLASS_STATE_LINKED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  private static int CLASS_STATE_BEING_INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private static int CLASS_STATE_FULLY_INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  private static int CLASS_STATE_INITIALIZATION_ERROR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    Type type            = db.lookupType("instanceKlass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    arrayKlasses         = new OopField(type.getOopField("_array_klasses"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    methods              = new OopField(type.getOopField("_methods"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    methodOrdering       = new OopField(type.getOopField("_method_ordering"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    localInterfaces      = new OopField(type.getOopField("_local_interfaces"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    transitiveInterfaces = new OopField(type.getOopField("_transitive_interfaces"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    fields               = new OopField(type.getOopField("_fields"), Oop.getHeaderSize());
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
    73
    javaFieldsCount      = new CIntField(type.getCIntegerField("_java_fields_count"), Oop.getHeaderSize());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    constants            = new OopField(type.getOopField("_constants"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    classLoader          = new OopField(type.getOopField("_class_loader"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    protectionDomain     = new OopField(type.getOopField("_protection_domain"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    signers              = new OopField(type.getOopField("_signers"), Oop.getHeaderSize());
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
    78
    sourceFileName       = type.getAddressField("_source_file_name");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
    79
    sourceDebugExtension = type.getAddressField("_source_debug_extension");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    innerClasses         = new OopField(type.getOopField("_inner_classes"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    nonstaticFieldSize   = new CIntField(type.getCIntegerField("_nonstatic_field_size"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    staticFieldSize      = new CIntField(type.getCIntegerField("_static_field_size"), Oop.getHeaderSize());
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
    83
    staticOopFieldCount   = new CIntField(type.getCIntegerField("_static_oop_field_count"), Oop.getHeaderSize());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    nonstaticOopMapSize  = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), Oop.getHeaderSize());
11440
dea12ec80745 7129240: backout fix for 7102776 until 7128770 is resolved
dcubed
parents: 11405
diff changeset
    85
    isMarkedDependent    = new CIntField(type.getCIntegerField("_is_marked_dependent"), Oop.getHeaderSize());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    initState            = new CIntField(type.getCIntegerField("_init_state"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    vtableLen            = new CIntField(type.getCIntegerField("_vtable_len"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    itableLen            = new CIntField(type.getCIntegerField("_itable_len"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    breakpoints          = type.getAddressField("_breakpoints");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
    90
    genericSignature     = type.getAddressField("_generic_signature");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    majorVersion         = new CIntField(type.getCIntegerField("_major_version"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    minorVersion         = new CIntField(type.getCIntegerField("_minor_version"), Oop.getHeaderSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    headerSize           = alignObjectOffset(Oop.getHeaderSize() + type.getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    // read field offset constants
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
    96
    ACCESS_FLAGS_OFFSET            = db.lookupIntConstant("FieldInfo::access_flags_offset").intValue();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
    97
    NAME_INDEX_OFFSET              = db.lookupIntConstant("FieldInfo::name_index_offset").intValue();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
    98
    SIGNATURE_INDEX_OFFSET         = db.lookupIntConstant("FieldInfo::signature_index_offset").intValue();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
    99
    INITVAL_INDEX_OFFSET           = db.lookupIntConstant("FieldInfo::initval_index_offset").intValue();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   100
    LOW_OFFSET                     = db.lookupIntConstant("FieldInfo::low_offset").intValue();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   101
    HIGH_OFFSET                    = db.lookupIntConstant("FieldInfo::high_offset").intValue();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   102
    GENERIC_SIGNATURE_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::generic_signature_offset").intValue();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   103
    FIELD_SLOTS                    = db.lookupIntConstant("FieldInfo::field_slots").intValue();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // read ClassState constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    CLASS_STATE_UNPARSABLE_BY_GC = db.lookupIntConstant("instanceKlass::unparsable_by_gc").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    CLASS_STATE_ALLOCATED = db.lookupIntConstant("instanceKlass::allocated").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    CLASS_STATE_LOADED = db.lookupIntConstant("instanceKlass::loaded").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    CLASS_STATE_LINKED = db.lookupIntConstant("instanceKlass::linked").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    CLASS_STATE_BEING_INITIALIZED = db.lookupIntConstant("instanceKlass::being_initialized").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("instanceKlass::fully_initialized").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    CLASS_STATE_INITIALIZATION_ERROR = db.lookupIntConstant("instanceKlass::initialization_error").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  InstanceKlass(OopHandle handle, ObjectHeap heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    super(handle, heap);
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   117
    if (getJavaFieldsCount() != getAllFieldsCount()) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   118
      // Exercise the injected field logic
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   119
      for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   120
        getFieldName(i);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   121
        getFieldSignature(i);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   122
      }
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   123
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  private static OopField  arrayKlasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  private static OopField  methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  private static OopField  methodOrdering;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  private static OopField  localInterfaces;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  private static OopField  transitiveInterfaces;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  private static OopField  fields;
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   132
  private static CIntField javaFieldsCount;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  private static OopField  constants;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  private static OopField  classLoader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  private static OopField  protectionDomain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  private static OopField  signers;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   137
  private static AddressField  sourceFileName;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   138
  private static AddressField  sourceDebugExtension;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  private static OopField  innerClasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  private static CIntField nonstaticFieldSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  private static CIntField staticFieldSize;
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
   142
  private static CIntField staticOopFieldCount;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  private static CIntField nonstaticOopMapSize;
11440
dea12ec80745 7129240: backout fix for 7102776 until 7128770 is resolved
dcubed
parents: 11405
diff changeset
   144
  private static CIntField isMarkedDependent;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  private static CIntField initState;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  private static CIntField vtableLen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  private static CIntField itableLen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  private static AddressField breakpoints;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   149
  private static AddressField  genericSignature;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  private static CIntField majorVersion;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  private static CIntField minorVersion;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // type safe enum for ClassState from instanceKlass.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  public static class ClassState {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
     public static final ClassState UNPARSABLE_BY_GC = new ClassState("unparsable_by_gc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
     public static final ClassState ALLOCATED    = new ClassState("allocated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
     public static final ClassState LOADED       = new ClassState("loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
     public static final ClassState LINKED       = new ClassState("linked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
     public static final ClassState BEING_INITIALIZED      = new ClassState("beingInitialized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
     public static final ClassState FULLY_INITIALIZED    = new ClassState("fullyInitialized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
     public static final ClassState INITIALIZATION_ERROR = new ClassState("initializationError");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
     private ClassState(String value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        this.value = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
     public String toString() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        return value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
     private String value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   174
  public int  getInitStateAsInt() { return (int) initState.getValue(this); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  public ClassState getInitState() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
     int state = getInitStateAsInt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
     if (state == CLASS_STATE_UNPARSABLE_BY_GC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        return ClassState.UNPARSABLE_BY_GC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
     } else if (state == CLASS_STATE_ALLOCATED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        return ClassState.ALLOCATED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
     } else if (state == CLASS_STATE_LOADED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        return ClassState.LOADED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
     } else if (state == CLASS_STATE_LINKED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        return ClassState.LINKED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
     } else if (state == CLASS_STATE_BEING_INITIALIZED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        return ClassState.BEING_INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
     } else if (state == CLASS_STATE_FULLY_INITIALIZED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        return ClassState.FULLY_INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
     } else if (state == CLASS_STATE_INITIALIZATION_ERROR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        return ClassState.INITIALIZATION_ERROR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
     } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // initialization state quaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  public boolean isLoaded() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
     return getInitStateAsInt() >= CLASS_STATE_LOADED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  public boolean isLinked() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
     return getInitStateAsInt() >= CLASS_STATE_LINKED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  public boolean isInitialized() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
     return getInitStateAsInt() == CLASS_STATE_FULLY_INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  public boolean isNotInitialized() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
     return getInitStateAsInt() < CLASS_STATE_BEING_INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  public boolean isBeingInitialized() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
     return getInitStateAsInt() == CLASS_STATE_BEING_INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  public boolean isInErrorState() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
     return getInitStateAsInt() == CLASS_STATE_INITIALIZATION_ERROR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  public int getClassStatus() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
     int result = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
     if (isLinked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        result |= JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
     if (isInitialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
           Assert.that(isLinked(), "Class status is not consistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        result |= JVMDIClassStatus.INITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
     if (isInErrorState()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        result |= JVMDIClassStatus.ERROR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
     return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // Byteside of the header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  private static long headerSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   243
  public long getObjectSize(Oop object) {
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   244
    return getSizeHelper() * VM.getVM().getAddressSize();
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   245
  }
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   246
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  public static long getHeaderSize() { return headerSize; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   249
  public short getFieldAccessFlags(int index) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   250
    return getFields().getShortAt(index * FIELD_SLOTS + ACCESS_FLAGS_OFFSET);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   251
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   252
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   253
  public short getFieldNameIndex(int index) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   254
    if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   255
    return getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   256
  }
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   257
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   258
  public Symbol getFieldName(int index) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   259
    int nameIndex = getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   260
    if (index < getJavaFieldsCount()) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   261
      return getConstants().getSymbolAt(nameIndex);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   262
    } else {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   263
      return vmSymbols.symbolAt(nameIndex);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   264
    }
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   265
  }
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   266
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   267
  public short getFieldSignatureIndex(int index) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   268
    if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   269
    return getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET);
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   270
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   271
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   272
  public Symbol getFieldSignature(int index) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   273
    int signatureIndex = getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET);
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   274
    if (index < getJavaFieldsCount()) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   275
      return getConstants().getSymbolAt(signatureIndex);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   276
    } else {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   277
      return vmSymbols.symbolAt(signatureIndex);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   278
    }
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   279
  }
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   280
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   281
  public short getFieldGenericSignatureIndex(int index) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   282
    return getFields().getShortAt(index * FIELD_SLOTS + GENERIC_SIGNATURE_INDEX_OFFSET);
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   283
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   284
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   285
  public Symbol getFieldGenericSignature(int index) {
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   286
    short genericSignatureIndex = getFieldGenericSignatureIndex(index);
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   287
    if (genericSignatureIndex != 0)  {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   288
      return getConstants().getSymbolAt(genericSignatureIndex);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   289
    }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   290
    return null;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   291
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   292
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   293
  public short getFieldInitialValueIndex(int index) {
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   294
    if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   295
    return getFields().getShortAt(index * FIELD_SLOTS + INITVAL_INDEX_OFFSET);
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   296
  }
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   297
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   298
  public int getFieldOffset(int index) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   299
    TypeArray fields = getFields();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   300
    return VM.getVM().buildIntFromShorts(fields.getShortAt(index * FIELD_SLOTS + LOW_OFFSET),
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   301
                                         fields.getShortAt(index * FIELD_SLOTS + HIGH_OFFSET));
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   302
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   303
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Accessors for declared fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  public Klass     getArrayKlasses()        { return (Klass)        arrayKlasses.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  public ObjArray  getMethods()             { return (ObjArray)     methods.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  public TypeArray getMethodOrdering()      { return (TypeArray)    methodOrdering.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  public ObjArray  getLocalInterfaces()     { return (ObjArray)     localInterfaces.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  public ObjArray  getTransitiveInterfaces() { return (ObjArray)     transitiveInterfaces.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  public TypeArray getFields()              { return (TypeArray)    fields.getValue(this); }
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   311
  public int       getJavaFieldsCount()     { return                (int) javaFieldsCount.getValue(this); }
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   312
  public int       getAllFieldsCount()      { return                (int)getFields().getLength() / FIELD_SLOTS; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  public ConstantPool getConstants()        { return (ConstantPool) constants.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  public Oop       getClassLoader()         { return                classLoader.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  public Oop       getProtectionDomain()    { return                protectionDomain.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  public ObjArray  getSigners()             { return (ObjArray)     signers.getValue(this); }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   317
  public Symbol    getSourceFileName()      { return getSymbol(sourceFileName); }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   318
  public Symbol    getSourceDebugExtension(){ return getSymbol(sourceDebugExtension); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  public TypeArray getInnerClasses()        { return (TypeArray)    innerClasses.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  public long      getNonstaticFieldSize()  { return                nonstaticFieldSize.getValue(this); }
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
   321
  public long      getStaticOopFieldCount() { return                staticOopFieldCount.getValue(this); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  public long      getNonstaticOopMapSize() { return                nonstaticOopMapSize.getValue(this); }
11440
dea12ec80745 7129240: backout fix for 7102776 until 7128770 is resolved
dcubed
parents: 11405
diff changeset
   323
  public boolean   getIsMarkedDependent()   { return                isMarkedDependent.getValue(this) != 0; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  public long      getVtableLen()           { return                vtableLen.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  public long      getItableLen()           { return                itableLen.getValue(this); }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   326
  public Symbol    getGenericSignature()    { return getSymbol(genericSignature); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  public long      majorVersion()           { return                majorVersion.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  public long      minorVersion()           { return                minorVersion.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  // "size helper" == instance size in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  public long getSizeHelper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    int lh = getLayoutHelper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      Assert.that(lh > 0, "layout helper initialized for instance class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    return lh / VM.getVM().getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  // same as enum InnerClassAttributeOffset in VM code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  public static interface InnerClassAttributeOffset {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    // from JVM spec. "InnerClasses" attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    public static final int innerClassInnerClassInfoOffset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    public static final int innerClassOuterClassInfoOffset = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    public static final int innerClassInnerNameOffset = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    public static final int innerClassAccessFlagsOffset = 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    public static final int innerClassNextOffset = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   349
  public static interface EnclosingMethodAttributeOffset {
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   350
    public static final int enclosing_method_class_index_offset = 0;
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   351
    public static final int enclosing_method_method_index_offset = 1;
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   352
    public static final int enclosing_method_attribute_size = 2;
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   353
  };
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   354
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // refer to compute_modifier_flags in VM code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  public long computeModifierFlags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    long access = getAccessFlags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    // But check if it happens to be member class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    TypeArray innerClassList = getInnerClasses();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    int length = ( innerClassList == null)? 0 : (int) innerClassList.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    if (length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
       if (Assert.ASSERTS_ENABLED) {
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   363
          Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0 ||
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   364
                      length % InnerClassAttributeOffset.innerClassNextOffset == EnclosingMethodAttributeOffset.enclosing_method_attribute_size,
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   365
                      "just checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
       for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) {
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   368
          if (i == length - EnclosingMethodAttributeOffset.enclosing_method_attribute_size) {
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   369
              break;
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   370
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
          int ioff = innerClassList.getShortAt(i +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                         InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
          // 'ioff' can be zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
          // refer to JVM spec. section 4.7.5.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
          if (ioff != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
             // only look at classes that are already loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
             // since we are looking for the flags for our self.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   378
             ConstantPool.CPSlot classInfo = getConstants().getSlotAt(ioff);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
             Symbol name = null;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   380
             if (classInfo.isOop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   381
               name = ((Klass) classInfo.getOop()).getName();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   382
             } else if (classInfo.isMetaData()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   383
               name = classInfo.getSymbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
             } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
                throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
             if (name.equals(getName())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
                // This is really a member class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
                access = innerClassList.getShortAt(i +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                        InnerClassAttributeOffset.innerClassAccessFlagsOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
       } // for inner classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    // Remember to strip ACC_SUPER bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // whether given Symbol is name of an inner/nested Klass of this Klass?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  // anonymous and local classes are excluded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  public boolean isInnerClassName(Symbol sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    return isInInnerClasses(sym, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // whether given Symbol is name of an inner/nested Klass of this Klass?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // anonymous classes excluded, but local classes are included.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  public boolean isInnerOrLocalClassName(Symbol sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    return isInInnerClasses(sym, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  private boolean isInInnerClasses(Symbol sym, boolean includeLocals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    TypeArray innerClassList = getInnerClasses();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    int length = ( innerClassList == null)? 0 : (int) innerClassList.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    if (length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
       if (Assert.ASSERTS_ENABLED) {
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   420
         Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0 ||
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   421
                     length % InnerClassAttributeOffset.innerClassNextOffset == EnclosingMethodAttributeOffset.enclosing_method_attribute_size,
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   422
                     "just checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
       for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) {
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   425
         if (i == length - EnclosingMethodAttributeOffset.enclosing_method_attribute_size) {
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   426
             break;
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11440
diff changeset
   427
         }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
         int ioff = innerClassList.getShortAt(i +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
                        InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
         // 'ioff' can be zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
         // refer to JVM spec. section 4.7.5.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
         if (ioff != 0) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   433
            ConstantPool.CPSlot iclassInfo = getConstants().getSlotAt(ioff);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
            Symbol innerName = null;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   435
            if (iclassInfo.isOop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   436
              innerName = ((Klass) iclassInfo.getOop()).getName();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   437
            } else if (iclassInfo.isMetaData()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   438
              innerName = iclassInfo.getSymbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
               throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
            Symbol myname = getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
            int ooff = innerClassList.getShortAt(i +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
                        InnerClassAttributeOffset.innerClassOuterClassInfoOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
            // for anonymous classes inner_name_index of InnerClasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
            // attribute is zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
            int innerNameIndex = innerClassList.getShortAt(i +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                        InnerClassAttributeOffset.innerClassInnerNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
            // if this is not a member (anonymous, local etc.), 'ooff' will be zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
            // refer to JVM spec. section 4.7.5.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
            if (ooff == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
               if (includeLocals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
                  // does it looks like my local class?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
                  if (innerName.equals(sym) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
                     innerName.asString().startsWith(myname.asString())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
                     // exclude anonymous classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
                     return (innerNameIndex != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
            } else {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   462
               ConstantPool.CPSlot oclassInfo = getConstants().getSlotAt(ooff);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
               Symbol outerName = null;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   464
               if (oclassInfo.isOop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   465
                 outerName = ((Klass) oclassInfo.getOop()).getName();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   466
               } else if (oclassInfo.isMetaData()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   467
                 outerName = oclassInfo.getSymbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
               } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
                  throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
               // include only if current class is outer class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
               if (outerName.equals(myname) && innerName.equals(sym)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
                  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
       } // for inner classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
       return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
       return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  public boolean implementsInterface(Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
      Assert.that(k.isInterface(), "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    ObjArray interfaces =  getTransitiveInterfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    final int len = (int) interfaces.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
      if (interfaces.getObjAt(i).equals(k)) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  boolean computeSubtypeOf(Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    if (k.isInterface()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
      return implementsInterface(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
      return super.computeSubtypeOf(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  public void printValueOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    tty.print("InstanceKlass for " + getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  public void iterateFields(OopVisitor visitor, boolean doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    super.iterateFields(visitor, doVMFields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    if (doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
      visitor.doOop(arrayKlasses, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
      visitor.doOop(methods, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      visitor.doOop(methodOrdering, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
      visitor.doOop(localInterfaces, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
      visitor.doOop(transitiveInterfaces, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
      visitor.doOop(fields, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      visitor.doOop(constants, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      visitor.doOop(classLoader, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      visitor.doOop(protectionDomain, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      visitor.doOop(signers, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
      visitor.doOop(innerClasses, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      visitor.doCInt(nonstaticFieldSize, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
      visitor.doCInt(staticFieldSize, true);
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
   525
      visitor.doCInt(staticOopFieldCount, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      visitor.doCInt(nonstaticOopMapSize, true);
11440
dea12ec80745 7129240: backout fix for 7102776 until 7128770 is resolved
dcubed
parents: 11405
diff changeset
   527
      visitor.doCInt(isMarkedDependent, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      visitor.doCInt(initState, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      visitor.doCInt(vtableLen, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      visitor.doCInt(itableLen, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    }
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   532
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   534
  /*
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   535
   *  Visit the static fields of this InstanceKlass with the obj of
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   536
   *  the visitor set to the oop holding the fields, which is
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   537
   *  currently the java mirror.
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   538
   */
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   539
  public void iterateStaticFields(OopVisitor visitor) {
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   540
    visitor.setObj(getJavaMirror());
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   541
    visitor.prologue();
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   542
    iterateStaticFieldsInternal(visitor);
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   543
    visitor.epilogue();
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   544
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   545
  }
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   546
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   547
  void iterateStaticFieldsInternal(OopVisitor visitor) {
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   548
    int length = getJavaFieldsCount();
10552
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   549
    for (int index = 0; index < length; index++) {
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   550
      short accessFlags    = getFieldAccessFlags(index);
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   551
      FieldType   type   = new FieldType(getFieldSignature(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      AccessFlags access = new AccessFlags(accessFlags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      if (access.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
        visitField(visitor, type, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  public Klass getJavaSuper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    return getSuper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   563
  public static class StaticField {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   564
    public AccessFlags flags;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   565
    public Field field;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   566
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   567
    StaticField(Field field, AccessFlags flags) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   568
      this.field = field;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   569
      this.flags = flags;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   570
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   571
  }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10546
diff changeset
   572
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   573
  public void iterateNonStaticFields(OopVisitor visitor, Oop obj) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    if (getSuper() != null) {
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 8725
diff changeset
   575
      ((InstanceKlass) getSuper()).iterateNonStaticFields(visitor, obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    }
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   577
    int length = getJavaFieldsCount();
10552
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   578
    for (int index = 0; index < length; index++) {
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   579
      short accessFlags    = getFieldAccessFlags(index);
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   580
      FieldType   type   = new FieldType(getFieldSignature(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      AccessFlags access = new AccessFlags(accessFlags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
      if (!access.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
        visitField(visitor, type, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  /** Field access by name. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  public Field findLocalField(Symbol name, Symbol sig) {
10567
149651837c4a 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 10552
diff changeset
   590
    int length = getJavaFieldsCount();
10552
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   591
    for (int i = 0; i < length; i++) {
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   592
      Symbol f_name = getFieldName(i);
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   593
      Symbol f_sig  = getFieldSignature(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
      if (name.equals(f_name) && sig.equals(f_sig)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
        return newField(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  /** Find field in direct superinterfaces. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  public Field findInterfaceField(Symbol name, Symbol sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    ObjArray interfaces = getLocalInterfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    int n = (int) interfaces.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    for (int i = 0; i < n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
        Assert.that(intf1.isInterface(), "just checking type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      // search for field in current interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      Field f = intf1.findLocalField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
      if (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
          Assert.that(f.getAccessFlagsObj().isStatic(), "interface field must be static");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
        return f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
      // search for field in direct superinterfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
      f = intf1.findInterfaceField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
      if (f != null) return f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    // otherwise field lookup fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  /** Find field according to JVM spec 5.4.3.2, returns the klass in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
      which the field is defined. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  public Field findField(Symbol name, Symbol sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    // search order according to newest JVM spec (5.4.3.2, p.167).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    // 1) search for field in current klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    Field f = findLocalField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    if (f != null) return f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    // 2) search for field recursively in direct superinterfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    f = findInterfaceField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    if (f != null) return f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    // 3) apply field lookup recursively if superclass exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    InstanceKlass supr = (InstanceKlass) getSuper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    if (supr != null) return supr.findField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    // 4) otherwise field lookup fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  /** Find field according to JVM spec 5.4.3.2, returns the klass in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
      which the field is defined (convenience routine) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  public Field findField(String name, String sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    SymbolTable symbols = VM.getVM().getSymbolTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    Symbol nameSym = symbols.probe(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    Symbol sigSym  = symbols.probe(sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    if (nameSym == null || sigSym == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    return findField(nameSym, sigSym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  /** Find field according to JVM spec 5.4.3.2, returns the klass in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      which the field is defined (retained only for backward
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      compatibility with jdbx) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  public Field findFieldDbg(String name, String sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    return findField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  /** Get field by its index in the fields array. Only designed for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      use in a debugging system. */
10552
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   668
  public Field getFieldByIndex(int fieldIndex) {
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   669
    return newField(fieldIndex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    /** Return a List of SA Fields for the fields declared in this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
        Inherited fields are not included.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
        Return an empty list if there are no fields declared in this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
        Only designed for use in a debugging system. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    public List getImmediateFields() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
        // A list of Fields for each field declared in this class/interface,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
        // not including inherited fields.
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   680
        int length = getJavaFieldsCount();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8878
diff changeset
   681
        List immediateFields = new ArrayList(length);
10552
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   682
        for (int index = 0; index < length; index++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
            immediateFields.add(getFieldByIndex(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
        return immediateFields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    /** Return a List of SA Fields for all the java fields in this class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
        including all inherited fields.  This includes hidden
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
        fields.  Thus the returned list can contain fields with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
        the same name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
        Return an empty list if there are no fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
        Only designed for use in a debugging system. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
    public List getAllFields() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
        // Contains a Field for each field in this class, including immediate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
        // fields and inherited fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
        List  allFields = getImmediateFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
        // transitiveInterfaces contains all interfaces implemented
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
        // by this class and its superclass chain with no duplicates.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
        ObjArray interfaces = getTransitiveInterfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
        int n = (int) interfaces.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
        for (int i = 0; i < n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
            InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
            if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
                Assert.that(intf1.isInterface(), "just checking type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
            allFields.addAll(intf1.getImmediateFields());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
        // Get all fields in the superclass, recursively.  But, don't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
        // include fields in interfaces implemented by superclasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
        // we already have all those.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
        if (!isInterface()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
            InstanceKlass supr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
            if  ( (supr = (InstanceKlass) getSuper()) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
                allFields.addAll(supr.getImmediateFields());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
        return allFields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    /** Return a List of SA Methods declared directly in this class/interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
        Return an empty list if there are none, or if this isn't a class/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
        interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    public List getImmediateMethods() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
      // Contains a Method for each method declared in this class/interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
      // not including inherited methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
      ObjArray methods = getMethods();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
      int length = (int)methods.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
      Object[] tmp = new Object[length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
      TypeArray methodOrdering = getMethodOrdering();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
      if (methodOrdering.getLength() != length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
         // no ordering info present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
         for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
            tmp[index] = methods.getObjAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
         for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
            int originalIndex = getMethodOrdering().getIntAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
            tmp[originalIndex] = methods.getObjAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
      return Arrays.asList(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    /** Return a List containing an SA InstanceKlass for each
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
        interface named in this class's 'implements' clause.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    public List getDirectImplementedInterfaces() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
        // Contains an InstanceKlass for each interface in this classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
        // 'implements' clause.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
        ObjArray interfaces = getLocalInterfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
        int length = (int) interfaces.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
        List directImplementedInterfaces = new ArrayList(length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
        for (int index = 0; index < length; index ++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
            directImplementedInterfaces.add(interfaces.getObjAt(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
        return directImplementedInterfaces;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  public long getObjectSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    long bodySize =    alignObjectOffset(getVtableLen() * getHeap().getOopSize())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
                     + alignObjectOffset(getItableLen() * getHeap().getOopSize())
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
   777
                     + (getNonstaticOopMapSize()) * getHeap().getOopSize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    return alignObjectSize(headerSize + bodySize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  public Klass arrayKlassImpl(boolean orNull, int n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
    // FIXME: in reflective system this would need to change to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    // actually allocate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    if (getArrayKlasses() == null) { return null; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    ObjArrayKlass oak = (ObjArrayKlass) getArrayKlasses();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    if (orNull) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
      return oak.arrayKlassOrNull(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    return oak.arrayKlass(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  public Klass arrayKlassImpl(boolean orNull) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    return arrayKlassImpl(orNull, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  public String signature() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
     return "L" + super.signature() + ";";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  /** Convenience routine taking Strings; lookup is done in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      SymbolTable. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  public Method findMethod(String name, String sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    SymbolTable syms = VM.getVM().getSymbolTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    Symbol nameSym = syms.probe(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    Symbol sigSym  = syms.probe(sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    if (nameSym == null || sigSym == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    return findMethod(nameSym, sigSym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  /** Find method in vtable. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  public Method findMethod(Symbol name, Symbol sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    return findMethod(getMethods(), name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  /** Breakpoint support (see methods on methodOop for details) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  public BreakpointInfo getBreakpoints() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
    Address addr = getHandle().getAddressAt(Oop.getHeaderSize() + breakpoints.getOffset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    return (BreakpointInfo) VMObjectFactory.newObject(BreakpointInfo.class, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  private void visitField(OopVisitor visitor, FieldType type, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    Field f = newField(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    if (type.isOop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
      visitor.doOop((OopField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    if (type.isByte()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
      visitor.doByte((ByteField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    if (type.isChar()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
      visitor.doChar((CharField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    if (type.isDouble()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
      visitor.doDouble((DoubleField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    if (type.isFloat()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      visitor.doFloat((FloatField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    if (type.isInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
      visitor.doInt((IntField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    if (type.isLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
      visitor.doLong((LongField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    if (type.isShort()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
      visitor.doShort((ShortField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    if (type.isBoolean()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
      visitor.doBoolean((BooleanField) f, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  // Creates new field from index in fields TypeArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  private Field newField(int index) {
10552
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10547
diff changeset
   869
    FieldType type = new FieldType(getFieldSignature(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    if (type.isOop()) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   871
     if (VM.getVM().isCompressedOopsEnabled()) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   872
        return new NarrowOopField(this, index);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   873
     } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   874
        return new OopField(this, index);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   875
     }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
    if (type.isByte()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
      return new ByteField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    if (type.isChar()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
      return new CharField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    if (type.isDouble()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
      return new DoubleField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    if (type.isFloat()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
      return new FloatField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
    if (type.isInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
      return new IntField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    if (type.isLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
      return new LongField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
    if (type.isShort()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      return new ShortField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
    if (type.isBoolean()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
      return new BooleanField(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    throw new RuntimeException("Illegal field type at index " + index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  private static Method findMethod(ObjArray methods, Symbol name, Symbol signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
    int len = (int) methods.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    // methods are sorted, so do binary search
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
    int l = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    int h = len - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    while (l <= h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      int mid = (l + h) >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      Method m = (Method) methods.getObjAt(mid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
      int res = m.getName().fastCompare(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
      if (res == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
        // found matching name; do linear search to find matching signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
        // first, quick check for common case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
        if (m.getSignature().equals(signature)) return m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
        // search downwards through overloaded methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
        int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
        for (i = mid - 1; i >= l; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
          Method m1 = (Method) methods.getObjAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
          if (!m1.getName().equals(name)) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
          if (m1.getSignature().equals(signature)) return m1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
        // search upwards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
        for (i = mid + 1; i <= h; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
          Method m1 = (Method) methods.getObjAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
          if (!m1.getName().equals(name)) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
          if (m1.getSignature().equals(signature)) return m1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
        // not found
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
          int index = linearSearch(methods, name, signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
          if (index != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
            throw new DebuggerException("binary search bug: should have found entry " + index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
        return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
      } else if (res < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
        l = mid + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
        h = mid - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
      int index = linearSearch(methods, name, signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
      if (index != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
        throw new DebuggerException("binary search bug: should have found entry " + index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  private static int linearSearch(ObjArray methods, Symbol name, Symbol signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    int len = (int) methods.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    for (int index = 0; index < len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      Method m = (Method) methods.getObjAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
      if (m.getSignature().equals(signature) && m.getName().equals(name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
        return index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
}