Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/interpreter/BytecodeTableswitch.java
41161 views
/*1* Copyright (c) 2001, 2021, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.interpreter;2526import sun.jvm.hotspot.oops.*;27import sun.jvm.hotspot.utilities.*;2829public class BytecodeTableswitch extends Bytecode {30BytecodeTableswitch(Method method, int bci) {31super(method, bci);32}333435// Attributes36public int defaultOffset() { return javaSignedWordAt(alignedOffset(1 + 0*jintSize)); }37public int lowKey() { return javaSignedWordAt(alignedOffset(1 + 1*jintSize)); }38public int highKey() { return javaSignedWordAt(alignedOffset(1 + 2*jintSize)); }39public int length() { return highKey()-lowKey()+1; }40public int destOffsetAt(int i) {41int x2 = alignedOffset(1 + (3 + i)*jintSize);42int val = javaSignedWordAt(x2);43return javaSignedWordAt(alignedOffset(1 + (3 + i)*jintSize));44}4546public void verify() {47if (Assert.ASSERTS_ENABLED) {48Assert.that(isValid(), "check tableswitch");49}50}5152public boolean isValid() {53boolean result = javaCode() == Bytecodes._tableswitch;54if (result == false) return false;55int lo = lowKey();56int hi = highKey();57if (hi < lo) // incorrect hi/lo values in tableswitch58return false;5960int i = hi - lo - 1 ;61while (i-- > 0) {62// no special check needed63}64return true;65}6667public static BytecodeTableswitch at(Method method, int bci) {68BytecodeTableswitch b = new BytecodeTableswitch(method, bci);69if (Assert.ASSERTS_ENABLED) {70b.verify();71}72return b;73}7475/** Like at, but returns null if the BCI is not at tableswitch */76public static BytecodeTableswitch atCheck(Method method, int bci) {77BytecodeTableswitch b = new BytecodeTableswitch(method, bci);78return (b.isValid() ? b : null);79}8081public static BytecodeTableswitch at(BytecodeStream bcs) {82return new BytecodeTableswitch(bcs.method(), bcs.bci());83}8485public String toString() {86StringBuilder buf = new StringBuilder();87buf.append("tableswitch");88buf.append(spaces);89buf.append("default: ");90buf.append(bci() + defaultOffset());91buf.append(comma);92int lo = lowKey();93int hi = highKey();94int i = hi - lo - 1 ;95while (i-- > 0) {96buf.append("case ");97buf.append(lo + i);98buf.append(':');99buf.append(bci() + destOffsetAt(i));100buf.append(comma);101}102return buf.toString();103}104}105106107