Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/interpreter/Bytecode.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.*;28import sun.jvm.hotspot.runtime.VM;2930public class Bytecode {31Method method;32int bci;33static final int jintSize = 4;34static final String spaces = " ";35static final String comma = ", ";3637Bytecode(Method method, int bci) {38this.method = method;39this.bci = bci;40}4142// Address computation43// NOTE: assumes that the start of the method's bytecodes is 4-byte aligned44int alignedOffset(int offset) {45return Bits.roundTo(bci + offset, jintSize) - bci;46}4748public int getIndexU1() { return method.getBytecodeOrBPAt(bci() + 1) & 0xFF; }49public int getIndexU2(int bc, boolean isWide) {50if (can_use_native_byte_order(bc, isWide)) {51return method.getNativeShortArg(bci() + (isWide ? 2 : 1)) & 0xFFFF;52}53return method.getBytecodeShortArg(bci() + (isWide ? 2 : 1)) & 0xFFFF;54}55public int getIndexU4() { return method.getNativeIntArg(bci() + 1); }56public boolean hasIndexU4() { return code() == Bytecodes._invokedynamic; }5758public int getIndexU1Cpcache() { return method.getBytecodeOrBPAt(bci() + 1) & 0xFF; }59public int getIndexU2Cpcache() { return method.getNativeShortArg(bci() + 1) & 0xFFFF; }6061static boolean can_use_native_byte_order(int bc, boolean is_wide) {62return (VM.getVM().isBigEndian() || Bytecodes.native_byte_order(bc /*, is_wide*/));63}6465int javaSignedWordAt(int offset) {66return method.getBytecodeIntArg(bci + offset);67}6869short javaShortAt(int offset) {70return method.getBytecodeShortArg(bci + offset);71}7273byte javaByteAt(int offset) {74return method.getBytecodeByteArg(bci + offset);75}7677public Method method() { return method; }78public int bci() { return bci; }7980// hotspot byte code81public int code() {82return Bytecodes.codeAt(method(), bci());83}8485// jvm byte code86public int javaCode() {87return Bytecodes.javaCode(code());88}8990public String getBytecodeName() {91return Bytecodes.name(code());92}9394public String getJavaBytecodeName() {95return Bytecodes.name(javaCode());96}9798public int getLength() {99return Bytecodes.lengthAt(method(), bci());100}101102public int getJavaLength() {103return Bytecodes.javaLengthAt(method(), bci());104}105106public String toString() {107StringBuilder buf = new StringBuilder(getJavaBytecodeName());108if (code() != javaCode()) {109buf.append(spaces);110buf.append('[');111buf.append(getBytecodeName());112buf.append(']');113}114return buf.toString();115}116}117118119