annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java @ 4528:e6e14d25e608

added two inlining policies for comparison
author Christian Haeubl <christian.haeubl@oracle.com>
date Tue, 07 Feb 2012 18:37:49 -0800
parents dad967b94d75
children fc78ad20ec38
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.*;
4363
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4312
diff changeset
27 import java.util.concurrent.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
4199
aaac4894175c Renamed cri packages from sun to oracle.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4195
diff changeset
29 import com.oracle.max.cri.ci.*;
aaac4894175c Renamed cri packages from sun to oracle.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4195
diff changeset
30 import com.oracle.max.cri.ri.*;
3733
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.*;
4363
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4312
diff changeset
33 import com.oracle.max.graal.debug.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 import com.oracle.max.graal.graph.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 import com.oracle.max.graal.nodes.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 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
37 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
38 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
39 import com.oracle.max.graal.nodes.extended.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 import com.oracle.max.graal.nodes.java.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 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
42 import com.oracle.max.graal.nodes.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 public class InliningUtil {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 public interface InliningCallback {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 StructuredGraph buildGraph(RiResolvedMethod method);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 double inliningWeight(RiResolvedMethod caller, RiResolvedMethod method, Invoke invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 void recordConcreteMethodAssumption(RiResolvedMethod method, RiResolvedType context, RiResolvedMethod impl);
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
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 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
53 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
54 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 private static String methodName(RiResolvedMethod method, Invoke invoke) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
57 if (Debug.isLogEnabled()) {
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
58 if (invoke != null && invoke.stateAfter() != null) {
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
59 RiMethod parent = invoke.stateAfter().method();
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
60 return parent.name() + "@" + invoke.bci() + ": " + CiUtil.format("%H.%n(%p):%r", method) + " (" + method.codeSize() + " bytes)";
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
61 } else {
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
62 return CiUtil.format("%H.%n(%p):%r", method) + " (" + method.codeSize() + " bytes)";
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
63 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 } else {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
65 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 }
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 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 * 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
71 * 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
72 * 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
73 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 public abstract static class InlineInfo implements Comparable<InlineInfo> {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 public final Invoke invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 public final double weight;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 public final int 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 public InlineInfo(Invoke invoke, double weight, int level) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 this.invoke = invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 this.weight = weight;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 this.level = level;
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
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
85 public abstract int compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
86
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 public int compareTo(InlineInfo o) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 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
90 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
92 protected static StructuredGraph getGraph(final RiResolvedMethod concrete, final InliningCallback callback) {
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
93 return Debug.scope("Inlining", concrete, new Callable<StructuredGraph>() {
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
94 @Override
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
95 public StructuredGraph call() throws Exception {
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
96 return callback.buildGraph(concrete);
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
97 }
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
98 });
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
99 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
100
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 public abstract boolean canDeopt();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 * 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
105 * 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
106 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 * @param runtime
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 * @param callback
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
111 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
112 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 * 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
116 * 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
117 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 private static class ExactInlineInfo extends InlineInfo {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 public final RiResolvedMethod concrete;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 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
122 super(invoke, weight, level);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 this.concrete = concrete;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
125
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 @Override
4461
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4460 4413
diff changeset
127 public void inline(StructuredGraph compilerGraph, GraalRuntime runtime, final InliningCallback callback) {
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
128 StructuredGraph graph = getGraph(concrete, callback);
4461
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4460 4413
diff changeset
129 InliningUtil.inline(invoke, graph, true);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 @Override
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
133 public int compiledCodeSize() {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
134 return concrete.compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
135 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
136
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
137 @Override
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 public String toString() {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
139 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
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 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 * 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
150 * 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
151 */
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
152 private static class TypeGuardInlineInfo extends InlineInfo {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
153 public final RiResolvedMethod concrete;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 public final RiResolvedType type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
156 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
157 super(invoke, weight, level);
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
158 this.concrete = concrete;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 this.type = type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 @Override
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
163 public int compiledCodeSize() {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
164 return concrete.compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
165 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
166
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
167 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
168 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
169 // 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
170 InliningUtil.receiverNullCheck(invoke);
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
171 ReadHubNode objectClass = graph.add(new ReadHubNode(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
172 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
173 FixedGuardNode guard = graph.add(new FixedGuardNode(isTypeNode));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 assert invoke.predecessor() != null;
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
175
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
176 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
177 graph.addBeforeFixed(invoke.node(), guard);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
179 Debug.log("inlining 1 method using 1 type check");
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
180
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
181 StructuredGraph calleeGraph = getGraph(concrete, callback);
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
182 InliningUtil.inline(invoke, calleeGraph, false);
3733
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 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
186 public String toString() {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
187 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
188 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
189
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
190 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 /**
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
197 * Polymorphic inlining of m methods with n type checks (n >= m) in case that the profiling information suggests a reasonable
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
198 * amounts of different receiver types and different methods. If an unknown type is encountered a deoptimization is triggered.
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
199 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
200 private static class MultiTypeGuardInlineInfo extends InlineInfo {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
201 public final List<RiResolvedMethod> concretes;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
202 public final RiResolvedType[] types;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
203 public final int[] typesToConcretes;
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
204 public final double[] branchProbabilities;
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
205 public final double notRecordedTypeProbability;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
206
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
207 public MultiTypeGuardInlineInfo(Invoke invoke, double weight, int level, List<RiResolvedMethod> concretes, RiResolvedType[] types,
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
208 int[] typesToConcretes, double[] branchProbabilities, double notRecordedTypeProbability) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
209 super(invoke, weight, level);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
210 assert concretes.size() > 0 && concretes.size() <= types.length : "must have at least one method but no more than types methods";
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
211 assert types.length == typesToConcretes.length && types.length == branchProbabilities.length : "array length must match";
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
212
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
213 this.concretes = concretes;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
214 this.types = types;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
215 this.typesToConcretes = typesToConcretes;
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
216 this.branchProbabilities = branchProbabilities;
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
217 this.notRecordedTypeProbability = notRecordedTypeProbability;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
218 }
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 @Override
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
221 public int compiledCodeSize() {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
222 int result = 0;
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
223 for (RiResolvedMethod m: concretes) {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
224 result += m.compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
225 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
226 return result;
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
227 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
228
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
229 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
230 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
231 int numberOfMethods = concretes.size();
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
232 boolean hasReturnValue = invoke.node().kind() != CiKind.Void;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
233
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
234 // 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
235 InliningUtil.receiverNullCheck(invoke);
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
236 if (numberOfMethods > 1 || shouldFallbackToInvoke()) {
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
237 inlineMultipleMethods(graph, callback, numberOfMethods, hasReturnValue);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
238 } else {
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
239 inlineSingleMethod(graph, callback);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
240 }
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
241
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
242 Debug.log("inlining %d methods with %d type checks and falling back to %s if violated", numberOfMethods, types.length, shouldFallbackToInvoke() ? "invocation" : "deoptimization");
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
243 }
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
244
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
245 private boolean shouldFallbackToInvoke() {
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
246 return notRecordedTypeProbability > 0;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
247 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
248
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
249 private void inlineMultipleMethods(StructuredGraph graph, InliningCallback callback, int numberOfMethods, boolean hasReturnValue) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
250 FixedNode continuation = invoke.next();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
251
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
252 // setup merge and phi nodes for results and exceptions
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
253 MergeNode returnMerge = graph.add(new MergeNode());
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
254 returnMerge.setProbability(invoke.probability());
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
255 returnMerge.setStateAfter(invoke.stateAfter());
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
256
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
257 PhiNode returnValuePhi = null;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
258 if (hasReturnValue) {
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
259 returnValuePhi = graph.unique(new PhiNode(invoke.node().kind(), returnMerge, PhiType.Value));
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
260 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
261
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
262 MergeNode exceptionMerge = null;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
263 PhiNode exceptionObjectPhi = null;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
264 if (invoke instanceof InvokeWithExceptionNode) {
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
265 InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
266 BeginNode exceptionEdge = invokeWithException.exceptionEdge();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
267 ExceptionObjectNode exceptionObject = (ExceptionObjectNode) exceptionEdge.next();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
268
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
269 exceptionMerge = graph.add(new MergeNode());
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
270 exceptionMerge.setProbability(exceptionEdge.probability());
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
271 exceptionMerge.setStateAfter(exceptionEdge.stateAfter());
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
272
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
273 FixedNode exceptionSux = exceptionObject.next();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
274 graph.addBeforeFixed(exceptionSux, exceptionMerge);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
275 exceptionObjectPhi = graph.unique(new PhiNode(CiKind.Object, exceptionMerge, PhiType.Value));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
276 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
277
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
278 // create one separate block for each invoked method
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
279 BeginNode[] calleeEntryNodes = new BeginNode[numberOfMethods];
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
280 for (int i = 0; i < numberOfMethods; i++) {
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
281 int predecessors = getPredecessorCount(i);
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
282 calleeEntryNodes[i] = createInvocationBlock(graph, invoke, returnMerge, returnValuePhi, exceptionMerge, exceptionObjectPhi, predecessors, true);
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
283 }
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
284
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
285 // create the successor for an unknown type
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
286 FixedNode unknownTypeNode;
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
287 if (shouldFallbackToInvoke()) {
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
288 unknownTypeNode = createInvocationBlock(graph, invoke, returnMerge, returnValuePhi, exceptionMerge, exceptionObjectPhi, 1, false);
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
289 } else {
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
290 unknownTypeNode = graph.add(new DeoptimizeNode(DeoptAction.InvalidateReprofile));
4449
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
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
293 // replace the invoke exception edge
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
294 if (invoke instanceof InvokeWithExceptionNode) {
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
295 InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invoke;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
296 BeginNode exceptionEdge = invokeWithExceptionNode.exceptionEdge();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
297 ExceptionObjectNode exceptionObject = (ExceptionObjectNode) exceptionEdge.next();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
298 exceptionObject.replaceAtUsages(exceptionObjectPhi);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
299 exceptionObject.setNext(null);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
300 GraphUtil.killCFG(invokeWithExceptionNode.exceptionEdge());
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
301 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
302
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
303 // replace the invoke with a cascade of if nodes
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
304 ReadHubNode objectClassNode = graph.add(new ReadHubNode(invoke.callTarget().receiver()));
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
305 graph.addBeforeFixed(invoke.node(), objectClassNode);
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
306 FixedNode dispatchOnType = createDispatchOnType(graph, objectClassNode, calleeEntryNodes, unknownTypeNode);
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
307
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
308 assert invoke.next() == continuation;
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
309 invoke.setNext(null);
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
310 returnMerge.setNext(continuation);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
311 invoke.node().replaceAtUsages(returnValuePhi);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
312 invoke.node().replaceAndDelete(dispatchOnType);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
313
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
314 // do the actual inlining for every invoke
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
315 for (int i = 0; i < calleeEntryNodes.length; i++) {
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
316 BeginNode node = calleeEntryNodes[i];
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
317 Invoke invokeForInlining = (Invoke) node.next();
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
318 StructuredGraph calleeGraph = getGraph(concretes.get(i), callback);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
319 InliningUtil.inline(invokeForInlining, calleeGraph, false);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
320 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
321 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
322
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
323 private void inlineSingleMethod(StructuredGraph graph, InliningCallback callback) {
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
324 assert concretes.size() == 1 && types.length > 1 && !shouldFallbackToInvoke() && notRecordedTypeProbability == 0;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
325
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
326 MergeNode calleeEntryNode = graph.add(new MergeNode());
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
327 calleeEntryNode.setProbability(invoke.probability());
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
328 ReadHubNode objectClassNode = graph.add(new ReadHubNode(invoke.callTarget().receiver()));
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
329 graph.addBeforeFixed(invoke.node(), objectClassNode);
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
330
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
331 FixedNode unknownTypeNode = graph.add(new DeoptimizeNode(DeoptAction.InvalidateReprofile));
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
332 FixedNode dispatchOnType = createDispatchOnType(graph, objectClassNode, new BeginNode[] {calleeEntryNode}, unknownTypeNode);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
333
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
334 FixedWithNextNode pred = (FixedWithNextNode) invoke.node().predecessor();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
335 pred.setNext(dispatchOnType);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
336 calleeEntryNode.setNext(invoke.node());
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
337
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
338 StructuredGraph calleeGraph = getGraph(concretes.get(0), callback);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
339 InliningUtil.inline(invoke, calleeGraph, false);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
340 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
341
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
342 private FixedNode createDispatchOnType(StructuredGraph graph, ReadHubNode objectClassNode, BeginNode[] calleeEntryNodes, FixedNode unknownTypeSux) {
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
343 assert types.length > 1;
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
344
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
345 // TODO (ch) set probabilities for all created fixed nodes...
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
346 int lastIndex = types.length - 1;
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
347 FixedNode nextNode = createTypeCheck(graph, objectClassNode, types[lastIndex], calleeEntryNodes[typesToConcretes[lastIndex]], unknownTypeSux, branchProbabilities[lastIndex]);
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
348 for (int i = lastIndex - 1; i >= 0; i--) {
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
349 nextNode = createTypeCheck(graph, objectClassNode, types[i], calleeEntryNodes[typesToConcretes[i]], nextNode, branchProbabilities[i]);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
350 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
351
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
352 return nextNode;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
353 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
354
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
355 private static FixedNode createTypeCheck(StructuredGraph graph, ReadHubNode objectClassNode, RiResolvedType type, BeginNode tsux, FixedNode nextNode, double tsuxProbability) {
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
356 IfNode result;
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
357 IsTypeNode isTypeNode = graph.unique(new IsTypeNode(objectClassNode, type));
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
358 if (tsux instanceof MergeNode) {
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
359 EndNode endNode = graph.add(new EndNode());
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
360 result = graph.add(new IfNode(isTypeNode, endNode, nextNode, tsuxProbability));
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
361 ((MergeNode) tsux).addEnd(endNode);
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
362 } else {
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
363 result = graph.add(new IfNode(isTypeNode, tsux, nextNode, tsuxProbability));
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
364 }
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
365 return result;
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
366 }
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
367
4454
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
368 private int getPredecessorCount(int concreteMethodIndex) {
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
369 if (concretes.size() == types.length) {
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
370 return 1;
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
371 } else {
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
372 int count = 0;
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
373 for (int i = 0; i < typesToConcretes.length; i++) {
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
374 if (typesToConcretes[i] == concreteMethodIndex) {
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
375 count++;
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
376 }
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
377 }
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
378 return count;
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
379 }
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
380 }
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
381
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
382 private static BeginNode createInvocationBlock(StructuredGraph graph, Invoke invoke, MergeNode returnMerge, PhiNode returnValuePhi,
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
383 MergeNode exceptionMerge, PhiNode exceptionObjectPhi, int predecessors, boolean useForInlining) {
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
384 Invoke duplicatedInvoke = duplicateInvokeForInlining(graph, invoke, exceptionMerge, exceptionObjectPhi, useForInlining);
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
385 // TODO (ch) set probabilities
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
386 BeginNode calleeEntryNode = graph.add(predecessors > 1 ? new MergeNode() : new BeginNode());
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
387 calleeEntryNode.setNext(duplicatedInvoke.node());
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
388
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
389 EndNode endNode = graph.add(new EndNode());
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
390 // TODO (ch) set probability
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
391 duplicatedInvoke.setNext(endNode);
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
392 returnMerge.addEnd(endNode);
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
393 if (returnValuePhi != null) {
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
394 returnValuePhi.addInput(duplicatedInvoke.node());
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
395 }
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
396 return calleeEntryNode;
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
397 }
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
398
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
399 private static Invoke duplicateInvokeForInlining(StructuredGraph graph, Invoke invoke, MergeNode exceptionMerge, PhiNode exceptionObjectPhi, boolean useForInlining) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
400 Invoke result = (Invoke) invoke.node().copyWithInputs();
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
401 result.setUseForInlining(useForInlining);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
402 if (invoke instanceof InvokeWithExceptionNode) {
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
403 assert exceptionMerge != null && exceptionObjectPhi != null;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
404
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
405 InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
406 BeginNode exceptionEdge = invokeWithException.exceptionEdge();
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
407 ExceptionObjectNode exceptionObject = (ExceptionObjectNode) exceptionEdge.next();
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
408
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
409 BeginNode newExceptionEdge = (BeginNode) exceptionEdge.copyWithInputs();
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
410 ExceptionObjectNode newExceptionObject = (ExceptionObjectNode) exceptionObject.copyWithInputs();
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
411 newExceptionEdge.setNext(newExceptionObject);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
412
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
413 EndNode endNode = graph.add(new EndNode());
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
414 newExceptionObject.setNext(endNode);
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
415 exceptionMerge.addEnd(endNode);
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
416 exceptionObjectPhi.addInput(newExceptionObject);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
417
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
418 ((InvokeWithExceptionNode) result).setExceptionEdge(newExceptionEdge);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
419 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
420 return result;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
421 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
422
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
423 @Override
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
424 public String toString() {
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
425 StringBuilder builder = new StringBuilder(String.format("inlining %d methods with %d type checks: ", concretes.size(), types.length));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
426 for (int i = 0; i < concretes.size(); i++) {
4464
f304ba0d4e24 inlining seems stable but deoptimizes too frequently
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4462
diff changeset
427 builder.append(CiUtil.format(" %H.%n(%p):%r", concretes.get(i)));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
428 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
429 return builder.toString();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
430 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
431
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
432 @Override
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
433 public boolean canDeopt() {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
434 return true;
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 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
437
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
438
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
439 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
440 * 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
441 * 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
442 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
443 private static class AssumptionInlineInfo extends ExactInlineInfo {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
444 public final RiResolvedType context;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
445
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
446 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
447 super(invoke, weight, level, concrete);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
448 this.context = context;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
449 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
450
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
451 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
452 public void inline(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
453 if (Debug.isLogEnabled()) {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
454 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
455 String concreteName = CiUtil.format("%H.%n(%p):%r", concrete);
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
456 Debug.log("recording concrete method assumption: %s on receiver type %s -> %s", targetName, context, concreteName);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
457 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
458 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
459
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
460 super.inline(graph, runtime, callback);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
461 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
462
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
463 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
464 public String toString() {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
465 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
466 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
467
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
468 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
469 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
470 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
471 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
472 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
473
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
474 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
475 * 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
476 * @param invoke the invoke that should be inlined
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
477 * @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
478 * @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
479 * @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
480 * @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
481 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
482 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
483 if (!checkInvokeConditions(invoke)) {
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 RiResolvedMethod parent = invoke.stateAfter().method();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
487 MethodCallTargetNode callTarget = invoke.callTarget();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
488
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
489 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
490 if (checkTargetConditions(callTarget.targetMethod())) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
491 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
492 return new ExactInlineInfo(invoke, weight, level, callTarget.targetMethod());
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 null;
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 (callTarget.receiver().exactType() != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
497 RiResolvedType exact = callTarget.receiver().exactType();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
498 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
499 RiResolvedMethod resolved = exact.resolveMethodImpl(callTarget.targetMethod());
4195
7703a9f4769f Removed inlining decisions from CRI.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4142
diff changeset
500 if (checkTargetConditions(resolved)) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
501 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
502 return new ExactInlineInfo(invoke, weight, level, resolved);
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 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
505 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
506 RiResolvedType holder = callTarget.targetMethod().holder();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
507
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
508 if (callTarget.receiver().declaredType() != null) {
4249
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
509 RiResolvedType declared = callTarget.receiver().declaredType();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
510 // 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
511 // TODO (ls) fix this
4249
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
512 if (declared != null && declared.isSubtypeOf(holder)) {
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
513 holder = declared;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
514 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
515 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
516 // TODO (tw) fix this
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
517 if (assumptions != null) {
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
518 RiResolvedMethod concrete = holder.uniqueConcreteMethod(callTarget.targetMethod());
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
519 if (concrete != null) {
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
520 if (checkTargetConditions(concrete)) {
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
521 double weight = callback == null ? 0 : callback.inliningWeight(parent, concrete, invoke);
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
522 return new AssumptionInlineInfo(invoke, weight, level, holder, concrete);
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
523 }
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
524 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
525 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
526 }
4440
271220b49abc profiling info fixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4249
diff changeset
527
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
528 // type check based inlining
4440
271220b49abc profiling info fixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4249
diff changeset
529 RiProfilingInfo profilingInfo = parent.profilingInfo();
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
530 RiTypeProfile typeProfile = profilingInfo.getTypeProfile(invoke.bci());
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
531 if (typeProfile != null) {
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
532 RiResolvedType[] types = typeProfile.getTypes();
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
533 double[] probabilities = typeProfile.getProbabilities();
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
534
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
535 if (types != null && probabilities != null && types.length > 0) {
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
536 assert types.length == probabilities.length : "length must match";
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
537 double notRecordedTypeProbability = typeProfile.getNotRecordedProbability();
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
538 if (types.length == 1 && notRecordedTypeProbability == 0) {
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
539 if (GraalOptions.InlineMonomorphicCalls) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
540 RiResolvedType type = types[0];
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
541 RiResolvedMethod concrete = type.resolveMethodImpl(callTarget.targetMethod());
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
542 if (concrete != null && checkTargetConditions(concrete)) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
543 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
544 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
545 }
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
546
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
547 Debug.log("not inlining %s because method can't be inlined", methodName(callTarget.targetMethod(), invoke));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
548 return null;
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
549 } else {
4461
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4460 4413
diff changeset
550 Debug.log("not inlining %s because GraalOptions.InlinePolymorphicCalls == false", methodName(callTarget.targetMethod(), invoke));
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
551 return null;
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
552 }
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
553 } else {
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
554 if (GraalOptions.InlinePolymorphicCalls && notRecordedTypeProbability == 0 || GraalOptions.InlineMegamorphicCalls && notRecordedTypeProbability > 0) {
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
555 // TODO (ch) inlining of multiple methods should work differently
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
556 // 1. check which methods can be inlined
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
557 // 2. for those methods, use weight and probability to compute which of them should be inlined
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
558 // 3. do the inlining
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
559 // a) all seen methods can be inlined -> do so and guard with deopt
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
560 // b) some methods can be inlined -> inline them and fall back to invocation if violated
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
561 // TODO (ch) sort types by probability
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
562
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
563 // 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
564 ArrayList<RiResolvedMethod> concreteMethods = new ArrayList<>();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
565 int[] typesToConcretes = new int[types.length];
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
566 for (int i = 0; i < types.length; i++) {
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
567 RiResolvedMethod concrete = types[i].resolveMethodImpl(callTarget.targetMethod());
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
568
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
569 int index = concreteMethods.indexOf(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
570 if (index < 0) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
571 index = concreteMethods.size();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
572 concreteMethods.add(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
573 }
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
574 typesToConcretes[i] = index;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
575 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
576
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
577 double totalWeight = 0;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
578 boolean canInline = true;
4464
f304ba0d4e24 inlining seems stable but deoptimizes too frequently
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4462
diff changeset
579 for (RiResolvedMethod concrete: concreteMethods) {
f304ba0d4e24 inlining seems stable but deoptimizes too frequently
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4462
diff changeset
580 if (concrete == null || !checkTargetConditions(concrete)) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
581 canInline = false;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
582 break;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
583 }
4464
f304ba0d4e24 inlining seems stable but deoptimizes too frequently
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4462
diff changeset
584 totalWeight += callback == null ? 0 : callback.inliningWeight(parent, concrete, invoke);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
585 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
586
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
587 if (canInline) {
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
588 convertTypeToBranchProbabilities(probabilities, notRecordedTypeProbability);
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
589 return new MultiTypeGuardInlineInfo(invoke, totalWeight, level, concreteMethods, types, typesToConcretes, probabilities, notRecordedTypeProbability);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
590 } else {
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
591 Debug.log("not inlining %s because it is a polymorphic method call and at least one invoked method cannot be inlined", methodName(callTarget.targetMethod(), invoke));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
592 return null;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
593 }
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
594 } else {
4461
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4460 4413
diff changeset
595 Debug.log("not inlining %s because GraalOptions.InlineMonomorphicCalls == false", methodName(callTarget.targetMethod(), invoke));
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
596 return null;
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
597 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
598 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
599 }
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
600
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
601 Debug.log("not inlining %s because no types/probabilities were recorded", methodName(callTarget.targetMethod(), invoke));
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
602 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
603 } else {
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
604 Debug.log("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
605 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
606 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
607 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
608
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
609 private static void convertTypeToBranchProbabilities(double[] typeProbabilities, double notRecordedTypeProbability) {
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
610 // avoid branches with 0.0/1.0 probability
4460
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4459
diff changeset
611 double total = Math.max(1E-10, notRecordedTypeProbability);
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
612
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
613 for (int i = typeProbabilities.length - 1; i >= 0; i--) {
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
614 total += typeProbabilities[i];
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
615 typeProbabilities[i] = typeProbabilities[i] / total;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
616 }
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
617 assert total > 0.99 && total < 1.01;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
618 }
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 private static boolean checkInvokeConditions(Invoke invoke) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
621 if (invoke.stateAfter() == null) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
622 Debug.log("not inlining %s because the invoke has no after state", methodName(invoke.callTarget().targetMethod(), invoke));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
623 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
624 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
625 if (invoke.predecessor() == null) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
626 Debug.log("not inlining %s because the invoke is dead code", methodName(invoke.callTarget().targetMethod(), invoke));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
627 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
628 }
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
629 if (!invoke.useForInlining()) {
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
630 Debug.log("not inlining %s because invoke is marked to be not used for inlining", methodName(invoke.callTarget().targetMethod(), invoke));
4473
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4472
diff changeset
631 return false;
4472
63cd21fda79b hotspot gc bugfix, added possibility to fallback to invocation if type check is violated
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4467
diff changeset
632 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
633 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
634 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
635
4195
7703a9f4769f Removed inlining decisions from CRI.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4142
diff changeset
636 private static boolean checkTargetConditions(RiMethod method) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
637 if (!(method instanceof RiResolvedMethod)) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
638 Debug.log("not inlining %s because it is unresolved", method.toString());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
639 return false;
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 RiResolvedMethod resolvedMethod = (RiResolvedMethod) method;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
642 if (Modifier.isNative(resolvedMethod.accessFlags())) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
643 Debug.log("not inlining %s because it is a native method", methodName(resolvedMethod));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
644 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
645 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
646 if (Modifier.isAbstract(resolvedMethod.accessFlags())) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
647 Debug.log("not inlining %s because it is an abstract method", methodName(resolvedMethod));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
648 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
649 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
650 if (!resolvedMethod.holder().isInitialized()) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
651 Debug.log("not inlining %s because of non-initialized class", methodName(resolvedMethod));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
652 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
653 }
4296
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
654 if (!resolvedMethod.canBeInlined()) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
655 Debug.log("not inlining %s because it is marked non-inlinable", methodName(resolvedMethod));
4296
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
656 return false;
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
657 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
658 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
659 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
660
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
661 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
662 * 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
663 * @param invoke the invoke that will be replaced
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
664 * @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
665 * @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
666 * @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
667 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
668 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
669 NodeInputList<ValueNode> parameters = invoke.callTarget().arguments();
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4305
diff changeset
670 StructuredGraph graph = (StructuredGraph) invoke.node().graph();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
671
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
672 FrameState stateAfter = invoke.stateAfter();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
673 assert stateAfter.isAlive();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
674
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
675 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
676 ArrayList<Node> nodes = new ArrayList<>();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
677 ReturnNode returnNode = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
678 UnwindNode unwindNode = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
679 BeginNode entryPointNode = inlineGraph.start();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
680 FixedNode firstCFGNode = entryPointNode.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
681 for (Node node : inlineGraph.getNodes()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
682 if (node == entryPointNode || node == entryPointNode.stateAfter()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
683 // Do nothing.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
684 } else if (node instanceof LocalNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
685 replacements.put(node, parameters.get(((LocalNode) node).index()));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
686 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
687 nodes.add(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
688 if (node instanceof ReturnNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
689 returnNode = (ReturnNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
690 } else if (node instanceof UnwindNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
691 unwindNode = (UnwindNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
692 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
693 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
694 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
695
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
696 assert invoke.node().successors().first() != null : invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
697 assert invoke.node().predecessor() != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
698
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
699 Map<Node, Node> duplicates = graph.addDuplicates(nodes, replacements);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
700 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
701 if (receiverNullCheck) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
702 receiverNullCheck(invoke);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
703 }
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4305
diff changeset
704 invoke.node().replaceAtPredecessors(firstCFGNodeDuplicate);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
705
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
706 FrameState stateAtExceptionEdge = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
707 if (invoke instanceof InvokeWithExceptionNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
708 InvokeWithExceptionNode invokeWithException = ((InvokeWithExceptionNode) invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
709 if (unwindNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
710 assert unwindNode.predecessor() != null;
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4312
diff changeset
711 assert invokeWithException.exceptionEdge().successors().count() == 1;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
712 ExceptionObjectNode obj = (ExceptionObjectNode) invokeWithException.exceptionEdge().next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
713 stateAtExceptionEdge = obj.stateAfter();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
714 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
715 obj.replaceAtUsages(unwindDuplicate.exception());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
716 unwindDuplicate.clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
717 Node n = obj.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
718 obj.setNext(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
719 unwindDuplicate.replaceAndDelete(n);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
720 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
721 invokeWithException.killExceptionEdge();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
722 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
723 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
724 if (unwindNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
725 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode);
4339
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
726 DeoptimizeNode deoptimizeNode = new DeoptimizeNode(DeoptAction.InvalidateRecompile);
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
727 unwindDuplicate.replaceAndDelete(graph.add(deoptimizeNode));
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
728 // move the deopt upwards if there is a monitor exit that tries to use the "after exception" frame state
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
729 // (because there is no "after exception" frame state!)
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
730 if (deoptimizeNode.predecessor() instanceof MonitorExitNode) {
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
731 MonitorExitNode monitorExit = (MonitorExitNode) deoptimizeNode.predecessor();
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
732 if (monitorExit.stateAfter() != null && monitorExit.stateAfter().bci == FrameState.AFTER_EXCEPTION_BCI) {
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
733 FrameState monitorFrameState = monitorExit.stateAfter();
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
734 graph.removeFixed(monitorExit);
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
735 monitorFrameState.safeDelete();
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
736 }
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
737 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
738 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
739 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
740
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
741 FrameState stateBefore = null;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
742 FrameState outerFrameState = null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
743 double invokeProbability = invoke.node().probability();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
744 for (Node node : duplicates.values()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
745 if (GraalOptions.ProbabilityAnalysis) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
746 if (node instanceof FixedNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
747 FixedNode fixed = (FixedNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
748 fixed.setProbability(fixed.probability() * invokeProbability);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
749 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
750 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
751 if (node instanceof FrameState) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
752 FrameState frameState = (FrameState) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
753 if (frameState.bci == FrameState.BEFORE_BCI) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
754 if (stateBefore == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
755 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
756 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
757 frameState.replaceAndDelete(stateBefore);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
758 } else if (frameState.bci == FrameState.AFTER_BCI) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
759 frameState.replaceAndDelete(stateAfter);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
760 } else if (frameState.bci == FrameState.AFTER_EXCEPTION_BCI) {
4339
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
761 if (frameState.isAlive()) {
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
762 assert stateAtExceptionEdge != null;
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
763 frameState.replaceAndDelete(stateAtExceptionEdge);
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
764 } else {
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
765 assert stateAtExceptionEdge == null;
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
766 }
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
767 } else {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
768 if (outerFrameState == null) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
769 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
770 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
771 frameState.setOuterFrameState(outerFrameState);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
772 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
773 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
774 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
775
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
776 Node returnValue = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
777 if (returnNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
778 if (returnNode.result() instanceof LocalNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
779 returnValue = replacements.get(returnNode.result());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
780 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
781 returnValue = duplicates.get(returnNode.result());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
782 }
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
783 invoke.node().replaceAtUsages(returnValue);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
784 Node returnDuplicate = duplicates.get(returnNode);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
785 returnDuplicate.clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
786 Node n = invoke.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
787 invoke.setNext(null);
4339
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
788 if (n instanceof BeginNode) {
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
789 BeginNode begin = (BeginNode) n;
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
790 FixedNode next = begin.next();
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
791 begin.setNext(null);
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
792 returnDuplicate.replaceAndDelete(next);
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
793 begin.safeDelete();
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
794 } else {
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
795 returnDuplicate.replaceAndDelete(n);
15ec30809d0f enable UseExceptionProbability by default and fix the InliningUtil to correctly handle FrameState.AFTER_EXCEPTION_BCI for Invokes without an exception edge
Lukas Stadler <lukas.stadler@jku.at>
parents: 4312
diff changeset
796 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
797 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
798
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
799 invoke.node().clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
800 invoke.node().replaceAtUsages(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
801 GraphUtil.killCFG(invoke.node());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
802
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
803 if (stateAfter.usages().isEmpty()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
804 stateAfter.safeDelete();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
805 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
806 }
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
807
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
808 public static void receiverNullCheck(Invoke invoke) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
809 MethodCallTargetNode callTarget = invoke.callTarget();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
810 StructuredGraph graph = (StructuredGraph) invoke.graph();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
811 NodeInputList<ValueNode> parameters = callTarget.arguments();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
812 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
813 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
814 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
815 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
816 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
817 }