comparison agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLoadConstant.java @ 3838:6a991dcb52bb

7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries Reviewed-by: kvn, twisti, jrose
author never
date Thu, 21 Jul 2011 08:38:25 -0700
parents 1d1603768966
children 2090c623107e
comparison
equal deleted inserted replaced
3837:43f9d800f276 3838:6a991dcb52bb
26 26
27 import sun.jvm.hotspot.oops.*; 27 import sun.jvm.hotspot.oops.*;
28 import sun.jvm.hotspot.runtime.*; 28 import sun.jvm.hotspot.runtime.*;
29 import sun.jvm.hotspot.utilities.*; 29 import sun.jvm.hotspot.utilities.*;
30 30
31 public class BytecodeLoadConstant extends BytecodeWithCPIndex { 31 public class BytecodeLoadConstant extends Bytecode {
32 BytecodeLoadConstant(Method method, int bci) { 32 BytecodeLoadConstant(Method method, int bci) {
33 super(method, bci); 33 super(method, bci);
34 } 34 }
35 35
36 public boolean hasCacheIndex() { 36 public boolean hasCacheIndex() {
37 // normal ldc uses CP index, but fast_aldc uses swapped CP cache index 37 // normal ldc uses CP index, but fast_aldc uses swapped CP cache index
38 return javaCode() != code(); 38 return code() >= Bytecodes.number_of_java_codes;
39 } 39 }
40 40
41 public int index() { 41 int rawIndex() {
42 int i = javaCode() == Bytecodes._ldc ? 42 if (javaCode() == Bytecodes._ldc)
43 (int) (0xFF & javaByteAt(1)) 43 return getIndexU1();
44 : (int) (0xFFFF & javaShortAt(1)); 44 else
45 if (hasCacheIndex()) { 45 return getIndexU2(code(), false);
46 return (0xFFFF & VM.getVM().getBytes().swapShort((short) i));
47 } else {
48 return i;
49 }
50 } 46 }
51 47
52 public int poolIndex() { 48 public int poolIndex() {
53 int i = index(); 49 int i = rawIndex();
54 if (hasCacheIndex()) { 50 if (hasCacheIndex()) {
55 ConstantPoolCache cpCache = method().getConstants().getCache(); 51 ConstantPoolCache cpCache = method().getConstants().getCache();
56 return cpCache.getEntryAt(i).getConstantPoolIndex(); 52 return cpCache.getEntryAt(i).getConstantPoolIndex();
57 } else { 53 } else {
58 return i; 54 return i;
59 } 55 }
60 } 56 }
61 57
62 public int cacheIndex() { 58 public int cacheIndex() {
63 if (hasCacheIndex()) { 59 if (hasCacheIndex()) {
64 return index(); 60 return rawIndex();
65 } else { 61 } else {
66 return -1; // no cache index 62 return -1; // no cache index
67 } 63 }
64 }
65
66 public BasicType resultType() {
67 int index = poolIndex();
68 ConstantTag tag = method().getConstants().getTagAt(index);
69 return tag.basicType();
68 } 70 }
69 71
70 private Oop getCachedConstant() { 72 private Oop getCachedConstant() {
71 int i = cacheIndex(); 73 int i = cacheIndex();
72 if (i >= 0) { 74 if (i >= 0) {
86 int jcode = javaCode(); 88 int jcode = javaCode();
87 boolean codeOk = jcode == Bytecodes._ldc || jcode == Bytecodes._ldc_w || 89 boolean codeOk = jcode == Bytecodes._ldc || jcode == Bytecodes._ldc_w ||
88 jcode == Bytecodes._ldc2_w; 90 jcode == Bytecodes._ldc2_w;
89 if (! codeOk) return false; 91 if (! codeOk) return false;
90 92
91 ConstantTag ctag = method().getConstants().getTagAt(index()); 93 ConstantTag ctag = method().getConstants().getTagAt(rawIndex());
92 if (jcode == Bytecodes._ldc2_w) { 94 if (jcode == Bytecodes._ldc2_w) {
93 // has to be double or long 95 // has to be double or long
94 return (ctag.isDouble() || ctag.isLong()) ? true: false; 96 return (ctag.isDouble() || ctag.isLong()) ? true: false;
95 } else { 97 } else {
96 // has to be int or float or String or Klass 98 // has to be int or float or String or Klass
105 int jcode = javaCode(); 107 int jcode = javaCode();
106 if (jcode == Bytecodes._ldc2_w) { 108 if (jcode == Bytecodes._ldc2_w) {
107 return false; 109 return false;
108 } 110 }
109 111
110 ConstantTag ctag = method().getConstants().getTagAt(index()); 112 ConstantTag ctag = method().getConstants().getTagAt(poolIndex());
111 return ctag.isKlass() || ctag.isUnresolvedKlass(); 113 return ctag.isKlass() || ctag.isUnresolvedKlass();
112 } 114 }
113 115
114 // return Symbol (if unresolved) or Klass (if resolved) 116 // return Symbol (if unresolved) or Klass (if resolved)
115 public Object getKlass() { 117 public Object getKlass() {
118 } 120 }
119 // tag change from 'unresolved' to 'klass' does not happen atomically. 121 // tag change from 'unresolved' to 'klass' does not happen atomically.
120 // We just look at the object at the corresponding index and 122 // We just look at the object at the corresponding index and
121 // decide based on the oop type. 123 // decide based on the oop type.
122 ConstantPool cpool = method().getConstants(); 124 ConstantPool cpool = method().getConstants();
123 int cpIndex = index(); 125 int cpIndex = poolIndex();
124 ConstantPool.CPSlot oop = cpool.getSlotAt(cpIndex); 126 ConstantPool.CPSlot oop = cpool.getSlotAt(cpIndex);
125 if (oop.isOop()) { 127 if (oop.isOop()) {
126 return (Klass) oop.getOop(); 128 return (Klass) oop.getOop();
127 } else if (oop.isMetaData()) { 129 } else if (oop.isMetaData()) {
128 return oop.getSymbol(); 130 return oop.getSymbol();