What to do about dead labels?

Brian Goetz brian.goetz at oracle.com
Thu Aug 18 20:51:42 UTC 2022


There are a number of FIXME comments in the code that remind us that we 
haven't made a decision of what to do about dead labels, which are 
labels that are not assigned a point in the element stream.

Sometimes a dead label is an outright error, such as:

     .withCode(b -> { Label lab = Label.of();
                      b.branch(GOTO, lab);
                    });

You can't jump to a location that is not defined.  But sometimes a label 
can get accidentally snipped out, and yet still show up in LVT, LVTT, or 
the exception table.  For example, suppose we have some code:

     start();
     try {       // X
         int x;

         blah();
     }           // Y
     catch (FooException f) {
         // Z
         blahblah();
         // W
     }
     // Q
     end();
     moo();

When we traverse this, we will get something like:

    exceptionCatch(X, Y, Z, W, FooException)
    local("x", X, Y)
    invoke start
    label(X)
    invoke blah
    label(y)
    goto Q
    label(Z)
    invoke blahblah
    label(W)
    label(Q)
    invoke end
    invoke moo

If the user decides to transform this such that anything between "begin" 
and "end" are removed, we could get this stream:

exceptionCatch(X, Y, Z, W, FooException)
local("x", X, Y)
    invoke start
    invoke end
    invoke moo

and the labels in the exception table / local metadata are dead.  This 
really isn't the user's fault, especially as we send the metadata up 
front.  (One reason for this is that early rounds sending it in order 
had a measurable performance cost; we should re-measure that.  But also, 
its not always obvious that there is a "right" time, or that it would be 
immune to such transforms.)

Separate from whether we should try to reorder the elements to reduce 
the error surface, we have two choices for how to deal with dead labels 
in metadata:

  - try to sanitize the metadata.  If we find an exception table / LVT / 
LVTT entry with dead labels, just drop it, and write the class out.
  - fail fast.  If we find an entry with data labels, throw.

(I am hoping that there is a reasonable answer that is not "make it an 
option to do either.")



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220818/c2f358f9/attachment.htm>


More information about the classfile-api-dev mailing list