[External] : Re: Classfile API cleanup of labelToBci from CodeModel and CodeBuilder and removal of impl.LabelResolver
Michael van Acken
michael.van.acken at gmail.com
Fri Aug 19 10:07:40 UTC 2022
Am Fr., 19. Aug. 2022 um 09:58 Uhr schrieb Adam Sotona <
adam.sotona at oracle.com>:
>
>
>
>
> *From: *Michael van Acken <michael.van.acken at gmail.com>
>
> I was referring to the part where the code of the finally block is
> duplicated
>
> into all paths right after their respective handled regions. Looking at
> the
>
> CodeBuilder source code, I can't find any of this.
>
>
>
> This is an example use case of CodeBuilder::trying:
>
> codeBuilder.trying(tryBuilder -> {
>
> // try block code
>
> }, catchBuilder -> {
>
> catchBuilder.catching(CD_IOOBE, handlerBuilder -> {
>
> // catch handler code can
>
> }).catchingAll(finallyBuilder -> {
>
> // finally handler code
>
> });
>
> });
>
I tried to follow your suggestion, but was not able to complete the
try/finally output.
The Clojure code is probably not that helpful here, but if I put this
method through
javac I get output whose [8, 16[ (right after the region covered by
exceptionCatch)
I cannot emulate with the trying() construction you describe.
public static void tryFinally() {
try {
System.out.println("Hello World!");
} finally {
System.out.println("Finally...");
}
}
0: getstatic #7 // Field
java/lang/System.out:Ljava/io/PrintStream;
3: ldc #13 // String Hello World!
5: invokevirtual #15 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
8: getstatic #7 // Field
java/lang/System.out:Ljava/io/PrintStream;
11: ldc #21 // String Finally...
13: invokevirtual #15 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
16: goto 30
19: astore_0
20: getstatic #7 // Field
java/lang/System.out:Ljava/io/PrintStream;
23: ldc #21 // String Finally...
25: invokevirtual #15 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
28: aload_0
29: athrow
30: return
Exception table:
from to target type
0 8 19 any
>
> This method encapsulates a BlockCodeBuilder instance, but does not
>
> provide it to the caller (the `child` below):
>
>
>
> This is an example use case of CodeBuilder::block:
>
>
>
> codeBuilder.block(blockBuilder -> {
>
> // block code
>
>
>
> if( blockBuilder.isEmpty()) …
>
> });
>
This is extremely helpful. I can either transport the isEmpty() status via
side-effect
out of the closure (ugly), or wrap the whole t/c/f in this block()
(probably better). In
either case I can get rid of my labelToBci calls. Right now I have to cast
to
BlockCodeBuilderImpl to get to isEmpty().
-- mva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220819/fabe6c05/attachment.htm>
More information about the classfile-api-dev
mailing list