Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8339368

Switch targets are not inflated in CodeModel if no StackMap

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • core-libs
    • None

      This bug is filled based on: https://mail.openjdk.org/pipermail/classfile-api-dev/2024-August/000549.html


      Method jdk/internal/CodeImpl.inflateJumpTargets should also inflate switch instructions.
       
      Perhaps BranchInstruction, JsrInstruction, TableSwitchInstruction, LookupSwitchInstruction should implement an interface with method List<Label> targets().
       
      build test method
      ```
         private static void build(CodeBuilder cob) {
             Label L1 = cob.newLabel();
             Label L2 = cob.newLabel();
             SwitchCase sc1 = SwitchCase.of(0,L2);
             List<SwitchCase> cases = new ArrayList<>();
             cases.add(sc1);
             cob.iload(0)
                .lookupswitch(L1, cases)
                .labelBinding(L2)
                .iconst_1()
                .ireturn()
                .labelBinding(L1)
                .iconst_0()
                .ireturn();
         }
      ```
      print of elements in CodeModel
      ```
      Load[OP=ILOAD_0, slot=0]
      LookupSwitch[OP=LOOKUPSWITCH]
      UnboundIntrinsicConstantInstruction[op=ICONST_1]
      Return[OP=IRETURN]
      UnboundIntrinsicConstantInstruction[op=ICONST_0]
      Return[OP=IRETURN]
      ```
      test driver class
      ```
         public static void main(String[] args) throws IOException {
             byte[] bytes = ClassFile.of()
                     .build(ClassDesc.of("TestSwitchInflate"),
                           clb -> clb.withFlags(ClassFile.ACC_PUBLIC | ClassFile.ACC_SUPER)
                     .withVersion(49,0)
                     .withMethodBody("Table", MethodTypeDesc.ofDescriptor("(I)I"),
                          ClassFile.ACC_STATIC, SwitchInflate::build));
             ClassFile.of().parse(bytes)
                 .methods().stream()
                      .flatMap(m -> m.code().stream())
                     .flatMap(c -> c.elementStream())
                     .forEach(System.out::println);
         }
      ```

            asotona Adam Sotona
            asotona Adam Sotona
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: