W3cubDocs

/OpenJDK 25

Interface Label

public sealed interface Label
A marker for a position within the instructions of a method body. The position is a cursor position in the list of instructions, similar to that of a ListIterator.

Reading Labels

Labels read from class files represent positions in the code array of a Code attribute. It is associated with a bci (bytecode index), also known as pc (program counter), the index into the code array; the actual cursor position is immediately before the given index, so a label at the beginning of the instructions has bci 0, and a label at the end of the instructions has bci codeLength() + 1. The bci can be inspected through CodeAttribute::labelToBci.

In generic CodeModels, a label may not have a bci value; the position of a label can be found by searching for the corresponding LabelTarget within that model.

Writing Labels

Many models in java.lang.classfile refer to labels. To write a label, a label must be obtained, it must be bound to a CodeBuilder.

To obtain a label:

A label must be bound exactly once in the CodeBuilder where it is used; otherwise, writing fails. To bind an unbound label:

Note that a label read from another model is not automatically bound in a CodeBuilder; they are separate entities and the label is bound to different positions in them.
Since:
24
See Also:

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/Label.html