Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/interpreter/BytecodeInvoke.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.runtime.*;28import sun.jvm.hotspot.utilities.*;2930public class BytecodeInvoke extends BytecodeWithCPIndex {31BytecodeInvoke(Method method, int bci) {32super(method, bci);33}3435public static BytecodeInvoke at(Method method, int bci) {36BytecodeInvoke b = new BytecodeInvoke(method, bci);37if (Assert.ASSERTS_ENABLED) {38b.verify();39}40return b;41}4243/** Like at, but returns null if the BCI is not at an invoke */44public static BytecodeInvoke atCheck(Method method, int bci) {45BytecodeInvoke b = new BytecodeInvoke(method, bci);46return (b.isValid() ? b : null);47}4849public static BytecodeInvoke at(BytecodeStream bcs) {50return new BytecodeInvoke(bcs.method(), bcs.bci());51}5253// returns the name of the invoked method54public Symbol name() {55ConstantPool cp = method().getConstants();56if (isInvokedynamic()) {57return cp.uncachedGetNameRefAt(indexForFieldOrMethod());58}59return cp.getNameRefAt(index());60}6162// returns the signature of the invoked method63public Symbol signature() {64ConstantPool cp = method().getConstants();65if (isInvokedynamic()) {66return cp.uncachedGetSignatureRefAt(indexForFieldOrMethod());67}68return cp.getSignatureRefAt(index());69}7071public Method getInvokedMethod() {72return method().getConstants().getMethodRefAt(index());73}7475// returns the result type (see BasicType.java) of the invoke76public int resultType() {77ResultTypeFinder rts = new ResultTypeFinder(signature());78rts.iterate();79return rts.type();80}8182public int adjustedInvokeCode() {83return javaCode();84}8586// "specified" method (from constant pool)87// FIXME: elided for now88// public Method staticTarget();8990// Testers91public boolean isInvokeinterface() { return adjustedInvokeCode() == Bytecodes._invokeinterface; }92public boolean isInvokevirtual() { return adjustedInvokeCode() == Bytecodes._invokevirtual; }93public boolean isInvokestatic() { return adjustedInvokeCode() == Bytecodes._invokestatic; }94public boolean isInvokespecial() { return adjustedInvokeCode() == Bytecodes._invokespecial; }95public boolean isInvokedynamic() { return adjustedInvokeCode() == Bytecodes._invokedynamic; }9697public boolean isValid() { return isInvokeinterface() ||98isInvokevirtual() ||99isInvokestatic() ||100isInvokespecial(); }101public void verify() {102if (Assert.ASSERTS_ENABLED) {103Assert.that(isValid(), "check invoke");104}105}106107public String toString() {108StringBuilder buf = new StringBuilder();109buf.append(getJavaBytecodeName());110buf.append(spaces);111buf.append('#');112buf.append(indexForFieldOrMethod());113if (isInvokedynamic()) {114ConstantPool cp = method.getConstants();115buf.append('(');116int poolIndex = cp.invokeDynamicNameAndTypeRefIndexAt(indexForFieldOrMethod());117buf.append(poolIndex);118buf.append(')');119buf.append(" [Name and Type ");120buf.append(name().asString());121buf.append(":");122buf.append(signature().asString().replace('/', '.'));123} else {124buf.append(" [Method ");125StringBuffer sigBuf = new StringBuffer();126new SignatureConverter(signature(), sigBuf).iterateReturntype();127buf.append(sigBuf.toString().replace('/', '.'));128buf.append(spaces);129buf.append(name().asString());130buf.append('(');131sigBuf = new StringBuffer();132new SignatureConverter(signature(), sigBuf).iterateParameters();133buf.append(sigBuf.toString().replace('/', '.'));134buf.append(')');135}136buf.append(']');137if (code() != javaCode()) {138buf.append(spaces);139buf.append('[');140buf.append(getBytecodeName());141buf.append(']');142}143return buf.toString();144}145}146147148