Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLoadConstant.java @ 2426:1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
Summary: Update the copyright to be 2010 on all changed files in OpenJDK
Reviewed-by: ohair
author | trims |
---|---|
date | Tue, 05 Apr 2011 14:12:31 -0700 |
parents | 3582bf76420e |
children | 6a991dcb52bb |
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 | |
31 public class BytecodeLoadConstant extends BytecodeWithCPIndex { | |
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 | |
38 return javaCode() != code(); | |
39 } | |
40 | |
0 | 41 public int index() { |
1602 | 42 int i = javaCode() == Bytecodes._ldc ? |
0 | 43 (int) (0xFF & javaByteAt(1)) |
44 : (int) (0xFFFF & javaShortAt(1)); | |
1602 | 45 if (hasCacheIndex()) { |
46 return (0xFFFF & VM.getVM().getBytes().swapShort((short) i)); | |
47 } else { | |
48 return i; | |
49 } | |
50 } | |
51 | |
52 public int poolIndex() { | |
53 int i = index(); | |
54 if (hasCacheIndex()) { | |
55 ConstantPoolCache cpCache = method().getConstants().getCache(); | |
56 return cpCache.getEntryAt(i).getConstantPoolIndex(); | |
57 } else { | |
58 return i; | |
59 } | |
60 } | |
61 | |
62 public int cacheIndex() { | |
63 if (hasCacheIndex()) { | |
64 return index(); | |
65 } else { | |
66 return -1; // no cache index | |
67 } | |
68 } | |
69 | |
70 private Oop getCachedConstant() { | |
71 int i = cacheIndex(); | |
72 if (i >= 0) { | |
73 ConstantPoolCache cpCache = method().getConstants().getCache(); | |
74 return cpCache.getEntryAt(i).getF1(); | |
75 } | |
76 return null; | |
0 | 77 } |
78 | |
79 public void verify() { | |
80 if (Assert.ASSERTS_ENABLED) { | |
81 Assert.that(isValid(), "check load constant"); | |
82 } | |
83 } | |
84 | |
85 public boolean isValid() { | |
86 int jcode = javaCode(); | |
87 boolean codeOk = jcode == Bytecodes._ldc || jcode == Bytecodes._ldc_w || | |
88 jcode == Bytecodes._ldc2_w; | |
89 if (! codeOk) return false; | |
90 | |
91 ConstantTag ctag = method().getConstants().getTagAt(index()); | |
92 if (jcode == Bytecodes._ldc2_w) { | |
93 // has to be double or long | |
94 return (ctag.isDouble() || ctag.isLong()) ? true: false; | |
95 } else { | |
96 // has to be int or float or String or Klass | |
97 return (ctag.isUnresolvedString() || ctag.isString() | |
98 || ctag.isUnresolvedKlass() || ctag.isKlass() | |
1602 | 99 || ctag.isMethodHandle() || ctag.isMethodType() |
0 | 100 || ctag.isInt() || ctag.isFloat())? true: false; |
101 } | |
102 } | |
103 | |
104 public boolean isKlassConstant() { | |
105 int jcode = javaCode(); | |
106 if (jcode == Bytecodes._ldc2_w) { | |
107 return false; | |
108 } | |
109 | |
110 ConstantTag ctag = method().getConstants().getTagAt(index()); | |
111 return ctag.isKlass() || ctag.isUnresolvedKlass(); | |
112 } | |
113 | |
114 // 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
|
115 public Object getKlass() { |
0 | 116 if (Assert.ASSERTS_ENABLED) { |
117 Assert.that(isKlassConstant(), "not a klass literal"); | |
118 } | |
119 // tag change from 'unresolved' to 'klass' does not happen atomically. | |
120 // We just look at the object at the corresponding index and | |
121 // decide based on the oop type. | |
122 ConstantPool cpool = method().getConstants(); | |
123 int cpIndex = index(); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
124 ConstantPool.CPSlot oop = cpool.getSlotAt(cpIndex); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
125 if (oop.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
126 return (Klass) oop.getOop(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
127 } else if (oop.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
128 return oop.getSymbol(); |
0 | 129 } else { |
130 throw new RuntimeException("should not reach here"); | |
131 } | |
132 } | |
133 | |
134 public static BytecodeLoadConstant at(Method method, int bci) { | |
135 BytecodeLoadConstant b = new BytecodeLoadConstant(method, bci); | |
136 if (Assert.ASSERTS_ENABLED) { | |
137 b.verify(); | |
138 } | |
139 return b; | |
140 } | |
141 | |
142 /** Like at, but returns null if the BCI is not at ldc or ldc_w or ldc2_w */ | |
143 public static BytecodeLoadConstant atCheck(Method method, int bci) { | |
144 BytecodeLoadConstant b = new BytecodeLoadConstant(method, bci); | |
145 return (b.isValid() ? b : null); | |
146 } | |
147 | |
148 public static BytecodeLoadConstant at(BytecodeStream bcs) { | |
149 return new BytecodeLoadConstant(bcs.method(), bcs.bci()); | |
150 } | |
151 | |
152 public String getConstantValue() { | |
153 ConstantPool cpool = method().getConstants(); | |
1602 | 154 int cpIndex = poolIndex(); |
0 | 155 ConstantTag ctag = cpool.getTagAt(cpIndex); |
156 if (ctag.isInt()) { | |
157 return "<int " + Integer.toString(cpool.getIntAt(cpIndex)) +">"; | |
158 } else if (ctag.isLong()) { | |
159 return "<long " + Long.toString(cpool.getLongAt(cpIndex)) + "L>"; | |
160 } else if (ctag.isFloat()) { | |
161 return "<float " + Float.toString(cpool.getFloatAt(cpIndex)) + "F>"; | |
162 } else if (ctag.isDouble()) { | |
163 return "<double " + Double.toString(cpool.getDoubleAt(cpIndex)) + "D>"; | |
164 } else if (ctag.isString() || ctag.isUnresolvedString()) { | |
165 // tag change from 'unresolved' to 'string' does not happen atomically. | |
166 // We just look at the object at the corresponding index and | |
167 // decide based on the oop type. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
168 ConstantPool.CPSlot obj = cpool.getSlotAt(cpIndex); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
169 if (obj.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
170 Symbol sym = obj.getSymbol(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
171 return "<String \"" + sym.asString() + "\">"; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
172 } else if (obj.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
173 return "<String \"" + OopUtilities.stringOopToString(obj.getOop()) + "\">"; |
0 | 174 } else { |
175 throw new RuntimeException("should not reach here"); | |
176 } | |
177 } else if (ctag.isKlass() || ctag.isUnresolvedKlass()) { | |
178 // tag change from 'unresolved' to 'klass' does not happen atomically. | |
179 // We just look at the object at the corresponding index and | |
180 // decide based on the oop type. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
181 ConstantPool.CPSlot obj = cpool.getSlotAt(cpIndex); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
182 if (obj.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
183 Klass k = (Klass) obj.getOop(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
184 return "<Class " + k.getName().asString() + "@" + k.getHandle() + ">"; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
185 } else if (obj.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
186 Symbol sym = obj.getSymbol(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1913
diff
changeset
|
187 return "<Class " + sym.asString() + ">"; |
0 | 188 } else { |
189 throw new RuntimeException("should not reach here"); | |
190 } | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1602
diff
changeset
|
191 } else if (ctag.isMethodHandle()) { |
1602 | 192 Oop x = getCachedConstant(); |
193 int refidx = cpool.getMethodHandleIndexAt(cpIndex); | |
194 int refkind = cpool.getMethodHandleRefKindAt(cpIndex); | |
195 return "<MethodHandle kind=" + Integer.toString(refkind) + | |
196 " ref=" + Integer.toString(refidx) | |
197 + (x == null ? "" : " @" + x.getHandle()) + ">"; | |
198 } else if (ctag.isMethodType()) { | |
199 Oop x = getCachedConstant(); | |
200 int refidx = cpool.getMethodTypeIndexAt(cpIndex); | |
201 return "<MethodType " + cpool.getSymbolAt(refidx).asString() | |
202 + (x == null ? "" : " @" + x.getHandle()) + ">"; | |
0 | 203 } else { |
204 if (Assert.ASSERTS_ENABLED) { | |
205 Assert.that(false, "invalid load constant type"); | |
206 } | |
207 return null; | |
208 } | |
209 } | |
210 | |
211 public String toString() { | |
212 StringBuffer buf = new StringBuffer(); | |
213 buf.append(getJavaBytecodeName()); | |
214 buf.append(spaces); | |
215 buf.append('#'); | |
1602 | 216 buf.append(Integer.toString(poolIndex())); |
217 if (hasCacheIndex()) { | |
218 buf.append('('); | |
219 buf.append(Integer.toString(cacheIndex())); | |
220 buf.append(')'); | |
221 } | |
0 | 222 buf.append(spaces); |
223 buf.append(getConstantValue()); | |
224 if (code() != javaCode()) { | |
225 buf.append(spaces); | |
226 buf.append('['); | |
227 buf.append(getBytecodeName()); | |
228 buf.append(']'); | |
229 } | |
230 return buf.toString(); | |
231 } | |
232 } |