Spec-Zone.ru › 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:

  • Use a label read from other models.
  • Use pre-defined labels from a CodeBuilder, such as CodeBuilder::startLabel, CodeBuilder::endLabel, or BlockCodeBuilder::breakLabel. They are already bound.
  • Create labels with CodeBuilder::newLabel or CodeBuilder::newBoundLabel.

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

  • Send a read LabelTarget to a CodeBuilder.
  • Use CodeBuilder::labelBinding.
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:
  • CodeAttribute::labelToBci
  • CodeBuilder::newLabel
  • CodeBuilder::labelBinding

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2025, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 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

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API