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