On Thu, 30 Mar 2023 17:11:44 GMT, Jorn Vernee <[email protected]> wrote:
> Rewrite BindingSpecializer to use the new class file API.
>
> Note: There is a big try/catch/finally block generated in the `specialize`
> method that currently uses labels. I looked at replacing this with a call to
> `CodeBuilder::trying` but it would require threading the nested code builders
> through all the `emit*` methods, which currently access the 'global'
> CodeBuilder instance attached to the BindingSpecializer instance. Since there
> didn't really seem to be a big benefit to this, I've kept that
> try/catch/finally block as is, using labels.
>
> The current implementation could also use `CheckClassAdapter` to do
> additional verification on the generated bytecode (ahead of the VM's
> verifier). I'm not sure if the new API has a replacement for that?
src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java
line 77:
> 75: private static final int CLASSFILE_VERSION =
> ClassFileFormatVersion.latest().major();
> 76:
> 77: private static final MethodTypeDesc MTD_VOID =
> MethodTypeDesc.of(CD_void);
Now that there's a `MTD_void` in ConstantDescs, can switch to use that.
src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java
line 216:
> 214: if (PERFORM_VERIFICATION) {
> 215: boolean printResults = false; // only print in case of
> exception
> 216: CheckClassAdapter.verify(new ClassReader(bytes), null,
> printResults, new PrintWriter(System.err));
Classfile API provides verification functionality as well, as seen here:
https://github.com/openjdk/jdk/blob/83cf28f99639d80e62c4031c4c9752460de5f36c/test/jdk/jdk/classfile/ClassHierarchyInfoTest.java#L105
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13247#discussion_r1153653198
PR Review Comment: https://git.openjdk.org/jdk/pull/13247#discussion_r1153654815