001/* 002 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.nodes; 024 025import jdk.internal.jvmci.meta.*; 026 027import com.oracle.graal.compiler.common.type.*; 028import com.oracle.graal.graph.*; 029import com.oracle.graal.nodes.CallTargetNode.InvokeKind; 030import com.oracle.graal.nodes.extended.*; 031import com.oracle.graal.nodes.java.*; 032import com.oracle.graal.nodes.spi.*; 033import com.oracle.graal.nodes.type.*; 034 035public interface Invoke extends StateSplit, Lowerable, DeoptimizingNode.DeoptDuring, GuardedNode, UncheckedInterfaceProvider { 036 037 FixedNode next(); 038 039 void setNext(FixedNode x); 040 041 CallTargetNode callTarget(); 042 043 int bci(); 044 045 FixedNode asNode(); 046 047 Node predecessor(); 048 049 void intrinsify(Node node); 050 051 boolean useForInlining(); 052 053 void setUseForInlining(boolean value); 054 055 /** 056 * True if this invocation is almost certainly polymorphic, false when in doubt. 057 */ 058 boolean isPolymorphic(); 059 060 void setPolymorphic(boolean value); 061 062 /** 063 * Returns the {@linkplain ResolvedJavaMethod method} from which this invoke is executed. This 064 * is the caller method and in the case of inlining may be different from the method of the 065 * graph this node is in. 066 * 067 * @return the method from which this invoke is executed. 068 */ 069 default ResolvedJavaMethod getContextMethod() { 070 FrameState state = stateAfter(); 071 if (state == null) { 072 state = stateDuring(); 073 } 074 return state.method(); 075 } 076 077 /** 078 * Returns the {@linkplain ResolvedJavaType type} from which this invoke is executed. This is 079 * the declaring type of the caller method. 080 * 081 * @return the type from which this invoke is executed. 082 */ 083 default ResolvedJavaType getContextType() { 084 return getContextMethod().getDeclaringClass(); 085 } 086 087 @Override 088 default void computeStateDuring(FrameState stateAfter) { 089 FrameState newStateDuring = stateAfter.duplicateModifiedDuringCall(bci(), asNode().getKind()); 090 setStateDuring(newStateDuring); 091 } 092 093 default ValueNode getReceiver() { 094 assert getInvokeKind().hasReceiver(); 095 return callTarget().arguments().get(0); 096 } 097 098 default ResolvedJavaType getReceiverType() { 099 ResolvedJavaType receiverType = StampTool.typeOrNull(getReceiver()); 100 if (receiverType == null) { 101 receiverType = ((MethodCallTargetNode) callTarget()).targetMethod().getDeclaringClass(); 102 } 103 return receiverType; 104 } 105 106 default InvokeKind getInvokeKind() { 107 return callTarget().invokeKind(); 108 } 109 110 default Stamp uncheckedStamp() { 111 if (callTarget() instanceof MethodCallTargetNode) { 112 MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) callTarget(); 113 return UncheckedInterfaceProvider.uncheckedOrNull(methodCallTargetNode.returnType(), asNode().stamp()); 114 } 115 return null; 116 } 117}