annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java @ 4453:c0430421d43d

bugfixes for inlining multiple methods
author Christian Haeubl <christian.haeubl@oracle.com>
date Fri, 27 Jan 2012 21:17:33 -0800
parents b225da954a32
children 008a5ea590ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
4233
fa53d5e4aa35 Remove lock information from frame states, and compute it instead when LIR is generated.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4205
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.max.graal.compiler.util;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.lang.reflect.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27
4199
aaac4894175c Renamed cri packages from sun to oracle.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4195
diff changeset
28 import com.oracle.max.cri.ci.*;
aaac4894175c Renamed cri packages from sun to oracle.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4195
diff changeset
29 import com.oracle.max.cri.ri.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 import com.oracle.max.criutils.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 import com.oracle.max.graal.compiler.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import com.oracle.max.graal.cri.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 import com.oracle.max.graal.graph.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 import com.oracle.max.graal.nodes.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 import com.oracle.max.graal.nodes.DeoptimizeNode.DeoptAction;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
36 import com.oracle.max.graal.nodes.PhiNode.PhiType;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 import com.oracle.max.graal.nodes.calc.*;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
38 import com.oracle.max.graal.nodes.extended.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 import com.oracle.max.graal.nodes.java.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 import com.oracle.max.graal.nodes.java.MethodCallTargetNode.InvokeKind;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 import com.oracle.max.graal.nodes.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 public class InliningUtil {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 public interface InliningCallback {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 StructuredGraph buildGraph(RiResolvedMethod method);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 double inliningWeight(RiResolvedMethod caller, RiResolvedMethod method, Invoke invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 void recordConcreteMethodAssumption(RiResolvedMethod method, RiResolvedType context, RiResolvedMethod impl);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 public static String methodName(RiResolvedMethod method) {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
52 return CiUtil.format("%H.%n(%p):%r", method) + " (" + method.codeSize() + " bytes)";
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 private static String methodName(RiResolvedMethod method, Invoke invoke) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 if (invoke != null && invoke.stateAfter() != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 RiMethod parent = invoke.stateAfter().method();
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
58 return parent.name() + "@" + invoke.bci() + ": " + CiUtil.format("%H.%n(%p):%r", method) + " (" + method.codeSize() + " bytes)";
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 } else {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
60 return CiUtil.format("%H.%n(%p):%r", method) + " (" + method.codeSize() + " bytes)";
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 * Represents an opportunity for inlining at the given invoke, with the given weight and level.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 * The weight is the amortized weight of the additional code - so smaller is better.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 * The level is the number of nested inlinings that lead to this invoke.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 public abstract static class InlineInfo implements Comparable<InlineInfo> {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 public final Invoke invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 public final double weight;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 public final int level;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 public InlineInfo(Invoke invoke, double weight, int level) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 this.invoke = invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 this.weight = weight;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 this.level = level;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 public int compareTo(InlineInfo o) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 return (weight < o.weight) ? -1 : (weight > o.weight) ? 1 : 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
85 protected static StructuredGraph getGraph(Invoke invoke, RiResolvedMethod concrete, InliningCallback callback) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
86 // TODO: Solve graph caching differently! GraphBuilderPhase.cachedGraphs.get(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
87 // if (graph != null) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
88 // if (GraalOptions.TraceInlining) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
89 // TTY.println("Reusing graph for %s", methodName(concrete, invoke));
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
90 // }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
91 // } else {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
92 if (GraalOptions.TraceInlining) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
93 TTY.println("Building graph for %s, locals: %d, stack: %d", methodName(concrete, invoke), concrete.maxLocals(), concrete.maxStackSize());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
94 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
95 return callback.buildGraph(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
96 // }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
97 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
98
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 public abstract boolean canDeopt();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 * Performs the inlining described by this object and returns the node that represents the return value of the
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 * inlined method (or null for void methods and methods that have no non-exceptional exit).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 * @param runtime
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 * @param callback
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
109 public abstract void inline(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 * Represents an inlining opportunity where the compiler can statically determine a monomorphic target method and
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 * therefore is able to determine the called method exactly.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116 private static class ExactInlineInfo extends InlineInfo {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 public final RiResolvedMethod concrete;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 public ExactInlineInfo(Invoke invoke, double weight, int level, RiResolvedMethod concrete) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 super(invoke, weight, level);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 this.concrete = concrete;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 @Override
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
125 public void inline(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
126 StructuredGraph calleeGraph = getGraph(invoke, concrete, callback);
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
127 InliningUtil.inline(invoke, calleeGraph, true);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 public String toString() {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
132 return "exact inlining " + CiUtil.format("%H.%n(%p):%r", concrete);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 * Represents an inlining opportunity for which profiling information suggests a monomorphic receiver, but for which
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 * the receiver type cannot be proven. A type check guard will be generated if this inlining is performed.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 */
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
145 private static class TypeGuardInlineInfo extends InlineInfo {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
146 public final RiResolvedMethod concrete;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147 public final RiResolvedType type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
149 public TypeGuardInlineInfo(Invoke invoke, double weight, int level, RiResolvedMethod concrete, RiResolvedType type) {
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
150 super(invoke, weight, level);
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
151 this.concrete = concrete;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 this.type = type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
156 public void inline(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) {
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
157 // receiver null check must be before the type check
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
158 InliningUtil.receiverNullCheck(invoke);
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
159 ReadClassNode objectClass = graph.add(new ReadClassNode(invoke.callTarget().receiver()));
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
160 IsTypeNode isTypeNode = graph.unique(new IsTypeNode(objectClass, type));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
161 FixedGuardNode guard = graph.add(new FixedGuardNode(isTypeNode));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 assert invoke.predecessor() != null;
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
163
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
164 graph.addBeforeFixed(invoke.node(), objectClass);
4305
0768bf0a4898 move part of the cfg-modifying operations into one place (currently: StructuredGraph)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4249
diff changeset
165 graph.addBeforeFixed(invoke.node(), guard);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167 if (GraalOptions.TraceInlining) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
168 TTY.println("inlining 1 method using 1 type check");
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 }
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
170
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
171 StructuredGraph calleeGraph = getGraph(invoke, concrete, callback);
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
172 InliningUtil.inline(invoke, calleeGraph, false);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 public String toString() {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
177 return "type-checked inlining " + CiUtil.format("%H.%n(%p):%r", concrete);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
186 /**
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
187 * Polymorphic inlining of m methods with n type checks (n >= m) in case that the profiling information suggests a reasonable
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
188 * amounts of different receiver types and different methods.
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
189 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
190 private static class MultiTypeGuardInlineInfo extends InlineInfo {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
191 public final List<RiResolvedMethod> concretes;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
192 public final RiResolvedType[] types;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
193 public final int[] typesToConcretes;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
194 public final double[] probabilities;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
195
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
196 public MultiTypeGuardInlineInfo(Invoke invoke, double weight, int level, List<RiResolvedMethod> concretes, RiResolvedType[] types, int[] typesToConcretes, double[] probabilities) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
197 super(invoke, weight, level);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
198 assert concretes.size() > 0 && concretes.size() <= types.length : "must have at least one method but no more than types methods";
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
199 assert types.length == typesToConcretes.length && types.length == probabilities.length : "array length must match";
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
200
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
201 this.concretes = concretes;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
202 this.types = types;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
203 this.typesToConcretes = typesToConcretes;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
204 this.probabilities = probabilities;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
205 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
206
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
207 @Override
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
208 public void inline(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
209 MethodCallTargetNode callTargetNode = invoke.callTarget();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
210 int numberOfMethods = concretes.size();
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
211 boolean hasReturnValue = callTargetNode.kind() != CiKind.Void;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
212
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
213 // receiver null check must be the first node
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
214 InliningUtil.receiverNullCheck(invoke);
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
215
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
216 // save node after invoke so that invoke can be deleted safely
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
217 FixedNode continuation = invoke.next();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
218 invoke.setNext(null);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
219
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
220 // setup a merge node and a phi node for the result
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
221 MergeNode merge = null;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
222 PhiNode returnValuePhi = null;
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
223 Node returnValue = null;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
224 if (numberOfMethods > 1) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
225 merge = graph.add(new MergeNode());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
226 merge.setNext(continuation);
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
227 if (hasReturnValue) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
228 returnValuePhi = graph.unique(new PhiNode(callTargetNode.kind(), merge, PhiType.Value));
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
229 returnValue = returnValuePhi;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
230 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
231 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
232
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
233 // TODO (ch) do not create merge nodes if not necessary. Otherwise GraphVisualizer seems to loose half of the phase outputs?
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
234
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
235 // create a separate block for each invoked method
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
236 MergeNode[] successorMethods = new MergeNode[numberOfMethods];
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
237 for (int i = 0; i < numberOfMethods; i++) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
238 Invoke duplicatedInvoke = duplicateInvoke(invoke);
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
239 MergeNode calleeEntryNode = graph.add(new MergeNode());
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
240 calleeEntryNode.setNext(duplicatedInvoke.node());
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
241 successorMethods[i] = calleeEntryNode;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
242
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
243 if (merge != null) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
244 EndNode endNode = graph.add(new EndNode());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
245 duplicatedInvoke.setNext(endNode);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
246 merge.addEnd(endNode);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
247 if (returnValuePhi != null) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
248 returnValuePhi.addInput(duplicatedInvoke.node());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
249 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
250 } else {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
251 duplicatedInvoke.setNext(continuation);
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
252 if (hasReturnValue) {
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
253 returnValue = (Node) duplicatedInvoke;
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
254 }
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
255 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
256 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
257
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
258 // create a cascade of ifs with the type checks
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
259 ReadClassNode objectClassNode = graph.add(new ReadClassNode(invoke.callTarget().receiver()));
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
260 graph.addBeforeFixed(invoke.node(), objectClassNode);
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
261
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
262 int lastIndex = types.length - 1;
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
263 MergeNode tsux = successorMethods[typesToConcretes[lastIndex]];
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
264 IsTypeNode isTypeNode = graph.unique(new IsTypeNode(objectClassNode, types[lastIndex]));
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
265 EndNode endNode = graph.add(new EndNode());
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
266 FixedGuardNode guardNode = graph.add(new FixedGuardNode(isTypeNode));
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
267 guardNode.setNext(endNode);
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
268 tsux.addEnd(endNode);
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
269
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
270 FixedNode nextNode = guardNode;
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
271 for (int i = lastIndex - 1; i >= 0; i--) {
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
272 tsux = successorMethods[typesToConcretes[i]];
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
273 isTypeNode = graph.unique(new IsTypeNode(objectClassNode, types[i]));
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
274 endNode = graph.add(new EndNode());
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
275 nextNode = graph.add(new IfNode(isTypeNode, endNode, nextNode, probabilities[i]));
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
276 tsux.addEnd(endNode);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
277 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
278
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
279 // replace the original invocation with a cascade of if nodes and replace the usages of invoke with the return value (phi or duplicatedInvoke)
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
280 invoke.node().replaceAtUsages(returnValue);
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
281 invoke.node().replaceAndDelete(nextNode);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
282 GraphUtil.killCFG(invoke.node());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
283
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
284 // do the actual inlining for every invocation
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
285 for (int i = 0; i < successorMethods.length; i++) {
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
286 MergeNode node = successorMethods[i];
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
287 Invoke invokeForInlining = (Invoke) node.next();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
288 StructuredGraph calleeGraph = getGraph(invokeForInlining, concretes.get(i), callback);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
289 InliningUtil.inline(invokeForInlining, calleeGraph, false);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
290 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
291
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
292 if (GraalOptions.TraceInlining) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
293 TTY.println("inlining %d methods with %d type checks", numberOfMethods, types.length);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
294 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
295 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
296
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
297 private static Invoke duplicateInvoke(Invoke invoke) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
298 Invoke result = (Invoke) invoke.node().copyWithInputs();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
299 if (invoke instanceof InvokeWithExceptionNode) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
300 InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
301 BeginNode exceptionEdge = invokeWithException.exceptionEdge();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
302 ExceptionObjectNode exceptionObject = (ExceptionObjectNode) exceptionEdge.next();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
303
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
304 BeginNode newExceptionEdge = (BeginNode) exceptionEdge.copyWithInputs();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
305 ExceptionObjectNode newExceptionObject = (ExceptionObjectNode) exceptionObject.copyWithInputs();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
306 newExceptionEdge.setNext(newExceptionObject);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
307 newExceptionObject.setNext(exceptionObject.next());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
308
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
309 ((InvokeWithExceptionNode) result).setExceptionEdge(newExceptionEdge);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
310 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
311 return result;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
312 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
313
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
314 @Override
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
315 public String toString() {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
316 StringBuilder builder = new StringBuilder("type-checked inlining of multiple methods: ");
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
317 for (int i = 0; i < concretes.size(); i++) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
318 CiUtil.format("\n%H.%n(%p):%r", concretes.get(i));
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
319 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
320 return builder.toString();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
321 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
322
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
323 @Override
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
324 public boolean canDeopt() {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
325 return true;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
326 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
327 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
328
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
329
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
330 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
331 * Represents an inlining opportunity where the current class hierarchy leads to a monomorphic target method,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
332 * but for which an assumption has to be registered because of non-final classes.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
333 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
334 private static class AssumptionInlineInfo extends ExactInlineInfo {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
335 public final RiResolvedType context;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
336
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
337 public AssumptionInlineInfo(Invoke invoke, double weight, int level, RiResolvedType context, RiResolvedMethod concrete) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
338 super(invoke, weight, level, concrete);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
339 this.context = context;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
340 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
341
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
342 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
343 public void inline(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
344 if (GraalOptions.TraceInlining) {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
345 String targetName = CiUtil.format("%H.%n(%p):%r", invoke.callTarget().targetMethod());
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
346 String concreteName = CiUtil.format("%H.%n(%p):%r", concrete);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
347 TTY.println("recording concrete method assumption: %s on receiver type %s -> %s", targetName, context, concreteName);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
348 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
349 callback.recordConcreteMethodAssumption(invoke.callTarget().targetMethod(), context, concrete);
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
350
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
351 super.inline(graph, runtime, callback);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
352 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
353
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
355 public String toString() {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
356 return "inlining with assumption " + CiUtil.format("%H.%n(%p):%r", concrete);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
357 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
358
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
359 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
360 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
361 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
362 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
363 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
364
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
365 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
366 * Determines if inlining is possible at the given invoke node.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
367 * @param invoke the invoke that should be inlined
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
368 * @param level the number of nested inlinings that lead to this invoke, or 0 if the invoke was part of the initial graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
369 * @param runtime a GraalRuntime instance used to determine of the invoke can be inlined and/or should be intrinsified
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
370 * @param callback a callback that is used to determine the weight of a specific inlining
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
371 * @return an instance of InlineInfo, or null if no inlining is possible at the given invoke
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
372 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
373 public static InlineInfo getInlineInfo(Invoke invoke, int level, GraalRuntime runtime, CiAssumptions assumptions, InliningCallback callback) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
374 if (!checkInvokeConditions(invoke)) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
375 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
376 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
377 RiResolvedMethod parent = invoke.stateAfter().method();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
378 MethodCallTargetNode callTarget = invoke.callTarget();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
379
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
380 if (callTarget.invokeKind() == InvokeKind.Special || callTarget.targetMethod().canBeStaticallyBound()) {
4195
7703a9f4769f Removed inlining decisions from CRI.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4142
diff changeset
381 if (checkTargetConditions(callTarget.targetMethod())) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
382 double weight = callback == null ? 0 : callback.inliningWeight(parent, callTarget.targetMethod(), invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
383 return new ExactInlineInfo(invoke, weight, level, callTarget.targetMethod());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
384 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
385 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
386 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
387 if (callTarget.receiver().exactType() != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
388 RiResolvedType exact = callTarget.receiver().exactType();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
389 assert exact.isSubtypeOf(callTarget.targetMethod().holder()) : exact + " subtype of " + callTarget.targetMethod().holder();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
390 RiResolvedMethod resolved = exact.resolveMethodImpl(callTarget.targetMethod());
4195
7703a9f4769f Removed inlining decisions from CRI.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4142
diff changeset
391 if (checkTargetConditions(resolved)) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
392 double weight = callback == null ? 0 : callback.inliningWeight(parent, resolved, invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
393 return new ExactInlineInfo(invoke, weight, level, resolved);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
394 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
395 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
396 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
397 RiResolvedType holder = callTarget.targetMethod().holder();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
398
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
399 if (callTarget.receiver().declaredType() != null) {
4249
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
400 RiResolvedType declared = callTarget.receiver().declaredType();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
401 // the invoke target might be more specific than the holder (happens after inlining: locals lose their declared type...)
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402 // TODO (ls) fix this
4249
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
403 if (declared != null && declared.isSubtypeOf(holder)) {
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
404 holder = declared;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
405 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
406 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
407 // TODO (tw) fix this
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
408 if (assumptions == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
409 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
410 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
411 RiResolvedMethod concrete = holder.uniqueConcreteMethod(callTarget.targetMethod());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
412 if (concrete != null) {
4195
7703a9f4769f Removed inlining decisions from CRI.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4142
diff changeset
413 if (checkTargetConditions(concrete)) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
414 double weight = callback == null ? 0 : callback.inliningWeight(parent, concrete, invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
415 return new AssumptionInlineInfo(invoke, weight, level, holder, concrete);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
416 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
417 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
418 }
4440
271220b49abc profiling info fixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4249
diff changeset
419
271220b49abc profiling info fixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4249
diff changeset
420 RiProfilingInfo profilingInfo = parent.profilingInfo();
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
421 RiTypeProfile typeProfile = profilingInfo.getTypeProfile(invoke.bci());
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
422 if (typeProfile != null) {
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
423 RiResolvedType[] types = typeProfile.getTypes();
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
424 double[] probabilities = typeProfile.getProbabilities();
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
425 if (types != null && probabilities != null && types.length > 0) {
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
426 assert types.length == probabilities.length : "length must match";
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
427 if (GraalOptions.InlineWithTypeCheck) {
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
428 // type check and inlining...
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
429 if (types.length == 1) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
430 RiResolvedType type = types[0];
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
431 concrete = type.resolveMethodImpl(callTarget.targetMethod());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
432 if (concrete != null && checkTargetConditions(concrete)) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
433 double weight = callback == null ? 0 : callback.inliningWeight(parent, concrete, invoke);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
434 return new TypeGuardInlineInfo(invoke, weight, level, concrete, type);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
435 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
436 return null;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
437 } else {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
438 // TODO (ch) sort types by probability
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
439 // determine concrete methods and map type to specific method
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
440 ArrayList<RiResolvedMethod> concreteMethods = new ArrayList<>();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
441 int[] typesToConcretes = new int[types.length];
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
442 for (int i = 0; i < types.length; i++) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
443 concrete = types[i].resolveMethodImpl(callTarget.targetMethod());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
444
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
445 int index = concreteMethods.indexOf(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
446 if (index < 0) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
447 index = concreteMethods.size();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
448 concreteMethods.add(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
449 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
450 typesToConcretes[index] = index;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
451 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
452
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
453 double totalWeight = 0;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
454 boolean canInline = true;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
455 for (RiResolvedMethod method: concreteMethods) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
456 if (method == null || !checkTargetConditions(method)) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
457 canInline = false;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
458 break;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
459 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
460 totalWeight += callback == null ? 0 : callback.inliningWeight(parent, method, invoke);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
461 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
462
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
463 if (canInline) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
464 return new MultiTypeGuardInlineInfo(invoke, totalWeight, level, concreteMethods, types, typesToConcretes, probabilities);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
465 } else {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
466 if (GraalOptions.TraceInlining) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
467 TTY.println("not inlining %s because it is a polymorphic method call and at least one invoked method cannot be inlined", methodName(callTarget.targetMethod(), invoke));
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
468 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
469 return null;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
470 }
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
471 }
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
472 } else {
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
473 if (GraalOptions.TraceInlining) {
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
474 TTY.println("not inlining %s because GraalOptions.InlineWithTypeCheck == false", methodName(callTarget.targetMethod(), invoke));
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
475 }
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
476 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
477 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
478 }
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
479 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
480 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
481 if (GraalOptions.TraceInlining) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
482 TTY.println("not inlining %s because no type profile exists", methodName(callTarget.targetMethod(), invoke));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
483 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
484 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
485 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
486 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
487
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
488
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
489 private static boolean checkInvokeConditions(Invoke invoke) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
490 if (invoke.stateAfter() == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
491 if (GraalOptions.TraceInlining) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
492 TTY.println("not inlining %s because the invoke has no after state", methodName(invoke.callTarget().targetMethod(), invoke));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
493 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
494 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
495 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
496 if (invoke.predecessor() == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
497 if (GraalOptions.TraceInlining) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
498 TTY.println("not inlining %s because the invoke is dead code", methodName(invoke.callTarget().targetMethod(), invoke));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
499 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
500 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
501 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
502 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
503 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
504
4195
7703a9f4769f Removed inlining decisions from CRI.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4142
diff changeset
505 private static boolean checkTargetConditions(RiMethod method) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
506 if (!(method instanceof RiResolvedMethod)) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
507 if (GraalOptions.TraceInlining) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
508 TTY.println("not inlining %s because it is unresolved", method.toString());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
509 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
510 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
511 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
512 RiResolvedMethod resolvedMethod = (RiResolvedMethod) method;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
513 if (Modifier.isNative(resolvedMethod.accessFlags())) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
514 if (GraalOptions.TraceInlining) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
515 TTY.println("not inlining %s because it is a native method", methodName(resolvedMethod));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
516 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
517 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
518 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
519 if (Modifier.isAbstract(resolvedMethod.accessFlags())) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
520 if (GraalOptions.TraceInlining) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
521 TTY.println("not inlining %s because it is an abstract method", methodName(resolvedMethod));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
522 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
523 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
524 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
525 if (!resolvedMethod.holder().isInitialized()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
526 if (GraalOptions.TraceInlining) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
527 TTY.println("not inlining %s because of non-initialized class", methodName(resolvedMethod));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
528 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
529 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
530 }
4296
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
531 if (!resolvedMethod.canBeInlined()) {
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
532 if (GraalOptions.TraceInlining) {
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
533 TTY.println("not inlining %s because it is marked non-inlinable", methodName(resolvedMethod));
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
534 }
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
535 return false;
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
536 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
537 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
538 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
539
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
540 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
541 * Performs an actual inlining, thereby replacing the given invoke with the given inlineGraph.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
542 * @param invoke the invoke that will be replaced
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
543 * @param inlineGraph the graph that the invoke will be replaced with
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
544 * @param receiverNullCheck true if a null check needs to be generated for non-static inlinings, false if no such check is required
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
545 * @return The node that represents the return value, or null for void methods and methods that have no non-exceptional exit.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
546 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
547 public static void inline(Invoke invoke, StructuredGraph inlineGraph, boolean receiverNullCheck) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
548 NodeInputList<ValueNode> parameters = invoke.callTarget().arguments();
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4305
diff changeset
549 StructuredGraph graph = (StructuredGraph) invoke.node().graph();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
550
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
551 FrameState stateAfter = invoke.stateAfter();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
552 assert stateAfter.isAlive();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
553
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
554 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
555 ArrayList<Node> nodes = new ArrayList<>();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
556 ReturnNode returnNode = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
557 UnwindNode unwindNode = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
558 BeginNode entryPointNode = inlineGraph.start();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
559 FixedNode firstCFGNode = entryPointNode.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
560 for (Node node : inlineGraph.getNodes()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
561 if (node == entryPointNode || node == entryPointNode.stateAfter()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
562 // Do nothing.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
563 } else if (node instanceof LocalNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
564 replacements.put(node, parameters.get(((LocalNode) node).index()));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
565 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
566 nodes.add(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
567 if (node instanceof ReturnNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
568 returnNode = (ReturnNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
569 } else if (node instanceof UnwindNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
570 unwindNode = (UnwindNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
571 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
572 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
573 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
574
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
575 assert invoke.node().successors().first() != null : invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
576 assert invoke.node().predecessor() != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
577
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
578 Map<Node, Node> duplicates = graph.addDuplicates(nodes, replacements);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
579 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
580 if (receiverNullCheck) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
581 receiverNullCheck(invoke);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
582 }
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4305
diff changeset
583 invoke.node().replaceAtPredecessors(firstCFGNodeDuplicate);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
584
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
585 FrameState stateAtExceptionEdge = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
586 if (invoke instanceof InvokeWithExceptionNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
587 InvokeWithExceptionNode invokeWithException = ((InvokeWithExceptionNode) invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
588 if (unwindNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
589 assert unwindNode.predecessor() != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
590 assert invokeWithException.exceptionEdge().successors().explicitCount() == 1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
591 ExceptionObjectNode obj = (ExceptionObjectNode) invokeWithException.exceptionEdge().next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
592 stateAtExceptionEdge = obj.stateAfter();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
593 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
594 for (Node usage : obj.usages().snapshot()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
595 usage.replaceFirstInput(obj, unwindDuplicate.exception());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
596 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
597 unwindDuplicate.clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
598 Node n = obj.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
599 obj.setNext(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
600 unwindDuplicate.replaceAndDelete(n);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
601 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
602 invokeWithException.killExceptionEdge();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
603 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
604 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
605 if (unwindNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
606 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
607 unwindDuplicate.replaceAndDelete(graph.add(new DeoptimizeNode(DeoptAction.InvalidateRecompile)));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
608 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
609 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
610
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
611 FrameState stateBefore = null;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
612 FrameState outerFrameState = null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
613 double invokeProbability = invoke.node().probability();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
614 for (Node node : duplicates.values()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
615 if (GraalOptions.ProbabilityAnalysis) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
616 if (node instanceof FixedNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
617 FixedNode fixed = (FixedNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
618 fixed.setProbability(fixed.probability() * invokeProbability);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
619 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
620 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
621 if (node instanceof FrameState) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
622 FrameState frameState = (FrameState) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
623 if (frameState.bci == FrameState.BEFORE_BCI) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
624 if (stateBefore == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
625 stateBefore = stateAfter.duplicateModified(invoke.bci(), false, invoke.node().kind(), parameters.toArray(new ValueNode[parameters.size()]));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
626 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
627 frameState.replaceAndDelete(stateBefore);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
628 } else if (frameState.bci == FrameState.AFTER_BCI) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
629 frameState.replaceAndDelete(stateAfter);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
630 } else if (frameState.bci == FrameState.AFTER_EXCEPTION_BCI) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
631 assert stateAtExceptionEdge != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
632 frameState.replaceAndDelete(stateAtExceptionEdge);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
633 } else {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
634 if (outerFrameState == null) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
635 outerFrameState = stateAfter.duplicateModified(invoke.bci(), stateAfter.rethrowException(), invoke.node().kind());
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
636 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
637 frameState.setOuterFrameState(outerFrameState);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
638 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
639 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
640 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
641
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
642 Node returnValue = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
643 if (returnNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
644 if (returnNode.result() instanceof LocalNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
645 returnValue = replacements.get(returnNode.result());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
646 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
647 returnValue = duplicates.get(returnNode.result());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
648 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
649 for (Node usage : invoke.node().usages().snapshot()) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
650 usage.replaceFirstInput(invoke.node(), returnValue);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
651 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
652 Node returnDuplicate = duplicates.get(returnNode);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
653 returnDuplicate.clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
654 Node n = invoke.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
655 invoke.setNext(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
656 returnDuplicate.replaceAndDelete(n);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
657 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
658
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
659 invoke.node().clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
660 invoke.node().replaceAtUsages(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
661 GraphUtil.killCFG(invoke.node());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
662
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
663 if (stateAfter.usages().isEmpty()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
664 stateAfter.safeDelete();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
665 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
666 }
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
667
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
668 public static void receiverNullCheck(Invoke invoke) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
669 MethodCallTargetNode callTarget = invoke.callTarget();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
670 StructuredGraph graph = (StructuredGraph) invoke.graph();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
671 NodeInputList<ValueNode> parameters = callTarget.arguments();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
672 ValueNode firstParam = parameters.size() <= 0 ? null : parameters.get(0);
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
673 if (!callTarget.isStatic() && firstParam.kind() == CiKind.Object && !firstParam.stamp().nonNull()) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
674 graph.addBeforeFixed(invoke.node(), graph.add(new FixedGuardNode(graph.unique(new NullCheckNode(firstParam, false)))));
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
675 }
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
676 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
677 }