Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java @ 20001:0e7bb9cced6b
ignore forced MethodSubstitutions during graph builder inlining (it breaks economy compiler configuration)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 23 Mar 2015 14:18:32 +0100 |
parents | 43661c648060 |
children | b7477f2df553 |
rev | line source |
---|---|
7076 | 1 /* |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8981
diff
changeset
|
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
7076 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
8414
diff
changeset
|
23 package com.oracle.graal.replacements; |
7076 | 24 |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
25 import static com.oracle.graal.api.meta.MetaUtil.*; |
11491
a03452edfc4d
made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents:
11402
diff
changeset
|
26 import static com.oracle.graal.compiler.GraalCompiler.*; |
15259
d90e5c22ba55
Move GraalOptions to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
27 import static com.oracle.graal.compiler.common.GraalOptions.*; |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
28 import static com.oracle.graal.java.AbstractBytecodeParser.Options.*; |
17065
37d6d174bc40
denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
29 import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.*; |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
30 import static java.lang.String.*; |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
31 |
7076 | 32 import java.lang.reflect.*; |
33 import java.util.*; | |
34 import java.util.concurrent.*; | |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
35 import java.util.concurrent.atomic.*; |
7076 | 36 |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
37 import sun.misc.*; |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
38 |
7076 | 39 import com.oracle.graal.api.code.*; |
40 import com.oracle.graal.api.meta.*; | |
8420
5d3fa6f949fb
created com.oracle.graal.api.replacements project and moved ClassSubstitution and MethodSubstitution there
Doug Simon <doug.simon@oracle.com>
parents:
8419
diff
changeset
|
41 import com.oracle.graal.api.replacements.*; |
16772
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
42 import com.oracle.graal.compiler.*; |
15193
96bb07a5d667
Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents:
15053
diff
changeset
|
43 import com.oracle.graal.compiler.common.*; |
7076 | 44 import com.oracle.graal.debug.*; |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
45 import com.oracle.graal.debug.Debug.Scope; |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
46 import com.oracle.graal.graph.*; |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
47 import com.oracle.graal.graph.Node.NodeIntrinsic; |
19883
4d33cd6e0c8f
refactored GraphBuilderConfiguration (and its component classes) into a separate project
Doug Simon <doug.simon@oracle.com>
parents:
19882
diff
changeset
|
48 import com.oracle.graal.graphbuilderconf.*; |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
49 import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
50 import com.oracle.graal.graphbuilderconf.GraphBuilderContext.*; |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
51 import com.oracle.graal.graphbuilderconf.InlineInvokePlugin.InlineInfo; |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
52 import com.oracle.graal.java.AbstractBytecodeParser.IntrinsicContext; |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
53 import com.oracle.graal.java.AbstractBytecodeParser.ReplacementContext; |
7076 | 54 import com.oracle.graal.java.*; |
14739
553527010fc4
Allow subclasses to provide their own graph builder
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14636
diff
changeset
|
55 import com.oracle.graal.java.GraphBuilderPhase.Instance; |
7076 | 56 import com.oracle.graal.nodes.*; |
19306
a0a760b0fb5f
pulled method evolution dependencies out of Assumptions and directly into StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents:
19254
diff
changeset
|
57 import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; |
7076 | 58 import com.oracle.graal.nodes.java.*; |
8637
ce5750014c3d
moved Replacements and MacroSubstitution from the graal.api.replacements project to graal.nodes project and reversed the dependency between these two projects (the latter now/again depends on the former)
Doug Simon <doug.simon@oracle.com>
parents:
8631
diff
changeset
|
59 import com.oracle.graal.nodes.spi.*; |
7076 | 60 import com.oracle.graal.phases.*; |
61 import com.oracle.graal.phases.common.*; | |
11569
2f6734f8126a
Avoid direct usage of CanonicalizerPhase.Instance in replacements processing.
Roland Schatz <roland.schatz@oracle.com>
parents:
11491
diff
changeset
|
62 import com.oracle.graal.phases.tiers.*; |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
63 import com.oracle.graal.phases.util.*; |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
64 import com.oracle.graal.word.*; |
7076 | 65 |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
66 public class ReplacementsImpl implements Replacements, InlineInvokePlugin { |
7076 | 67 |
18371
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
68 public final Providers providers; |
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
69 public final SnippetReflectionProvider snippetReflection; |
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
70 public final TargetDescription target; |
19418
7d3140f2de2e
reuse a single NodeIntrinsificationPhase instance in ReplacementsImpl (since the former is stateless)
Doug Simon <doug.simon@oracle.com>
parents:
19410
diff
changeset
|
71 public final NodeIntrinsificationPhase nodeIntrinsificationPhase; |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
72 private GraphBuilderConfiguration.Plugins graphBuilderPlugins; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
73 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
74 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
75 * The preprocessed replacement graphs. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
76 */ |
13146
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
77 protected final ConcurrentMap<ResolvedJavaMethod, StructuredGraph> graphs; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
78 |
19882
0c29075aeafe
graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents:
19881
diff
changeset
|
79 public void setGraphBuilderPlugins(GraphBuilderConfiguration.Plugins plugins) { |
0c29075aeafe
graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents:
19881
diff
changeset
|
80 assert this.graphBuilderPlugins == null; |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
81 this.graphBuilderPlugins = plugins; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
82 } |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
83 |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
84 protected boolean hasGenericInvocationPluginAnnotation(ResolvedJavaMethod method) { |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
85 return nodeIntrinsificationPhase.getIntrinsic(method) != null || method.getAnnotation(Word.Operation.class) != null || nodeIntrinsificationPhase.isFoldable(method); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
86 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
87 |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
88 private static final int MAX_GRAPH_INLINING_DEPTH = 100; // more than enough |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
89 |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
90 /** |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
91 * Determines whether a given method should be inlined based on whether it has a substitution or |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
92 * whether the inlining context is already within a substitution. |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
93 * |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
94 * @return an {@link InlineInfo} object specifying how {@code method} is to be inlined or null |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
95 * if it should not be inlined based on substitution related criteria |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
96 */ |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
97 public InlineInfo getInlineInfo(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, JavaType returnType) { |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
98 ResolvedJavaMethod subst = getMethodSubstitutionMethod(method); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
99 if (subst != null) { |
20001
0e7bb9cced6b
ignore forced MethodSubstitutions during graph builder inlining (it breaks economy compiler configuration)
Doug Simon <doug.simon@oracle.com>
parents:
19999
diff
changeset
|
100 if (b.parsingReplacement() || InlineDuringParsing.getValue()) { |
19999
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
101 // Forced inlining of intrinsics |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
102 return new InlineInfo(subst, true, true); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
103 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
104 return null; |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
105 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
106 if (b.parsingReplacement()) { |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
107 assert !hasGenericInvocationPluginAnnotation(method) : format("%s should have been handled by %s", method.format("%H.%n(%p)"), DefaultGenericInvocationPlugin.class.getName()); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
108 |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
109 assert b.getDepth() < MAX_GRAPH_INLINING_DEPTH : "inlining limit exceeded"; |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
110 |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
111 if (method.getName().startsWith("$jacoco")) { |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
112 throw new GraalInternalError("Found call to JaCoCo instrumentation method " + method.format("%H.%n(%p)") + ". Placing \"//JaCoCo Exclude\" anywhere in " + |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
113 b.getMethod().getDeclaringClass().getSourceFileName() + " should fix this."); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
114 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
115 |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
116 // Force inlining when parsing replacements |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
117 return new InlineInfo(method, true, true); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
118 } else { |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
119 assert nodeIntrinsificationPhase.getIntrinsic(method) == null : String.format("@%s method %s must only be called from within a replacement%n%s", NodeIntrinsic.class.getSimpleName(), |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
120 method.format("%h.%n"), b); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
121 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
122 return null; |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
123 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
124 |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
125 public void notifyOfNoninlinedInvoke(GraphBuilderContext b, ResolvedJavaMethod method, Invoke invoke) { |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
126 if (b.parsingReplacement()) { |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
127 boolean compilingSnippet = b.getRootMethod().getAnnotation(Snippet.class) != null; |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
128 Replacement replacement = b.getReplacement(); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
129 assert compilingSnippet : format("All calls in the replacement %s must be inlined or intrinsified: found call to %s", replacement.getReplacementMethod().format("%H.%n(%p)"), |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
130 method.format("%h.%n(%p)")); |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
131 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
132 } |
43661c648060
moved non-HotSpot specific inlining functionality into non-HotSpot specific location
Doug Simon <doug.simon@oracle.com>
parents:
19994
diff
changeset
|
133 |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
134 /** |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
135 * Encapsulates method and macro substitutions for a single class. |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
136 */ |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
137 protected class ClassReplacements { |
18743
220d7f242e57
use deterministic iteration-order data structures
Doug Simon <doug.simon@oracle.com>
parents:
18639
diff
changeset
|
138 public final Map<ResolvedJavaMethod, ResolvedJavaMethod> methodSubstitutions = CollectionsFactory.newMap(); |
220d7f242e57
use deterministic iteration-order data structures
Doug Simon <doug.simon@oracle.com>
parents:
18639
diff
changeset
|
139 public final Map<ResolvedJavaMethod, Class<? extends FixedWithNextNode>> macroSubstitutions = CollectionsFactory.newMap(); |
17140
f95ddcd3e08a
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17094
diff
changeset
|
140 public final Set<ResolvedJavaMethod> forcedSubstitutions = new HashSet<>(); |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
141 |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
142 public ClassReplacements(Class<?>[] substitutionClasses, AtomicReference<ClassReplacements> ref) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
143 for (Class<?> substitutionClass : substitutionClasses) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
144 ClassSubstitution classSubstitution = substitutionClass.getAnnotation(ClassSubstitution.class); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
145 assert !Snippets.class.isAssignableFrom(substitutionClass); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
146 SubstitutionGuard defaultGuard = getGuard(classSubstitution.defaultGuard()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
147 for (Method substituteMethod : substitutionClass.getDeclaredMethods()) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
148 if (ref.get() != null) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
149 // Bail if another thread beat us creating the substitutions |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
150 return; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
151 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
152 MethodSubstitution methodSubstitution = substituteMethod.getAnnotation(MethodSubstitution.class); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
153 MacroSubstitution macroSubstitution = substituteMethod.getAnnotation(MacroSubstitution.class); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
154 if (methodSubstitution == null && macroSubstitution == null) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
155 continue; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
156 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
157 |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
158 int modifiers = substituteMethod.getModifiers(); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
159 if (!Modifier.isStatic(modifiers)) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
160 throw new GraalInternalError("Substitution methods must be static: " + substituteMethod); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
161 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
162 |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
163 if (methodSubstitution != null) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
164 SubstitutionGuard guard = getGuard(methodSubstitution.guard()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
165 if (guard == null) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
166 guard = defaultGuard; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
167 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
168 |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
169 if (macroSubstitution != null && macroSubstitution.isStatic() != methodSubstitution.isStatic()) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
170 throw new GraalInternalError("Macro and method substitution must agree on isStatic attribute: " + substituteMethod); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
171 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
172 if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
173 throw new GraalInternalError("Substitution method must not be abstract or native: " + substituteMethod); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
174 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
175 String originalName = originalName(substituteMethod, methodSubstitution.value()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
176 JavaSignature originalSignature = originalSignature(substituteMethod, methodSubstitution.signature(), methodSubstitution.isStatic()); |
19777
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
177 Executable[] originalMethods = originalMethods(classSubstitution, classSubstitution.optional(), originalName, originalSignature); |
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
178 if (originalMethods != null) { |
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
179 for (Executable originalMethod : originalMethods) { |
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
180 if (originalMethod != null && (guard == null || guard.execute())) { |
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
181 ResolvedJavaMethod original = registerMethodSubstitution(this, originalMethod, substituteMethod); |
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
182 if (original != null && methodSubstitution.forced() && shouldIntrinsify(original)) { |
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
183 forcedSubstitutions.add(original); |
017eb83853dd
fixed npe when the target class of optional method substitutions is not present
Doug Simon <doug.simon@oracle.com>
parents:
19776
diff
changeset
|
184 } |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
185 } |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
186 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
187 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
188 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
189 // We don't have per method guards for macro substitutions but at |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
190 // least respect the defaultGuard if there is one. |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
191 if (macroSubstitution != null && (defaultGuard == null || defaultGuard.execute())) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
192 String originalName = originalName(substituteMethod, macroSubstitution.value()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
193 JavaSignature originalSignature = originalSignature(substituteMethod, macroSubstitution.signature(), macroSubstitution.isStatic()); |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
194 Executable[] originalMethods = originalMethods(classSubstitution, macroSubstitution.optional(), originalName, originalSignature); |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
195 for (Executable originalMethod : originalMethods) { |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
196 if (originalMethod != null) { |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
197 ResolvedJavaMethod original = registerMacroSubstitution(this, originalMethod, macroSubstitution.macro()); |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
198 if (original != null && macroSubstitution.forced() && shouldIntrinsify(original)) { |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
199 forcedSubstitutions.add(original); |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
200 } |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
201 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
202 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
203 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
204 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
205 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
206 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
207 |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
208 private JavaSignature originalSignature(Method substituteMethod, String methodSubstitution, boolean isStatic) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
209 Class<?>[] parameters; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
210 Class<?> returnType; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
211 if (methodSubstitution.isEmpty()) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
212 parameters = substituteMethod.getParameterTypes(); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
213 if (!isStatic) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
214 assert parameters.length > 0 : "must be a static method with the 'this' object as its first parameter"; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
215 parameters = Arrays.copyOfRange(parameters, 1, parameters.length); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
216 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
217 returnType = substituteMethod.getReturnType(); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
218 } else { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
219 Signature signature = providers.getMetaAccess().parseMethodDescriptor(methodSubstitution); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
220 parameters = new Class[signature.getParameterCount(false)]; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
221 for (int i = 0; i < parameters.length; i++) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
222 parameters[i] = resolveClass(signature.getParameterType(i, null)); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
223 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
224 returnType = resolveClass(signature.getReturnType(null)); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
225 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
226 return new JavaSignature(returnType, parameters); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
227 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
228 |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
229 private Executable[] originalMethods(ClassSubstitution classSubstitution, boolean optional, String name, JavaSignature signature) { |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
230 Class<?> originalClass = classSubstitution.value(); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
231 if (originalClass == ClassSubstitution.class) { |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
232 ArrayList<Executable> result = new ArrayList<>(); |
19017
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
233 for (String className : classSubstitution.className()) { |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
234 originalClass = resolveClass(className, classSubstitution.optional()); |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
235 if (originalClass != null) { |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
236 result.add(lookupOriginalMethod(originalClass, name, signature, optional)); |
19017
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
237 } |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
238 } |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
239 if (result.size() == 0) { |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
240 // optional class was not found |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
241 return null; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
242 } |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
243 return result.toArray(new Executable[result.size()]); |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
244 } |
19057
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
245 Executable original = lookupOriginalMethod(originalClass, name, signature, optional); |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
246 if (original != null) { |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
247 return new Executable[]{original}; |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
248 } |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
249 return null; |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
250 } |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
251 |
eb6af69e0195
Properly handle multiple class names for ClassSubstitution
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19017
diff
changeset
|
252 private Executable lookupOriginalMethod(Class<?> originalClass, String name, JavaSignature signature, boolean optional) throws GraalInternalError { |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
253 try { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
254 if (name.equals("<init>")) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
255 assert signature.returnType.equals(void.class) : signature; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
256 Constructor<?> original = originalClass.getDeclaredConstructor(signature.parameters); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
257 return original; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
258 } else { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
259 Method original = originalClass.getDeclaredMethod(name, signature.parameters); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
260 if (!original.getReturnType().equals(signature.returnType)) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
261 throw new NoSuchMethodException(originalClass.getName() + "." + name + signature); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
262 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
263 return original; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
264 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
265 } catch (NoSuchMethodException | SecurityException e) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
266 if (optional) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
267 return null; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
268 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
269 throw new GraalInternalError(e); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
270 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
271 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
272 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
273 |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
274 /** |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
275 * Per-class replacements. The entries in these maps are all fully initialized during |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
276 * single-threaded compiler startup and so do not need to be concurrent. |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
277 */ |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
278 private final Map<String, AtomicReference<ClassReplacements>> classReplacements; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
279 private final Map<String, Class<?>[]> internalNameToSubstitutionClasses; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
280 |
18880
5be321eab6ac
made ReplacementsImpl.snippetTemplateCache stable across VM executions to support replay compilation
Doug Simon <doug.simon@oracle.com>
parents:
18845
diff
changeset
|
281 // This map is key'ed by a class name instead of a Class object so that |
5be321eab6ac
made ReplacementsImpl.snippetTemplateCache stable across VM executions to support replay compilation
Doug Simon <doug.simon@oracle.com>
parents:
18845
diff
changeset
|
282 // it is stable across VM executions (in support of replay compilation). |
5be321eab6ac
made ReplacementsImpl.snippetTemplateCache stable across VM executions to support replay compilation
Doug Simon <doug.simon@oracle.com>
parents:
18845
diff
changeset
|
283 private final Map<String, SnippetTemplateCache> snippetTemplateCache; |
7076 | 284 |
19254
835e950b38b9
removed vestige usages of Assumptions independent of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents:
19250
diff
changeset
|
285 public ReplacementsImpl(Providers providers, SnippetReflectionProvider snippetReflection, TargetDescription target) { |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
12408
diff
changeset
|
286 this.providers = providers.copyWith(this); |
18743
220d7f242e57
use deterministic iteration-order data structures
Doug Simon <doug.simon@oracle.com>
parents:
18639
diff
changeset
|
287 this.classReplacements = CollectionsFactory.newMap(); |
220d7f242e57
use deterministic iteration-order data structures
Doug Simon <doug.simon@oracle.com>
parents:
18639
diff
changeset
|
288 this.internalNameToSubstitutionClasses = CollectionsFactory.newMap(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15002
diff
changeset
|
289 this.snippetReflection = snippetReflection; |
13132
922dd1415c0a
Commit pass target as a parameter to ReplacementImpl, so that it does not require a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13128
diff
changeset
|
290 this.target = target; |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
291 this.graphs = new ConcurrentHashMap<>(); |
18743
220d7f242e57
use deterministic iteration-order data structures
Doug Simon <doug.simon@oracle.com>
parents:
18639
diff
changeset
|
292 this.snippetTemplateCache = CollectionsFactory.newMap(); |
19418
7d3140f2de2e
reuse a single NodeIntrinsificationPhase instance in ReplacementsImpl (since the former is stateless)
Doug Simon <doug.simon@oracle.com>
parents:
19410
diff
changeset
|
293 this.nodeIntrinsificationPhase = createNodeIntrinsificationPhase(); |
7076 | 294 } |
295 | |
12706
bb5fa27daa20
added ability to disable snippet graph preparation cache (-Dgraal.useSnippetGraphCache=false)
Doug Simon <doug.simon@oracle.com>
parents:
12432
diff
changeset
|
296 private static final boolean UseSnippetGraphCache = Boolean.parseBoolean(System.getProperty("graal.useSnippetGraphCache", "true")); |
12714
655c87d8d3c2
added SnippetPreparationTime metric
Doug Simon <doug.simon@oracle.com>
parents:
12706
diff
changeset
|
297 private static final DebugTimer SnippetPreparationTime = Debug.timer("SnippetPreparationTime"); |
12706
bb5fa27daa20
added ability to disable snippet graph preparation cache (-Dgraal.useSnippetGraphCache=false)
Doug Simon <doug.simon@oracle.com>
parents:
12432
diff
changeset
|
298 |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
299 /** |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
300 * Gets the method and macro replacements for a given class. This method will parse the |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
301 * replacements in the substitution classes associated with {@code internalName} the first time |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
302 * this method is called for {@code internalName}. |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
303 */ |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
304 protected ClassReplacements getClassReplacements(String internalName) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
305 Class<?>[] substitutionClasses = internalNameToSubstitutionClasses.get(internalName); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
306 if (substitutionClasses != null) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
307 AtomicReference<ClassReplacements> crRef = classReplacements.get(internalName); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
308 if (crRef.get() == null) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
309 crRef.compareAndSet(null, new ClassReplacements(substitutionClasses, crRef)); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
310 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
311 return crRef.get(); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
312 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
313 return null; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
314 } |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
315 |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
316 public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
317 return getSnippet(method, null, args); |
13604
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
318 } |
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
319 |
13146
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
320 @Override |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
321 public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args) { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8981
diff
changeset
|
322 assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName(); |
18823
5a21cac1968f
Add utilities ModifiersProvider#isConcrete, ResolvedJavaMethod#hasReceiver, ResolvedJavaMethod#hasBytecodes to Graal API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18822
diff
changeset
|
323 assert method.hasBytecodes() : "Snippet must not be abstract or native"; |
7076 | 324 |
12706
bb5fa27daa20
added ability to disable snippet graph preparation cache (-Dgraal.useSnippetGraphCache=false)
Doug Simon <doug.simon@oracle.com>
parents:
12432
diff
changeset
|
325 StructuredGraph graph = UseSnippetGraphCache ? graphs.get(method) : null; |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
326 if (graph == null) { |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19540
diff
changeset
|
327 try (DebugCloseable a = SnippetPreparationTime.start()) { |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
328 FrameStateProcessing frameStateProcessing = method.getAnnotation(Snippet.class).removeAllFrameStates() ? FrameStateProcessing.Removal |
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
329 : FrameStateProcessing.CollapseFrameForSingleSideEffect; |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
330 StructuredGraph newGraph = makeGraph(method, args, recursiveEntry, frameStateProcessing); |
14616
aa7bcf1fa423
expanded Debug API to avoid any allocation for timer and metric creation if debugging is disabled
Doug Simon <doug.simon@oracle.com>
parents:
14589
diff
changeset
|
331 Debug.metric("SnippetNodeCount[%#s]", method).add(newGraph.getNodeCount()); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
332 if (!UseSnippetGraphCache || args != null) { |
12714
655c87d8d3c2
added SnippetPreparationTime metric
Doug Simon <doug.simon@oracle.com>
parents:
12706
diff
changeset
|
333 return newGraph; |
655c87d8d3c2
added SnippetPreparationTime metric
Doug Simon <doug.simon@oracle.com>
parents:
12706
diff
changeset
|
334 } |
655c87d8d3c2
added SnippetPreparationTime metric
Doug Simon <doug.simon@oracle.com>
parents:
12706
diff
changeset
|
335 graphs.putIfAbsent(method, newGraph); |
655c87d8d3c2
added SnippetPreparationTime metric
Doug Simon <doug.simon@oracle.com>
parents:
12706
diff
changeset
|
336 graph = graphs.get(method); |
12706
bb5fa27daa20
added ability to disable snippet graph preparation cache (-Dgraal.useSnippetGraphCache=false)
Doug Simon <doug.simon@oracle.com>
parents:
12432
diff
changeset
|
337 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
338 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
339 return graph; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
340 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
341 |
13146
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
342 @Override |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
343 public void registerSnippet(ResolvedJavaMethod method) { |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
344 // No initialization needed as snippet graphs are created on demand in getSnippet |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
345 } |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
346 |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
347 @Override |
13222
de8f74d49690
rename Replacements.prepareSnippetCopyAfterInstantiation
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13197
diff
changeset
|
348 public void notifyAfterConstantsBound(StructuredGraph specializedSnippet) { |
13146
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
349 |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
350 // Do deferred intrinsification of node intrinsics |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
351 |
19418
7d3140f2de2e
reuse a single NodeIntrinsificationPhase instance in ReplacementsImpl (since the former is stateless)
Doug Simon <doug.simon@oracle.com>
parents:
19410
diff
changeset
|
352 nodeIntrinsificationPhase.apply(specializedSnippet); |
19709
2fd45bb25118
Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19686
diff
changeset
|
353 new CanonicalizerPhase().apply(specializedSnippet, new PhaseContext(providers)); |
13222
de8f74d49690
rename Replacements.prepareSnippetCopyAfterInstantiation
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13197
diff
changeset
|
354 NodeIntrinsificationVerificationPhase.verify(specializedSnippet); |
13146
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
355 } |
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
356 |
17140
f95ddcd3e08a
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17094
diff
changeset
|
357 protected NodeIntrinsificationPhase createNodeIntrinsificationPhase() { |
19881
6a684aeb1590
NodeIntrinsificationPhase is given only the providers it needs instead of a Providers object
Doug Simon <doug.simon@oracle.com>
parents:
19880
diff
changeset
|
358 return new NodeIntrinsificationPhase(providers.getMetaAccess(), providers.getConstantReflection(), snippetReflection, providers.getForeignCalls(), providers.getStampProvider()); |
17140
f95ddcd3e08a
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17094
diff
changeset
|
359 } |
f95ddcd3e08a
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17094
diff
changeset
|
360 |
13146
ffbfc3e78746
extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents:
13132
diff
changeset
|
361 @Override |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
362 public StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) { |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
363 ClassReplacements cr = getClassReplacements(original.getDeclaringClass().getName()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
364 ResolvedJavaMethod substitute = cr == null ? null : cr.methodSubstitutions.get(original); |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
365 if (substitute == null) { |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
366 return null; |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
367 } |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
368 StructuredGraph graph = graphs.get(substitute); |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
369 if (graph == null) { |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
370 graph = makeGraph(substitute, null, original, FrameStateProcessing.None); |
13980
68ae6fae9d2e
freeze graphs before inserting into table
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13977
diff
changeset
|
371 graph.freeze(); |
68ae6fae9d2e
freeze graphs before inserting into table
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13977
diff
changeset
|
372 graphs.putIfAbsent(substitute, graph); |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
373 graph = graphs.get(substitute); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
374 } |
13744
d96dbd96bb45
Always copy method substitutions. Add some assertion checking for it.
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13629
diff
changeset
|
375 assert graph.isFrozen(); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
376 return graph; |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
377 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
378 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
379 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
380 public Class<? extends FixedWithNextNode> getMacroSubstitution(ResolvedJavaMethod method) { |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
381 ClassReplacements cr = getClassReplacements(method.getDeclaringClass().getName()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
382 return cr == null ? null : cr.macroSubstitutions.get(method); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
383 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
384 |
18495
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
385 private SubstitutionGuard getGuard(Class<? extends SubstitutionGuard> guardClass) { |
13629
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
386 if (guardClass != SubstitutionGuard.class) { |
18495
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
387 Constructor<?>[] constructors = guardClass.getConstructors(); |
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
388 if (constructors.length != 1) { |
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
389 throw new GraalInternalError("Substitution guard " + guardClass.getSimpleName() + " must have a single public constructor"); |
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
390 } |
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
391 Constructor<?> constructor = constructors[0]; |
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
392 Class<?>[] paramTypes = constructor.getParameterTypes(); |
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
393 // Check for supported constructor signatures |
13629
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
394 try { |
18514
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
395 Object[] args = new Object[constructor.getParameterCount()]; |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
396 for (int i = 0; i < args.length; i++) { |
18639
56f806632622
fixed bugs in support for arbitrary types in SubstitutionGuard constructors
Doug Simon <doug.simon@oracle.com>
parents:
18514
diff
changeset
|
397 Object arg = snippetReflection.getSubstitutionGuardParameter(paramTypes[i]); |
18514
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
398 if (arg != null) { |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
399 args[i] = arg; |
18639
56f806632622
fixed bugs in support for arbitrary types in SubstitutionGuard constructors
Doug Simon <doug.simon@oracle.com>
parents:
18514
diff
changeset
|
400 } else if (paramTypes[i].isInstance(target.arch)) { |
18514
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
401 args[i] = target.arch; |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
402 } else { |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
403 throw new GraalInternalError("Unsupported type %s in substitution guard constructor: %s", paramTypes[i].getName(), constructor); |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
404 } |
18495
fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
Doug Simon <doug.simon@oracle.com>
parents:
18465
diff
changeset
|
405 } |
18514
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
406 |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18495
diff
changeset
|
407 return (SubstitutionGuard) constructor.newInstance(args); |
13629
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
408 } catch (Exception e) { |
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
409 throw new GraalInternalError(e); |
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
410 } |
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
411 } |
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
412 return null; |
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
413 } |
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
414 |
19017
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
415 private static boolean checkSubstitutionInternalName(Class<?> substitutions, String internalName) { |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
416 ClassSubstitution cs = substitutions.getAnnotation(ClassSubstitution.class); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
417 assert cs != null : substitutions + " must be annotated by " + ClassSubstitution.class.getSimpleName(); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
418 if (cs.value() == ClassSubstitution.class) { |
19017
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
419 for (String className : cs.className()) { |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
420 if (toInternalName(className).equals(internalName)) { |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
421 return true; |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
422 } |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
423 } |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
424 assert false : internalName + " not found in " + Arrays.toString(cs.className()); |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
425 } else { |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
426 String originalInternalName = toInternalName(cs.value().getName()); |
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
427 assert originalInternalName.equals(internalName) : originalInternalName + " != " + internalName; |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
428 } |
19017
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
429 return true; |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
430 } |
13629
5348da19751d
Add locally specified guards to substitutions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
13618
diff
changeset
|
431 |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
432 public void registerSubstitutions(Type original, Class<?> substitutionClass) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
433 String internalName = toInternalName(original.getTypeName()); |
19017
b7797e485eb8
Make BlackholeSubstitutions work with older versions of JMH
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18880
diff
changeset
|
434 assert checkSubstitutionInternalName(substitutionClass, internalName); |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
435 Class<?>[] classes = internalNameToSubstitutionClasses.get(internalName); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
436 if (classes == null) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
437 classes = new Class<?>[]{substitutionClass}; |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
438 } else { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
439 assert !Arrays.asList(classes).contains(substitutionClass); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
440 classes = Arrays.copyOf(classes, classes.length + 1); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
441 classes[classes.length - 1] = substitutionClass; |
7076 | 442 } |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
443 internalNameToSubstitutionClasses.put(internalName, classes); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
444 AtomicReference<ClassReplacements> existing = classReplacements.put(internalName, new AtomicReference<>()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
445 assert existing == null || existing.get() == null; |
7076 | 446 } |
447 | |
7373
6b2c55fc9ba8
reworked mechanism for omitting intrinsics if the underlying hardware support is not available and used it to make intrinsification of Integer.bitCount() dependent on whether the POPCNT instruction is available
Doug Simon <doug.simon@oracle.com>
parents:
7360
diff
changeset
|
448 /** |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
449 * Registers a method substitution. |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14908
diff
changeset
|
450 * |
8431
be5ce3e9d473
rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents:
8430
diff
changeset
|
451 * @param originalMember a method or constructor being substituted |
7373
6b2c55fc9ba8
reworked mechanism for omitting intrinsics if the underlying hardware support is not available and used it to make intrinsification of Integer.bitCount() dependent on whether the POPCNT instruction is available
Doug Simon <doug.simon@oracle.com>
parents:
7360
diff
changeset
|
452 * @param substituteMethod the substitute method |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
453 * @return the original method |
7373
6b2c55fc9ba8
reworked mechanism for omitting intrinsics if the underlying hardware support is not available and used it to make intrinsification of Integer.bitCount() dependent on whether the POPCNT instruction is available
Doug Simon <doug.simon@oracle.com>
parents:
7360
diff
changeset
|
454 */ |
18373
91283d4a1218
Use the base class Executable (introduced in Java 8) to unify the handling of Method and Constructor in MetaAccessProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18371
diff
changeset
|
455 protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Executable originalMember, Method substituteMethod) { |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
456 MetaAccessProvider metaAccess = providers.getMetaAccess(); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11870
diff
changeset
|
457 ResolvedJavaMethod substitute = metaAccess.lookupJavaMethod(substituteMethod); |
18373
91283d4a1218
Use the base class Executable (introduced in Java 8) to unify the handling of Method and Constructor in MetaAccessProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18371
diff
changeset
|
458 ResolvedJavaMethod original = metaAccess.lookupJavaMethod(originalMember); |
14636
733e50d96f9b
fixed usages of Debug.log()
Doug Simon <doug.simon@oracle.com>
parents:
14616
diff
changeset
|
459 if (Debug.isLogEnabled()) { |
16480
10c12d09a8d2
moved format(String format, JavaMethod method) from MetaUtil to be a default method in JavaMethod
Doug Simon <doug.simon@oracle.com>
parents:
16479
diff
changeset
|
460 Debug.log("substitution: %s --> %s", original.format("%H.%n(%p) %r"), substitute.format("%H.%n(%p) %r")); |
14636
733e50d96f9b
fixed usages of Debug.log()
Doug Simon <doug.simon@oracle.com>
parents:
14616
diff
changeset
|
461 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
462 |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
463 cr.methodSubstitutions.put(original, substitute); |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
464 return original; |
7373
6b2c55fc9ba8
reworked mechanism for omitting intrinsics if the underlying hardware support is not available and used it to make intrinsification of Integer.bitCount() dependent on whether the POPCNT instruction is available
Doug Simon <doug.simon@oracle.com>
parents:
7360
diff
changeset
|
465 } |
6b2c55fc9ba8
reworked mechanism for omitting intrinsics if the underlying hardware support is not available and used it to make intrinsification of Integer.bitCount() dependent on whether the POPCNT instruction is available
Doug Simon <doug.simon@oracle.com>
parents:
7360
diff
changeset
|
466 |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
467 /** |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
468 * Registers a macro substitution. |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14908
diff
changeset
|
469 * |
8360
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
470 * @param originalMethod a method or constructor being substituted |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
471 * @param macro the substitute macro node class |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
472 * @return the original method |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
473 */ |
18373
91283d4a1218
Use the base class Executable (introduced in Java 8) to unify the handling of Method and Constructor in MetaAccessProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18371
diff
changeset
|
474 protected ResolvedJavaMethod registerMacroSubstitution(ClassReplacements cr, Executable originalMethod, Class<? extends FixedWithNextNode> macro) { |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
475 MetaAccessProvider metaAccess = providers.getMetaAccess(); |
18373
91283d4a1218
Use the base class Executable (introduced in Java 8) to unify the handling of Method and Constructor in MetaAccessProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18371
diff
changeset
|
476 ResolvedJavaMethod originalJavaMethod = metaAccess.lookupJavaMethod(originalMethod); |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
477 cr.macroSubstitutions.put(originalJavaMethod, macro); |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
478 return originalJavaMethod; |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
479 } |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
480 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
481 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
482 * Creates a preprocessed graph for a snippet or method substitution. |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14908
diff
changeset
|
483 * |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
484 * @param method the snippet or method substitution for which a graph will be created |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
485 * @param args |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
486 * @param original the original method if {@code method} is a {@linkplain MethodSubstitution |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
487 * substitution} otherwise null |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
488 * @param frameStateProcessing controls how {@link FrameState FrameStates} should be handled. |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
489 */ |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
490 public StructuredGraph makeGraph(ResolvedJavaMethod method, Object[] args, ResolvedJavaMethod original, FrameStateProcessing frameStateProcessing) { |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
491 return createGraphMaker(method, original, frameStateProcessing).makeGraph(args); |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
492 } |
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
493 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
494 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
495 * Can be overridden to return an object that specializes various parts of graph preprocessing. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
496 */ |
16383
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
497 protected GraphMaker createGraphMaker(ResolvedJavaMethod substitute, ResolvedJavaMethod original, FrameStateProcessing frameStateProcessing) { |
18371
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
498 return new GraphMaker(this, substitute, original, frameStateProcessing); |
7076 | 499 } |
500 | |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
501 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
502 * Cache to speed up preprocessing of replacement graphs. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
503 */ |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
504 final ConcurrentMap<ResolvedJavaMethod, StructuredGraph> graphCache = new ConcurrentHashMap<>(); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
505 |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
506 public enum FrameStateProcessing { |
14908
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14756
diff
changeset
|
507 None, |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
508 /** |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
509 * @see CollapseFrameForSingleSideEffectPhase |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
510 */ |
14908
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14756
diff
changeset
|
511 CollapseFrameForSingleSideEffect, |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
512 /** |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
513 * Removes frame states from all nodes in the graph. |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
514 */ |
14908
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14756
diff
changeset
|
515 Removal |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
516 } |
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
517 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
518 /** |
16772
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
519 * Calls in snippets to methods matching one of these filters are elided. Only void methods are |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
520 * considered for elision. |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
521 */ |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
522 private static final MethodFilter[] MethodsElidedInSnippets = getMethodsElidedInSnippets(); |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
523 |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
524 private static MethodFilter[] getMethodsElidedInSnippets() { |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
525 String commaSeparatedPatterns = System.getProperty("graal.MethodsElidedInSnippets"); |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
526 if (commaSeparatedPatterns != null) { |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
527 return MethodFilter.parse(commaSeparatedPatterns); |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
528 } |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
529 return null; |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
530 } |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
531 |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
532 /** |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
533 * Creates and preprocesses a graph for a replacement. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
534 */ |
18371
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
535 public static class GraphMaker { |
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
536 /** The replacements object that the graphs are created for. */ |
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
537 protected final ReplacementsImpl replacements; |
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
538 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
539 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
540 * The method for which a graph is being created. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
541 */ |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
542 protected final ResolvedJavaMethod method; |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
543 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
544 /** |
16383
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
545 * The original method which {@link #method} is substituting. Calls to {@link #method} or |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
546 * {@link #substitutedMethod} will be replaced with a forced inline of |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
547 * {@link #substitutedMethod}. |
13604
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
548 */ |
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
549 protected final ResolvedJavaMethod substitutedMethod; |
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
550 |
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
551 /** |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
552 * Controls how FrameStates are processed. |
13604
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
553 */ |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
554 private FrameStateProcessing frameStateProcessing; |
13604
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
555 |
18371
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
556 protected GraphMaker(ReplacementsImpl replacements, ResolvedJavaMethod substitute, ResolvedJavaMethod substitutedMethod, FrameStateProcessing frameStateProcessing) { |
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
557 this.replacements = replacements; |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
558 this.method = substitute; |
13604
bd21ee1a874c
fix recursion problem around macro nodes (e.g. array copy)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13603
diff
changeset
|
559 this.substitutedMethod = substitutedMethod; |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
560 this.frameStateProcessing = frameStateProcessing; |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
561 } |
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
562 |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
563 public StructuredGraph makeGraph(Object[] args) { |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
564 try (Scope s = Debug.scope("BuildSnippetGraph", method)) { |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
565 StructuredGraph graph = parseGraph(method, args); |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
566 |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
567 if (args == null) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
568 // Cannot have a finalized version of a graph in the cache |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
569 graph = graph.copy(); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
570 } |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
571 |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
572 finalizeGraph(graph); |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
573 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
574 Debug.dump(graph, "%s: Final", method.getName()); |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
575 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
576 return graph; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
577 } catch (Throwable e) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
578 throw Debug.handle(e); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
579 } |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
580 } |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
581 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
582 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
583 * Does final processing of a snippet graph. |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
584 */ |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
585 protected void finalizeGraph(StructuredGraph graph) { |
19418
7d3140f2de2e
reuse a single NodeIntrinsificationPhase instance in ReplacementsImpl (since the former is stateless)
Doug Simon <doug.simon@oracle.com>
parents:
19410
diff
changeset
|
586 replacements.nodeIntrinsificationPhase.apply(graph); |
9302
c78ef1df7b06
made verification of node intrinsification always be run, independent of whether assertions are enabled
Doug Simon <doug.simon@oracle.com>
parents:
9234
diff
changeset
|
587 if (!SnippetTemplate.hasConstantParameter(method)) { |
c78ef1df7b06
made verification of node intrinsification always be run, independent of whether assertions are enabled
Doug Simon <doug.simon@oracle.com>
parents:
9234
diff
changeset
|
588 NodeIntrinsificationVerificationPhase.verify(graph); |
c78ef1df7b06
made verification of node intrinsification always be run, independent of whether assertions are enabled
Doug Simon <doug.simon@oracle.com>
parents:
9234
diff
changeset
|
589 } |
16126
dbd32c5942e8
complain when deleting side effecting nodes from snippets
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15942
diff
changeset
|
590 int sideEffectCount = 0; |
16383
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
591 assert (sideEffectCount = graph.getNodes().filter(e -> hasSideEffect(e)).count()) >= 0; |
19540
9a749d774c73
Refactor ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19420
diff
changeset
|
592 new ConvertDeoptimizeToGuardPhase().apply(graph, null); |
16383
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
593 assert sideEffectCount == graph.getNodes().filter(e -> hasSideEffect(e)).count() : "deleted side effecting node"; |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
594 |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
595 switch (frameStateProcessing) { |
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
596 case Removal: |
11870
a80d09922fc1
new parameter on Snippet annotation to remove all frame states
Lukas Stadler <lukas.stadler@jku.at>
parents:
11717
diff
changeset
|
597 for (Node node : graph.getNodes()) { |
a80d09922fc1
new parameter on Snippet annotation to remove all frame states
Lukas Stadler <lukas.stadler@jku.at>
parents:
11717
diff
changeset
|
598 if (node instanceof StateSplit) { |
a80d09922fc1
new parameter on Snippet annotation to remove all frame states
Lukas Stadler <lukas.stadler@jku.at>
parents:
11717
diff
changeset
|
599 ((StateSplit) node).setStateAfter(null); |
a80d09922fc1
new parameter on Snippet annotation to remove all frame states
Lukas Stadler <lukas.stadler@jku.at>
parents:
11717
diff
changeset
|
600 } |
a80d09922fc1
new parameter on Snippet annotation to remove all frame states
Lukas Stadler <lukas.stadler@jku.at>
parents:
11717
diff
changeset
|
601 } |
13618
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
602 break; |
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
603 case CollapseFrameForSingleSideEffect: |
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
604 new CollapseFrameForSingleSideEffectPhase().apply(graph); |
b87fcab6624a
Replacements: use enum to describe framestate action
Bernhard Urban <bernhard.urban@jku.at>
parents:
13604
diff
changeset
|
605 break; |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
606 } |
17094
86888df288ec
fixed case of Optionality constants
Doug Simon <doug.simon@oracle.com>
parents:
17065
diff
changeset
|
607 new DeadCodeEliminationPhase(Required).apply(graph); |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
608 } |
7076 | 609 |
16383
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
610 /** |
16418 | 611 * Filter nodes which have side effects and shouldn't be deleted from snippets when |
612 * converting deoptimizations to guards. Currently this only allows exception constructors | |
613 * to be eliminated to cover the case when Java assertions are in the inlined code. | |
16383
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
614 * |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
615 * @param node |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
616 * @return true for nodes that have side effects and are unsafe to delete |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
617 */ |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
618 private boolean hasSideEffect(Node node) { |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
619 if (node instanceof StateSplit) { |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
620 if (((StateSplit) node).hasSideEffect()) { |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
621 if (node instanceof Invoke) { |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
622 CallTargetNode callTarget = ((Invoke) node).callTarget(); |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
623 if (callTarget instanceof MethodCallTargetNode) { |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
624 ResolvedJavaMethod targetMethod = ((MethodCallTargetNode) callTarget).targetMethod(); |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
625 if (targetMethod.isConstructor()) { |
18371
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
626 ResolvedJavaType throwableType = replacements.providers.getMetaAccess().lookupJavaType(Throwable.class); |
16383
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
627 return !throwableType.isAssignableFrom(targetMethod.getDeclaringClass()); |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
628 } |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
629 } |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
630 } |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
631 // Not an exception constructor call |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
632 return true; |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
633 } |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
634 } |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
635 // Not a StateSplit |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
636 return false; |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
637 } |
657ff04a7b73
look for original method and substitution when processing snippet graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16176
diff
changeset
|
638 |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
639 private StructuredGraph parseGraph(final ResolvedJavaMethod methodToParse, Object[] args) { |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
640 StructuredGraph graph = args == null ? replacements.graphCache.get(methodToParse) : null; |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
641 if (graph == null) { |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
642 StructuredGraph newGraph = null; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
643 try (Scope s = Debug.scope("ParseGraph", methodToParse)) { |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
644 newGraph = buildGraph(methodToParse, args); |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
645 } catch (Throwable e) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
646 throw Debug.handle(e); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
647 } |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
648 if (args == null) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
649 replacements.graphCache.putIfAbsent(methodToParse, newGraph); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
650 graph = replacements.graphCache.get(methodToParse); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
651 } else { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
652 graph = newGraph; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
653 } |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
654 assert graph != null; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
655 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
656 return graph; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
657 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
658 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
659 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
660 * Builds the initial graph for a snippet. |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
661 */ |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
662 protected StructuredGraph buildInitialGraph(final ResolvedJavaMethod methodToParse, Object[] args) { |
19250
8ab925a6f724
made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents:
19179
diff
changeset
|
663 // Replacements cannot have optimistic assumptions since they have |
8ab925a6f724
made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents:
19179
diff
changeset
|
664 // to be valid for the entire run of the VM. |
19306
a0a760b0fb5f
pulled method evolution dependencies out of Assumptions and directly into StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents:
19254
diff
changeset
|
665 final StructuredGraph graph = new StructuredGraph(methodToParse, AllowAssumptions.NO); |
19319
5664cadb3cee
don't record method dependencies for snippets, stubs or replacements
Doug Simon <doug.simon@oracle.com>
parents:
19306
diff
changeset
|
666 |
5664cadb3cee
don't record method dependencies for snippets, stubs or replacements
Doug Simon <doug.simon@oracle.com>
parents:
19306
diff
changeset
|
667 // They will also never be never be evolved or have breakpoints set in them |
19346
2b392a92e27b
made it explicit that a StructuredGraph only records method dependencies for inlined methods - the root method is not recorded as it is already available in the 'method' field
Doug Simon <doug.simon@oracle.com>
parents:
19319
diff
changeset
|
668 graph.disableInlinedMethodRecording(); |
19319
5664cadb3cee
don't record method dependencies for snippets, stubs or replacements
Doug Simon <doug.simon@oracle.com>
parents:
19306
diff
changeset
|
669 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
670 try (Scope s = Debug.scope("buildInitialGraph", graph)) { |
18371
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
671 MetaAccessProvider metaAccess = replacements.providers.getMetaAccess(); |
16772
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
672 |
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
673 if (MethodsElidedInSnippets != null && methodToParse.getSignature().getReturnKind() == Kind.Void && MethodFilter.matches(MethodsElidedInSnippets, methodToParse)) { |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18823
diff
changeset
|
674 graph.addAfterFixed(graph.start(), graph.add(new ReturnNode(null))); |
16772
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
675 } else { |
19882
0c29075aeafe
graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents:
19881
diff
changeset
|
676 Plugins plugins = new Plugins(replacements.graphBuilderPlugins); |
0c29075aeafe
graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents:
19881
diff
changeset
|
677 GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
678 if (args != null) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
679 plugins.setParameterPlugin(new ConstantBindingParameterPlugin(args, plugins.getParameterPlugin(), metaAccess, replacements.snippetReflection)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
680 } |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
681 createGraphBuilder(metaAccess, replacements.providers.getStampProvider(), replacements.providers.getConstantReflection(), config, OptimisticOptimizations.NONE).apply(graph); |
16772
5992012d3bca
support for eliding methods in snippets (e.g., to handle instrumentation agents)
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
682 } |
17140
f95ddcd3e08a
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17094
diff
changeset
|
683 afterParsing(graph); |
10707
a643c88d164f
Add scopes to capture the graphs in ReplacementsImpl
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9908
diff
changeset
|
684 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
685 if (OptCanonicalizer.getValue()) { |
19709
2fd45bb25118
Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19686
diff
changeset
|
686 new CanonicalizerPhase().apply(graph, new PhaseContext(replacements.providers)); |
10707
a643c88d164f
Add scopes to capture the graphs in ReplacementsImpl
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9908
diff
changeset
|
687 } |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
688 } catch (Throwable e) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
689 throw Debug.handle(e); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
690 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
691 return graph; |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
692 } |
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
693 |
19250
8ab925a6f724
made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents:
19179
diff
changeset
|
694 protected Instance createGraphBuilder(MetaAccessProvider metaAccess, StampProvider stampProvider, ConstantReflectionProvider constantReflection, GraphBuilderConfiguration graphBuilderConfig, |
8ab925a6f724
made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents:
19179
diff
changeset
|
695 OptimisticOptimizations optimisticOpts) { |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
696 ReplacementContext initialReplacementContext = null; |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
697 if (method.getAnnotation(MethodSubstitution.class) != null) { |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
698 // Late inlined intrinsic |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
699 initialReplacementContext = new IntrinsicContext(substitutedMethod, method, null, -1); |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
700 } else { |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
701 // Snippet |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
702 assert method.getAnnotation(Snippet.class) != null; |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
703 ResolvedJavaMethod original = substitutedMethod != null ? substitutedMethod : method; |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
704 initialReplacementContext = new ReplacementContext(original, method); |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
705 } |
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
706 return new GraphBuilderPhase.Instance(metaAccess, stampProvider, constantReflection, graphBuilderConfig, optimisticOpts, initialReplacementContext); |
14739
553527010fc4
Allow subclasses to provide their own graph builder
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14636
diff
changeset
|
707 } |
553527010fc4
Allow subclasses to provide their own graph builder
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14636
diff
changeset
|
708 |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
709 /** |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
710 * @param graph |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
711 */ |
18371
837e4c31f9d8
Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17140
diff
changeset
|
712 protected void afterParsing(StructuredGraph graph) { |
17140
f95ddcd3e08a
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17094
diff
changeset
|
713 } |
f95ddcd3e08a
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
17094
diff
changeset
|
714 |
11588 | 715 protected Object beforeInline(@SuppressWarnings("unused") MethodCallTargetNode callTarget, @SuppressWarnings("unused") StructuredGraph callee) { |
716 return null; | |
717 } | |
718 | |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
719 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
720 * Called after a graph is inlined. |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14908
diff
changeset
|
721 * |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
722 * @param caller the graph into which {@code callee} was inlined |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
723 * @param callee the graph that was inlined into {@code caller} |
11588 | 724 * @param beforeInlineData value returned by {@link #beforeInline}. |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
725 */ |
11588 | 726 protected void afterInline(StructuredGraph caller, StructuredGraph callee, Object beforeInlineData) { |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9601
diff
changeset
|
727 if (OptCanonicalizer.getValue()) { |
19709
2fd45bb25118
Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19686
diff
changeset
|
728 new CanonicalizerPhase().apply(caller, new PhaseContext(replacements.providers)); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
729 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
730 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
731 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
732 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
733 * Called after all inlining for a given graph is complete. |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
734 */ |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
735 protected void afterInlining(StructuredGraph graph) { |
19418
7d3140f2de2e
reuse a single NodeIntrinsificationPhase instance in ReplacementsImpl (since the former is stateless)
Doug Simon <doug.simon@oracle.com>
parents:
19410
diff
changeset
|
736 replacements.nodeIntrinsificationPhase.apply(graph); |
17094
86888df288ec
fixed case of Optionality constants
Doug Simon <doug.simon@oracle.com>
parents:
17065
diff
changeset
|
737 new DeadCodeEliminationPhase(Optional).apply(graph); |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9601
diff
changeset
|
738 if (OptCanonicalizer.getValue()) { |
19709
2fd45bb25118
Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19686
diff
changeset
|
739 new CanonicalizerPhase().apply(graph, new PhaseContext(replacements.providers)); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
740 } |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
741 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
742 |
19994
aaf5039e56d7
made partial intrinsification work (i.e., intrinsics that call the original method to handle slow/uncommon paths)
Doug Simon <doug.simon@oracle.com>
parents:
19883
diff
changeset
|
743 private StructuredGraph buildGraph(final ResolvedJavaMethod methodToParse, Object[] args) { |
18823
5a21cac1968f
Add utilities ModifiersProvider#isConcrete, ResolvedJavaMethod#hasReceiver, ResolvedJavaMethod#hasBytecodes to Graal API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18822
diff
changeset
|
744 assert methodToParse.hasBytecodes() : methodToParse; |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
745 final StructuredGraph graph = buildInitialGraph(methodToParse, args); |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
746 try (Scope s = Debug.scope("buildGraph", graph)) { |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
747 |
19403
61d3cb8e1280
Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19346
diff
changeset
|
748 for (LoopEndNode end : graph.getNodes(LoopEndNode.TYPE)) { |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
749 end.disableSafepoint(); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
750 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
751 |
17094
86888df288ec
fixed case of Optionality constants
Doug Simon <doug.simon@oracle.com>
parents:
17065
diff
changeset
|
752 new DeadCodeEliminationPhase(Required).apply(graph); |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
753 } catch (Throwable e) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
754 throw Debug.handle(e); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
13177
diff
changeset
|
755 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
756 return graph; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
757 } |
7076 | 758 } |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
759 |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
760 private static String originalName(Method substituteMethod, String methodSubstitution) { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
761 if (methodSubstitution.isEmpty()) { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
762 return substituteMethod.getName(); |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
763 } else { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
764 return methodSubstitution; |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
765 } |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
766 } |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
767 |
8373
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
768 /** |
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
769 * Resolves a name to a class. |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14908
diff
changeset
|
770 * |
8373
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
771 * @param className the name of the class to resolve |
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
772 * @param optional if true, resolution failure returns null |
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
773 * @return the resolved class or null if resolution fails and {@code optional} is true |
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
774 */ |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
19783
diff
changeset
|
775 public static Class<?> resolveClass(String className, boolean optional) { |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
776 try { |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
777 // Need to use launcher class path to handle classes |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
778 // that are not on the boot class path |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
779 ClassLoader cl = Launcher.getLauncher().getClassLoader(); |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
780 return Class.forName(className, false, cl); |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
781 } catch (ClassNotFoundException e) { |
8373
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
782 if (optional) { |
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
783 return null; |
86a9e3ea8fe9
support substitutions for classes that made not be part of the runtime (GRAAL-123)
Doug Simon <doug.simon@oracle.com>
parents:
8360
diff
changeset
|
784 } |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
785 throw new GraalInternalError("Could not resolve type " + className); |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
786 } |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
787 } |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
788 |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
789 private static Class<?> resolveClass(JavaType type) { |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
790 JavaType base = type; |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
791 int dimensions = 0; |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
792 while (base.getComponentType() != null) { |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
793 base = base.getComponentType(); |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
794 dimensions++; |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
795 } |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
796 |
16479
558cf39c646b
moved toJavaName(JavaType type) from MetaUtil to be a default method in JavaType
Doug Simon <doug.simon@oracle.com>
parents:
16418
diff
changeset
|
797 Class<?> baseClass = base.getKind() != Kind.Object ? base.getKind().toJavaClass() : resolveClass(base.toJavaName(), false); |
7360
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
798 return dimensions == 0 ? baseClass : Array.newInstance(baseClass, new int[dimensions]).getClass(); |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
799 } |
12bd634440d0
support substitution of methods that are not in the bootstrap class path and/or whose signature contains non-accessible types
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
800 |
13177
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
801 static class JavaSignature { |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
802 final Class<?> returnType; |
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
803 final Class<?>[] parameters; |
13177
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
804 |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
805 public JavaSignature(Class<?> returnType, Class<?>[] parameters) { |
13177
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
806 this.parameters = parameters; |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
807 this.returnType = returnType; |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
808 } |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
809 |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
810 @Override |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
811 public String toString() { |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
812 StringBuilder sb = new StringBuilder("("); |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
813 for (int i = 0; i < parameters.length; i++) { |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
814 if (i != 0) { |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
815 sb.append(", "); |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
816 } |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
817 sb.append(parameters[i].getName()); |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
818 } |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
819 return sb.append(") ").append(returnType.getName()).toString(); |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
820 } |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
821 } |
74cfcd0fbedf
made method substitution take return types into account (GRAAL-612)
Doug Simon <doug.simon@oracle.com>
parents:
13146
diff
changeset
|
822 |
8912
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
823 @Override |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
824 public Collection<ResolvedJavaMethod> getAllReplacements() { |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
825 HashSet<ResolvedJavaMethod> result = new HashSet<>(); |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
826 for (String internalName : classReplacements.keySet()) { |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
827 ClassReplacements cr = getClassReplacements(internalName); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
828 result.addAll(cr.methodSubstitutions.keySet()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
829 result.addAll(cr.macroSubstitutions.keySet()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
830 } |
8912
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
831 return result; |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
832 } |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
833 |
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
834 @Override |
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
835 public boolean isForcedSubstitution(ResolvedJavaMethod method) { |
15942
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
836 ClassReplacements cr = getClassReplacements(method.getDeclaringClass().getName()); |
5c73b162eec2
reduced execution time of ReplacementsImple.registerSubstitutions() by deferring parsing of substitution classes until the first request for a substitute method is received
Doug Simon <doug.simon@oracle.com>
parents:
15470
diff
changeset
|
837 return cr != null && cr.forcedSubstitutions.contains(method); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
838 } |
9187
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
839 |
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
840 @Override |
19410
e4d40c71954b
added InlineInvokePlugin for Graal
Doug Simon <doug.simon@oracle.com>
parents:
19346
diff
changeset
|
841 public ResolvedJavaMethod getMethodSubstitutionMethod(ResolvedJavaMethod original) { |
e4d40c71954b
added InlineInvokePlugin for Graal
Doug Simon <doug.simon@oracle.com>
parents:
19346
diff
changeset
|
842 ClassReplacements cr = getClassReplacements(original.getDeclaringClass().getName()); |
e4d40c71954b
added InlineInvokePlugin for Graal
Doug Simon <doug.simon@oracle.com>
parents:
19346
diff
changeset
|
843 return cr == null ? null : cr.methodSubstitutions.get(original); |
e4d40c71954b
added InlineInvokePlugin for Graal
Doug Simon <doug.simon@oracle.com>
parents:
19346
diff
changeset
|
844 } |
e4d40c71954b
added InlineInvokePlugin for Graal
Doug Simon <doug.simon@oracle.com>
parents:
19346
diff
changeset
|
845 |
e4d40c71954b
added InlineInvokePlugin for Graal
Doug Simon <doug.simon@oracle.com>
parents:
19346
diff
changeset
|
846 @Override |
9187
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
847 public void registerSnippetTemplateCache(SnippetTemplateCache templates) { |
18880
5be321eab6ac
made ReplacementsImpl.snippetTemplateCache stable across VM executions to support replay compilation
Doug Simon <doug.simon@oracle.com>
parents:
18845
diff
changeset
|
848 assert snippetTemplateCache.get(templates.getClass().getName()) == null; |
5be321eab6ac
made ReplacementsImpl.snippetTemplateCache stable across VM executions to support replay compilation
Doug Simon <doug.simon@oracle.com>
parents:
18845
diff
changeset
|
849 snippetTemplateCache.put(templates.getClass().getName(), templates); |
9187
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
850 } |
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
851 |
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
852 @Override |
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
853 public <T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass) { |
18880
5be321eab6ac
made ReplacementsImpl.snippetTemplateCache stable across VM executions to support replay compilation
Doug Simon <doug.simon@oracle.com>
parents:
18845
diff
changeset
|
854 SnippetTemplateCache ret = snippetTemplateCache.get(templatesClass.getName()); |
9187
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
855 return templatesClass.cast(ret); |
cd2600a2336e
Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents:
9147
diff
changeset
|
856 } |
7076 | 857 } |