annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java @ 5365:33b8603f180d

lowering checkcasts with Java snippets
author Doug Simon <doug.simon@oracle.com>
date Tue, 08 May 2012 21:32:35 +0200
parents dec5a35ddbe2
children 53cc37c27b04
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 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.compiler.util;
3733
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
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.compiler.*;
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
30 import com.oracle.graal.compiler.loop.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.compiler.phases.*;
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
32 import com.oracle.graal.compiler.phases.CanonicalizerPhase.IsImmutablePredicate;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
33 import com.oracle.graal.cri.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.debug.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
35 import com.oracle.graal.graph.*;
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
36 import com.oracle.graal.lir.cfg.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
37 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
38 import com.oracle.graal.nodes.PhiNode.PhiType;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
39 import com.oracle.graal.nodes.calc.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
40 import com.oracle.graal.nodes.extended.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
41 import com.oracle.graal.nodes.java.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
42 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind;
5339
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
43 import com.oracle.graal.nodes.type.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
44 import com.oracle.graal.nodes.util.*;
5339
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
45 import com.oracle.max.cri.ci.*;
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
46 import com.oracle.max.cri.ri.*;
5341
Lukas Stadler <lukas.stadler@jku.at>
parents: 5339 5335
diff changeset
47 import com.oracle.max.cri.ri.RiTypeProfile.ProfiledType;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 public class InliningUtil {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 public interface InliningCallback {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 StructuredGraph buildGraph(RiResolvedMethod method);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 double inliningWeight(RiResolvedMethod caller, RiResolvedMethod method, Invoke invoke);
4670
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4636
diff changeset
54 void recordMethodContentsAssumption(RiResolvedMethod method);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 void recordConcreteMethodAssumption(RiResolvedMethod method, RiResolvedType context, RiResolvedMethod impl);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57
5316
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
58 public static String methodName(RiResolvedMethod method, Invoke invoke) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
59 if (!Debug.isLogEnabled()) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
60 return null;
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
61 } else if (invoke != null && invoke.stateAfter() != null) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
62 return methodName(invoke.stateAfter(), invoke.bci()) + ": " + CiUtil.format("%H.%n(%p):%r", method) + " (" + method.codeSize() + " bytes)";
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 } else {
5316
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
64 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
65 }
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
5316
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
68 public static String methodName(InlineInfo info) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
69 if (!Debug.isLogEnabled()) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
70 return null;
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
71 } else if (info.invoke != null && info.invoke.stateAfter() != null) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
72 return methodName(info.invoke.stateAfter(), info.invoke.bci()) + ": " + info.toString();
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
73 } else {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
74 return info.toString();
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
75 }
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
76 }
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
77
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
78 private static String methodName(FrameState frameState, int bci) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
79 StringBuilder sb = new StringBuilder();
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
80 if (frameState.outerFrameState() != null) {
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
81 sb.append(methodName(frameState.outerFrameState(), frameState.outerFrameState().bci));
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
82 sb.append("->");
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
83 }
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
84 sb.append(CiUtil.format("%h.%n", frameState.method()));
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
85 sb.append("@").append(bci);
8ac40aed34bf Consistent output of inlining decisions. Make all inlining decisions be printable using -G:Log=InliningDecisions
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5210
diff changeset
86 return sb.toString();
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
87 }
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
88
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 * 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
91 * 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
92 * 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
93 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 public abstract static class InlineInfo implements Comparable<InlineInfo> {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 public final Invoke invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 public final double weight;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 public final int level;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 public InlineInfo(Invoke invoke, double weight, int level) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 this.invoke = invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 this.weight = weight;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 this.level = level;
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
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
105 public abstract int compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
106
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 public int compareTo(InlineInfo o) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 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
110 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
112 protected static StructuredGraph getGraph(final RiResolvedMethod concrete, final InliningCallback callback) {
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
113 return Debug.scope("Inlining", concrete, new Callable<StructuredGraph>() {
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
114 @Override
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
115 public StructuredGraph call() throws Exception {
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
116 return callback.buildGraph(concrete);
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
117 }
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
118 });
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
119 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
120
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 public abstract boolean canDeopt();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 * 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
125 * 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
126 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 * @param graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128 * @param runtime
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 * @param callback
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
131 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
132 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 * 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
136 * 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
137 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 private static class ExactInlineInfo extends InlineInfo {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 public final RiResolvedMethod concrete;
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 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
142 super(invoke, weight, level);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 this.concrete = concrete;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 }
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 @Override
4461
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4460 4413
diff changeset
147 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
148 StructuredGraph graph = getGraph(concrete, callback);
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
149 assert !IntrinsificationPhase.canIntrinsify(invoke, concrete, runtime);
4670
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4636
diff changeset
150 callback.recordMethodContentsAssumption(concrete);
4461
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4460 4413
diff changeset
151 InliningUtil.inline(invoke, graph, true);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 @Override
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
155 public int compiledCodeSize() {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
156 return concrete.compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
157 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
158
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
159 @Override
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 public String toString() {
5020
77f816847d91 some more changes to inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
161 return "exact " + CiUtil.format("%H.%n(%p):%r", concrete);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171 * 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
172 * 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
173 */
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
174 private static class TypeGuardInlineInfo extends InlineInfo {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
175 public final RiResolvedMethod concrete;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 public final RiResolvedType type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
178 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
179 super(invoke, weight, level);
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
180 this.concrete = concrete;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 this.type = type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 }
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 @Override
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
185 public int compiledCodeSize() {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
186 return concrete.compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
187 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
188
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
189 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
190 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
191 // 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
192 InliningUtil.receiverNullCheck(invoke);
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
193 ValueNode receiver = invoke.callTarget().receiver();
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
194 ReadHubNode objectClass = graph.add(new ReadHubNode(receiver));
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
195 IsTypeNode isTypeNode = graph.unique(new IsTypeNode(objectClass, type));
5160
6e385457d6fc Add a RiDeoptAction to Guards and FixedGuards
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5130
diff changeset
196 FixedGuardNode guard = graph.add(new FixedGuardNode(isTypeNode, RiDeoptReason.TypeCheckedInliningViolated, RiDeoptAction.InvalidateReprofile, invoke.leafGraphId()));
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
197 AnchorNode anchor = graph.add(new AnchorNode());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 assert invoke.predecessor() != null;
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
199
5339
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
200 ValueNode anchoredReceiver = createAnchoredReceiver(graph, anchor, type, receiver);
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
201 invoke.callTarget().replaceFirstInput(receiver, anchoredReceiver);
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
202
4453
c0430421d43d bugfixes for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4452
diff changeset
203 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
204 graph.addBeforeFixed(invoke.node(), guard);
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
205 graph.addBeforeFixed(invoke.node(), anchor);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206
4462
428a91f18858 fixes after merge
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4461
diff changeset
207 StructuredGraph calleeGraph = getGraph(concrete, callback);
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
208 assert !IntrinsificationPhase.canIntrinsify(invoke, concrete, runtime);
4670
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4636
diff changeset
209 callback.recordMethodContentsAssumption(concrete);
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
210 InliningUtil.inline(invoke, calleeGraph, false);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 public String toString() {
5020
77f816847d91 some more changes to inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
215 return "type-checked " + CiUtil.format("%H.%n(%p):%r", concrete);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224 /**
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
225 * 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
226 * 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
227 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
228 private static class MultiTypeGuardInlineInfo extends InlineInfo {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
229 public final List<RiResolvedMethod> concretes;
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
230 public final ProfiledType[] ptypes;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
231 public final int[] typesToConcretes;
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
232 public final double notRecordedTypeProbability;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
233
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
234 public MultiTypeGuardInlineInfo(Invoke invoke, double weight, int level, List<RiResolvedMethod> concretes, ProfiledType[] ptypes,
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
235 int[] typesToConcretes, double notRecordedTypeProbability) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
236 super(invoke, weight, level);
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
237 assert concretes.size() > 0 && concretes.size() <= ptypes.length : "must have at least one method but no more than types methods";
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
238 assert ptypes.length == typesToConcretes.length : "array lengths must match";
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
239
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
240 this.concretes = concretes;
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
241 this.ptypes = ptypes;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
242 this.typesToConcretes = typesToConcretes;
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
243 this.notRecordedTypeProbability = notRecordedTypeProbability;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
244 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
245
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
246 @Override
4528
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
247 public int compiledCodeSize() {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
248 int result = 0;
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
249 for (RiResolvedMethod m: concretes) {
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
250 result += m.compiledCodeSize();
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
251 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
252 return result;
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
253 }
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
254
e6e14d25e608 added two inlining policies for comparison
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4473
diff changeset
255 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
256 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
257 int numberOfMethods = concretes.size();
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
258 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
259
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
260 // 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
261 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
262 if (numberOfMethods > 1 || shouldFallbackToInvoke()) {
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
263 inlineMultipleMethods(graph, runtime, callback, numberOfMethods, hasReturnValue);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
264 } else {
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
265 inlineSingleMethod(graph, runtime, callback);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
266 }
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
267 }
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
268
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
269 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
270 return notRecordedTypeProbability > 0;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
271 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
272
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
273 private void inlineMultipleMethods(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback, int numberOfMethods, boolean hasReturnValue) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
274 FixedNode continuation = invoke.next();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
275
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
276 // setup merge and phi nodes for results and exceptions
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
277 MergeNode returnMerge = graph.add(new MergeNode());
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
278 returnMerge.setProbability(invoke.probability());
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
279 returnMerge.setStateAfter(invoke.stateAfter().duplicate(invoke.stateAfter().bci));
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
280
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
281 PhiNode returnValuePhi = null;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
282 if (hasReturnValue) {
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
283 returnValuePhi = graph.unique(new PhiNode(invoke.node().kind(), returnMerge, PhiType.Value));
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
284 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
285
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
286 MergeNode exceptionMerge = null;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
287 PhiNode exceptionObjectPhi = null;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
288 if (invoke instanceof InvokeWithExceptionNode) {
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
289 InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
290 BeginNode exceptionEdge = invokeWithException.exceptionEdge();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
291 ExceptionObjectNode exceptionObject = (ExceptionObjectNode) exceptionEdge.next();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
292
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
293 exceptionMerge = graph.add(new MergeNode());
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
294 exceptionMerge.setProbability(exceptionEdge.probability());
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
295
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
296 FixedNode exceptionSux = exceptionObject.next();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
297 graph.addBeforeFixed(exceptionSux, exceptionMerge);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
298 exceptionObjectPhi = graph.unique(new PhiNode(CiKind.Object, exceptionMerge, PhiType.Value));
4692
9d48ccb39292 Fixed a wrong frame state for the exception edge after a polymorphic inlining. Removed a NPE allocation in a runtime call branch introduced for Graal.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4687
diff changeset
299 exceptionMerge.setStateAfter(exceptionEdge.stateAfter().duplicateModified(invoke.stateAfter().bci, true, CiKind.Void, exceptionObjectPhi));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
300 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
301
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
302 // create one separate block for each invoked method
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
303 BeginNode[] calleeEntryNodes = new BeginNode[numberOfMethods];
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
304 for (int i = 0; i < numberOfMethods; i++) {
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
305 int predecessors = 0;
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
306 double probability = 0;
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
307 for (int j = 0; j < typesToConcretes.length; j++) {
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
308 if (typesToConcretes[j] == i) {
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
309 predecessors++;
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
310 probability += ptypes[j].probability;
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
311 }
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
312 }
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
313
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
314 calleeEntryNodes[i] = createInvocationBlock(graph, invoke, returnMerge, returnValuePhi, exceptionMerge, exceptionObjectPhi, predecessors, invoke.probability() * probability, true);
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
315 }
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
316
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
317 // 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
318 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
319 if (shouldFallbackToInvoke()) {
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
320 unknownTypeNode = createInvocationBlock(graph, invoke, returnMerge, returnValuePhi, exceptionMerge, exceptionObjectPhi, 1, notRecordedTypeProbability, 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
321 } else {
5130
Lukas Stadler <lukas.stadler@jku.at>
parents: 5129 5127
diff changeset
322 unknownTypeNode = graph.add(new DeoptimizeNode(RiDeoptAction.InvalidateReprofile, RiDeoptReason.TypeCheckedInliningViolated, invoke.leafGraphId()));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
323 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
324
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
325 // replace the invoke exception edge
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
326 if (invoke instanceof InvokeWithExceptionNode) {
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
327 InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invoke;
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
328 BeginNode exceptionEdge = invokeWithExceptionNode.exceptionEdge();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
329 ExceptionObjectNode exceptionObject = (ExceptionObjectNode) exceptionEdge.next();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
330 exceptionObject.replaceAtUsages(exceptionObjectPhi);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
331 exceptionObject.setNext(null);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
332 GraphUtil.killCFG(invokeWithExceptionNode.exceptionEdge());
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
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
335 // replace the invoke with a cascade of if nodes
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
336 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
337 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
338 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
339
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
340 assert invoke.next() == continuation;
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
341 invoke.setNext(null);
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
342 returnMerge.setNext(continuation);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
343 invoke.node().replaceAtUsages(returnValuePhi);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
344 invoke.node().replaceAndDelete(dispatchOnType);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
345
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
346 // do the actual inlining for every invoke
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
347 for (int i = 0; i < calleeEntryNodes.length; i++) {
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
348 BeginNode node = calleeEntryNodes[i];
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
349 Invoke invokeForInlining = (Invoke) node.next();
4636
495a81cd6969 avoid code generation for typechecks that are only used for anchoring
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4635
diff changeset
350
4635
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
351 RiResolvedType commonType = getLeastCommonType(i);
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
352 ValueNode receiver = invokeForInlining.callTarget().receiver();
5339
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
353 ValueNode anchoredReceiver = createAnchoredReceiver(graph, node, commonType, receiver);
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
354 invokeForInlining.callTarget().replaceFirstInput(receiver, anchoredReceiver);
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
355
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
356 RiResolvedMethod concrete = concretes.get(i);
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
357 StructuredGraph calleeGraph = getGraph(concrete, callback);
4670
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4636
diff changeset
358 callback.recordMethodContentsAssumption(concrete);
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
359 assert !IntrinsificationPhase.canIntrinsify(invokeForInlining, concrete, runtime);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
360 InliningUtil.inline(invokeForInlining, calleeGraph, false);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
361 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
362 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
363
4635
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
364 private RiResolvedType getLeastCommonType(int concreteMethodIndex) {
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
365 RiResolvedType commonType = null;
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
366 for (int i = 0; i < typesToConcretes.length; i++) {
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
367 if (typesToConcretes[i] == concreteMethodIndex) {
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
368 if (commonType == null) {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
369 commonType = ptypes[i].type;
4635
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
370 } else {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
371 commonType = commonType.leastCommonAncestor(ptypes[i].type);
4635
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
372 }
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
373 }
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
374 }
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
375 assert commonType != null;
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
376 return commonType;
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
377 }
f35c183f33ce fixed checkcast when inlining more than one method
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4627
diff changeset
378
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
379 private void inlineSingleMethod(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
380 assert concretes.size() == 1 && ptypes.length > 1 && !shouldFallbackToInvoke() && notRecordedTypeProbability == 0;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
381
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
382 MergeNode calleeEntryNode = graph.add(new MergeNode());
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
383 calleeEntryNode.setProbability(invoke.probability());
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
384 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
385 graph.addBeforeFixed(invoke.node(), objectClassNode);
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
386
5130
Lukas Stadler <lukas.stadler@jku.at>
parents: 5129 5127
diff changeset
387 FixedNode unknownTypeNode = graph.add(new DeoptimizeNode(RiDeoptAction.InvalidateReprofile, RiDeoptReason.TypeCheckedInliningViolated, invoke.leafGraphId()));
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
388 FixedNode dispatchOnType = createDispatchOnType(graph, objectClassNode, new BeginNode[] {calleeEntryNode}, unknownTypeNode);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
389
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
390 FixedWithNextNode pred = (FixedWithNextNode) invoke.node().predecessor();
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
391 pred.setNext(dispatchOnType);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
392 calleeEntryNode.setNext(invoke.node());
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
393
4590
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
394 RiResolvedMethod concrete = concretes.get(0);
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
395 StructuredGraph calleeGraph = getGraph(concrete, callback);
d8d865b9de30 added assertion to ensure that methods are only inlined if they cannot be intrinsified
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4571
diff changeset
396 assert !IntrinsificationPhase.canIntrinsify(invoke, concrete, runtime);
4670
41034914e2ee add MethodContents assumption to fix debbugging issue
Lukas Stadler <lukas.stadler@jku.at>
parents: 4636
diff changeset
397 callback.recordMethodContentsAssumption(concrete);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
398 InliningUtil.inline(invoke, calleeGraph, false);
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
399 }
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
400
4467
ed73455e9c03 fixed endless recompiles
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4464
diff changeset
401 private FixedNode createDispatchOnType(StructuredGraph graph, ReadHubNode objectClassNode, BeginNode[] calleeEntryNodes, FixedNode unknownTypeSux) {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
402 assert ptypes.length > 1;
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
403
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
404 int lastIndex = ptypes.length - 1;
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
405 double[] branchProbabilities = convertTypeToBranchProbabilities(ptypes, notRecordedTypeProbability);
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
406 double nodeProbability = ptypes[lastIndex].probability;
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
407 IfNode nextNode = createTypeCheck(graph, objectClassNode, ptypes[lastIndex].type, calleeEntryNodes[typesToConcretes[lastIndex]], unknownTypeSux, branchProbabilities[lastIndex], invoke.probability() * nodeProbability);
4452
b225da954a32 inlining of multiple trival methods at one call site works
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4451
diff changeset
408 for (int i = lastIndex - 1; i >= 0; i--) {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
409 nodeProbability += ptypes[i].probability;
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
410 nextNode = createTypeCheck(graph, objectClassNode, ptypes[i].type, calleeEntryNodes[typesToConcretes[i]], nextNode, branchProbabilities[i], invoke.probability() * nodeProbability);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
411 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
412
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
413 return nextNode;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
414 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
415
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
416 private static IfNode createTypeCheck(StructuredGraph graph, ReadHubNode objectClassNode, RiResolvedType type, BeginNode tsux, FixedNode nextNode, double tsuxProbability, double probability) {
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
417 IfNode result;
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
418 IsTypeNode isTypeNode = graph.unique(new IsTypeNode(objectClassNode, type));
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
419 if (tsux instanceof MergeNode) {
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
420 EndNode endNode = graph.add(new EndNode());
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
421 result = graph.add(new IfNode(isTypeNode, endNode, nextNode, tsuxProbability));
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4571
diff changeset
422 ((MergeNode) tsux).addForwardEnd(endNode);
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
423 } else {
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
424 result = graph.add(new IfNode(isTypeNode, tsux, nextNode, tsuxProbability));
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
425 }
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
426 result.setProbability(probability);
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
427 return result;
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
428 }
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
429
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
430 private static double[] convertTypeToBranchProbabilities(ProfiledType[] ptypes, double notRecordedTypeProbability) {
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
431 double[] result = new double[ptypes.length];
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
432 double total = notRecordedTypeProbability;
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
433 for (int i = ptypes.length - 1; i >= 0; i--) {
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
434 total += ptypes[i].probability;
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
435 result[i] = ptypes[i].probability / total;
4454
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
436 }
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
437 assert total > 0.99 && total < 1.01;
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
438 return result;
4454
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
439 }
008a5ea590ca fixed merge control flow for inlining
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
440
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
441 private static BeginNode createInvocationBlock(StructuredGraph graph, Invoke invoke, MergeNode returnMerge, PhiNode returnValuePhi,
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
442 MergeNode exceptionMerge, PhiNode exceptionObjectPhi, int predecessors, double probability, boolean useForInlining) {
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
443 Invoke duplicatedInvoke = duplicateInvokeForInlining(graph, invoke, exceptionMerge, exceptionObjectPhi, useForInlining, probability);
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
444 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
445 calleeEntryNode.setNext(duplicatedInvoke.node());
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
446 calleeEntryNode.setProbability(probability);
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
447
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
448 EndNode endNode = graph.add(new EndNode());
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
449 endNode.setProbability(probability);
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
450
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
451 duplicatedInvoke.setNext(endNode);
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4571
diff changeset
452 returnMerge.addForwardEnd(endNode);
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
453
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
454 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
455 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
456 }
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
457 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
458 }
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
459
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
460 private static Invoke duplicateInvokeForInlining(StructuredGraph graph, Invoke invoke, MergeNode exceptionMerge, PhiNode exceptionObjectPhi, boolean useForInlining, double probability) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
461 Invoke result = (Invoke) invoke.node().copyWithInputs();
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
462 Node callTarget = result.callTarget().copyWithInputs();
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4618
diff changeset
463 result.node().replaceFirstInput(result.callTarget(), callTarget);
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
464 result.setUseForInlining(useForInlining);
5005
c2ebd3d559f7 fixed probabilities when polymorphic inlining is used
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5003
diff changeset
465 result.setProbability(probability);
4539
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
466
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
467 CiKind kind = invoke.node().kind();
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
468 if (!kind.isVoid()) {
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
469 FrameState stateAfter = invoke.stateAfter();
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
470 stateAfter = stateAfter.duplicate(stateAfter.bci);
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
471 stateAfter.replaceFirstInput(invoke.node(), result.node());
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
472 result.setStateAfter(stateAfter);
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
473 }
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
474
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
475 if (invoke instanceof InvokeWithExceptionNode) {
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
476 assert exceptionMerge != null && exceptionObjectPhi != null;
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
477
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
478 InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
479 BeginNode exceptionEdge = invokeWithException.exceptionEdge();
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
480 ExceptionObjectNode exceptionObject = (ExceptionObjectNode) exceptionEdge.next();
4539
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
481 FrameState stateAfterException = exceptionObject.stateAfter();
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
482
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
483 BeginNode newExceptionEdge = (BeginNode) exceptionEdge.copyWithInputs();
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
484 ExceptionObjectNode newExceptionObject = (ExceptionObjectNode) exceptionObject.copyWithInputs();
4529
fc78ad20ec38 fixed exception framestate
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4528
diff changeset
485 // set new state (pop old exception object, push new one)
4539
98b3b255913c Fix stateAfter for multiple type inline
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4530
diff changeset
486 newExceptionObject.setStateAfter(stateAfterException.duplicateModified(stateAfterException.bci, stateAfterException.rethrowException(), CiKind.Object, newExceptionObject));
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
487 newExceptionEdge.setNext(newExceptionObject);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
488
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
489 EndNode endNode = graph.add(new EndNode());
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
490 newExceptionObject.setNext(endNode);
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4571
diff changeset
491 exceptionMerge.addForwardEnd(endNode);
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
492 exceptionObjectPhi.addInput(newExceptionObject);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
493
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
494 ((InvokeWithExceptionNode) result).setExceptionEdge(newExceptionEdge);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
495 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
496 return result;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
497 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
498
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
499 @Override
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
500 public String toString() {
5019
836e4fce33ab changed inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5005
diff changeset
501 StringBuilder builder = new StringBuilder(shouldFallbackToInvoke() ? "megamorphic" : "polymorphic");
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
502 builder.append(String.format(", %d methods with %d type checks:", concretes.size(), ptypes.length));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
503 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
504 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
505 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
506 return builder.toString();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
507 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
508
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
509 @Override
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
510 public boolean canDeopt() {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
511 return true;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
512 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
513 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
514
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
515
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
516 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
517 * 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
518 * 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
519 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
520 private static class AssumptionInlineInfo extends ExactInlineInfo {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
521 public final RiResolvedType context;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
522
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
523 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
524 super(invoke, weight, level, concrete);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
525 this.context = context;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
526 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
527
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
528 @Override
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
529 public void inline(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
530 if (Debug.isLogEnabled()) {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
531 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
532 String concreteName = CiUtil.format("%H.%n(%p):%r", concrete);
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
533 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
534 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
535 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
536
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
537 super.inline(graph, runtime, callback);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
538 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
539
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
540 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
541 public String toString() {
5020
77f816847d91 some more changes to inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5019
diff changeset
542 return "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
543 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
544
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
545 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
546 public boolean canDeopt() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
547 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
548 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
549 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
550
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
551 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
552 * 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
553 * @param invoke the invoke that should be inlined
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
554 * @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
555 * @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
556 * @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
557 * @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
558 */
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5110
diff changeset
559 public static InlineInfo getInlineInfo(Invoke invoke, int level, GraalRuntime runtime, CiAssumptions assumptions, InliningCallback callback, OptimisticOptimizations optimisticOpts) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
560 RiResolvedMethod parent = invoke.stateAfter().method();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
561 MethodCallTargetNode callTarget = invoke.callTarget();
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
562 RiResolvedMethod targetMethod = callTarget.targetMethod();
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
563 if (targetMethod == null) {
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
564 return null;
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
565 }
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
566 if (!checkInvokeConditions(invoke)) {
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
567 return null;
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
568 }
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
569
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
570 if (callTarget.invokeKind() == InvokeKind.Special || targetMethod.canBeStaticallyBound()) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
571 if (checkTargetConditions(invoke, targetMethod, optimisticOpts)) {
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
572 double weight = callback == null ? 0 : callback.inliningWeight(parent, targetMethod, invoke);
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
573 return new ExactInlineInfo(invoke, weight, level, targetMethod);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
574 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
575 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
576 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
577 if (callTarget.receiver().exactType() != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
578 RiResolvedType exact = callTarget.receiver().exactType();
4624
3b632ae14d47 Make assert in getInlineInfo output more information
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4622
diff changeset
579 assert exact.isSubtypeOf(targetMethod.holder()) : exact + " subtype of " + targetMethod.holder() + " for " + targetMethod;
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
580 RiResolvedMethod resolved = exact.resolveMethodImpl(targetMethod);
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
581 if (checkTargetConditions(invoke, resolved, optimisticOpts)) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
582 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
583 return new ExactInlineInfo(invoke, weight, level, resolved);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
584 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
585 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
586 }
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
587 RiResolvedType holder = targetMethod.holder();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
588
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
589 if (callTarget.receiver().declaredType() != null) {
4249
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
590 RiResolvedType declared = callTarget.receiver().declaredType();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
591 // the invoke target might be more specific than the holder (happens after inlining: locals lose their declared type...)
5056
2f2c6347fce4 comments cleanup/retagging
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5020
diff changeset
592 // TODO (lstadler) fix this
4249
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
593 if (declared != null && declared.isSubtypeOf(holder)) {
1aaf3592e516 Fix some warnings from findbugs
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4233
diff changeset
594 holder = declared;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
595 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
596 }
5056
2f2c6347fce4 comments cleanup/retagging
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5020
diff changeset
597 // TODO (thomaswue) fix this
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
598 if (assumptions != null) {
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
599 RiResolvedMethod concrete = holder.uniqueConcreteMethod(targetMethod);
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
600 if (concrete != null) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
601 if (checkTargetConditions(invoke, concrete, optimisticOpts)) {
4457
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
602 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
603 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
604 }
5acf4a974e4a fixed framestate for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4456
diff changeset
605 return null;
3733
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 }
4440
271220b49abc profiling info fixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4249
diff changeset
608
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
609 // type check based inlining
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5110
diff changeset
610 return getTypeCheckedInlineInfo(invoke, level, callback, parent, targetMethod, optimisticOpts);
5109
6766253384bf more preparations for disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5105
diff changeset
611 }
6766253384bf more preparations for disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5105
diff changeset
612
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5110
diff changeset
613 private static InlineInfo getTypeCheckedInlineInfo(Invoke invoke, int level, InliningCallback callback, RiResolvedMethod parent, RiResolvedMethod targetMethod, OptimisticOptimizations optimisticOpts) {
4440
271220b49abc profiling info fixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4249
diff changeset
614 RiProfilingInfo profilingInfo = parent.profilingInfo();
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
615 RiTypeProfile typeProfile = profilingInfo.getTypeProfile(invoke.bci());
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
616 if (typeProfile != null) {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
617 ProfiledType[] ptypes = typeProfile.getTypes();
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
618
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
619 if (ptypes != null && ptypes.length > 0) {
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
620 double notRecordedTypeProbability = typeProfile.getNotRecordedProbability();
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
621 if (ptypes.length == 1 && notRecordedTypeProbability == 0) {
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5110
diff changeset
622 if (optimisticOpts.inlineMonomorphicCalls()) {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
623 RiResolvedType type = ptypes[0].type;
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
624 RiResolvedMethod concrete = type.resolveMethodImpl(targetMethod);
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
625 if (checkTargetConditions(invoke, concrete, optimisticOpts)) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
626 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
627 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
628 }
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
629
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
630 Debug.log("not inlining %s because method can't be inlined", methodName(targetMethod, invoke));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
631 return null;
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
632 } else {
5003
5e6f1026a63e fixes to vtable stub inlining: compute offset on demand, look out for interface methods
Lukas Stadler <lukas.stadler@jku.at>
parents: 4696
diff changeset
633 Debug.log("not inlining %s because GraalOptions.InlineMonomorphicCalls == false", methodName(targetMethod, invoke));
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
634 return null;
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
635 }
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
636 } else {
5003
5e6f1026a63e fixes to vtable stub inlining: compute offset on demand, look out for interface methods
Lukas Stadler <lukas.stadler@jku.at>
parents: 4696
diff changeset
637 invoke.setMegamorph(true);
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5110
diff changeset
638 if (optimisticOpts.inlinePolymorphicCalls() && notRecordedTypeProbability == 0 || optimisticOpts.inlineMegamorphicCalls() && notRecordedTypeProbability > 0) {
5057
3d7e78f17df5 more comments tag updates
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5056
diff changeset
639 // TODO (chaeubl) inlining of multiple methods should work differently
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
640 // 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
641 // 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
642 // 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
643 // 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
644 // b) some methods can be inlined -> inline them and fall back to invocation if violated
5057
3d7e78f17df5 more comments tag updates
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5056
diff changeset
645 // TODO (chaeubl) sort types by probability
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
646
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
647 // 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
648 ArrayList<RiResolvedMethod> concreteMethods = new ArrayList<>();
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
649 int[] typesToConcretes = new int[ptypes.length];
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
650 for (int i = 0; i < ptypes.length; i++) {
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
651 RiResolvedMethod concrete = ptypes[i].type.resolveMethodImpl(targetMethod);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
652
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
653 int index = concreteMethods.indexOf(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
654 if (index < 0) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
655 index = concreteMethods.size();
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
656 concreteMethods.add(concrete);
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
657 }
4458
cdf13998f705 inlining of multiple methods survives bootstrapping
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4457
diff changeset
658 typesToConcretes[i] = index;
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
659 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
660
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
661 double totalWeight = 0;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
662 boolean canInline = true;
4464
f304ba0d4e24 inlining seems stable but deoptimizes too frequently
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4462
diff changeset
663 for (RiResolvedMethod concrete: concreteMethods) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
664 if (!checkTargetConditions(invoke, concrete, optimisticOpts)) {
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
665 canInline = false;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
666 break;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
667 }
4464
f304ba0d4e24 inlining seems stable but deoptimizes too frequently
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4462
diff changeset
668 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
669 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
670
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
671 if (canInline) {
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5316
diff changeset
672 return new MultiTypeGuardInlineInfo(invoke, totalWeight, level, concreteMethods, ptypes, typesToConcretes, notRecordedTypeProbability);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
673 } else {
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
674 Debug.log("not inlining %s because it is a polymorphic method call and at least one invoked method cannot be inlined", methodName(targetMethod, invoke));
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
675 return null;
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
676 }
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4455
diff changeset
677 } else {
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5110
diff changeset
678 if (!optimisticOpts.inlinePolymorphicCalls() && notRecordedTypeProbability == 0) {
5019
836e4fce33ab changed inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5005
diff changeset
679 Debug.log("not inlining %s because GraalOptions.InlinePolymorphicCalls == false", methodName(targetMethod, invoke));
836e4fce33ab changed inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5005
diff changeset
680 } else {
836e4fce33ab changed inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5005
diff changeset
681 Debug.log("not inlining %s because GraalOptions.InlineMegamorphicCalls == false", methodName(targetMethod, invoke));
836e4fce33ab changed inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5005
diff changeset
682 }
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
683 return null;
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
684 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
685 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
686 }
4459
d389f4b5bdd6 fixed typecheck branch probability
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4458
diff changeset
687
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
688 Debug.log("not inlining %s because no types/probabilities were recorded", methodName(targetMethod, invoke));
4441
4e3aaf14cbc6 fixed graal to hotspot
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4440
diff changeset
689 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
690 } else {
4571
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4564
diff changeset
691 Debug.log("not inlining %s because no type profile exists", methodName(targetMethod, invoke));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
692 return null;
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
5339
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
696 private static ValueNode createAnchoredReceiver(StructuredGraph graph, FixedNode anchor, RiResolvedType commonType, ValueNode receiver) {
4636
495a81cd6969 avoid code generation for typechecks that are only used for anchoring
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4635
diff changeset
697 // to avoid that floating reads on receiver fields float above the type check
5339
e8f80481326d use PiNodes instead of CheckCastNodes to pin inlining receivers, remove emitCode flag
Lukas Stadler <lukas.stadler@jku.at>
parents: 5316
diff changeset
698 return graph.unique(new PiNode(receiver, anchor, StampFactory.declaredNonNull(commonType)));
4636
495a81cd6969 avoid code generation for typechecks that are only used for anchoring
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4635
diff changeset
699 }
495a81cd6969 avoid code generation for typechecks that are only used for anchoring
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4635
diff changeset
700
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
701 private static boolean checkInvokeConditions(Invoke invoke) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
702 if (invoke.stateAfter() == null) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
703 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
704 return false;
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 if (invoke.predecessor() == null) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
707 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
708 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
709 }
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
710 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
711 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
712 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
713 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
714 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
715 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
716
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
717 private static boolean checkTargetConditions(Invoke invoke, RiMethod method, OptimisticOptimizations optimisticOpts) {
4530
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4529
diff changeset
718 if (method == null) {
4564
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
719 Debug.log("not inlining because method is not resolved");
4530
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4529
diff changeset
720 return false;
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4529
diff changeset
721 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
722 if (!(method instanceof RiResolvedMethod)) {
4402
8220fa69f075 Remove TraceInlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4387
diff changeset
723 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
724 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
725 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
726 RiResolvedMethod resolvedMethod = (RiResolvedMethod) method;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
727 if (Modifier.isNative(resolvedMethod.accessFlags())) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
728 Debug.log("not inlining %s because it is a native method", methodName(resolvedMethod, invoke));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
729 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
730 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
731 if (Modifier.isAbstract(resolvedMethod.accessFlags())) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
732 Debug.log("not inlining %s because it is an abstract method", methodName(resolvedMethod, invoke));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
733 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
734 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
735 if (!resolvedMethod.holder().isInitialized()) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
736 Debug.log("not inlining %s because of non-initialized class", methodName(resolvedMethod, invoke));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
737 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
738 }
4296
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
739 if (!resolvedMethod.canBeInlined()) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
740 Debug.log("not inlining %s because it is marked non-inlinable", methodName(resolvedMethod, invoke));
4296
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
741 return false;
d089b71a5237 Add possibility to disable inlining for specific methods.
Andreas Woess <andreas.woess@jku.at>
parents: 4249
diff changeset
742 }
4564
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
743 if (computeRecursiveInliningLevel(invoke.stateAfter(), (RiResolvedMethod) method) > GraalOptions.MaximumRecursiveInlining) {
5127
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
744 Debug.log("not inlining %s because it exceeds the maximum recursive inlining depth", methodName(resolvedMethod, invoke));
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
745 return false;
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
746 }
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
747 OptimisticOptimizations calleeOpts = new OptimisticOptimizations(resolvedMethod);
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
748 if (calleeOpts.lessOptimisticThan(optimisticOpts)) {
7b2efb5ff2ea better inlining debug output
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5114
diff changeset
749 Debug.log("not inlining %s because callee uses less optimistic optimizations than caller", methodName(resolvedMethod, invoke));
4564
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
750 return false;
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
751 }
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
752
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
753 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
754 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
755
4564
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
756 private static int computeRecursiveInliningLevel(FrameState state, RiResolvedMethod method) {
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
757 assert state != null;
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
758
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
759 int count = 0;
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
760 FrameState curState = state;
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
761 while (curState != null) {
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
762 if (curState.method() == method) {
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
763 count++;
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
764 }
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
765 curState = curState.outerFrameState();
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
766 }
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
767 return count;
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
768 }
8fc6920e064b avoid recursive inlining, escape analysis does no longer restart inlining with level 0, bugfixes
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4539
diff changeset
769
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
770 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
771 * Performs an actual inlining, thereby replacing the given invoke with the given inlineGraph.
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
772 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
773 * @param invoke the invoke that will be replaced
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
774 * @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
775 * @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
776 */
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
777 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
778 NodeInputList<ValueNode> parameters = invoke.callTarget().arguments();
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4305
diff changeset
779 StructuredGraph graph = (StructuredGraph) invoke.node().graph();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
780
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
781 FrameState stateAfter = invoke.stateAfter();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
782 assert stateAfter.isAlive();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
783
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
784 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
785 ArrayList<Node> nodes = new ArrayList<>();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
786 ReturnNode returnNode = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
787 UnwindNode unwindNode = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
788 BeginNode entryPointNode = inlineGraph.start();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
789 FixedNode firstCFGNode = entryPointNode.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
790 for (Node node : inlineGraph.getNodes()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
791 if (node == entryPointNode || node == entryPointNode.stateAfter()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
792 // Do nothing.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
793 } else if (node instanceof LocalNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
794 replacements.put(node, parameters.get(((LocalNode) node).index()));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
795 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
796 nodes.add(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
797 if (node instanceof ReturnNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
798 returnNode = (ReturnNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
799 } else if (node instanceof UnwindNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
800 unwindNode = (UnwindNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
801 }
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 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
804
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
805 assert invoke.node().successors().first() != null : invoke;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
806 assert invoke.node().predecessor() != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
807
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
808 Map<Node, Node> duplicates = graph.addDuplicates(nodes, replacements);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
809 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
810 if (receiverNullCheck) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
811 receiverNullCheck(invoke);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
812 }
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4305
diff changeset
813 invoke.node().replaceAtPredecessors(firstCFGNodeDuplicate);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
814
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
815 FrameState stateAtExceptionEdge = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
816 if (invoke instanceof InvokeWithExceptionNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
817 InvokeWithExceptionNode invokeWithException = ((InvokeWithExceptionNode) invoke);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
818 if (unwindNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
819 assert unwindNode.predecessor() != null;
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4312
diff changeset
820 assert invokeWithException.exceptionEdge().successors().count() == 1;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
821 ExceptionObjectNode obj = (ExceptionObjectNode) invokeWithException.exceptionEdge().next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
822 stateAtExceptionEdge = obj.stateAfter();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
823 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode);
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
824 obj.replaceAtUsages(unwindDuplicate.exception());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
825 unwindDuplicate.clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
826 Node n = obj.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
827 obj.setNext(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
828 unwindDuplicate.replaceAndDelete(n);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
829 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
830 invokeWithException.killExceptionEdge();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
831 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
832 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
833 if (unwindNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
834 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode);
5130
Lukas Stadler <lukas.stadler@jku.at>
parents: 5129 5127
diff changeset
835 DeoptimizeNode deoptimizeNode = new DeoptimizeNode(RiDeoptAction.InvalidateRecompile, RiDeoptReason.NotCompiledExceptionHandler, invoke.leafGraphId());
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
836 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
837 // 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
838 // (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
839 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
840 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
841 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
842 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
843 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
844 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
845 }
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
846 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
847 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
848 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
849
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
850 FrameState outerFrameState = null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
851 double invokeProbability = invoke.node().probability();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
852 for (Node node : duplicates.values()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
853 if (GraalOptions.ProbabilityAnalysis) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
854 if (node instanceof FixedNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
855 FixedNode fixed = (FixedNode) node;
4605
f0569f6336f7 disabled megamorphic calls, trying an inlining policy where invokes within loops do not have any advantages
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4590
diff changeset
856 double newProbability = fixed.probability() * invokeProbability;
f0569f6336f7 disabled megamorphic calls, trying an inlining policy where invokes within loops do not have any advantages
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4590
diff changeset
857 if (GraalOptions.LimitInlinedProbability) {
f0569f6336f7 disabled megamorphic calls, trying an inlining policy where invokes within loops do not have any advantages
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4590
diff changeset
858 newProbability = Math.min(newProbability, invokeProbability);
f0569f6336f7 disabled megamorphic calls, trying an inlining policy where invokes within loops do not have any advantages
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4590
diff changeset
859 }
f0569f6336f7 disabled megamorphic calls, trying an inlining policy where invokes within loops do not have any advantages
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4590
diff changeset
860 fixed.setProbability(newProbability);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
861 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
862 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
863 if (node instanceof FrameState) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
864 FrameState frameState = (FrameState) node;
4687
bacc18e07f7b Removed dead code from the inlining util. STATE_BEFORE is only used in BlockBegin, which in turn is not added to the caller graph during inlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4678
diff changeset
865 assert frameState.bci != FrameState.BEFORE_BCI;
bacc18e07f7b Removed dead code from the inlining util. STATE_BEFORE is only used in BlockBegin, which in turn is not added to the caller graph during inlining.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4678
diff changeset
866 if (frameState.bci == FrameState.AFTER_BCI) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
867 frameState.replaceAndDelete(stateAfter);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
868 } 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
869 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
870 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
871 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
872 } 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
873 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
874 }
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
875 } else {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
876 if (outerFrameState == null) {
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
877 outerFrameState = stateAfter.duplicateModified(invoke.bci(), stateAfter.rethrowException(), invoke.node().kind());
4678
a03f3fd16b22 Fix reexecute boolean in HotSpot debug information. Introduce "duringCall" flag in FrameState that indicates that the bci of the frame state denotes an invoke that should *not* be reexecuted.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4670
diff changeset
878 outerFrameState.setDuringCall(true);
4449
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
879 }
d84ccb0cc897 some parts for inlining multiple methods
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4442
diff changeset
880 frameState.setOuterFrameState(outerFrameState);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
881 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
882 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
883 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
884
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
885 Node returnValue = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
886 if (returnNode != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
887 if (returnNode.result() instanceof LocalNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
888 returnValue = replacements.get(returnNode.result());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
889 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
890 returnValue = duplicates.get(returnNode.result());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
891 }
4455
b788ebbb7ef8 cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4454
diff changeset
892 invoke.node().replaceAtUsages(returnValue);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
893 Node returnDuplicate = duplicates.get(returnNode);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
894 returnDuplicate.clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
895 Node n = invoke.next();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
896 invoke.setNext(null);
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5160
diff changeset
897 returnDuplicate.replaceAndDelete(n);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
898 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
899
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
900 invoke.node().clearInputs();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
901 invoke.node().replaceAtUsages(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
902 GraphUtil.killCFG(invoke.node());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
903
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
904 if (stateAfter.usages().isEmpty()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
905 stateAfter.safeDelete();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
906 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
907 }
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
908
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
909 /**
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
910 * Performs replacement of a node with a snippet graph.
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
911 *
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
912 * @param replacee the node that will be replaced
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
913 * @param anchor the control flow replacee
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
914 * @param snippetGraph the graph that the replacee will be replaced with
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
915 * @param explodeLoops specifies if all the loops in the snippet graph are counted loops that must be completely unrolled
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
916 * @param args
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
917 */
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
918 public static void inlineSnippet(final RiRuntime runtime,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
919 final Node replacee,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
920 final FixedWithNextNode anchor,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
921 final StructuredGraph snippetGraph,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
922 final boolean explodeLoops,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
923 final IsImmutablePredicate immutabilityPredicate,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
924 final Object... args) {
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
925 Debug.scope("InliningSnippet", snippetGraph.method(), new Runnable() {
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
926 @Override
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
927 public void run() {
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
928 inlineSnippet0(runtime, replacee, anchor, snippetGraph, explodeLoops, immutabilityPredicate, args);
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
929 }
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
930 });
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
931 }
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
932 private static void inlineSnippet0(RiRuntime runtime,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
933 Node replacee,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
934 FixedWithNextNode anchor,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
935 StructuredGraph snippetGraph,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
936 boolean explodeLoops,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
937 IsImmutablePredicate immutabilityPredicate,
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
938 Object... args) {
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
939 // Copy snippet graph, replacing parameters with given args in the process
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
940 StructuredGraph snippetCopy = new StructuredGraph(snippetGraph.name, snippetGraph.method());
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
941 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
942 replacements.put(snippetGraph.start(), snippetCopy.start());
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
943 int localCount = 0;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
944 for (LocalNode local : snippetGraph.getNodes(LocalNode.class)) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
945 int index = local.index();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
946 if (args[index] instanceof CiConstant) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
947 CiConstant arg = (CiConstant) args[index];
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
948 assert arg.kind.stackKind() == local.kind() : arg.kind + " != " + local.kind();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
949 ConstantNode argNode = ConstantNode.forCiConstant(arg, runtime, snippetCopy);
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
950 replacements.put(local, argNode);
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
951 args[index] = null;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
952 } else {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
953 assert args[index] instanceof ValueNode;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
954 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
955 localCount++;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
956 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
957 assert localCount == args.length : "snippet argument count mismatch";
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
958 snippetCopy.addDuplicates(snippetGraph.getNodes(), replacements);
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
959 if (!replacements.isEmpty()) {
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
960 new CanonicalizerPhase(null, runtime, null, false, immutabilityPredicate).apply(snippetCopy);
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
961 }
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
962
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
963 // Explode all loops in the snippet if requested
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
964 if (explodeLoops && snippetCopy.hasLoops()) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
965 ControlFlowGraph cfg = ControlFlowGraph.compute(snippetCopy, true, true, false, false);
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
966 for (Loop loop : cfg.getLoops()) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
967 LoopBeginNode loopBegin = loop.loopBegin();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
968 SuperBlock wholeLoop = LoopTransformUtil.wholeLoop(loop);
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
969 Debug.dump(snippetCopy, "Before exploding loop %s", loopBegin);
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
970 while (!loopBegin.isDeleted()) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
971 snippetCopy.mark();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
972 LoopTransformUtil.peel(loop, wholeLoop);
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
973 new CanonicalizerPhase(null, runtime, null, true, immutabilityPredicate).apply(snippetCopy);
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
974 }
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
975 Debug.dump(snippetCopy, "After exploding loop %s", loopBegin);
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
976 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
977 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
978
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
979 // Gather the nodes in the snippets that are to be inlined
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
980 ArrayList<Node> nodes = new ArrayList<>();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
981 ReturnNode returnNode = null;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
982 BeginNode entryPointNode = snippetCopy.start();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
983 FixedNode firstCFGNode = entryPointNode.next();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
984 replacements.clear();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
985 for (Node node : snippetCopy.getNodes()) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
986 if (node == entryPointNode || node == entryPointNode.stateAfter()) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
987 // Do nothing.
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
988 } else if (node instanceof LocalNode) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
989 LocalNode local = (LocalNode) node;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
990 int index = local.index();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
991 assert args[index] instanceof ValueNode;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
992 ValueNode arg = (ValueNode) args[index];
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
993 assert arg.kind() == local.kind();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
994 replacements.put(node, arg);
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
995 args[index] = null;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
996 } else {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
997 nodes.add(node);
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
998 if (node instanceof ReturnNode) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
999 returnNode = (ReturnNode) node;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1000 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1001 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1002 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1003
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1004 // Inline the gathered snippet nodes
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1005 StructuredGraph graph = (StructuredGraph) replacee.graph();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1006 Map<Node, Node> duplicates = graph.addDuplicates(nodes, replacements);
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1007
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1008 // Remove all frame states from the inlined snippet graph. Snippets must be atomic (i.e. free
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1009 // of side-effects that prevent deoptimizing to a point before the snippet).
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1010 for (Node node : duplicates.values()) {
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1011 if (node instanceof StateSplit) {
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1012 StateSplit stateSplit = (StateSplit) node;
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1013 FrameState frameState = stateSplit.stateAfter();
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1014 assert !stateSplit.hasSideEffect() : "snippets cannot contain side-effecting node " + node;
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1015 if (frameState != null) {
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1016 stateSplit.setStateAfter(null);
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1017 }
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1018 }
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1019 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1020
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1021 // Rewire the control flow graph around the replacee
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1022 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1023 anchor.replaceAtPredecessors(firstCFGNodeDuplicate);
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1024 FixedNode next = anchor.next();
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1025 anchor.setNext(null);
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1026
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1027 // Replace all usages of the replacee with the value returned by the snippet
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1028 Node returnValue = null;
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1029 if (returnNode != null) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1030 if (returnNode.result() instanceof LocalNode) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1031 returnValue = replacements.get(returnNode.result());
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1032 } else {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1033 returnValue = duplicates.get(returnNode.result());
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1034 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1035 assert returnValue != null || replacee.usages().isEmpty();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1036 replacee.replaceAtUsages(returnValue);
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1037
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1038 Node returnDuplicate = duplicates.get(returnNode);
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1039 returnDuplicate.clearInputs();
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1040 returnDuplicate.replaceAndDelete(next);
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1041 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1042
5365
33b8603f180d lowering checkcasts with Java snippets
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
1043 // Remove the replacee from its graph
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1044 replacee.clearInputs();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1045 replacee.replaceAtUsages(null);
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1046 if (replacee instanceof FixedNode) {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1047 GraphUtil.killCFG((FixedNode) replacee);
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1048 } else {
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1049 replacee.safeDelete();
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1050 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1051 }
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5341
diff changeset
1052
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
1053 public static void receiverNullCheck(Invoke invoke) {
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
1054 MethodCallTargetNode callTarget = invoke.callTarget();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
1055 StructuredGraph graph = (StructuredGraph) invoke.graph();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
1056 NodeInputList<ValueNode> parameters = callTarget.arguments();
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
1057 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
1058 if (!callTarget.isStatic() && firstParam.kind() == CiKind.Object && !firstParam.stamp().nonNull()) {
5160
6e385457d6fc Add a RiDeoptAction to Guards and FixedGuards
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5130
diff changeset
1059 graph.addBeforeFixed(invoke.node(), graph.add(new FixedGuardNode(graph.unique(new NullCheckNode(firstParam, false)), RiDeoptReason.ClassCastException, RiDeoptAction.InvalidateReprofile, invoke.leafGraphId())));
4451
defa1b705f14 NullCheck and IsTypeNode were in wrong order
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4449
diff changeset
1060 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1061 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1062 }