1/* 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23package org.graalvm.compiler.nodes; 24 25import org.graalvm.compiler.graph.Node; 26import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind; 27import org.graalvm.compiler.nodes.java.MethodCallTargetNode; 28import org.graalvm.compiler.nodes.spi.Lowerable; 29import org.graalvm.compiler.nodes.type.StampTool; 30 31import jdk.vm.ci.meta.ResolvedJavaMethod; 32import jdk.vm.ci.meta.ResolvedJavaType; 33 34public interface Invoke extends StateSplit, Lowerable, DeoptimizingNode.DeoptDuring, FixedNodeInterface { 35 36 FixedNode next(); 37 38 void setNext(FixedNode x); 39 40 CallTargetNode callTarget(); 41 42 int bci(); 43 44 Node predecessor(); 45 46 ValueNode classInit(); 47 48 void setClassInit(ValueNode node); 49 50 void intrinsify(Node node); 51 52 boolean useForInlining(); 53 54 void setUseForInlining(boolean value); 55 56 /** 57 * True if this invocation is almost certainly polymorphic, false when in doubt. 58 */ 59 boolean isPolymorphic(); 60 61 void setPolymorphic(boolean value); 62 63 /** 64 * Returns the {@linkplain ResolvedJavaMethod method} from which this invoke is executed. This 65 * is the caller method and in the case of inlining may be different from the method of the 66 * graph this node is in. 67 * 68 * @return the method from which this invoke is executed. 69 */ 70 default ResolvedJavaMethod getContextMethod() { 71 FrameState state = stateAfter(); 72 if (state == null) { 73 state = stateDuring(); 74 } 75 return state.getMethod(); 76 } 77 78 /** 79 * Returns the {@linkplain ResolvedJavaType type} from which this invoke is executed. This is 80 * the declaring type of the caller method. 81 * 82 * @return the type from which this invoke is executed. 83 */ 84 default ResolvedJavaType getContextType() { 85 ResolvedJavaMethod contextMethod = getContextMethod(); 86 if (contextMethod == null) { 87 return null; 88 } 89 return contextMethod.getDeclaringClass(); 90 } 91 92 @Override 93 default void computeStateDuring(FrameState stateAfter) { 94 FrameState newStateDuring = stateAfter.duplicateModifiedDuringCall(bci(), asNode().getStackKind()); 95 setStateDuring(newStateDuring); 96 } 97 98 default ValueNode getReceiver() { 99 assert getInvokeKind().hasReceiver(); 100 return callTarget().arguments().get(0); 101 } 102 103 default ResolvedJavaType getReceiverType() { 104 ResolvedJavaType receiverType = StampTool.typeOrNull(getReceiver()); 105 if (receiverType == null) { 106 receiverType = ((MethodCallTargetNode) callTarget()).targetMethod().getDeclaringClass(); 107 } 108 return receiverType; 109 } 110 111 default InvokeKind getInvokeKind() { 112 return callTarget().invokeKind(); 113 } 114} 115