hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/Method.java
author never
Thu, 21 Jul 2011 08:38:25 -0700
changeset 10251 71b8938a2821
parent 8921 14bfe81f2a9d
child 10547 ea4a2ec31ae2
permissions -rw-r--r--
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries Reviewed-by: kvn, twisti, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8076
diff changeset
     2
 * Copyright (c) 2000, 2011, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.interpreter.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// A Method represents a Java method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
public class Method extends Oop {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    Type type                  = db.lookupType("methodOopDesc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    constMethod                = new OopField(type.getOopField("_constMethod"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    constants                  = new OopField(type.getOopField("_constants"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    methodSize                 = new CIntField(type.getCIntegerField("_method_size"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    maxStack                   = new CIntField(type.getCIntegerField("_max_stack"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    maxLocals                  = new CIntField(type.getCIntegerField("_max_locals"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    sizeOfParameters           = new CIntField(type.getCIntegerField("_size_of_parameters"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    accessFlags                = new CIntField(type.getCIntegerField("_access_flags"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    code                       = type.getAddressField("_code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    vtableIndex                = new CIntField(type.getCIntegerField("_vtable_index"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      invocationCounter        = new CIntField(type.getCIntegerField("_invocation_counter"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    bytecodeOffset = type.getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    interpreterEntry           = type.getAddressField("_interpreter_entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    fromCompiledCodeEntryPoint = type.getAddressField("_from_compiled_code_entry_point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    objectInitializerName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    classInitializerName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  Method(OopHandle handle, ObjectHeap heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    super(handle, heap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  public boolean isMethod()            { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  private static OopField  constMethod;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  private static OopField  constants;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  private static CIntField methodSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  private static CIntField maxStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  private static CIntField maxLocals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  private static CIntField sizeOfParameters;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  private static CIntField accessFlags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  private static CIntField vtableIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  private static CIntField invocationCounter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  private static long      bytecodeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  private static AddressField       code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // constant method names - <init>, <clinit>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Initialized lazily to avoid initialization ordering dependencies between Method and SymbolTable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  private static Symbol objectInitializerName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  private static Symbol classInitializerName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  private static Symbol objectInitializerName() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    if (objectInitializerName == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      objectInitializerName = VM.getVM().getSymbolTable().probe("<init>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    return objectInitializerName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  private static Symbol classInitializerName() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (classInitializerName == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      classInitializerName = VM.getVM().getSymbolTable().probe("<clinit>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return classInitializerName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  private static AddressCField       interpreterEntry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  private static AddressCField       fromCompiledCodeEntryPoint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Accessors for declared fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  public ConstMethod  getConstMethod()                { return (ConstMethod)  constMethod.getValue(this);       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  public ConstantPool getConstants()                  { return (ConstantPool) constants.getValue(this);         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  public TypeArray    getExceptionTable()             { return getConstMethod().getExceptionTable();            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  /** WARNING: this is in words, not useful in this system; use getObjectSize() instead */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  public long         getMethodSize()                 { return                methodSize.getValue(this);        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  public long         getMaxStack()                   { return                maxStack.getValue(this);          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  public long         getMaxLocals()                  { return                maxLocals.getValue(this);         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  public long         getSizeOfParameters()           { return                sizeOfParameters.getValue(this);  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  public long         getNameIndex()                  { return                getConstMethod().getNameIndex();  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  public long         getSignatureIndex()             { return            getConstMethod().getSignatureIndex(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  public long         getGenericSignatureIndex()      { return     getConstMethod().getGenericSignatureIndex(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  public long         getAccessFlags()                { return                accessFlags.getValue(this);       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  public long         getCodeSize()                   { return                getConstMethod().getCodeSize();   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  public long         getVtableIndex()                { return                vtableIndex.getValue(this);       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  public long         getInvocationCounter()          {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      Assert.that(!VM.getVM().isCore(), "must not be used in core build");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    return invocationCounter.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // get associated compiled native method, if available, else return null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  public NMethod getNativeMethod() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    Address addr = code.getValue(getHandle());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    return (NMethod) VMObjectFactory.newObject(NMethod.class, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Convenience routine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  public AccessFlags getAccessFlagsObj() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    return new AccessFlags(getAccessFlags());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  /** Get a bytecode or breakpoint at the given bci */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public int getBytecodeOrBPAt(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return getConstMethod().getBytecodeOrBPAt(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  /** Fetch the original non-breakpoint bytecode at the specified
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      bci. It is required that there is currently a bytecode at this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      bci. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  public int getOrigBytecodeAt(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    BreakpointInfo bp = ((InstanceKlass) getMethodHolder()).getBreakpoints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    for (; bp != null; bp = bp.getNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      if (bp.match(this, bci)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        return bp.getOrigBytecode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    System.err.println("Requested bci " + bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    for (; bp != null; bp = bp.getNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      System.err.println("Breakpoint at bci " + bp.getBCI() + ", bytecode " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                         bp.getOrigBytecode());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    Assert.that(false, "Should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    return -1; // not reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  public byte getBytecodeByteArg(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    return getConstMethod().getBytecodeByteArg(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  /** Fetches a 16-bit big-endian ("Java ordered") value from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      bytecode stream */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  public short getBytecodeShortArg(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    return getConstMethod().getBytecodeShortArg(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   183
  /** Fetches a 16-bit native ordered value from the
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   184
      bytecode stream */
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   185
  public short getNativeShortArg(int bci) {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   186
    return getConstMethod().getNativeShortArg(bci);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   187
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   188
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  /** Fetches a 32-bit big-endian ("Java ordered") value from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      bytecode stream */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  public int getBytecodeIntArg(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    return getConstMethod().getBytecodeIntArg(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   195
  /** Fetches a 32-bit native ordered value from the
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   196
      bytecode stream */
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   197
  public int getNativeIntArg(int bci) {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   198
    return getConstMethod().getNativeIntArg(bci);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   199
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   200
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  public byte[] getByteCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    return getConstMethod().getByteCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  public Address      getCode()                       { return codeField.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  public Address      getInterpreterEntry()           { return interpreterEntryField.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  public Address      getFromCompiledCodeEntryPoint() { return fromCompiledCodeEntryPointField.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  // Accessors
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   211
  public Symbol  getName()          { return getConstants().getSymbolAt(getNameIndex());         }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   212
  public Symbol  getSignature()     { return getConstants().getSymbolAt(getSignatureIndex());    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  public Symbol  getGenericSignature() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
     long index = getGenericSignatureIndex();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 5547
diff changeset
   215
     return (index != 0L) ? getConstants().getSymbolAt(index) : null;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // Method holder (the Klass holding this method)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  public Klass   getMethodHolder()  { return getConstants().getPoolHolder();                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // Access flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  public boolean isPublic()         { return getAccessFlagsObj().isPublic();                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  public boolean isPrivate()        { return getAccessFlagsObj().isPrivate();                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  public boolean isProtected()      { return getAccessFlagsObj().isProtected();                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  public boolean isPackagePrivate() { AccessFlags af = getAccessFlagsObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
                                      return (!af.isPublic() && !af.isPrivate() && !af.isProtected()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  public boolean isStatic()         { return getAccessFlagsObj().isStatic();                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  public boolean isFinal()          { return getAccessFlagsObj().isFinal();                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  public boolean isSynchronized()   { return getAccessFlagsObj().isSynchronized();                     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  public boolean isBridge()         { return getAccessFlagsObj().isBridge();                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  public boolean isVarArgs()        { return getAccessFlagsObj().isVarArgs();                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  public boolean isNative()         { return getAccessFlagsObj().isNative();                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  public boolean isAbstract()       { return getAccessFlagsObj().isAbstract();                         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  public boolean isStrict()         { return getAccessFlagsObj().isStrict();                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  public boolean isSynthetic()      { return getAccessFlagsObj().isSynthetic();                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  public boolean isConstructor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
     return (!isStatic()) && getName().equals(objectInitializerName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  public boolean isStaticInitializer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
     return isStatic() && getName().equals(classInitializerName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  public boolean isObsolete() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
     return getAccessFlagsObj().isObsolete();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  public OopMapCacheEntry getMaskFor(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    OopMapCacheEntry entry = new OopMapCacheEntry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    entry.fill(this, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  public long getObjectSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    return getMethodSize() * getHeap().getOopSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  public void printValueOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    tty.print("Method " + getName().asString() + getSignature().asString() + "@" + getHandle());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  public void iterateFields(OopVisitor visitor, boolean doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    super.iterateFields(visitor, doVMFields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    if (doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      visitor.doOop(constMethod, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      visitor.doOop(constants, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      visitor.doCInt(methodSize, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      visitor.doCInt(maxStack, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      visitor.doCInt(maxLocals, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      visitor.doCInt(sizeOfParameters, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      visitor.doCInt(accessFlags, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  public boolean hasLineNumberTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return getConstMethod().hasLineNumberTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  public int getLineNumberFromBCI(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    return getConstMethod().getLineNumberFromBCI(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  public LineNumberTableElement[] getLineNumberTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    return getConstMethod().getLineNumberTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  public boolean hasLocalVariableTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    return getConstMethod().hasLocalVariableTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  /** Should only be called if table is present */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  public LocalVariableTableElement[] getLocalVariableTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    return getConstMethod().getLocalVariableTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  public Symbol getLocalVariableName(int bci, int slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    if (! hasLocalVariableTable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
       return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    LocalVariableTableElement[] locals = getLocalVariableTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    for (int l = 0; l < locals.length; l++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
       LocalVariableTableElement local = locals[l];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
       if ((bci >= local.getStartBCI()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
          (bci < (local.getStartBCI() + local.getLength())) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
          slot == local.getSlot()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
          return getConstants().getSymbolAt(local.getNameCPIndex());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  public boolean hasCheckedExceptions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    return getConstMethod().hasCheckedExceptions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  /** Should only be called if table is present */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  public CheckedExceptionElement[] getCheckedExceptions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    return getConstMethod().getCheckedExceptions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  /** Returns name and signature in external form for debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      purposes */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  public String externalNameAndSignature() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    final StringBuffer buf = new StringBuffer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    buf.append(getMethodHolder().getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    buf.append(".");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    buf.append(getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    buf.append("(");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    new SignatureConverter(getSignature(), buf).iterateParameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    buf.append(")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    return buf.toString().replace('/', '.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
}