< prev index next >

test/jdk/lib/testlibrary/bytecode/jdk/experimental/bytecode/BytePoolHelper.java

Print this page
rev 47761 : 8186209: Tool support for ConstantDynamic
8186046: Minimal ConstantDynamic support
Reviewed-by: acorn
Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com, paul.sandoz@oracle.com
* * *
Minor Hotspot code cleanup changes resulting from condy review
Summary: Addressed missing DynamicInError condition, removed unused TraceDynamicConstants
Reviewed-by: acorn, psandoz
rev 47762 : 8187742: Minimal set of bootstrap methods for constant dynamic
Contributed-by: brian.goetz@oracle.com, john.r.rose@oracle.com, paul.sandoz@oracle.com
Reviewed-by: forax


 473         if (poolKey == null) {
 474             poolKey = key.dup();
 475             int nameAndType_idx = putNameAndType(constName, constType);
 476             poolKey.at(currentIndex++);
 477             entries.enter(poolKey);
 478             pool.writeByte(PoolTag.CONSTANT_DYNAMIC.tag);
 479             pool.writeChar(bsmIndex);
 480             pool.writeChar(nameAndType_idx);
 481         }
 482         return poolKey.index;
 483     }
 484 
 485     private int putBsmInternal(String bsmClass, CharSequence bsmName, String bsmType, Consumer<StaticArgListBuilder<S, T, byte[]>> staticArgs) {
 486         ByteStaticArgListBuilder staticArgsBuilder = new ByteStaticArgListBuilder();
 487         staticArgs.accept(staticArgsBuilder);
 488         List<Integer> static_idxs = staticArgsBuilder.indexes;
 489         bsmKey.set(bsmClass, bsmName, bsmType, static_idxs);
 490         BsmKey poolKey = bootstraps.lookup(bsmKey);
 491         if (poolKey == null) {
 492             poolKey = bsmKey.dup();
 493             int bsm_ref = putHandleInternal(MethodHandleInfo.REF_invokeStatic, bsmClass, bsmName, bsmType);

 494             poolKey.at(currentBsmIndex++);
 495             bootstraps.enter(poolKey);
 496             bsm_attr.writeChar(bsm_ref);
 497             bsm_attr.writeChar(static_idxs.size());
 498             for (int i : static_idxs) {
 499                 bsm_attr.writeChar(i);
 500             }
 501         }
 502         return poolKey.index;
 503     }
 504     //where
 505         class ByteStaticArgListBuilder implements StaticArgListBuilder<S, T, byte[]> {
 506 
 507             List<Integer> indexes = new ArrayList<>();
 508 
 509             public ByteStaticArgListBuilder add(int i) {
 510                 indexes.add(putInt(i));
 511                 return this;
 512             }
 513             public ByteStaticArgListBuilder add(float f) {


 545     public int putMethodType(T s) {
 546         return putMethodTypeInternal(typeToString.apply(s));
 547     }
 548 
 549     private int putMethodTypeInternal(String s) {
 550         key.setMethodType(s);
 551         PoolKey poolKey = entries.lookup(key);
 552         if (poolKey == null) {
 553             poolKey = key.dup();
 554             int desc_idx = putUtf8(s);
 555             poolKey.at(currentIndex++);
 556             entries.enter(poolKey);
 557             pool.writeByte(PoolTag.CONSTANT_METHODTYPE.tag);
 558             pool.writeChar(desc_idx);
 559         }
 560         return poolKey.index;
 561     }
 562 
 563     @Override
 564     public int putHandle(int refKind, S owner, CharSequence name, T type) {
 565         return putHandleInternal(refKind, symbolToString.apply(owner), name, typeToString.apply(type));
 566     }
 567 
 568     private int putHandleInternal(int refKind, String owner, CharSequence name, String type) {





 569         key.setMethodHandle(refKind, owner, name, type);
 570         PoolKey poolKey = entries.lookup(key);
 571         if (poolKey == null) {
 572             poolKey = key.dup();
 573             int ref_idx = putMemberRefInternal(fromKind(refKind), owner, name, type);
 574             poolKey.at(currentIndex++);
 575             entries.enter(poolKey);
 576             pool.writeByte(PoolTag.CONSTANT_METHODHANDLE.tag);
 577             pool.writeByte(refKind);
 578             pool.writeChar(ref_idx);
 579         }
 580         return poolKey.index;
 581     }
 582 
 583     PoolTag fromKind(int bsmKind) {
 584         switch (bsmKind) {
 585             case 1: // REF_getField
 586             case 2: // REF_getStatic
 587             case 3: // REF_putField
 588             case 4: // REF_putStatic
 589                 return PoolTag.CONSTANT_FIELDREF;
 590             case 5: // REF_invokeVirtual
 591             case 6: // REF_invokeStatic
 592             case 7: // REF_invokeSpecial
 593             case 8: // REF_newInvokeSpecial
 594                 return PoolTag.CONSTANT_METHODREF;
 595             case 9: // REF_invokeInterface
 596                 return PoolTag.CONSTANT_INTERFACEMETHODREF;
 597             default:
 598                 throw new IllegalStateException();
 599         }
 600     }
 601 
 602     @Override
 603     public int putType(T s) {
 604         return putUtf8(typeToString.apply(s));
 605     }
 606 
 607     public int putUtf8(CharSequence s) {
 608         key.setUtf8(s);
 609         PoolKey poolKey = entries.lookup(key);
 610         if (poolKey == null) {
 611             poolKey = key.dup();
 612             poolKey.at(currentIndex++);
 613             entries.enter(poolKey);
 614             pool.writeByte(PoolTag.CONSTANT_UTF8.tag);
 615             putUTF8Internal(s);
 616         }




 473         if (poolKey == null) {
 474             poolKey = key.dup();
 475             int nameAndType_idx = putNameAndType(constName, constType);
 476             poolKey.at(currentIndex++);
 477             entries.enter(poolKey);
 478             pool.writeByte(PoolTag.CONSTANT_DYNAMIC.tag);
 479             pool.writeChar(bsmIndex);
 480             pool.writeChar(nameAndType_idx);
 481         }
 482         return poolKey.index;
 483     }
 484 
 485     private int putBsmInternal(String bsmClass, CharSequence bsmName, String bsmType, Consumer<StaticArgListBuilder<S, T, byte[]>> staticArgs) {
 486         ByteStaticArgListBuilder staticArgsBuilder = new ByteStaticArgListBuilder();
 487         staticArgs.accept(staticArgsBuilder);
 488         List<Integer> static_idxs = staticArgsBuilder.indexes;
 489         bsmKey.set(bsmClass, bsmName, bsmType, static_idxs);
 490         BsmKey poolKey = bootstraps.lookup(bsmKey);
 491         if (poolKey == null) {
 492             poolKey = bsmKey.dup();
 493             // TODO the BSM could be a static method on an interface
 494             int bsm_ref = putHandleInternal(MethodHandleInfo.REF_invokeStatic, bsmClass, bsmName, bsmType, false);
 495             poolKey.at(currentBsmIndex++);
 496             bootstraps.enter(poolKey);
 497             bsm_attr.writeChar(bsm_ref);
 498             bsm_attr.writeChar(static_idxs.size());
 499             for (int i : static_idxs) {
 500                 bsm_attr.writeChar(i);
 501             }
 502         }
 503         return poolKey.index;
 504     }
 505     //where
 506         class ByteStaticArgListBuilder implements StaticArgListBuilder<S, T, byte[]> {
 507 
 508             List<Integer> indexes = new ArrayList<>();
 509 
 510             public ByteStaticArgListBuilder add(int i) {
 511                 indexes.add(putInt(i));
 512                 return this;
 513             }
 514             public ByteStaticArgListBuilder add(float f) {


 546     public int putMethodType(T s) {
 547         return putMethodTypeInternal(typeToString.apply(s));
 548     }
 549 
 550     private int putMethodTypeInternal(String s) {
 551         key.setMethodType(s);
 552         PoolKey poolKey = entries.lookup(key);
 553         if (poolKey == null) {
 554             poolKey = key.dup();
 555             int desc_idx = putUtf8(s);
 556             poolKey.at(currentIndex++);
 557             entries.enter(poolKey);
 558             pool.writeByte(PoolTag.CONSTANT_METHODTYPE.tag);
 559             pool.writeChar(desc_idx);
 560         }
 561         return poolKey.index;
 562     }
 563 
 564     @Override
 565     public int putHandle(int refKind, S owner, CharSequence name, T type) {
 566         return putHandleInternal(refKind, symbolToString.apply(owner), name, typeToString.apply(type), false);
 567     }
 568 
 569     @Override
 570     public int putHandle(int refKind, S owner, CharSequence name, T type, boolean isInterface) {
 571         return putHandleInternal(refKind, symbolToString.apply(owner), name, typeToString.apply(type), isInterface);
 572     }
 573 
 574     private int putHandleInternal(int refKind, String owner, CharSequence name, String type, boolean isInterface) {
 575         key.setMethodHandle(refKind, owner, name, type);
 576         PoolKey poolKey = entries.lookup(key);
 577         if (poolKey == null) {
 578             poolKey = key.dup();
 579             int ref_idx = putMemberRefInternal(fromKind(refKind, isInterface), owner, name, type);
 580             poolKey.at(currentIndex++);
 581             entries.enter(poolKey);
 582             pool.writeByte(PoolTag.CONSTANT_METHODHANDLE.tag);
 583             pool.writeByte(refKind);
 584             pool.writeChar(ref_idx);
 585         }
 586         return poolKey.index;
 587     }
 588 
 589     PoolTag fromKind(int bsmKind, boolean isInterface) {
 590         switch (bsmKind) {
 591             case 1: // REF_getField
 592             case 2: // REF_getStatic
 593             case 3: // REF_putField
 594             case 4: // REF_putStatic
 595                 return PoolTag.CONSTANT_FIELDREF;
 596             case 5: // REF_invokeVirtual
 597             case 6: // REF_invokeStatic
 598             case 7: // REF_invokeSpecial
 599             case 8: // REF_newInvokeSpecial

 600             case 9: // REF_invokeInterface
 601                 return isInterface ? PoolTag.CONSTANT_INTERFACEMETHODREF : PoolTag.CONSTANT_METHODREF;
 602             default:
 603                 throw new IllegalStateException();
 604         }
 605     }
 606 
 607     @Override
 608     public int putType(T s) {
 609         return putUtf8(typeToString.apply(s));
 610     }
 611 
 612     public int putUtf8(CharSequence s) {
 613         key.setUtf8(s);
 614         PoolKey poolKey = entries.lookup(key);
 615         if (poolKey == null) {
 616             poolKey = key.dup();
 617             poolKey.at(currentIndex++);
 618             entries.enter(poolKey);
 619             pool.writeByte(PoolTag.CONSTANT_UTF8.tag);
 620             putUTF8Internal(s);
 621         }


< prev index next >