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 */ 23 package org.graalvm.compiler.nodes; 24 25 import org.graalvm.compiler.graph.Node; 26 import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind; 27 import org.graalvm.compiler.nodes.extended.GuardedNode; 28 import org.graalvm.compiler.nodes.java.MethodCallTargetNode; 29 import org.graalvm.compiler.nodes.spi.Lowerable; 30 import org.graalvm.compiler.nodes.type.StampTool; 31 32 import jdk.vm.ci.meta.ResolvedJavaMethod; 33 import jdk.vm.ci.meta.ResolvedJavaType; 34 35 public interface Invoke extends StateSplit, Lowerable, DeoptimizingNode.DeoptDuring, GuardedNode, FixedNodeInterface { 36 37 FixedNode next(); 38 39 void setNext(FixedNode x); 40 41 CallTargetNode callTarget(); 42 43 int bci(); 44 45 Node predecessor(); 46 47 ValueNode classInit(); 48 49 void setClassInit(ValueNode node); 50 51 void intrinsify(Node node); 52 53 boolean useForInlining(); 54 55 void setUseForInlining(boolean value); 56 57 /** 58 * True if this invocation is almost certainly polymorphic, false when in doubt. 59 */ 60 boolean isPolymorphic(); 61 62 void setPolymorphic(boolean value); 63 64 /** 65 * Returns the {@linkplain ResolvedJavaMethod method} from which this invoke is executed. This 66 * is the caller method and in the case of inlining may be different from the method of the 67 * graph this node is in. 68 * 69 * @return the method from which this invoke is executed. 70 */ 71 default ResolvedJavaMethod getContextMethod() { 72 FrameState state = stateAfter(); 73 if (state == null) { 74 state = stateDuring(); 75 } 76 return state.getMethod(); 77 } 78 79 /** 80 * Returns the {@linkplain ResolvedJavaType type} from which this invoke is executed. This is 81 * the declaring type of the caller method. 82 * 83 * @return the type from which this invoke is executed. 84 */ 85 default ResolvedJavaType getContextType() { 86 ResolvedJavaMethod contextMethod = getContextMethod(); 87 if (contextMethod == null) { 88 return null; 89 } 90 return contextMethod.getDeclaringClass(); 91 } 92 93 @Override 94 default void computeStateDuring(FrameState stateAfter) { 95 FrameState newStateDuring = stateAfter.duplicateModifiedDuringCall(bci(), asNode().getStackKind()); 96 setStateDuring(newStateDuring); 97 } 98 99 default ValueNode getReceiver() { 100 assert getInvokeKind().hasReceiver(); 101 return callTarget().arguments().get(0); 102 } 103 104 default ResolvedJavaType getReceiverType() { 105 ResolvedJavaType receiverType = StampTool.typeOrNull(getReceiver()); 106 if (receiverType == null) { 107 receiverType = ((MethodCallTargetNode) callTarget()).targetMethod().getDeclaringClass(); 108 } 109 return receiverType; 110 } 111 112 default InvokeKind getInvokeKind() { 113 return callTarget().invokeKind(); 114 } 115 }