Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 1602:136b78722a08
6939203: JSR 292 needs method handle constants
Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode.
Reviewed-by: twisti, never
author | jrose |
---|---|
date | Wed, 09 Jun 2010 18:50:45 -0700 |
parents | c18cbe5936b8 |
children | 083fde3b838e |
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"; | |
0 | 300 case JVM_CONSTANT_Invalid: return "JVM_CONSTANT_Invalid"; |
301 case JVM_CONSTANT_UnresolvedClass: return "JVM_CONSTANT_UnresolvedClass"; | |
1385 | 302 case JVM_CONSTANT_UnresolvedClassInError: return "JVM_CONSTANT_UnresolvedClassInError"; |
0 | 303 case JVM_CONSTANT_ClassIndex: return "JVM_CONSTANT_ClassIndex"; |
304 case JVM_CONSTANT_UnresolvedString: return "JVM_CONSTANT_UnresolvedString"; | |
305 case JVM_CONSTANT_StringIndex: return "JVM_CONSTANT_StringIndex"; | |
306 } | |
1385 | 307 throw new InternalError("Unknown tag: " + tag); |
0 | 308 } |
309 | |
310 public void iterateFields(OopVisitor visitor, boolean doVMFields) { | |
311 super.iterateFields(visitor, doVMFields); | |
312 if (doVMFields) { | |
313 visitor.doOop(tags, true); | |
314 visitor.doOop(cache, true); | |
315 visitor.doOop(poolHolder, true); | |
316 | |
317 final int length = (int) getLength(); | |
318 // zero'th pool entry is always invalid. ignore it. | |
319 for (int index = 1; index < length; index++) { | |
320 int ctag = (int) getTags().getByteAt((int) index); | |
321 switch (ctag) { | |
322 case JVM_CONSTANT_ClassIndex: | |
323 case JVM_CONSTANT_StringIndex: | |
324 case JVM_CONSTANT_Integer: | |
325 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
326 break; | |
327 | |
328 case JVM_CONSTANT_Float: | |
329 visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
330 break; | |
331 | |
332 case JVM_CONSTANT_Long: | |
333 visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
334 // long entries occupy two slots | |
335 index++; | |
336 break; | |
337 | |
338 case JVM_CONSTANT_Double: | |
339 visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
340 // double entries occupy two slots | |
341 index++; | |
342 break; | |
343 | |
1385 | 344 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 345 case JVM_CONSTANT_UnresolvedClass: |
346 case JVM_CONSTANT_Class: | |
347 case JVM_CONSTANT_UnresolvedString: | |
348 case JVM_CONSTANT_Utf8: | |
349 visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
350 break; | |
351 | |
352 case JVM_CONSTANT_Fieldref: | |
353 case JVM_CONSTANT_Methodref: | |
354 case JVM_CONSTANT_InterfaceMethodref: | |
355 case JVM_CONSTANT_NameAndType: | |
1602 | 356 case JVM_CONSTANT_MethodHandle: |
357 case JVM_CONSTANT_MethodType: | |
0 | 358 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
359 break; | |
360 } | |
361 } | |
362 } | |
363 /* | |
364 int length = getLength(); | |
365 for (int index = 0; index < length; index++) { | |
366 long offset = baseOffset + (index + typeDataBase.getOopSize()); | |
367 visitor.doOop(new IndexableField(index, offset, false), getObjAt(index)); | |
368 } | |
369 */ | |
370 } | |
371 | |
372 public void writeBytes(OutputStream os) throws IOException { | |
373 // Map between any modified UTF-8 and it's constant pool index. | |
374 Map utf8ToIndex = new HashMap(); | |
375 DataOutputStream dos = new DataOutputStream(os); | |
376 TypeArray tags = getTags(); | |
377 int len = (int)getLength(); | |
378 int ci = 0; // constant pool index | |
379 | |
380 // collect all modified UTF-8 Strings from Constant Pool | |
381 | |
382 for (ci = 1; ci < len; ci++) { | |
383 byte cpConstType = tags.getByteAt(ci); | |
384 if(cpConstType == JVM_CONSTANT_Utf8) { | |
385 Symbol sym = getSymbolAt(ci); | |
386 utf8ToIndex.put(sym.asString(), new Short((short) ci)); | |
387 } | |
388 else if(cpConstType == JVM_CONSTANT_Long || | |
389 cpConstType == JVM_CONSTANT_Double) { | |
390 ci++; | |
391 } | |
392 } | |
393 | |
394 | |
395 for(ci = 1; ci < len; ci++) { | |
396 int cpConstType = (int)tags.getByteAt(ci); | |
397 // write cp_info | |
398 // write constant type | |
399 switch(cpConstType) { | |
400 case JVM_CONSTANT_Utf8: { | |
401 dos.writeByte(cpConstType); | |
402 Symbol sym = getSymbolAt(ci); | |
403 dos.writeShort((short)sym.getLength()); | |
404 dos.write(sym.asByteArray()); | |
405 if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString()); | |
406 break; | |
407 } | |
408 | |
409 case JVM_CONSTANT_Unicode: | |
410 throw new IllegalArgumentException("Unicode constant!"); | |
411 | |
412 case JVM_CONSTANT_Integer: | |
413 dos.writeByte(cpConstType); | |
414 dos.writeInt(getIntAt(ci)); | |
415 if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci)); | |
416 break; | |
417 | |
418 case JVM_CONSTANT_Float: | |
419 dos.writeByte(cpConstType); | |
420 dos.writeFloat(getFloatAt(ci)); | |
421 if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci)); | |
422 break; | |
423 | |
424 case JVM_CONSTANT_Long: { | |
425 dos.writeByte(cpConstType); | |
426 long l = getLongAt(ci); | |
427 // long entries occupy two pool entries | |
428 ci++; | |
429 dos.writeLong(l); | |
430 break; | |
431 } | |
432 | |
433 case JVM_CONSTANT_Double: | |
434 dos.writeByte(cpConstType); | |
435 dos.writeDouble(getDoubleAt(ci)); | |
436 // double entries occupy two pool entries | |
437 ci++; | |
438 break; | |
439 | |
440 case JVM_CONSTANT_Class: { | |
441 dos.writeByte(cpConstType); | |
442 // Klass already resolved. ConstantPool constains klassOop. | |
443 Klass refKls = (Klass) getObjAt(ci); | |
444 String klassName = refKls.getName().asString(); | |
445 Short s = (Short) utf8ToIndex.get(klassName); | |
446 dos.writeShort(s.shortValue()); | |
447 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
448 break; | |
449 } | |
450 | |
451 // case JVM_CONSTANT_ClassIndex: | |
1385 | 452 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 453 case JVM_CONSTANT_UnresolvedClass: { |
454 dos.writeByte(JVM_CONSTANT_Class); | |
455 String klassName = getSymbolAt(ci).asString(); | |
456 Short s = (Short) utf8ToIndex.get(klassName); | |
457 dos.writeShort(s.shortValue()); | |
458 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
459 break; | |
460 } | |
461 | |
462 case JVM_CONSTANT_String: { | |
463 dos.writeByte(cpConstType); | |
464 String str = OopUtilities.stringOopToString(getObjAt(ci)); | |
465 Short s = (Short) utf8ToIndex.get(str); | |
466 dos.writeShort(s.shortValue()); | |
467 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | |
468 break; | |
469 } | |
470 | |
471 // case JVM_CONSTANT_StringIndex: | |
472 case JVM_CONSTANT_UnresolvedString: { | |
473 dos.writeByte(JVM_CONSTANT_String); | |
474 String val = getSymbolAt(ci).asString(); | |
475 | |
476 Short s = (Short) utf8ToIndex.get(val); | |
477 dos.writeShort(s.shortValue()); | |
478 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | |
479 break; | |
480 } | |
481 | |
482 // all external, internal method/field references | |
483 case JVM_CONSTANT_Fieldref: | |
484 case JVM_CONSTANT_Methodref: | |
485 case JVM_CONSTANT_InterfaceMethodref: { | |
486 dos.writeByte(cpConstType); | |
487 int value = getIntAt(ci); | |
488 short klassIndex = (short) extractLowShortFromInt(value); | |
489 short nameAndTypeIndex = (short) extractHighShortFromInt(value); | |
490 dos.writeShort(klassIndex); | |
491 dos.writeShort(nameAndTypeIndex); | |
492 if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " + | |
493 klassIndex + ", N&T = " + nameAndTypeIndex); | |
494 break; | |
495 } | |
496 | |
497 case JVM_CONSTANT_NameAndType: { | |
498 dos.writeByte(cpConstType); | |
499 int value = getIntAt(ci); | |
500 short nameIndex = (short) extractLowShortFromInt(value); | |
501 short signatureIndex = (short) extractHighShortFromInt(value); | |
502 dos.writeShort(nameIndex); | |
503 dos.writeShort(signatureIndex); | |
504 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex | |
505 + ", type = " + signatureIndex); | |
506 break; | |
507 } | |
1602 | 508 |
509 case JVM_CONSTANT_MethodHandle: { | |
510 dos.writeByte(cpConstType); | |
511 int value = getIntAt(ci); | |
512 short nameIndex = (short) extractLowShortFromInt(value); | |
513 short signatureIndex = (short) extractHighShortFromInt(value); | |
514 dos.writeShort(nameIndex); | |
515 dos.writeShort(signatureIndex); | |
516 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex | |
517 + ", type = " + signatureIndex); | |
518 break; | |
519 } | |
1385 | 520 default: |
521 throw new InternalError("unknown tag: " + cpConstType); | |
0 | 522 } // switch |
523 } | |
524 dos.flush(); | |
525 return; | |
526 } | |
527 | |
528 public void printValueOn(PrintStream tty) { | |
529 tty.print("ConstantPool for " + getPoolHolder().getName().asString()); | |
530 } | |
531 | |
532 public long getObjectSize() { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
533 return alignObjectSize(headerSize + (getLength() * getElementSize())); |
0 | 534 } |
535 | |
536 //---------------------------------------------------------------------- | |
537 // Internals only below this point | |
538 // | |
539 | |
540 private static int extractHighShortFromInt(int val) { | |
1602 | 541 // must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc. |
0 | 542 return (val >> 16) & 0xFFFF; |
543 } | |
544 | |
545 private static int extractLowShortFromInt(int val) { | |
1602 | 546 // must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc. |
0 | 547 return val & 0xFFFF; |
548 } | |
549 } |