Try/catch/finally builder

Brian Goetz brian.goetz at oracle.com
Tue Aug 30 21:59:23 UTC 2022


Is there any case where we would want to nest BBs but allow the nested 
BB to bind a label defined by the parent BB?  I don't think so; what 
we're basically saying is that if you define a label in a block, it 
should be (a) defined before you finish building the block and (b) can 
only be defined in that block, not in sub-blocks.  Since LabelTarget is 
part of the base API, we probably have to document this constraint on 
valid labels targets.

if we have nested trys, each with finally blocks, I think we have to 
walk the stack of BBs to get this right:

    Y:
    while (goop) {
        try {
        X:
    while (blah) {
    try {
    if (wah) continue X;
                // need A but not B here
if (wooga) continue Y;
                    // need A and B here
    }
            finally { A }
    }
    finally { B }
     }

The first one uses a label defined in the outer try scope, so we only 
inline finally A here.  The second uses a label defined outside the 
outer try scope, so we have to inline A and B (in the right order) here.

On 8/30/2022 5:33 PM, Paul Sandoz wrote:
> Here’s an initial try at that.
>
>    https://github.com/openjdk/jdk-sandbox/compare/classfile-api-branch...PaulSandoz:jdk-sandbox:try-catch-finally-builder?expand=1
>
> BlockCodeBuilder tracks labels created via newLabel, and returns a “live” set of those labels. When a label is to be bound we reject labels that are not members of that set (we need to be careful to propagate the LabelTarget pseudoinstruction to the terminal builder).
>
> We inline a finally block if a the target label of a branch instruction is not a member of the block's labels.
>
> Ideally when block goes out of scope then all the block’s labels become “dead” and therefore they can never be used as targets (or bound if not already).
>
> Paul.
>
>
>> On Aug 25, 2022, at 5:49 AM, Brian Goetz<brian.goetz at oracle.com>  wrote:
>>
>>
>> So here's another possible thought: what if BlockBuilder could dispense labels, as well as dispensing blocks, and could then keep track of containment?  So if you are branching to a label *outside this block builder* (including returning), we'd inline the finally at that point.  (With nested block builders, we'd have to keep track of which BBs belonged to other BBs, but we already do this.)
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220830/8420e612/attachment.htm>


More information about the classfile-api-dev mailing list