Try/catch/finally builder

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Sep 5 17:21:09 UTC 2022


On 01/09/2022 18:32, Brian Goetz wrote:
>  - the automagic path, which we're exploring now -- retain enough 
> information at run time to determine which "block" owns the branch 
> target, and inline the finally blocks for the TCBs between the 
> outermost block and the branch target block. 

I think it *should* be possible.

Javac does something like this by keeping track of a generation context 
(GenContext) class. When there's a jump (break/continue/return), we call 
a routine which "traverses" the context, and adds finalizer calls for 
all pending finalizers:

https://github.com/openjdk/jdk/blob/master/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java#L365

Javac can do this because code is generated in a structured fashion - so 
javac knows the "boundaries" of each block of code involved. But, doing 
this with builders and lambdas should more or less land us in the same 
place.

Of course, mixing and matching (e.g. using both manual generation and 
auto generation) will not work, as some of the structured-ness 
assumptions would go out of the window.

Maurizio



More information about the classfile-api-dev mailing list