301 302 static class CpPatch { 303 304 final int index; 305 final String placeholder; 306 final Object value; 307 308 CpPatch(int index, String placeholder, Object value) { 309 this.index = index; 310 this.placeholder = placeholder; 311 this.value = value; 312 } 313 314 public String toString() { 315 return "CpPatch/index="+index+",placeholder="+placeholder+",value="+value; 316 } 317 } 318 319 @Override 320 public int putValue(Object v) { 321 if (v instanceof Class<?> || v instanceof MethodHandle || v instanceof MethodType) { 322 return patchPoolEntry(v); 323 } 324 return basicPoolHelper.putValue(v); 325 } 326 327 int patchPoolEntry(Object v) { 328 String cpPlaceholder = "CONSTANT_PLACEHOLDER_" + cph++; 329 if (MinimalValueTypes_1_0.DUMP_CLASS_FILES) cpPlaceholder += " <<" + debugString(v) + ">>"; 330 if (cpPatches.containsKey(cpPlaceholder)) { 331 throw new InternalError("observed CP placeholder twice: " + cpPlaceholder); 332 } 333 // insert placeholder in CP and remember the patch 334 int index = basicPoolHelper.putValue(cpPlaceholder); // TODO check if already in the constant pool 335 cpPatches.put(cpPlaceholder, new CpPatch(index, cpPlaceholder, v)); 336 return index; 337 } 338 339 @Override 340 Object[] patches() { 341 int size = size(); 342 Object[] res = new Object[size]; 343 for (CpPatch p : cpPatches.values()) { 344 if (p.index >= size) 345 throw new InternalError("bad cp patch index"); | 301 302 static class CpPatch { 303 304 final int index; 305 final String placeholder; 306 final Object value; 307 308 CpPatch(int index, String placeholder, Object value) { 309 this.index = index; 310 this.placeholder = placeholder; 311 this.value = value; 312 } 313 314 public String toString() { 315 return "CpPatch/index="+index+",placeholder="+placeholder+",value="+value; 316 } 317 } 318 319 @Override 320 public int putValue(Object v) { 321 if (v instanceof String || v instanceof Integer || v instanceof Float || v instanceof Double || v instanceof Long) { 322 return basicPoolHelper.putValue(v); 323 } 324 assert (!v.getClass().isPrimitive()) : v; 325 return patchPoolEntry(v); // CP patching support 326 } 327 328 int patchPoolEntry(Object v) { 329 String cpPlaceholder = "CONSTANT_PLACEHOLDER_" + cph++; 330 if (MinimalValueTypes_1_0.DUMP_CLASS_FILES) cpPlaceholder += " <<" + debugString(v) + ">>"; 331 if (cpPatches.containsKey(cpPlaceholder)) { 332 throw new InternalError("observed CP placeholder twice: " + cpPlaceholder); 333 } 334 // insert placeholder in CP and remember the patch 335 int index = basicPoolHelper.putValue(cpPlaceholder); // TODO check if already in the constant pool 336 cpPatches.put(cpPlaceholder, new CpPatch(index, cpPlaceholder, v)); 337 return index; 338 } 339 340 @Override 341 Object[] patches() { 342 int size = size(); 343 Object[] res = new Object[size]; 344 for (CpPatch p : cpPatches.values()) { 345 if (p.index >= size) 346 throw new InternalError("bad cp patch index"); |