RFR: 8187655: jdk.lambda.vm.InterfaceAccessFlagsTest.testPrivateMethodCall needs update after nestmates support
Chen Liang
liach at openjdk.org
Tue Nov 7 02:42:29 UTC 2023
On Mon, 6 Nov 2023 19:26:26 GMT, Mandy Chung <mchung at openjdk.org> wrote:
> `jdk.lambda.vm.InterfaceAccessFlagsTest` uses `ClassToInterfaceConverter` to mechanically convert a classfile for a Class into an in-memory class representation of an equivalent Interface. `testPrivateMethodCall` tests to invoke a private method. Before nestmates, invoking a private class method and a private interface method both use `Invokespecial`. With the nestmate changes, the class uses `invokevirtual` but the interface must use `invokeinterface` but this conversion is not handled by the existing `ClassToInterfaceConverter`.
>
> This fix converts `ClassToInterfaceConverter` to use the Class-File API to properly convert a classfile from a class to an interface including method invocation from `invokevirtual` to `invokeinterface`. The old custom bytecode manipulation code can be dropped.
test/jdk/jdk/lambda/separate/ClassToInterfaceConverter.java line 39:
> 37:
> 38: private byte[] convertToInterface(ClassModel classModel) {
> 39: return Classfile.of().build(classModel.thisClass().asSymbol(),
You can use `transform` to transform a class instead of `build`.
test/jdk/jdk/lambda/separate/ClassToInterfaceConverter.java line 43:
> 41: for (ClassElement ce : classModel) {
> 42: if (ce instanceof AccessFlags accessFlags) {
> 43: classBuilder.withFlags(0x0601); // ACC_INTERFACE | ACC_ABSTRACT | ACC_PUBLIC);
We can just use `withFlags(Classfile.ACC_INTERFACE | Classfile.ACC_ABSTRACT | Classfile.ACC_PUBLIC)` as it's a constant expression and inlined by javac. And the `accessFlags` variable above appears unused.
test/jdk/jdk/lambda/separate/ClassToInterfaceConverter.java line 52:
> 50: // by other methods in the interface, convert it to InterfaceMethodref and
> 51: // if opcode is invokevirtual, convert it to invokeinterface
> 52: classBuilder.withMethod(mm.methodName().stringValue(),
Same remark, use `classBuilder.transformMethod(mm, MethodTransform.transformCode((codeBuilder, e) -> {}))`
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16526#discussion_r1384280905
PR Review Comment: https://git.openjdk.org/jdk/pull/16526#discussion_r1384279751
PR Review Comment: https://git.openjdk.org/jdk/pull/16526#discussion_r1384284062
More information about the core-libs-dev
mailing list