-
Bug
-
Resolution: Fixed
-
P4
-
None
-
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);
}
```
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);
}
```
- links to
-
Commit(master) openjdk/jdk/a35fd386
-
Review(master) openjdk/jdk/20810