comparison graal/com.oracle.max.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java @ 5059:ed559a528128

Perform renames on files.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 08 Mar 2012 17:57:30 +0100
parents graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/MethodCallTargetNode.java@6845b56f7ce0
children 4ed4295ce15f
comparison
equal deleted inserted replaced
5058:26f8371c229c 5059:ed559a528128
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 com.oracle.max.graal.nodes.java;
24
25 import com.oracle.max.cri.ci.*;
26 import com.oracle.max.cri.ri.*;
27 import com.oracle.max.graal.graph.*;
28 import com.oracle.max.graal.nodes.*;
29 import com.oracle.max.graal.nodes.spi.*;
30 import com.oracle.max.graal.nodes.type.*;
31
32 public class MethodCallTargetNode extends CallTargetNode implements Node.IterableNodeType, Canonicalizable {
33 public enum InvokeKind {
34 Interface,
35 Special,
36 Static,
37 Virtual
38 }
39
40 @Data private final RiType returnType;
41 @Data private RiResolvedMethod targetMethod;
42 @Data private InvokeKind invokeKind;
43 private final Stamp returnStamp;
44
45 /**
46 * @param arguments
47 */
48 public MethodCallTargetNode(InvokeKind invokeKind, RiResolvedMethod targetMethod, ValueNode[] arguments, RiType returnType) {
49 super(arguments);
50 this.invokeKind = invokeKind;
51 this.returnType = returnType;
52 this.targetMethod = targetMethod;
53 CiKind returnKind = targetMethod.signature().returnKind(false);
54 if (returnKind == CiKind.Object && returnType instanceof RiResolvedType) {
55 returnStamp = StampFactory.declared((RiResolvedType) returnType);
56 } else {
57 returnStamp = StampFactory.forKind(returnKind);
58 }
59 }
60
61 @Override
62 public RiType returnType() {
63 return returnType;
64 }
65
66 /**
67 * Gets the target method for this invocation instruction.
68 * @return the target method
69 */
70 public RiResolvedMethod targetMethod() {
71 return targetMethod;
72 }
73
74 public InvokeKind invokeKind() {
75 return invokeKind;
76 }
77
78 public void setInvokeKind(InvokeKind kind) {
79 this.invokeKind = kind;
80 }
81
82 public void setTargetMethod(RiResolvedMethod method) {
83 targetMethod = method;
84 }
85
86 /**
87 * Gets the instruction that produces the receiver object for this invocation, if any.
88 * @return the instruction that produces the receiver object for this invocation if any, {@code null} if this
89 * invocation does not take a receiver object
90 */
91 public ValueNode receiver() {
92 return isStatic() ? null : arguments().get(0);
93 }
94
95 /**
96 * Checks whether this is an invocation of a static method.
97 * @return {@code true} if the invocation is a static invocation
98 */
99 public boolean isStatic() {
100 return invokeKind() == InvokeKind.Static;
101 }
102
103 @Override
104 public CiKind returnKind() {
105 return targetMethod().signature().returnKind(false);
106 }
107
108 public Invoke invoke() {
109 return (Invoke) this.usages().first();
110 }
111
112
113 @Override
114 public boolean verify() {
115 assert usages().size() <= 1 : "call target may only be used by a single invoke";
116 for (Node n : usages()) {
117 assertTrue(n instanceof Invoke, "call target can only be used from an invoke (%s)", n);
118 }
119 return super.verify();
120 }
121
122 @Override
123 public String toString(Verbosity verbosity) {
124 if (verbosity == Verbosity.Long) {
125 return super.toString(Verbosity.Short) + "(" + targetMethod() + ")";
126 } else {
127 return super.toString(verbosity);
128 }
129 }
130
131 @Override
132 public ValueNode canonical(CanonicalizerTool tool) {
133 if (!isStatic()) {
134 ValueNode receiver = receiver();
135 if (receiver != null && receiver.exactType() != null) {
136 if (invokeKind == InvokeKind.Interface || invokeKind == InvokeKind.Virtual) {
137 RiResolvedMethod method = receiver.exactType().resolveMethodImpl(targetMethod);
138 if (method != null) {
139 invokeKind = InvokeKind.Special;
140 targetMethod = method;
141 }
142 }
143 }
144 }
145 return this;
146 }
147
148 public Stamp returnStamp() {
149 return returnStamp;
150 }
151 }