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