Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/asm/Label.java
38918 views
/*1* Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.asm;2627import sun.tools.java.MemberDefinition;28import java.io.OutputStream;2930/**31* A label instruction. This is a 0 size instruction.32* It is the only valid target of a branch instruction.33*34* WARNING: The contents of this source file are not part of any35* supported API. Code that depends on them does so at its own risk:36* they are subject to change or removal without notice.37*/38public final39class Label extends Instruction {40static int labelCount = 0;41int ID;42int depth;43MemberDefinition locals[];4445/**46* Constructor47*/48public Label() {49super(0, opc_label, null);50this.ID = ++labelCount;51}5253/**54* Get the final destination, eliminate jumps gotos, and jumps to55* labels that are immediately folowed by another label. The depth56* field is used to leave bread crumbs to avoid infinite loops.57*/58Label getDestination() {59Label lbl = this;60if ((next != null) && (next != this) && (depth == 0)) {61depth = 1;6263switch (next.opc) {64case opc_label:65lbl = ((Label)next).getDestination();66break;6768case opc_goto:69lbl = ((Label)next.value).getDestination();70break;7172case opc_ldc:73case opc_ldc_w:74if (next.value instanceof Integer) {75Instruction inst = next.next;76if (inst.opc == opc_label) {77inst = ((Label)inst).getDestination().next;78}7980if (inst.opc == opc_ifeq) {81if (((Integer)next.value).intValue() == 0) {82lbl = (Label)inst.value;83} else {84lbl = new Label();85lbl.next = inst.next;86inst.next = lbl;87}88lbl = lbl.getDestination();89break;90}91if (inst.opc == opc_ifne) {92if (((Integer)next.value).intValue() == 0) {93lbl = new Label();94lbl.next = inst.next;95inst.next = lbl;96} else {97lbl = (Label)inst.value;98}99lbl = lbl.getDestination();100break;101}102}103break;104}105depth = 0;106}107return lbl;108}109110public String toString() {111String s = "$" + ID + ":";112if (value != null)113s = s + " stack=" + value;114return s;115}116}117118119