hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1 489c9b5090e2
child 10251 71b8938a2821
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2003, 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
public class ConstMethod extends Oop {
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
  // anon-enum constants for _flags.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private static int HAS_LINENUMBER_TABLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  private static int HAS_CHECKED_EXCEPTIONS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private static int HAS_LOCALVARIABLE_TABLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    Type type                  = db.lookupType("constMethodOopDesc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    // Backpointer to non-const methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    method                     = new OopField(type.getOopField("_method"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // The exception handler table. 4-tuples of ints [start_pc, end_pc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    // handler_pc, catch_type index] For methods with no exceptions the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    // table is pointing to Universe::the_empty_int_array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    exceptionTable             = new OopField(type.getOopField("_exception_table"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    constMethodSize            = new CIntField(type.getCIntegerField("_constMethod_size"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    flags                      = new ByteField(type.getJByteField("_flags"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    // enum constants for flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    HAS_LINENUMBER_TABLE      = db.lookupIntConstant("constMethodOopDesc::_has_linenumber_table").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    HAS_CHECKED_EXCEPTIONS     = db.lookupIntConstant("constMethodOopDesc::_has_checked_exceptions").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    HAS_LOCALVARIABLE_TABLE   = db.lookupIntConstant("constMethodOopDesc::_has_localvariable_table").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    // Size of Java bytecodes allocated immediately after constMethodOop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    codeSize                   = new CIntField(type.getCIntegerField("_code_size"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    nameIndex                  = new CIntField(type.getCIntegerField("_name_index"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    signatureIndex             = new CIntField(type.getCIntegerField("_signature_index"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    genericSignatureIndex      = new CIntField(type.getCIntegerField("_generic_signature_index"),0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    // start of byte code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    bytecodeOffset = type.getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    type                       = db.lookupType("CheckedExceptionElement");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    checkedExceptionElementSize = type.getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    type                       = db.lookupType("LocalVariableTableElement");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    localVariableTableElementSize = type.getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  ConstMethod(OopHandle handle, ObjectHeap heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    super(handle, heap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  private static OopField  method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  private static OopField  exceptionTable;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  private static CIntField constMethodSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  private static ByteField flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  private static CIntField codeSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  private static CIntField nameIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  private static CIntField signatureIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  private static CIntField genericSignatureIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // start of bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  private static long bytecodeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  private static long checkedExceptionElementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  private static long localVariableTableElementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Accessors for declared fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  public Method getMethod() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    return (Method) method.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  public TypeArray getExceptionTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    return (TypeArray) exceptionTable.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  public long getConstMethodSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    return constMethodSize.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  public byte getFlags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    return flags.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  public long getCodeSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return codeSize.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  public long getNameIndex() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    return nameIndex.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  public long getSignatureIndex() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    return signatureIndex.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  public long getGenericSignatureIndex() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    return genericSignatureIndex.getValue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  public Symbol getName() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    return getMethod().getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  public Symbol getSignature() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    return getMethod().getSignature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  public Symbol getGenericSignature() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    return getMethod().getGenericSignature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // bytecode accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  /** Get a bytecode or breakpoint at the given bci */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  public int getBytecodeOrBPAt(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    return getHandle().getJByteAt(bytecodeOffset + bci) & 0xFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  public byte getBytecodeByteArg(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    return (byte) getBytecodeOrBPAt(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  /** Fetches a 16-bit big-endian ("Java ordered") value from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      bytecode stream */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  public short getBytecodeShortArg(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    int hi = getBytecodeOrBPAt(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    int lo = getBytecodeOrBPAt(bci + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    return (short) ((hi << 8) | lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  /** Fetches a 32-bit big-endian ("Java ordered") value from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      bytecode stream */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  public int getBytecodeIntArg(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    int b4 = getBytecodeOrBPAt(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    int b3 = getBytecodeOrBPAt(bci + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    int b2 = getBytecodeOrBPAt(bci + 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    int b1 = getBytecodeOrBPAt(bci + 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  public byte[] getByteCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
     byte[] bc = new byte[ (int) getCodeSize() ];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
     for( int i=0; i < bc.length; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
     {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        long offs = bytecodeOffset + i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        bc[i] = getHandle().getJByteAt( offs );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
     return bc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  public long getObjectSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    return getConstMethodSize() * getHeap().getOopSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  public void printValueOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    tty.print("ConstMethod " + getName().asString() + getSignature().asString() + "@" + getHandle());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  public void iterateFields(OopVisitor visitor, boolean doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    super.iterateFields(visitor, doVMFields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    if (doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      visitor.doOop(method, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      visitor.doOop(exceptionTable, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      visitor.doCInt(constMethodSize, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      visitor.doByte(flags, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      visitor.doCInt(codeSize, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      visitor.doCInt(nameIndex, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      visitor.doCInt(signatureIndex, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      visitor.doCInt(genericSignatureIndex, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      visitor.doCInt(codeSize, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  public boolean hasLineNumberTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    return (getFlags() & HAS_LINENUMBER_TABLE) != 0;
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 int getLineNumberFromBCI(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      if (bci == DebugInformationRecorder.SYNCHRONIZATION_ENTRY_BCI) bci = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    if (isNative()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      Assert.that(bci == 0 || 0 <= bci && bci < getCodeSize(), "illegal bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    int bestBCI  =  0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    int bestLine = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    if (hasLineNumberTable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      // The line numbers are a short array of 2-tuples [start_pc, line_number].
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      // Not necessarily sorted and not necessarily one-to-one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      CompressedLineNumberReadStream stream =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        new CompressedLineNumberReadStream(getHandle(), (int) offsetOfCompressedLineNumberTable());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      while (stream.readPair()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        if (stream.bci() == bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
          // perfect match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
          return stream.line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
          // update best_bci/line
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
          if (stream.bci() < bci && stream.bci() >= bestBCI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
            bestBCI  = stream.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
            bestLine = stream.line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    return bestLine;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  public LineNumberTableElement[] getLineNumberTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      Assert.that(hasLineNumberTable(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
                  "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    int len = getLineNumberTableLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    CompressedLineNumberReadStream stream =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      new CompressedLineNumberReadStream(getHandle(), (int) offsetOfCompressedLineNumberTable());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    LineNumberTableElement[] ret = new LineNumberTableElement[len];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    for (int idx = 0; idx < len; idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      stream.readPair();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      ret[idx] = new LineNumberTableElement(stream.bci(), stream.line());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    return ret;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  public boolean hasLocalVariableTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    return (getFlags() & HAS_LOCALVARIABLE_TABLE) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  public Symbol getLocalVariableName(int bci, int slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    return getMethod().getLocalVariableName(bci, slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  /** Should only be called if table is present */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  public LocalVariableTableElement[] getLocalVariableTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      Assert.that(hasLocalVariableTable(), "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    LocalVariableTableElement[] ret = new LocalVariableTableElement[getLocalVariableTableLength()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    long offset = offsetOfLocalVariableTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    for (int i = 0; i < ret.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      ret[i] = new LocalVariableTableElement(getHandle(), offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      offset += localVariableTableElementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    return ret;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  public boolean hasCheckedExceptions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    return (getFlags() & HAS_CHECKED_EXCEPTIONS) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  public CheckedExceptionElement[] getCheckedExceptions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      Assert.that(hasCheckedExceptions(), "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    CheckedExceptionElement[] ret = new CheckedExceptionElement[getCheckedExceptionsLength()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    long offset = offsetOfCheckedExceptions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    for (int i = 0; i < ret.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      ret[i] = new CheckedExceptionElement(getHandle(), offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      offset += checkedExceptionElementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    return ret;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  private boolean isNative() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    return getMethod().isNative();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // Offset of end of code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  private long offsetOfCodeEnd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    return bytecodeOffset + getCodeSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  // Offset of start of compressed line number table (see methodOop.hpp)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  private long offsetOfCompressedLineNumberTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    return offsetOfCodeEnd() + (isNative() ? 2 * VM.getVM().getAddressSize() : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // Offset of last short in methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  private long offsetOfLastU2Element() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    return getObjectSize() - 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  private long offsetOfCheckedExceptionsLength() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    return offsetOfLastU2Element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  private int getCheckedExceptionsLength() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    if (hasCheckedExceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      return (int) getHandle().getCIntegerAt(offsetOfCheckedExceptionsLength(), 2, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // Offset of start of checked exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  private long offsetOfCheckedExceptions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    long offset = offsetOfCheckedExceptionsLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    long length = getCheckedExceptionsLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      Assert.that(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    offset -= length * checkedExceptionElementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    return offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  private int getLineNumberTableLength() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    int len = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    if (hasLineNumberTable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      CompressedLineNumberReadStream stream =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
        new CompressedLineNumberReadStream(getHandle(), (int) offsetOfCompressedLineNumberTable());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      while (stream.readPair()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
        len += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    return len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  private int getLocalVariableTableLength() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    if (hasLocalVariableTable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      return (int) getHandle().getCIntegerAt(offsetOfLocalVariableTableLength(), 2, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  // Offset of local variable table length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  private long offsetOfLocalVariableTableLength() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      Assert.that(hasLocalVariableTable(), "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    if (hasCheckedExceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      return offsetOfCheckedExceptions() - 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      return offsetOfLastU2Element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  private long offsetOfLocalVariableTable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    long offset = offsetOfLocalVariableTableLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    long length = getLocalVariableTableLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      Assert.that(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    offset -= length * localVariableTableElementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    return offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
}