hotspot/agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLoadConstant.java
author never
Thu, 21 Jul 2011 08:38:25 -0700
changeset 10251 71b8938a2821
parent 8921 14bfe81f2a9d
child 10513 27a4eec804ea
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) 2002, 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.interpreter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import sun.jvm.hotspot.oops.*;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    28
import sun.jvm.hotspot.runtime.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    31
public class BytecodeLoadConstant extends Bytecode {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  BytecodeLoadConstant(Method method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    super(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    36
  public boolean hasCacheIndex() {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    37
    // normal ldc uses CP index, but fast_aldc uses swapped CP cache index
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    38
    return code() >= Bytecodes.number_of_java_codes;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    39
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    40
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    41
  int rawIndex() {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    42
    if (javaCode() == Bytecodes._ldc)
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    43
      return getIndexU1();
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    44
    else
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    45
      return getIndexU2(code(), false);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    46
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    47
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    48
  public int poolIndex() {
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    49
    int i = rawIndex();
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    50
    if (hasCacheIndex()) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    51
      ConstantPoolCache cpCache = method().getConstants().getCache();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    52
      return cpCache.getEntryAt(i).getConstantPoolIndex();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    53
    } else {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    54
      return i;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    55
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    56
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    57
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    58
  public int cacheIndex() {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    59
    if (hasCacheIndex()) {
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    60
      return rawIndex();
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    61
    } else {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    62
      return -1;  // no cache index
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    63
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    64
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    65
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    66
  public BasicType resultType() {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    67
    int index = poolIndex();
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    68
    ConstantTag tag = method().getConstants().getTagAt(index);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    69
    return tag.basicType();
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    70
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    71
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    72
  private Oop getCachedConstant() {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    73
    int i = cacheIndex();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    74
    if (i >= 0) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    75
      ConstantPoolCache cpCache = method().getConstants().getCache();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    76
      return cpCache.getEntryAt(i).getF1();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    77
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
    78
    return null;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  public void verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      Assert.that(isValid(), "check load constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  public boolean isValid() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    int jcode = javaCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    boolean codeOk = jcode == Bytecodes._ldc || jcode == Bytecodes._ldc_w ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
           jcode == Bytecodes._ldc2_w;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (! codeOk) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
    93
    ConstantTag ctag = method().getConstants().getTagAt(rawIndex());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    if (jcode == Bytecodes._ldc2_w) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
       // has to be double or long
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
       return (ctag.isDouble() || ctag.isLong()) ? true: false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
       // has to be int or float or String or Klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
       return (ctag.isUnresolvedString() || ctag.isString()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
               || ctag.isUnresolvedKlass() || ctag.isKlass()
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   101
               || ctag.isMethodHandle() || ctag.isMethodType()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
               || ctag.isInt() || ctag.isFloat())? true: false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public boolean isKlassConstant() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    int jcode = javaCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if (jcode == Bytecodes._ldc2_w) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
       return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   112
    ConstantTag ctag = method().getConstants().getTagAt(poolIndex());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    return ctag.isKlass() || ctag.isUnresolvedKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // return Symbol (if unresolved) or Klass (if resolved)
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   117
  public Object getKlass() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      Assert.that(isKlassConstant(), "not a klass literal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // tag change from 'unresolved' to 'klass' does not happen atomically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // We just look at the object at the corresponding index and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // decide based on the oop type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    ConstantPool cpool = method().getConstants();
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 8921
diff changeset
   125
    int cpIndex = poolIndex();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   126
    ConstantPool.CPSlot oop = cpool.getSlotAt(cpIndex);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   127
    if (oop.isOop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   128
      return (Klass) oop.getOop();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   129
    } else if (oop.isMetaData()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   130
      return oop.getSymbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
       throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
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 static BytecodeLoadConstant at(Method method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    BytecodeLoadConstant b = new BytecodeLoadConstant(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      b.verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  /** Like at, but returns null if the BCI is not at ldc or ldc_w or ldc2_w  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  public static BytecodeLoadConstant atCheck(Method method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    BytecodeLoadConstant b = new BytecodeLoadConstant(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    return (b.isValid() ? b : null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public static BytecodeLoadConstant at(BytecodeStream bcs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return new BytecodeLoadConstant(bcs.method(), bcs.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
  public String getConstantValue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    ConstantPool cpool = method().getConstants();
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   156
    int cpIndex = poolIndex();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    ConstantTag ctag = cpool.getTagAt(cpIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (ctag.isInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
       return "<int " + Integer.toString(cpool.getIntAt(cpIndex)) +">";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    } else if (ctag.isLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
       return "<long " + Long.toString(cpool.getLongAt(cpIndex)) + "L>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    } else if (ctag.isFloat()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
       return "<float " + Float.toString(cpool.getFloatAt(cpIndex)) + "F>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    } else if (ctag.isDouble()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
       return "<double " + Double.toString(cpool.getDoubleAt(cpIndex)) + "D>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    } else if (ctag.isString() || ctag.isUnresolvedString()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
       // tag change from 'unresolved' to 'string' does not happen atomically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
       // We just look at the object at the corresponding index and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
       // decide based on the oop type.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   170
       ConstantPool.CPSlot obj = cpool.getSlotAt(cpIndex);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   171
       if (obj.isMetaData()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   172
         Symbol sym = obj.getSymbol();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   173
         return "<String \"" + sym.asString() + "\">";
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   174
       } else if (obj.isOop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   175
         return "<String \"" + OopUtilities.stringOopToString(obj.getOop()) + "\">";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
       } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
          throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    } else if (ctag.isKlass() || ctag.isUnresolvedKlass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
       // tag change from 'unresolved' to 'klass' does not happen atomically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
       // We just look at the object at the corresponding index and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
       // decide based on the oop type.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   183
       ConstantPool.CPSlot obj = cpool.getSlotAt(cpIndex);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   184
       if (obj.isOop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   185
         Klass k = (Klass) obj.getOop();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   186
         return "<Class " + k.getName().asString() + "@" + k.getHandle() + ">";
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   187
       } else if (obj.isMetaData()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   188
         Symbol sym = obj.getSymbol();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7114
diff changeset
   189
         return "<Class " + sym.asString() + ">";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
       } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
          throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
       }
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 5882
diff changeset
   193
    } else if (ctag.isMethodHandle()) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   194
       Oop x = getCachedConstant();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   195
       int refidx = cpool.getMethodHandleIndexAt(cpIndex);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   196
       int refkind = cpool.getMethodHandleRefKindAt(cpIndex);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   197
       return "<MethodHandle kind=" + Integer.toString(refkind) +
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   198
           " ref=" + Integer.toString(refidx)
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   199
           + (x == null ? "" : " @" + x.getHandle()) + ">";
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   200
    } else if (ctag.isMethodType()) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   201
       Oop x = getCachedConstant();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   202
       int refidx = cpool.getMethodTypeIndexAt(cpIndex);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   203
       return "<MethodType " + cpool.getSymbolAt(refidx).asString()
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   204
           + (x == null ? "" : " @" + x.getHandle()) + ">";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
       if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
         Assert.that(false, "invalid load constant type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
       return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    }
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 String toString() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    StringBuffer buf = new StringBuffer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    buf.append(getJavaBytecodeName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    buf.append(spaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    buf.append('#');
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   218
    buf.append(Integer.toString(poolIndex()));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   219
    if (hasCacheIndex()) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   220
       buf.append('(');
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   221
       buf.append(Integer.toString(cacheIndex()));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   222
       buf.append(')');
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   223
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    buf.append(spaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    buf.append(getConstantValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    if (code() != javaCode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
       buf.append(spaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
       buf.append('[');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
       buf.append(getBytecodeName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
       buf.append(']');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
}