Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java @ 9092:4720f96a15b7
fixed minor regression
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 12 Apr 2013 20:32:14 +0200 |
parents | 6d376d09880b |
children | 07f05f2a8149 |
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.*; |
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
|
26 |
7076 | 27 import java.lang.reflect.*; |
28 import java.util.*; | |
29 import java.util.concurrent.*; | |
30 | |
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 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
|
32 |
7076 | 33 import com.oracle.graal.api.code.*; |
34 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
|
35 import com.oracle.graal.api.replacements.*; |
7076 | 36 import com.oracle.graal.debug.*; |
37 import com.oracle.graal.graph.*; | |
38 import com.oracle.graal.java.*; | |
39 import com.oracle.graal.nodes.*; | |
40 import com.oracle.graal.nodes.java.*; | |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7295
diff
changeset
|
41 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind; |
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
|
42 import com.oracle.graal.nodes.spi.*; |
7076 | 43 import com.oracle.graal.phases.*; |
44 import com.oracle.graal.phases.common.*; | |
8419
11bada5f81a6
refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents:
8416
diff
changeset
|
45 import com.oracle.graal.replacements.Snippet.DefaultSnippetInliningPolicy; |
11bada5f81a6
refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents:
8416
diff
changeset
|
46 import com.oracle.graal.replacements.Snippet.SnippetInliningPolicy; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7295
diff
changeset
|
47 import com.oracle.graal.word.phases.*; |
7076 | 48 |
8628
77de2f3df379
renames: [HotSpot]ReplacementsInstaller -> [HotSpot]ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8627
diff
changeset
|
49 public class ReplacementsImpl implements Replacements { |
7076 | 50 |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
51 protected final MetaAccessProvider runtime; |
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
52 protected final TargetDescription target; |
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
53 protected final Assumptions assumptions; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
54 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
55 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
56 * The preprocessed replacement graphs. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
57 */ |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
58 private final ConcurrentMap<ResolvedJavaMethod, StructuredGraph> graphs; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
59 |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
60 // These data structures are all fully initialized during single-threaded |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
61 // compiler startup and so do not need to be concurrent. |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
62 private final Map<ResolvedJavaMethod, ResolvedJavaMethod> registeredMethodSubstitutions; |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
63 private final Map<ResolvedJavaMethod, Class<? extends FixedWithNextNode>> registerMacroSubstitutions; |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
64 private final Set<ResolvedJavaMethod> forcedSubstitutions; |
7076 | 65 |
8628
77de2f3df379
renames: [HotSpot]ReplacementsInstaller -> [HotSpot]ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8627
diff
changeset
|
66 public ReplacementsImpl(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target) { |
7076 | 67 this.runtime = runtime; |
68 this.target = target; | |
69 this.assumptions = assumptions; | |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
70 this.graphs = new ConcurrentHashMap<>(); |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
71 this.registeredMethodSubstitutions = new HashMap<>(); |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
72 this.registerMacroSubstitutions = new HashMap<>(); |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
73 this.forcedSubstitutions = new HashSet<>(); |
7076 | 74 } |
75 | |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8981
diff
changeset
|
76 public StructuredGraph getSnippet(ResolvedJavaMethod method) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8981
diff
changeset
|
77 assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8981
diff
changeset
|
78 assert !Modifier.isAbstract(method.getModifiers()) && !Modifier.isNative(method.getModifiers()) : "Snippet must not be abstract or native"; |
7076 | 79 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
80 StructuredGraph graph = graphs.get(method); |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
81 if (graph == null) { |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
82 graphs.putIfAbsent(method, makeGraph(method, null, inliningPolicy(method))); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
83 graph = graphs.get(method); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
84 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
85 return graph; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
86 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
87 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
88 public StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) { |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
89 ResolvedJavaMethod substitute = registeredMethodSubstitutions.get(original); |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
90 if (substitute == null) { |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
91 return null; |
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
92 } |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
93 StructuredGraph graph = graphs.get(substitute); |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
94 if (graph == null) { |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
95 graphs.putIfAbsent(substitute, makeGraph(substitute, original, inliningPolicy(substitute))); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
96 graph = graphs.get(substitute); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
97 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
98 return graph; |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
99 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
100 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
101 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
102 public Class<? extends FixedWithNextNode> getMacroSubstitution(ResolvedJavaMethod method) { |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
103 return registerMacroSubstitutions.get(method); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
104 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
105 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
106 public Assumptions getAssumptions() { |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
107 return assumptions; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
108 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
109 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
110 public void registerSubstitutions(Class<?> substitutions) { |
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
|
111 ClassSubstitution classSubstitution = substitutions.getAnnotation(ClassSubstitution.class); |
7545
b30b33d9da80
sanity checks for SnippetInstaller.installSubstitutions()
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
112 assert classSubstitution != null; |
8413
d9347ee39fbe
rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents:
8410
diff
changeset
|
113 assert !Snippets.class.isAssignableFrom(substitutions); |
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
|
114 for (Method substituteMethod : substitutions.getDeclaredMethods()) { |
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
|
115 MethodSubstitution methodSubstitution = substituteMethod.getAnnotation(MethodSubstitution.class); |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
116 MacroSubstitution macroSubstitution = substituteMethod.getAnnotation(MacroSubstitution.class); |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
117 if (methodSubstitution == null && macroSubstitution == null) { |
7076 | 118 continue; |
119 } | |
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
|
120 |
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
|
121 int modifiers = substituteMethod.getModifiers(); |
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
|
122 if (!Modifier.isStatic(modifiers)) { |
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
|
123 throw new RuntimeException("Substitution methods must be static: " + substituteMethod); |
7076 | 124 } |
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
|
125 |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
126 if (methodSubstitution != null) { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
127 if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
128 throw new RuntimeException("Substitution method must not be abstract or native: " + substituteMethod); |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
129 } |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
130 String originalName = originalName(substituteMethod, methodSubstitution.value()); |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
131 Class[] originalParameters = originalParameters(substituteMethod, methodSubstitution.signature(), methodSubstitution.isStatic()); |
8902
59e751e68bea
made method (and macro) substitution optional to support different JDK versions
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
132 Member originalMethod = originalMethod(classSubstitution, methodSubstitution.optional(), originalName, originalParameters); |
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
|
133 if (originalMethod != null) { |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
134 ResolvedJavaMethod original = registerMethodSubstitution(originalMethod, substituteMethod); |
8981
09cdf7224794
PEA: cleanup and documentation for recent changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8931
diff
changeset
|
135 if (original != null && methodSubstitution.forced()) { |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
136 forcedSubstitutions.add(original); |
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
137 } |
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
|
138 } |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
139 } |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
140 if (macroSubstitution != null) { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
141 String originalName = originalName(substituteMethod, macroSubstitution.value()); |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
142 Class[] originalParameters = originalParameters(substituteMethod, macroSubstitution.signature(), macroSubstitution.isStatic()); |
8902
59e751e68bea
made method (and macro) substitution optional to support different JDK versions
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
143 Member originalMethod = originalMethod(classSubstitution, macroSubstitution.optional(), originalName, originalParameters); |
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
|
144 if (originalMethod != null) { |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
145 ResolvedJavaMethod original = registerMacroSubstitution(originalMethod, macroSubstitution.macro()); |
8981
09cdf7224794
PEA: cleanup and documentation for recent changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8931
diff
changeset
|
146 if (original != null && macroSubstitution.forced()) { |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
147 forcedSubstitutions.add(original); |
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
148 } |
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
|
149 } |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
150 } |
7076 | 151 } |
152 } | |
153 | |
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
|
154 /** |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
155 * Registers a method substitution. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7510
diff
changeset
|
156 * |
8431
be5ce3e9d473
rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents:
8430
diff
changeset
|
157 * @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
|
158 * @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
|
159 * @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
|
160 */ |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
161 protected ResolvedJavaMethod registerMethodSubstitution(Member originalMember, Method substituteMethod) { |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
162 ResolvedJavaMethod substitute = runtime.lookupJavaMethod(substituteMethod); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
163 ResolvedJavaMethod original; |
8431
be5ce3e9d473
rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents:
8430
diff
changeset
|
164 if (originalMember instanceof Method) { |
be5ce3e9d473
rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents:
8430
diff
changeset
|
165 original = runtime.lookupJavaMethod((Method) originalMember); |
8360
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
166 } else { |
8431
be5ce3e9d473
rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents:
8430
diff
changeset
|
167 original = runtime.lookupJavaConstructor((Constructor) originalMember); |
8360
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
168 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
169 Debug.log("substitution: " + MetaUtil.format("%H.%n(%p)", original) + " --> " + MetaUtil.format("%H.%n(%p)", substitute)); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
170 |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
171 registeredMethodSubstitutions.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
|
172 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
|
173 } |
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
|
174 |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
175 /** |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
176 * Registers a macro substitution. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7510
diff
changeset
|
177 * |
8360
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
178 * @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
|
179 * @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
|
180 * @return the original method |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
181 */ |
8915
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
182 protected ResolvedJavaMethod registerMacroSubstitution(Member originalMethod, Class<? extends FixedWithNextNode> macro) { |
8360
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
183 ResolvedJavaMethod originalJavaMethod; |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
184 if (originalMethod instanceof Method) { |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
185 originalJavaMethod = runtime.lookupJavaMethod((Method) originalMethod); |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
186 } else { |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
187 originalJavaMethod = runtime.lookupJavaConstructor((Constructor) originalMethod); |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
188 } |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
189 registerMacroSubstitutions.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
|
190 return originalJavaMethod; |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
191 } |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
192 |
7096
585fc9f79ebc
Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7076
diff
changeset
|
193 private SnippetInliningPolicy inliningPolicy(ResolvedJavaMethod method) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7510
diff
changeset
|
194 Class<? extends SnippetInliningPolicy> policyClass = SnippetInliningPolicy.class; |
7076 | 195 Snippet snippet = method.getAnnotation(Snippet.class); |
196 if (snippet != null) { | |
197 policyClass = snippet.inlining(); | |
198 } | |
199 if (policyClass == SnippetInliningPolicy.class) { | |
8913
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
200 return new DefaultSnippetInliningPolicy(runtime); |
7076 | 201 } |
202 try { | |
203 return policyClass.getConstructor().newInstance(); | |
204 } catch (Exception e) { | |
205 throw new GraalInternalError(e); | |
206 } | |
207 } | |
208 | |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
209 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
210 * Creates a preprocessed graph for a snippet or method substitution. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
211 * |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
212 * @param method the snippet or method substitution for which a graph will be created |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
213 * @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
|
214 * substitution} otherwise null |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
215 * @param policy the inlining policy to use during preprocessing |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
216 */ |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
217 public StructuredGraph makeGraph(ResolvedJavaMethod method, ResolvedJavaMethod original, SnippetInliningPolicy policy) { |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
218 return createGraphMaker(method, original).makeGraph(policy); |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
219 } |
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
220 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
221 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
222 * 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
|
223 */ |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
224 protected GraphMaker createGraphMaker(ResolvedJavaMethod substitute, ResolvedJavaMethod original) { |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
225 return new GraphMaker(substitute, original); |
7076 | 226 } |
227 | |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
228 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
229 * 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
|
230 */ |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
231 final ConcurrentMap<ResolvedJavaMethod, StructuredGraph> graphCache = new ConcurrentHashMap<>(); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
232 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
233 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
234 * 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
|
235 */ |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
236 protected class GraphMaker { |
7076 | 237 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
238 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
239 * 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
|
240 */ |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
241 protected final ResolvedJavaMethod method; |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
242 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
243 /** |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
244 * The original method if {@link #method} is a {@linkplain MethodSubstitution substitution} |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
245 * otherwise null. |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
246 */ |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
247 protected final ResolvedJavaMethod original; |
7076 | 248 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
249 boolean substituteCallsOriginal; |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
250 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
251 protected GraphMaker(ResolvedJavaMethod substitute, ResolvedJavaMethod original) { |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
252 this.method = substitute; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
253 this.original = original; |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
254 } |
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
255 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
256 public StructuredGraph makeGraph(final SnippetInliningPolicy policy) { |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
257 return Debug.scope("BuildSnippetGraph", new Object[]{method}, new Callable<StructuredGraph>() { |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
258 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
259 @Override |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
260 public StructuredGraph call() throws Exception { |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
261 StructuredGraph graph = parseGraph(method, policy); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
262 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
263 // Cannot have a finalized version of a graph in the cache |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
264 graph = graph.copy(); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
265 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
266 finalizeGraph(graph); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
267 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
268 Debug.dump(graph, "%s: Final", method.getName()); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
269 |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
270 return graph; |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
271 } |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
272 }); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
273 } |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
274 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
275 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
276 * 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
|
277 */ |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
278 protected void finalizeGraph(StructuredGraph graph) { |
8913
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
279 new NodeIntrinsificationPhase(runtime).apply(graph); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
280 assert SnippetTemplate.hasConstantParameter(method) || NodeIntrinsificationVerificationPhase.verify(graph); |
8199
a68310b2b8b8
made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
281 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
282 if (original == null) { |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
283 new SnippetFrameStateCleanupPhase().apply(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
284 new DeadCodeEliminationPhase().apply(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
285 new InsertStateAfterPlaceholderPhase().apply(graph); |
7383
36474f315a8a
added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents:
7373
diff
changeset
|
286 } else { |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
287 new DeadCodeEliminationPhase().apply(graph); |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
288 } |
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
289 } |
7076 | 290 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
291 private StructuredGraph parseGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy) { |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
292 StructuredGraph graph = graphCache.get(methodToParse); |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
293 if (graph == null) { |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
294 graphCache.putIfAbsent(methodToParse, buildGraph(methodToParse, policy == null ? inliningPolicy(methodToParse) : policy)); |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
295 graph = graphCache.get(methodToParse); |
8630
f32fa4cdfbb1
fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8628
diff
changeset
|
296 assert graph != null; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
297 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
298 return graph; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
299 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
300 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
301 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
302 * 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
|
303 */ |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
304 protected StructuredGraph buildInitialGraph(final ResolvedJavaMethod methodToParse) { |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
305 final StructuredGraph graph = new StructuredGraph(methodToParse); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
306 GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
307 GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config, OptimisticOptimizations.NONE); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
308 graphBuilder.apply(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
309 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
310 Debug.dump(graph, "%s: %s", methodToParse.getName(), GraphBuilderPhase.class.getSimpleName()); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
311 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
312 new WordTypeVerificationPhase(runtime, target.wordKind).apply(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
313 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
314 return graph; |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
315 } |
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
316 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
317 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
318 * Called after a graph is inlined. |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
319 * |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
320 * @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
|
321 * @param callee the graph that was inlined into {@code caller} |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
322 */ |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
323 protected void afterInline(StructuredGraph caller, StructuredGraph callee) { |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
324 if (GraalOptions.OptCanonicalizer) { |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
325 new WordTypeRewriterPhase(runtime, target.wordKind).apply(caller); |
9049
6d376d09880b
Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9015
diff
changeset
|
326 new CanonicalizerPhase.Instance(runtime, assumptions).apply(caller); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
327 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
328 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
329 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
330 /** |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
331 * 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
|
332 */ |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
333 protected void afterInlining(StructuredGraph graph) { |
8913
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
334 new NodeIntrinsificationPhase(runtime).apply(graph); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
335 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
336 new WordTypeRewriterPhase(runtime, target.wordKind).apply(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
337 |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
338 new DeadCodeEliminationPhase().apply(graph); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
339 if (GraalOptions.OptCanonicalizer) { |
9049
6d376d09880b
Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9015
diff
changeset
|
340 new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
341 } |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7229
diff
changeset
|
342 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
343 |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
344 private StructuredGraph buildGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy) { |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
345 assert !Modifier.isAbstract(methodToParse.getModifiers()) && !Modifier.isNative(methodToParse.getModifiers()) : methodToParse; |
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
346 final StructuredGraph graph = buildInitialGraph(methodToParse); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
347 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
348 for (Invoke invoke : graph.getInvokes()) { |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
349 MethodCallTargetNode callTarget = invoke.methodCallTarget(); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
350 ResolvedJavaMethod callee = callTarget.targetMethod(); |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
351 if (callee == method) { |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
352 final StructuredGraph originalGraph = new StructuredGraph(original); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
353 new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault(), OptimisticOptimizations.NONE).apply(originalGraph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
354 InliningUtil.inline(invoke, originalGraph, true); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
355 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
356 Debug.dump(graph, "after inlining %s", callee); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
357 afterInline(graph, originalGraph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
358 substituteCallsOriginal = true; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
359 } else { |
8631
a5ad23f6f9ca
fixed more concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents:
8630
diff
changeset
|
360 if ((callTarget.invokeKind() == InvokeKind.Static || callTarget.invokeKind() == InvokeKind.Special) && policy.shouldInline(callee, methodToParse)) { |
8913
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
361 StructuredGraph targetGraph; |
8930 | 362 StructuredGraph intrinsicGraph = InliningUtil.getIntrinsicGraph(ReplacementsImpl.this, callee); |
8913
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
363 if (intrinsicGraph != null && policy.shouldUseReplacement(callee, methodToParse)) { |
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
364 targetGraph = intrinsicGraph; |
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
365 } else { |
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
366 targetGraph = parseGraph(callee, policy); |
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8912
diff
changeset
|
367 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
368 InliningUtil.inline(invoke, targetGraph, true); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
369 Debug.dump(graph, "after inlining %s", callee); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
370 afterInline(graph, targetGraph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
371 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
372 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
373 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
374 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
375 afterInlining(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
376 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
377 for (LoopEndNode end : graph.getNodes(LoopEndNode.class)) { |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
378 end.disableSafepoint(); |
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 |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
381 if (GraalOptions.ProbabilityAnalysis) { |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
382 new DeadCodeEliminationPhase().apply(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
383 new ComputeProbabilityPhase().apply(graph); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
384 } |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
385 return graph; |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
386 } |
7076 | 387 } |
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
|
388 |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
389 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
|
390 if (methodSubstitution.isEmpty()) { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
391 return substituteMethod.getName(); |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
392 } else { |
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
393 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
|
394 } |
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
|
395 } |
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
|
396 |
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
|
397 /** |
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
|
398 * Resolves a name to a class. |
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
|
399 * |
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
|
400 * @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
|
401 * @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
|
402 * @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
|
403 */ |
8466
c7a2a937233f
added @Alias annotation for accessing fields and methods otherwise inaccessible due to Java access rules
Doug Simon <doug.simon@oracle.com>
parents:
8450
diff
changeset
|
404 static Class resolveType(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
|
405 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
|
406 // 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
|
407 // 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
|
408 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
|
409 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
|
410 } 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
|
411 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
|
412 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
|
413 } |
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
|
414 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
|
415 } |
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
|
416 } |
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
|
417 |
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
|
418 private static Class resolveType(JavaType 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 } |
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
|
425 |
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
|
426 Class baseClass = base.getKind() != Kind.Object ? base.getKind().toJavaClass() : resolveType(toJavaName(base), 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
|
427 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
|
428 } |
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
|
429 |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
430 private Class[] originalParameters(Method substituteMethod, String methodSubstitution, boolean isStatic) { |
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
|
431 Class[] parameters; |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
432 if (methodSubstitution.isEmpty()) { |
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
|
433 parameters = substituteMethod.getParameterTypes(); |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
434 if (!isStatic) { |
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
|
435 assert parameters.length > 0 : "must be a static method with the 'this' object as its first parameter"; |
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
|
436 parameters = Arrays.copyOfRange(parameters, 1, parameters.length); |
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
|
437 } |
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
|
438 } else { |
7510
225002aba5a5
added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7383
diff
changeset
|
439 Signature signature = runtime.parseMethodDescriptor(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
|
440 parameters = new Class[signature.getParameterCount(false)]; |
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
|
441 for (int i = 0; i < parameters.length; i++) { |
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
|
442 parameters[i] = resolveType(signature.getParameterType(i, 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
|
443 } |
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
|
444 } |
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
|
445 return parameters; |
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
|
446 } |
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
|
447 |
8902
59e751e68bea
made method (and macro) substitution optional to support different JDK versions
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
448 private static Member originalMethod(ClassSubstitution classSubstitution, boolean optional, String name, Class[] parameters) { |
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
|
449 Class<?> originalClass = classSubstitution.value(); |
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
|
450 if (originalClass == ClassSubstitution.class) { |
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
|
451 originalClass = resolveType(classSubstitution.className(), classSubstitution.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
|
452 if (originalClass == 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
|
453 // optional class was not found |
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
|
454 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
|
455 } |
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
|
456 } |
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
|
457 try { |
8360
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
458 if (name.equals("<init>")) { |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
459 return originalClass.getDeclaredConstructor(parameters); |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
460 } else { |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
461 return originalClass.getDeclaredMethod(name, parameters); |
fa5a670a1682
added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents:
8199
diff
changeset
|
462 } |
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
|
463 } catch (NoSuchMethodException | SecurityException e) { |
8902
59e751e68bea
made method (and macro) substitution optional to support different JDK versions
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
464 if (optional) { |
59e751e68bea
made method (and macro) substitution optional to support different JDK versions
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
465 return null; |
59e751e68bea
made method (and macro) substitution optional to support different JDK versions
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
466 } |
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
|
467 throw new GraalInternalError(e); |
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
|
468 } |
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
|
469 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
470 |
8912
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
471 @Override |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
472 public Collection<ResolvedJavaMethod> getAllReplacements() { |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
473 HashSet<ResolvedJavaMethod> result = new HashSet<>(); |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
474 result.addAll(registeredMethodSubstitutions.keySet()); |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
475 result.addAll(registerMacroSubstitutions.keySet()); |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
476 return result; |
9631f95971a3
new GraalOption.BootstrapReplacements for debugging purposes
Lukas Stadler <lukas.stadler@jku.at>
parents:
8631
diff
changeset
|
477 } |
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 |
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
479 @Override |
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
480 public boolean isForcedSubstitution(ResolvedJavaMethod method) { |
880619fd6a67
allow MethodSubstitutions and MacroSubstitutions to be forced (instead of depending on inlining)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8913
diff
changeset
|
481 return forcedSubstitutions.contains(method); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8484
diff
changeset
|
482 } |
7076 | 483 } |