Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLoadConstant.java @ 3904:2090c623107e
7016881: JSR 292: JDI: sun.jvm.hotspot.utilities.AssertionFailure: index out of bounds
Reviewed-by: kvn, twisti
author | never |
---|---|
date | Fri, 02 Sep 2011 22:00:49 -0700 |
parents | 6a991dcb52bb |
children | da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.interpreter; | |
26 | |
27 import sun.jvm.hotspot.oops.*; | |
1602 | 28 import sun.jvm.hotspot.runtime.*; |
0 | 29 import sun.jvm.hotspot.utilities.*; |
30 | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
31 public class BytecodeLoadConstant extends Bytecode { |
0 | 32 BytecodeLoadConstant(Method method, int bci) { |
33 super(method, bci); | |
34 } | |
35 | |
1602 | 36 public boolean hasCacheIndex() { |
37 // normal ldc uses CP index, but fast_aldc uses swapped CP cache index | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
38 return code() >= Bytecodes.number_of_java_codes; |
1602 | 39 } |
40 | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
41 int rawIndex() { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
42 if (javaCode() == Bytecodes._ldc) |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
43 return getIndexU1(); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
44 else |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
45 return getIndexU2(code(), false); |
1602 | 46 } |
47 | |
48 public int poolIndex() { | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
49 int i = rawIndex(); |
1602 | 50 if (hasCacheIndex()) { |
51 ConstantPoolCache cpCache = method().getConstants().getCache(); | |
52 return cpCache.getEntryAt(i).getConstantPoolIndex(); | |
53 } else { | |
54 return i; | |
55 } | |
56 } | |
57 | |
58 public int cacheIndex() { | |
59 if (hasCacheIndex()) { | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
60 return rawIndex(); |
1602 | 61 } else { |
62 return -1; // no cache index | |
63 } | |
64 } | |
65 | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
66 public BasicType resultType() { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
67 int index = poolIndex(); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
68 ConstantTag tag = method().getConstants().getTagAt(index); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
69 return tag.basicType(); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
70 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
71 |
1602 | 72 private Oop getCachedConstant() { |
73 int i = cacheIndex(); | |
74 if (i >= 0) { | |
75 ConstantPoolCache cpCache = method().getConstants().getCache(); | |
76 return cpCache.getEntryAt(i).getF1(); | |
77 } | |
78 return null; | |
0 | 79 } |
80 | |
81 public void verify() { | |
82 if (Assert.ASSERTS_ENABLED) { | |
83 Assert.that(isValid(), "check load constant"); | |
84 } | |
85 } | |
86 | |
87 public boolean isValid() { | |
88 int jcode = javaCode(); | |
89 boolean codeOk = jcode == Bytecodes._ldc || jcode == Bytecodes._ldc_w || | |
90 jcode == Bytecodes._ldc2_w; | |
91 if (! codeOk) return false; | |
92 | |
3904
2090c623107e
7016881: JSR 292: JDI: sun.jvm.hotspot.utilities.AssertionFailure: index out of bounds
never
parents:
3838
diff
changeset
|
93 ConstantTag ctag = method().getConstants().getTagAt(poolIndex()); |
0 | 94 if (jcode == Bytecodes._ldc2_w) { |
95 // has to be double or long | |
96 return (ctag.isDouble() || ctag.isLong()) ? true: false; | |
97 } else { | |
98 // has to be int or float or String or Klass | |
99 return (ctag.isUnresolvedString() || ctag.isString() | |
100 || ctag.isUnresolvedKlass() || ctag.isKlass() | |
1602 | 101 || ctag.isMethodHandle() || ctag.isMethodType() |
0 | 102 || ctag.isInt() || ctag.isFloat())? true: false; |
103 } | |
104 } | |
105 | |
106 public boolean isKlassConstant() { | |
107 int jcode = javaCode(); | |
108 if (jcode == Bytecodes._ldc2_w) { | |
109 return false; | |
110 } | |
111 | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
112 ConstantTag ctag = method().getConstants().getTagAt(poolIndex()); |
0 | 113 return ctag.isKlass() || ctag.isUnresolvedKlass(); |
114 } | |
115 | |
116 // return Symbol (if unresolved) or Klass (if resolved) | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
117 public Object getKlass() { |
0 | 118 if (Assert.ASSERTS_ENABLED) { |
119 Assert.that(isKlassConstant(), "not a klass literal"); | |
120 } | |
121 // tag change from 'unresolved' to 'klass' does not happen atomically. | |
122 // We just look at the object at the corresponding index and | |
123 // decide based on the oop type. | |
124 ConstantPool cpool = method().getConstants(); | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2426
diff
changeset
|
125 int cpIndex = poolIndex(); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
126 ConstantPool.CPSlot oop = cpool.getSlotAt(cpIndex); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
127 if (oop.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
128 return (Klass) oop.getOop(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
129 } else if (oop.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
130 return oop.getSymbol(); |
0 | 131 } else { |
132 throw new RuntimeException("should not reach here"); | |
133 } | |
134 } | |
135 | |
136 public static BytecodeLoadConstant at(Method method, int bci) { | |
137 BytecodeLoadConstant b = new BytecodeLoadConstant(method, bci); | |
138 if (Assert.ASSERTS_ENABLED) { | |
139 b.verify(); | |
140 } | |
141 return b; | |
142 } | |
143 | |
144 /** Like at, but returns null if the BCI is not at ldc or ldc_w or ldc2_w */ | |
145 public static BytecodeLoadConstant atCheck(Method method, int bci) { | |
146 BytecodeLoadConstant b = new BytecodeLoadConstant(method, bci); | |
147 return (b.isValid() ? b : null); | |
148 } | |
149 | |
150 public static BytecodeLoadConstant at(BytecodeStream bcs) { | |
151 return new BytecodeLoadConstant(bcs.method(), bcs.bci()); | |
152 } | |
153 | |
154 public String getConstantValue() { | |
155 ConstantPool cpool = method().getConstants(); | |
1602 | 156 int cpIndex = poolIndex(); |
0 | 157 ConstantTag ctag = cpool.getTagAt(cpIndex); |
158 if (ctag.isInt()) { | |
159 return "<int " + Integer.toString(cpool.getIntAt(cpIndex)) +">"; | |
160 } else if (ctag.isLong()) { | |
161 return "<long " + Long.toString(cpool.getLongAt(cpIndex)) + "L>"; | |
162 } else if (ctag.isFloat()) { | |
163 return "<float " + Float.toString(cpool.getFloatAt(cpIndex)) + "F>"; | |
164 } else if (ctag.isDouble()) { | |
165 return "<double " + Double.toString(cpool.getDoubleAt(cpIndex)) + "D>"; | |
166 } else if (ctag.isString() || ctag.isUnresolvedString()) { | |
167 // tag change from 'unresolved' to 'string' does not happen atomically. | |
168 // We just look at the object at the corresponding index and | |
169 // decide based on the oop type. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
170 ConstantPool.CPSlot obj = cpool.getSlotAt(cpIndex); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
171 if (obj.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
172 Symbol sym = obj.getSymbol(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
173 return "<String \"" + sym.asString() + "\">"; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
174 } else if (obj.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
175 return "<String \"" + OopUtilities.stringOopToString(obj.getOop()) + "\">"; |
0 | 176 } else { |
177 throw new RuntimeException("should not reach here"); | |
178 } | |
179 } else if (ctag.isKlass() || ctag.isUnresolvedKlass()) { | |
180 // tag change from 'unresolved' to 'klass' does not happen atomically. | |
181 // We just look at the object at the corresponding index and | |
182 // decide based on the oop type. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
183 ConstantPool.CPSlot obj = cpool.getSlotAt(cpIndex); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
184 if (obj.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
185 Klass k = (Klass) obj.getOop(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
186 return "<Class " + k.getName().asString() + "@" + k.getHandle() + ">"; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
187 } else if (obj.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
188 Symbol sym = obj.getSymbol(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
189 return "<Class " + sym.asString() + ">"; |
0 | 190 } else { |
191 throw new RuntimeException("should not reach here"); | |
192 } | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1602
diff
changeset
|
193 } else if (ctag.isMethodHandle()) { |
1602 | 194 Oop x = getCachedConstant(); |
195 int refidx = cpool.getMethodHandleIndexAt(cpIndex); | |
196 int refkind = cpool.getMethodHandleRefKindAt(cpIndex); | |
197 return "<MethodHandle kind=" + Integer.toString(refkind) + | |
198 " ref=" + Integer.toString(refidx) | |
199 + (x == null ? "" : " @" + x.getHandle()) + ">"; | |
200 } else if (ctag.isMethodType()) { | |
201 Oop x = getCachedConstant(); | |
202 int refidx = cpool.getMethodTypeIndexAt(cpIndex); | |
203 return "<MethodType " + cpool.getSymbolAt(refidx).asString() | |
204 + (x == null ? "" : " @" + x.getHandle()) + ">"; | |
0 | 205 } else { |
206 if (Assert.ASSERTS_ENABLED) { | |
207 Assert.that(false, "invalid load constant type"); | |
208 } | |
209 return null; | |
210 } | |
211 } | |
212 | |
213 public String toString() { | |
214 StringBuffer buf = new StringBuffer(); | |
215 buf.append(getJavaBytecodeName()); | |
216 buf.append(spaces); | |
217 buf.append('#'); | |
1602 | 218 buf.append(Integer.toString(poolIndex())); |
219 if (hasCacheIndex()) { | |
220 buf.append('('); | |
221 buf.append(Integer.toString(cacheIndex())); | |
222 buf.append(')'); | |
223 } | |
0 | 224 buf.append(spaces); |
225 buf.append(getConstantValue()); | |
226 if (code() != javaCode()) { | |
227 buf.append(spaces); | |
228 buf.append('['); | |
229 buf.append(getBytecodeName()); | |
230 buf.append(']'); | |
231 } | |
232 return buf.toString(); | |
233 } | |
234 } |