comparison agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 1913:3b2dea75431e

6984311: JSR 292 needs optional bootstrap method parameters Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands. Reviewed-by: twisti
author jrose
date Sat, 30 Oct 2010 13:08:23 -0700
parents 083fde3b838e
children dad31fc330cd
comparison
equal deleted inserted replaced
1912:8213b0f5c92d 1913:3b2dea75431e
51 } 51 }
52 52
53 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 53 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
54 Type type = db.lookupType("constantPoolOopDesc"); 54 Type type = db.lookupType("constantPoolOopDesc");
55 tags = new OopField(type.getOopField("_tags"), 0); 55 tags = new OopField(type.getOopField("_tags"), 0);
56 operands = new OopField(type.getOopField("_operands"), 0);
56 cache = new OopField(type.getOopField("_cache"), 0); 57 cache = new OopField(type.getOopField("_cache"), 0);
57 poolHolder = new OopField(type.getOopField("_pool_holder"), 0); 58 poolHolder = new OopField(type.getOopField("_pool_holder"), 0);
58 length = new CIntField(type.getCIntegerField("_length"), 0); 59 length = new CIntField(type.getCIntegerField("_length"), 0);
59 headerSize = type.getSize(); 60 headerSize = type.getSize();
60 elementSize = 0; 61 elementSize = 0;
62 // fetch constants:
63 MULTI_OPERAND_COUNT_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_multi_operand_count_offset").intValue();
64 MULTI_OPERAND_BASE_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_multi_operand_base_offset").intValue();
65 INDY_BSM_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_bsm_offset").intValue();
66 INDY_NT_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_nt_offset").intValue();
67 INDY_ARGC_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argc_offset").intValue();
68 INDY_ARGV_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argv_offset").intValue();
61 } 69 }
62 70
63 ConstantPool(OopHandle handle, ObjectHeap heap) { 71 ConstantPool(OopHandle handle, ObjectHeap heap) {
64 super(handle, heap); 72 super(handle, heap);
65 } 73 }
66 74
67 public boolean isConstantPool() { return true; } 75 public boolean isConstantPool() { return true; }
68 76
69 private static OopField tags; 77 private static OopField tags;
78 private static OopField operands;
70 private static OopField cache; 79 private static OopField cache;
71 private static OopField poolHolder; 80 private static OopField poolHolder;
72 private static CIntField length; // number of elements in oop 81 private static CIntField length; // number of elements in oop
73 82
74 private static long headerSize; 83 private static long headerSize;
75 private static long elementSize; 84 private static long elementSize;
76 85
86 private static int MULTI_OPERAND_COUNT_OFFSET;
87 private static int MULTI_OPERAND_BASE_OFFSET;
88 private static int INDY_BSM_OFFSET;
89 private static int INDY_NT_OFFSET;
90 private static int INDY_ARGC_OFFSET;
91 private static int INDY_ARGV_OFFSET;
92
77 public TypeArray getTags() { return (TypeArray) tags.getValue(this); } 93 public TypeArray getTags() { return (TypeArray) tags.getValue(this); }
94 public TypeArray getOperands() { return (TypeArray) operands.getValue(this); }
78 public ConstantPoolCache getCache() { return (ConstantPoolCache) cache.getValue(this); } 95 public ConstantPoolCache getCache() { return (ConstantPoolCache) cache.getValue(this); }
79 public Klass getPoolHolder() { return (Klass) poolHolder.getValue(this); } 96 public Klass getPoolHolder() { return (Klass) poolHolder.getValue(this); }
80 public int getLength() { return (int)length.getValue(this); } 97 public int getLength() { return (int)length.getValue(this); }
81 98
82 private long getElementSize() { 99 private long getElementSize() {
274 int res = getIntAt(i); 291 int res = getIntAt(i);
275 if (DEBUG) { 292 if (DEBUG) {
276 System.err.println("ConstantPool.getMethodHandleTypeAt(" + i + "): result = " + res); 293 System.err.println("ConstantPool.getMethodHandleTypeAt(" + i + "): result = " + res);
277 } 294 }
278 return res; 295 return res;
296 }
297
298 /** Lookup for multi-operand (InvokeDynamic) entries. */
299 public int[] getMultiOperandsAt(int i) {
300 if (Assert.ASSERTS_ENABLED) {
301 Assert.that(getTagAt(i).isInvokeDynamic(), "Corrupted constant pool");
302 }
303 int pos = this.getIntAt(i);
304 int countPos = pos + MULTI_OPERAND_COUNT_OFFSET; // == pos-1
305 int basePos = pos + MULTI_OPERAND_BASE_OFFSET; // == pos
306 if (countPos < 0) return null; // safety first
307 TypeArray operands = getOperands();
308 if (operands == null) return null; // safety first
309 int length = operands.getIntAt(countPos);
310 int[] values = new int[length];
311 for (int j = 0; j < length; j++) {
312 values[j] = operands.getIntAt(basePos+j);
313 }
314 return values;
279 } 315 }
280 316
281 final private static String[] nameForTag = new String[] { 317 final private static String[] nameForTag = new String[] {
282 }; 318 };
283 319
520 break; 556 break;
521 } 557 }
522 558
523 case JVM_CONSTANT_InvokeDynamic: { 559 case JVM_CONSTANT_InvokeDynamic: {
524 dos.writeByte(cpConstType); 560 dos.writeByte(cpConstType);
525 int value = getIntAt(ci); 561 int[] values = getMultiOperandsAt(ci);
526 short bootstrapMethodIndex = (short) extractLowShortFromInt(value); 562 for (int vn = 0; vn < values.length; vn++) {
527 short nameAndTypeIndex = (short) extractHighShortFromInt(value); 563 dos.writeShort(values[vn]);
528 dos.writeShort(bootstrapMethodIndex); 564 }
529 dos.writeShort(nameAndTypeIndex); 565 int bootstrapMethodIndex = values[INDY_BSM_OFFSET];
566 int nameAndTypeIndex = values[INDY_NT_OFFSET];
567 int argumentCount = values[INDY_ARGC_OFFSET];
568 assert(INDY_ARGV_OFFSET + argumentCount == values.length);
530 if (DEBUG) debugMessage("CP[" + ci + "] = indy BSM = " + bootstrapMethodIndex 569 if (DEBUG) debugMessage("CP[" + ci + "] = indy BSM = " + bootstrapMethodIndex
531 + ", N&T = " + nameAndTypeIndex); 570 + ", N&T = " + nameAndTypeIndex
532 break; 571 + ", argc = " + argumentCount);
533 } 572 break;
573 }
574
534 default: 575 default:
535 throw new InternalError("unknown tag: " + cpConstType); 576 throw new InternalError("unknown tag: " + cpConstType);
536 } // switch 577 } // switch
537 } 578 }
538 dos.flush(); 579 dos.flush();