Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 2011:dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
Reviewed-by: twisti
author | jrose |
---|---|
date | Fri, 03 Dec 2010 15:53:57 -0800 |
parents | 3b2dea75431e |
children | 3582bf76420e |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
2 * Copyright (c) 2000, 2010, 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:
1385
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
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:
1385
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.oops; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 import sun.jvm.hotspot.debugger.*; | |
30 import sun.jvm.hotspot.runtime.*; | |
31 import sun.jvm.hotspot.types.*; | |
32 import sun.jvm.hotspot.utilities.*; | |
33 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
34 // A ConstantPool is an oop containing class constants |
0 | 35 // as described in the class file |
36 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
37 public class ConstantPool extends Oop implements ClassConstants { |
0 | 38 // Used for debugging this code |
39 private static final boolean DEBUG = false; | |
40 | |
41 protected void debugMessage(String message) { | |
42 System.out.println(message); | |
43 } | |
44 | |
45 static { | |
46 VM.registerVMInitializedObserver(new Observer() { | |
47 public void update(Observable o, Object data) { | |
48 initialize(VM.getVM().getTypeDataBase()); | |
49 } | |
50 }); | |
51 } | |
52 | |
53 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { | |
54 Type type = db.lookupType("constantPoolOopDesc"); | |
55 tags = new OopField(type.getOopField("_tags"), 0); | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
56 operands = new OopField(type.getOopField("_operands"), 0); |
0 | 57 cache = new OopField(type.getOopField("_cache"), 0); |
58 poolHolder = new OopField(type.getOopField("_pool_holder"), 0); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
59 length = new CIntField(type.getCIntegerField("_length"), 0); |
0 | 60 headerSize = type.getSize(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
61 elementSize = 0; |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
62 // fetch constants: |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
63 INDY_BSM_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_bsm_offset").intValue(); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
64 INDY_ARGC_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argc_offset").intValue(); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
65 INDY_ARGV_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argv_offset").intValue(); |
0 | 66 } |
67 | |
68 ConstantPool(OopHandle handle, ObjectHeap heap) { | |
69 super(handle, heap); | |
70 } | |
71 | |
72 public boolean isConstantPool() { return true; } | |
73 | |
74 private static OopField tags; | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
75 private static OopField operands; |
0 | 76 private static OopField cache; |
77 private static OopField poolHolder; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
78 private static CIntField length; // number of elements in oop |
0 | 79 |
80 private static long headerSize; | |
81 private static long elementSize; | |
82 | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
83 private static int INDY_BSM_OFFSET; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
84 private static int INDY_ARGC_OFFSET; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
85 private static int INDY_ARGV_OFFSET; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
86 |
0 | 87 public TypeArray getTags() { return (TypeArray) tags.getValue(this); } |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
88 public TypeArray getOperands() { return (TypeArray) operands.getValue(this); } |
0 | 89 public ConstantPoolCache getCache() { return (ConstantPoolCache) cache.getValue(this); } |
90 public Klass getPoolHolder() { return (Klass) poolHolder.getValue(this); } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
91 public int getLength() { return (int)length.getValue(this); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
92 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
93 private long getElementSize() { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
94 if (elementSize !=0 ) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
95 return elementSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
96 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
97 elementSize = VM.getVM().getOopSize(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
98 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
99 return elementSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
100 } |
0 | 101 |
102 private long indexOffset(long index) { | |
103 if (Assert.ASSERTS_ENABLED) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
104 Assert.that(index > 0 && index < getLength(), "invalid cp index " + index + " " + getLength()); |
0 | 105 } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
106 return (index * getElementSize()) + headerSize; |
0 | 107 } |
108 | |
109 public ConstantTag getTagAt(long index) { | |
110 return new ConstantTag(getTags().getByteAt((int) index)); | |
111 } | |
112 | |
113 public Oop getObjAt(long index){ | |
114 return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index))); | |
115 } | |
116 | |
117 public Symbol getSymbolAt(long index) { | |
118 return (Symbol) getObjAt(index); | |
119 } | |
120 | |
121 public int getIntAt(long index){ | |
122 return getHandle().getJIntAt(indexOffset(index)); | |
123 } | |
124 | |
125 public float getFloatAt(long index){ | |
126 return getHandle().getJFloatAt(indexOffset(index)); | |
127 } | |
128 | |
129 public long getLongAt(long index) { | |
130 int oneHalf = getHandle().getJIntAt(indexOffset(index + 1)); | |
131 int otherHalf = getHandle().getJIntAt(indexOffset(index)); | |
132 // buildLongFromIntsPD accepts higher address value, lower address value | |
133 // in that order. | |
134 return VM.getVM().buildLongFromIntsPD(oneHalf, otherHalf); | |
135 } | |
136 | |
137 public double getDoubleAt(long index) { | |
138 return Double.longBitsToDouble(getLongAt(index)); | |
139 } | |
140 | |
141 public int getFieldOrMethodAt(int which) { | |
142 if (DEBUG) { | |
143 System.err.print("ConstantPool.getFieldOrMethodAt(" + which + "): new index = "); | |
144 } | |
145 int i = -1; | |
146 ConstantPoolCache cache = getCache(); | |
147 if (cache == null) { | |
148 i = which; | |
149 } else { | |
150 // change byte-ordering and go via cache | |
151 i = cache.getEntryAt(0xFFFF & VM.getVM().getBytes().swapShort((short) which)).getConstantPoolIndex(); | |
152 } | |
153 if (Assert.ASSERTS_ENABLED) { | |
154 Assert.that(getTagAt(i).isFieldOrMethod(), "Corrupted constant pool"); | |
155 } | |
156 if (DEBUG) { | |
157 System.err.println(i); | |
158 } | |
159 int res = getIntAt(i); | |
160 if (DEBUG) { | |
161 System.err.println("ConstantPool.getFieldOrMethodAt(" + i + "): result = " + res); | |
162 } | |
163 return res; | |
164 } | |
165 | |
1602 | 166 public int[] getNameAndTypeAt(int which) { |
0 | 167 if (Assert.ASSERTS_ENABLED) { |
168 Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool"); | |
169 } | |
170 int i = getIntAt(which); | |
171 if (DEBUG) { | |
172 System.err.println("ConstantPool.getNameAndTypeAt(" + which + "): result = " + i); | |
173 } | |
1602 | 174 return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) }; |
0 | 175 } |
176 | |
177 public Symbol getNameRefAt(int which) { | |
1602 | 178 int nameIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[0]; |
0 | 179 return getSymbolAt(nameIndex); |
180 } | |
181 | |
182 public Symbol getSignatureRefAt(int which) { | |
1602 | 183 int sigIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[1]; |
0 | 184 return getSymbolAt(sigIndex); |
185 } | |
186 | |
187 // returns null, if not resolved. | |
188 public Klass getKlassRefAt(int which) { | |
189 if( ! getTagAt(which).isKlass()) return null; | |
190 return (Klass) getObjAt(which); | |
191 } | |
192 | |
193 // returns null, if not resolved. | |
194 public InstanceKlass getFieldOrMethodKlassRefAt(int which) { | |
195 int refIndex = getFieldOrMethodAt(which); | |
196 int klassIndex = extractLowShortFromInt(refIndex); | |
197 return (InstanceKlass) getKlassRefAt(klassIndex); | |
198 } | |
199 | |
200 // returns null, if not resolved. | |
201 public Method getMethodRefAt(int which) { | |
202 InstanceKlass klass = getFieldOrMethodKlassRefAt(which); | |
203 if (klass == null) return null; | |
204 Symbol name = getNameRefAt(which); | |
205 Symbol sig = getSignatureRefAt(which); | |
206 return klass.findMethod(name, sig); | |
207 } | |
208 | |
209 // returns null, if not resolved. | |
210 public Field getFieldRefAt(int which) { | |
211 InstanceKlass klass = getFieldOrMethodKlassRefAt(which); | |
212 if (klass == null) return null; | |
213 Symbol name = getNameRefAt(which); | |
214 Symbol sig = getSignatureRefAt(which); | |
215 return klass.findField(name, sig); | |
216 } | |
217 | |
218 public int getNameAndTypeRefIndexAt(int index) { | |
219 int refIndex = getFieldOrMethodAt(index); | |
220 if (DEBUG) { | |
221 System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): refIndex = " + refIndex); | |
222 } | |
223 int i = extractHighShortFromInt(refIndex); | |
224 if (DEBUG) { | |
225 System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): result = " + i); | |
226 } | |
227 return i; | |
228 } | |
229 | |
230 /** Lookup for entries consisting of (name_index, signature_index) */ | |
231 public int getNameRefIndexAt(int index) { | |
1602 | 232 int[] refIndex = getNameAndTypeAt(index); |
0 | 233 if (DEBUG) { |
1602 | 234 System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]); |
0 | 235 } |
1602 | 236 int i = refIndex[0]; |
0 | 237 if (DEBUG) { |
238 System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): result = " + i); | |
239 } | |
240 return i; | |
241 } | |
242 | |
243 /** Lookup for entries consisting of (name_index, signature_index) */ | |
244 public int getSignatureRefIndexAt(int index) { | |
1602 | 245 int[] refIndex = getNameAndTypeAt(index); |
0 | 246 if (DEBUG) { |
1602 | 247 System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]); |
0 | 248 } |
1602 | 249 int i = refIndex[1]; |
0 | 250 if (DEBUG) { |
251 System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): result = " + i); | |
252 } | |
253 return i; | |
254 } | |
255 | |
1602 | 256 /** Lookup for MethodHandle entries. */ |
257 public int getMethodHandleIndexAt(int i) { | |
258 if (Assert.ASSERTS_ENABLED) { | |
259 Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool"); | |
260 } | |
261 int res = extractHighShortFromInt(getIntAt(i)); | |
262 if (DEBUG) { | |
263 System.err.println("ConstantPool.getMethodHandleIndexAt(" + i + "): result = " + res); | |
264 } | |
265 return res; | |
266 } | |
267 | |
268 /** Lookup for MethodHandle entries. */ | |
269 public int getMethodHandleRefKindAt(int i) { | |
270 if (Assert.ASSERTS_ENABLED) { | |
271 Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool"); | |
272 } | |
273 int res = extractLowShortFromInt(getIntAt(i)); | |
274 if (DEBUG) { | |
275 System.err.println("ConstantPool.getMethodHandleRefKindAt(" + i + "): result = " + res); | |
276 } | |
277 return res; | |
278 } | |
279 | |
280 /** Lookup for MethodType entries. */ | |
281 public int getMethodTypeIndexAt(int i) { | |
282 if (Assert.ASSERTS_ENABLED) { | |
283 Assert.that(getTagAt(i).isMethodType(), "Corrupted constant pool"); | |
284 } | |
285 int res = getIntAt(i); | |
286 if (DEBUG) { | |
287 System.err.println("ConstantPool.getMethodHandleTypeAt(" + i + "): result = " + res); | |
288 } | |
289 return res; | |
290 } | |
291 | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
292 /** Lookup for multi-operand (InvokeDynamic) entries. */ |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
293 public short[] getBootstrapSpecifierAt(int i) { |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
294 if (Assert.ASSERTS_ENABLED) { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
295 Assert.that(getTagAt(i).isInvokeDynamic(), "Corrupted constant pool"); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
296 } |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
297 if (getTagAt(i).value() == JVM_CONSTANT_InvokeDynamicTrans) |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
298 return null; |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
299 int bsmSpec = extractLowShortFromInt(this.getIntAt(i)); |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
300 TypeArray operands = getOperands(); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
301 if (operands == null) return null; // safety first |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
302 int basePos = VM.getVM().buildIntFromShorts(operands.getShortAt(bsmSpec * 2 + 0), |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
303 operands.getShortAt(bsmSpec * 2 + 1)); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
304 int argv = basePos + INDY_ARGV_OFFSET; |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
305 int argc = operands.getShortAt(basePos + INDY_ARGC_OFFSET); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
306 int endPos = argv + argc; |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
307 short[] values = new short[endPos - basePos]; |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
308 for (int j = 0; j < values.length; j++) { |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
309 values[j] = operands.getShortAt(basePos+j); |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
310 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
311 return values; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
312 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
313 |
0 | 314 final private static String[] nameForTag = new String[] { |
315 }; | |
316 | |
317 private String nameForTag(int tag) { | |
318 switch (tag) { | |
319 case JVM_CONSTANT_Utf8: return "JVM_CONSTANT_Utf8"; | |
320 case JVM_CONSTANT_Unicode: return "JVM_CONSTANT_Unicode"; | |
321 case JVM_CONSTANT_Integer: return "JVM_CONSTANT_Integer"; | |
322 case JVM_CONSTANT_Float: return "JVM_CONSTANT_Float"; | |
323 case JVM_CONSTANT_Long: return "JVM_CONSTANT_Long"; | |
324 case JVM_CONSTANT_Double: return "JVM_CONSTANT_Double"; | |
325 case JVM_CONSTANT_Class: return "JVM_CONSTANT_Class"; | |
326 case JVM_CONSTANT_String: return "JVM_CONSTANT_String"; | |
327 case JVM_CONSTANT_Fieldref: return "JVM_CONSTANT_Fieldref"; | |
328 case JVM_CONSTANT_Methodref: return "JVM_CONSTANT_Methodref"; | |
329 case JVM_CONSTANT_InterfaceMethodref: return "JVM_CONSTANT_InterfaceMethodref"; | |
330 case JVM_CONSTANT_NameAndType: return "JVM_CONSTANT_NameAndType"; | |
1602 | 331 case JVM_CONSTANT_MethodHandle: return "JVM_CONSTANT_MethodHandle"; |
332 case JVM_CONSTANT_MethodType: return "JVM_CONSTANT_MethodType"; | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
333 case JVM_CONSTANT_InvokeDynamic: return "JVM_CONSTANT_InvokeDynamic"; |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
334 case JVM_CONSTANT_InvokeDynamicTrans: return "JVM_CONSTANT_InvokeDynamic/transitional"; |
0 | 335 case JVM_CONSTANT_Invalid: return "JVM_CONSTANT_Invalid"; |
336 case JVM_CONSTANT_UnresolvedClass: return "JVM_CONSTANT_UnresolvedClass"; | |
1385 | 337 case JVM_CONSTANT_UnresolvedClassInError: return "JVM_CONSTANT_UnresolvedClassInError"; |
0 | 338 case JVM_CONSTANT_ClassIndex: return "JVM_CONSTANT_ClassIndex"; |
339 case JVM_CONSTANT_UnresolvedString: return "JVM_CONSTANT_UnresolvedString"; | |
340 case JVM_CONSTANT_StringIndex: return "JVM_CONSTANT_StringIndex"; | |
341 } | |
1385 | 342 throw new InternalError("Unknown tag: " + tag); |
0 | 343 } |
344 | |
345 public void iterateFields(OopVisitor visitor, boolean doVMFields) { | |
346 super.iterateFields(visitor, doVMFields); | |
347 if (doVMFields) { | |
348 visitor.doOop(tags, true); | |
349 visitor.doOop(cache, true); | |
350 visitor.doOop(poolHolder, true); | |
351 | |
352 final int length = (int) getLength(); | |
353 // zero'th pool entry is always invalid. ignore it. | |
354 for (int index = 1; index < length; index++) { | |
355 int ctag = (int) getTags().getByteAt((int) index); | |
356 switch (ctag) { | |
357 case JVM_CONSTANT_ClassIndex: | |
358 case JVM_CONSTANT_StringIndex: | |
359 case JVM_CONSTANT_Integer: | |
360 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
361 break; | |
362 | |
363 case JVM_CONSTANT_Float: | |
364 visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
365 break; | |
366 | |
367 case JVM_CONSTANT_Long: | |
368 visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
369 // long entries occupy two slots | |
370 index++; | |
371 break; | |
372 | |
373 case JVM_CONSTANT_Double: | |
374 visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
375 // double entries occupy two slots | |
376 index++; | |
377 break; | |
378 | |
1385 | 379 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 380 case JVM_CONSTANT_UnresolvedClass: |
381 case JVM_CONSTANT_Class: | |
382 case JVM_CONSTANT_UnresolvedString: | |
383 case JVM_CONSTANT_Utf8: | |
384 visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
385 break; | |
386 | |
387 case JVM_CONSTANT_Fieldref: | |
388 case JVM_CONSTANT_Methodref: | |
389 case JVM_CONSTANT_InterfaceMethodref: | |
390 case JVM_CONSTANT_NameAndType: | |
1602 | 391 case JVM_CONSTANT_MethodHandle: |
392 case JVM_CONSTANT_MethodType: | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
393 case JVM_CONSTANT_InvokeDynamic: |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
394 case JVM_CONSTANT_InvokeDynamicTrans: |
0 | 395 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
396 break; | |
397 } | |
398 } | |
399 } | |
400 /* | |
401 int length = getLength(); | |
402 for (int index = 0; index < length; index++) { | |
403 long offset = baseOffset + (index + typeDataBase.getOopSize()); | |
404 visitor.doOop(new IndexableField(index, offset, false), getObjAt(index)); | |
405 } | |
406 */ | |
407 } | |
408 | |
409 public void writeBytes(OutputStream os) throws IOException { | |
410 // Map between any modified UTF-8 and it's constant pool index. | |
411 Map utf8ToIndex = new HashMap(); | |
412 DataOutputStream dos = new DataOutputStream(os); | |
413 TypeArray tags = getTags(); | |
414 int len = (int)getLength(); | |
415 int ci = 0; // constant pool index | |
416 | |
417 // collect all modified UTF-8 Strings from Constant Pool | |
418 | |
419 for (ci = 1; ci < len; ci++) { | |
420 byte cpConstType = tags.getByteAt(ci); | |
421 if(cpConstType == JVM_CONSTANT_Utf8) { | |
422 Symbol sym = getSymbolAt(ci); | |
423 utf8ToIndex.put(sym.asString(), new Short((short) ci)); | |
424 } | |
425 else if(cpConstType == JVM_CONSTANT_Long || | |
426 cpConstType == JVM_CONSTANT_Double) { | |
427 ci++; | |
428 } | |
429 } | |
430 | |
431 | |
432 for(ci = 1; ci < len; ci++) { | |
433 int cpConstType = (int)tags.getByteAt(ci); | |
434 // write cp_info | |
435 // write constant type | |
436 switch(cpConstType) { | |
437 case JVM_CONSTANT_Utf8: { | |
438 dos.writeByte(cpConstType); | |
439 Symbol sym = getSymbolAt(ci); | |
440 dos.writeShort((short)sym.getLength()); | |
441 dos.write(sym.asByteArray()); | |
442 if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString()); | |
443 break; | |
444 } | |
445 | |
446 case JVM_CONSTANT_Unicode: | |
447 throw new IllegalArgumentException("Unicode constant!"); | |
448 | |
449 case JVM_CONSTANT_Integer: | |
450 dos.writeByte(cpConstType); | |
451 dos.writeInt(getIntAt(ci)); | |
452 if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci)); | |
453 break; | |
454 | |
455 case JVM_CONSTANT_Float: | |
456 dos.writeByte(cpConstType); | |
457 dos.writeFloat(getFloatAt(ci)); | |
458 if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci)); | |
459 break; | |
460 | |
461 case JVM_CONSTANT_Long: { | |
462 dos.writeByte(cpConstType); | |
463 long l = getLongAt(ci); | |
464 // long entries occupy two pool entries | |
465 ci++; | |
466 dos.writeLong(l); | |
467 break; | |
468 } | |
469 | |
470 case JVM_CONSTANT_Double: | |
471 dos.writeByte(cpConstType); | |
472 dos.writeDouble(getDoubleAt(ci)); | |
473 // double entries occupy two pool entries | |
474 ci++; | |
475 break; | |
476 | |
477 case JVM_CONSTANT_Class: { | |
478 dos.writeByte(cpConstType); | |
479 // Klass already resolved. ConstantPool constains klassOop. | |
480 Klass refKls = (Klass) getObjAt(ci); | |
481 String klassName = refKls.getName().asString(); | |
482 Short s = (Short) utf8ToIndex.get(klassName); | |
483 dos.writeShort(s.shortValue()); | |
484 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
485 break; | |
486 } | |
487 | |
488 // case JVM_CONSTANT_ClassIndex: | |
1385 | 489 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 490 case JVM_CONSTANT_UnresolvedClass: { |
491 dos.writeByte(JVM_CONSTANT_Class); | |
492 String klassName = getSymbolAt(ci).asString(); | |
493 Short s = (Short) utf8ToIndex.get(klassName); | |
494 dos.writeShort(s.shortValue()); | |
495 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
496 break; | |
497 } | |
498 | |
499 case JVM_CONSTANT_String: { | |
500 dos.writeByte(cpConstType); | |
501 String str = OopUtilities.stringOopToString(getObjAt(ci)); | |
502 Short s = (Short) utf8ToIndex.get(str); | |
503 dos.writeShort(s.shortValue()); | |
504 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | |
505 break; | |
506 } | |
507 | |
508 // case JVM_CONSTANT_StringIndex: | |
509 case JVM_CONSTANT_UnresolvedString: { | |
510 dos.writeByte(JVM_CONSTANT_String); | |
511 String val = getSymbolAt(ci).asString(); | |
512 | |
513 Short s = (Short) utf8ToIndex.get(val); | |
514 dos.writeShort(s.shortValue()); | |
515 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | |
516 break; | |
517 } | |
518 | |
519 // all external, internal method/field references | |
520 case JVM_CONSTANT_Fieldref: | |
521 case JVM_CONSTANT_Methodref: | |
522 case JVM_CONSTANT_InterfaceMethodref: { | |
523 dos.writeByte(cpConstType); | |
524 int value = getIntAt(ci); | |
525 short klassIndex = (short) extractLowShortFromInt(value); | |
526 short nameAndTypeIndex = (short) extractHighShortFromInt(value); | |
527 dos.writeShort(klassIndex); | |
528 dos.writeShort(nameAndTypeIndex); | |
529 if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " + | |
530 klassIndex + ", N&T = " + nameAndTypeIndex); | |
531 break; | |
532 } | |
533 | |
534 case JVM_CONSTANT_NameAndType: { | |
535 dos.writeByte(cpConstType); | |
536 int value = getIntAt(ci); | |
537 short nameIndex = (short) extractLowShortFromInt(value); | |
538 short signatureIndex = (short) extractHighShortFromInt(value); | |
539 dos.writeShort(nameIndex); | |
540 dos.writeShort(signatureIndex); | |
541 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex | |
542 + ", type = " + signatureIndex); | |
543 break; | |
544 } | |
1602 | 545 |
546 case JVM_CONSTANT_MethodHandle: { | |
547 dos.writeByte(cpConstType); | |
548 int value = getIntAt(ci); | |
549 short nameIndex = (short) extractLowShortFromInt(value); | |
550 short signatureIndex = (short) extractHighShortFromInt(value); | |
551 dos.writeShort(nameIndex); | |
552 dos.writeShort(signatureIndex); | |
553 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex | |
554 + ", type = " + signatureIndex); | |
555 break; | |
556 } | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
557 |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
558 case JVM_CONSTANT_InvokeDynamicTrans: |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
559 case JVM_CONSTANT_InvokeDynamic: { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
560 dos.writeByte(cpConstType); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
561 int value = getIntAt(ci); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
562 short bsmIndex = (short) extractLowShortFromInt(value); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
563 short nameAndTypeIndex = (short) extractHighShortFromInt(value); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
564 dos.writeShort(bsmIndex); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
565 dos.writeShort(nameAndTypeIndex); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
566 if (DEBUG) debugMessage("CP[" + ci + "] = indy BSM = " + bsmIndex |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
567 + ", N&T = " + nameAndTypeIndex); |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
568 break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
569 } |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
570 |
1385 | 571 default: |
572 throw new InternalError("unknown tag: " + cpConstType); | |
0 | 573 } // switch |
574 } | |
575 dos.flush(); | |
576 return; | |
577 } | |
578 | |
579 public void printValueOn(PrintStream tty) { | |
580 tty.print("ConstantPool for " + getPoolHolder().getName().asString()); | |
581 } | |
582 | |
583 public long getObjectSize() { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
584 return alignObjectSize(headerSize + (getLength() * getElementSize())); |
0 | 585 } |
586 | |
587 //---------------------------------------------------------------------- | |
588 // Internals only below this point | |
589 // | |
590 | |
591 private static int extractHighShortFromInt(int val) { | |
1602 | 592 // must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc. |
0 | 593 return (val >> 16) & 0xFFFF; |
594 } | |
595 | |
596 private static int extractLowShortFromInt(int val) { | |
1602 | 597 // must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc. |
0 | 598 return val & 0xFFFF; |
599 } | |
600 } |