annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java @ 8630:f32fa4cdfbb1

fixed concurrency issues in ReplacementsImpl
author Doug Simon <doug.simon@oracle.com>
date Wed, 03 Apr 2013 22:52:11 +0200
parents 77de2f3df379
children a5ad23f6f9ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
1 /*
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
4 *
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
7 * published by the Free Software Foundation.
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
8 *
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
13 * accompanied this code).
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
14 *
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
15 * You should have received a copy of the GNU General Public License version
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
18 *
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
21 * questions.
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8414
diff changeset
23 package com.oracle.graal.replacements;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
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
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
27 import java.lang.reflect.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
28 import java.util.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
29 import java.util.concurrent.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
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
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
33 import com.oracle.graal.api.code.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
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
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
36 import com.oracle.graal.debug.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
37 import com.oracle.graal.graph.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
38 import com.oracle.graal.java.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
39 import com.oracle.graal.nodes.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
40 import com.oracle.graal.nodes.extended.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
41 import com.oracle.graal.nodes.java.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7295
diff changeset
42 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
43 import com.oracle.graal.phases.*;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
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
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
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
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
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
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
55 private BoxingMethodPool pool;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
56
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
57 private final ConcurrentMap<ResolvedJavaMethod, StructuredGraph> graphCache;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
58
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
59 // 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
60 // 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
61 private final Map<ResolvedJavaMethod, ResolvedJavaMethod> registeredMethodSubstitutions;
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
62 private final Set<ResolvedJavaMethod> registeredSnippets;
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;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
64
8628
77de2f3df379 renames: [HotSpot]ReplacementsInstaller -> [HotSpot]ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8627
diff changeset
65 public ReplacementsImpl(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target) {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
66 this.runtime = runtime;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
67 this.target = target;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
68 this.assumptions = assumptions;
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
69 this.graphCache = new ConcurrentHashMap<>();
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
70 this.registeredMethodSubstitutions = new HashMap<>();
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
71 this.registeredSnippets = new HashSet<>();
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
72 this.registerMacroSubstitutions = new HashMap<>();
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
73 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
74
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
75 public void registerSnippets(Class<?> snippets) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
76 assert Snippets.class.isAssignableFrom(snippets);
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8410
diff changeset
77 for (Method method : snippets.getDeclaredMethods()) {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
78 if (method.getAnnotation(Snippet.class) != null) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
79 int modifiers = method.getModifiers();
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
80 if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
81 throw new RuntimeException("Snippet must not be abstract or native");
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
82 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
83 ResolvedJavaMethod snippet = runtime.lookupJavaMethod(method);
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
84 registeredSnippets.add(snippet);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
85 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
86 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
87 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
88
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
89 public StructuredGraph getSnippet(ResolvedJavaMethod method) {
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
90 if (!registeredSnippets.contains(method)) {
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 }
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
93 StructuredGraph graph = graphCache.get(method);
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
94 if (graph == null) {
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
95 graph = createGraphMaker(null, null).makeGraph(method, inliningPolicy(method));
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
96 assert graph == graphCache.get(method);
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 StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) {
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
103 ResolvedJavaMethod substitute = registeredMethodSubstitutions.get(original);
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
104 if (substitute == null) {
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
105 return null;
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
106 }
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
107 StructuredGraph graph = graphCache.get(original);
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
108 if (graph == null) {
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
109 graph = createGraphMaker(substitute, original).makeGraph(substitute, inliningPolicy(substitute));
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
110 assert graph == graphCache.get(substitute);
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
111 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
112 return graph;
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
113
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
114 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
115
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
116 public Class<? extends FixedWithNextNode> getMacroSubstitution(ResolvedJavaMethod method) {
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
117 return registerMacroSubstitutions.get(method);
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
118 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
119
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
120 public Assumptions getAssumptions() {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
121 return assumptions;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
122 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
123
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
124 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
125 ClassSubstitution classSubstitution = substitutions.getAnnotation(ClassSubstitution.class);
7545
b30b33d9da80 sanity checks for SnippetInstaller.installSubstitutions()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
126 assert classSubstitution != null;
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8410
diff changeset
127 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
128 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
129 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
130 MacroSubstitution macroSubstitution = substituteMethod.getAnnotation(MacroSubstitution.class);
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
131 if (methodSubstitution == null && macroSubstitution == null) {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
132 continue;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
133 }
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
134
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
135 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
136 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
137 throw new RuntimeException("Substitution methods must be static: " + substituteMethod);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
138 }
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
139
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
140 if (methodSubstitution != null) {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
141 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
142 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
143 }
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
144 String originalName = originalName(substituteMethod, methodSubstitution.value());
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
145 Class[] originalParameters = originalParameters(substituteMethod, methodSubstitution.signature(), methodSubstitution.isStatic());
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
146 Member originalMethod = originalMethod(classSubstitution, 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
147 if (originalMethod != null) {
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
148 registerMethodSubstitution(originalMethod, substituteMethod);
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 }
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
151 if (macroSubstitution != null) {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
152 String originalName = originalName(substituteMethod, macroSubstitution.value());
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
153 Class[] originalParameters = originalParameters(substituteMethod, macroSubstitution.signature(), macroSubstitution.isStatic());
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
154 Member originalMethod = originalMethod(classSubstitution, 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
155 if (originalMethod != null) {
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
156 registerMacroSubstitution(originalMethod, macroSubstitution.macro());
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
157 }
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
158 }
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
159 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
160 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
161
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
162 /**
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
163 * Registers a method substitution.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
164 *
8431
be5ce3e9d473 rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents: 8430
diff changeset
165 * @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
166 * @param substituteMethod the substitute method
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
167 */
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
168 protected void registerMethodSubstitution(Member originalMember, Method substituteMethod) {
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
169 ResolvedJavaMethod substitute = runtime.lookupJavaMethod(substituteMethod);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
170 ResolvedJavaMethod original;
8431
be5ce3e9d473 rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents: 8430
diff changeset
171 if (originalMember instanceof Method) {
be5ce3e9d473 rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents: 8430
diff changeset
172 original = runtime.lookupJavaMethod((Method) originalMember);
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
173 } else {
8431
be5ce3e9d473 rename: originalMethod -> originalMember
Doug Simon <doug.simon@oracle.com>
parents: 8430
diff changeset
174 original = runtime.lookupJavaConstructor((Constructor) originalMember);
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
175 }
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
176 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
177
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
178 registeredMethodSubstitutions.put(original, substitute);
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
179 }
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
180
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
181 /**
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
182 * Registers a macro substitution.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
183 *
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
184 * @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
185 * @param macro the substitute macro node class
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
186 */
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
187 protected void registerMacroSubstitution(Member originalMethod, Class<? extends FixedWithNextNode> macro) {
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
188 ResolvedJavaMethod originalJavaMethod;
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
189 if (originalMethod instanceof Method) {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
190 originalJavaMethod = runtime.lookupJavaMethod((Method) originalMethod);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
191 } else {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
192 originalJavaMethod = runtime.lookupJavaConstructor((Constructor) originalMethod);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
193 }
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
194 registerMacroSubstitutions.put(originalJavaMethod, macro);
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
195 }
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
196
7096
585fc9f79ebc Remove ResolvedJavaType.isClass()
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7076
diff changeset
197 private SnippetInliningPolicy inliningPolicy(ResolvedJavaMethod method) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
198 Class<? extends SnippetInliningPolicy> policyClass = SnippetInliningPolicy.class;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
199 Snippet snippet = method.getAnnotation(Snippet.class);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
200 if (snippet != null) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
201 policyClass = snippet.inlining();
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
202 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
203 if (policyClass == SnippetInliningPolicy.class) {
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
204 return new DefaultSnippetInliningPolicy(runtime, pool());
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
205 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
206 try {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
207 return policyClass.getConstructor().newInstance();
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
208 } catch (Exception e) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
209 throw new GraalInternalError(e);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
210 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
211 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
212
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
213 public StructuredGraph makeGraph(ResolvedJavaMethod method, SnippetInliningPolicy policy) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
214 return createGraphMaker(null, null).makeGraph(method, 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
215 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
216
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
217 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
218 return new GraphMaker(substitute, original);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
219 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
220
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
221 protected class GraphMaker {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
222
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
223 // These fields are used to detect calls from the substitute method to the original method.
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
224 protected final ResolvedJavaMethod substitute;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
225 protected final ResolvedJavaMethod original;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
226
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
227 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
228
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
229 protected GraphMaker(ResolvedJavaMethod substitute, ResolvedJavaMethod original) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
230 this.substitute = substitute;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
231 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
232 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
233
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
234 /**
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
235 * 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
236 */
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
237 protected void finalizeGraph(ResolvedJavaMethod method, StructuredGraph graph) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
238 new NodeIntrinsificationPhase(runtime, pool()).apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
239 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
240
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
241 if (substitute == null) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
242 new SnippetFrameStateCleanupPhase().apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
243 new DeadCodeEliminationPhase().apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
244 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
245 } else {
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
246 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
247 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
248 }
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
249
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
250 public StructuredGraph makeGraph(final ResolvedJavaMethod method, final SnippetInliningPolicy policy) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
251 return Debug.scope("BuildSnippetGraph", new Object[]{method}, new Callable<StructuredGraph>() {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
252
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
253 @Override
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
254 public StructuredGraph call() throws Exception {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
255 StructuredGraph graph = parseGraph(method, policy);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
256
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
257 finalizeGraph(method, graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
258
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
259 Debug.dump(graph, "%s: Final", method.getName());
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
260
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
261 return graph;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
262 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
263 });
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
264 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
265
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
266 private StructuredGraph parseGraph(final ResolvedJavaMethod method, final SnippetInliningPolicy policy) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
267 StructuredGraph graph = graphCache.get(method);
8630
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
268 if (graph == null) {
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
269 graphCache.putIfAbsent(method, buildGraph(method, policy == null ? inliningPolicy(method) : policy));
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
270 graph = graphCache.get(method);
f32fa4cdfbb1 fixed concurrency issues in ReplacementsImpl
Doug Simon <doug.simon@oracle.com>
parents: 8628
diff changeset
271 assert graph != null;
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
272 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
273 return graph;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
274 }
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 /**
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
277 * 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
278 */
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
279 protected StructuredGraph buildInitialGraph(final ResolvedJavaMethod method) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
280 final StructuredGraph graph = new StructuredGraph(method);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
281 GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault();
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
282 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
283 graphBuilder.apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
284
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
285 Debug.dump(graph, "%s: %s", method.getName(), GraphBuilderPhase.class.getSimpleName());
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
286
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
287 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
288 new NodeIntrinsificationPhase(runtime, pool()).apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
289
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
290 return graph;
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
291 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
292
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
293 /**
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
294 * Called after a graph is inlined.
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
295 *
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
296 * @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
297 * @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
298 */
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
299 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
300 if (GraalOptions.OptCanonicalizer) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
301 new WordTypeRewriterPhase(runtime, target.wordKind).apply(caller);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
302 new CanonicalizerPhase(runtime, assumptions).apply(caller);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
303 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
304 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
305
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
306 /**
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
307 * 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
308 */
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
309 protected void afterInlining(StructuredGraph graph) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
310 new NodeIntrinsificationPhase(runtime, pool()).apply(graph);
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 WordTypeRewriterPhase(runtime, target.wordKind).apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
313
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
314 new DeadCodeEliminationPhase().apply(graph);
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
315 if (GraalOptions.OptCanonicalizer) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
316 new CanonicalizerPhase(runtime, assumptions).apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
317 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
318 }
8627
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 private StructuredGraph buildGraph(final ResolvedJavaMethod method, final SnippetInliningPolicy policy) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
321 assert !Modifier.isAbstract(method.getModifiers()) && !Modifier.isNative(method.getModifiers()) : method;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
322 final StructuredGraph graph = buildInitialGraph(method);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
323
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
324 for (Invoke invoke : graph.getInvokes()) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
325 MethodCallTargetNode callTarget = invoke.methodCallTarget();
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
326 ResolvedJavaMethod callee = callTarget.targetMethod();
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
327 if (callee == substitute) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
328 final StructuredGraph originalGraph = new StructuredGraph(original);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
329 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
330 InliningUtil.inline(invoke, originalGraph, true);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
331
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
332 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
333 afterInline(graph, originalGraph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
334 substituteCallsOriginal = true;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
335 } else {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
336 if ((callTarget.invokeKind() == InvokeKind.Static || callTarget.invokeKind() == InvokeKind.Special) && policy.shouldInline(callee, method)) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
337 StructuredGraph targetGraph = parseGraph(callee, policy);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
338 InliningUtil.inline(invoke, targetGraph, true);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
339 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
340 afterInline(graph, targetGraph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
341 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
342 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
343 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
344
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
345 afterInlining(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
346
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
347 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
348 end.disableSafepoint();
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
349 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
350
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
351 if (GraalOptions.ProbabilityAnalysis) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
352 new DeadCodeEliminationPhase().apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
353 new ComputeProbabilityPhase().apply(graph);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
354 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
355 return graph;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
356 }
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
357 }
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
358
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
359 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
360 if (methodSubstitution.isEmpty()) {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
361 return substituteMethod.getName();
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
362 } else {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
363 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
364 }
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
365 }
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
366
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
367 /**
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
368 * 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
369 *
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
370 * @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
371 * @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
372 * @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
373 */
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
374 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
375 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
376 // 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
377 // 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
378 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
379 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
380 } 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
381 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
382 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
383 }
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
384 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
385 }
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
386 }
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
387
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 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
389 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
390 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
391 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
392 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
393 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
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
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
396 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
397 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
398 }
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
399
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
400 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
401 Class[] parameters;
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
402 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
403 parameters = substituteMethod.getParameterTypes();
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
404 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
405 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
406 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
407 }
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 } else {
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
409 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
410 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
411 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
412 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
413 }
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 }
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 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
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
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
418 private static Member originalMethod(ClassSubstitution classSubstitution, 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
419 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
420 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
421 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
422 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
423 // 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
424 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
425 }
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
426 }
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 try {
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
428 if (name.equals("<init>")) {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
429 return originalClass.getDeclaredConstructor(parameters);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
430 } else {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
431 return originalClass.getDeclaredMethod(name, parameters);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
432 }
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 } catch (NoSuchMethodException | SecurityException 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
434 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
435 }
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 }
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
437
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
438 protected BoxingMethodPool pool() {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
439 if (pool == null) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
440 // A race to create the pool is ok
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
441 pool = new BoxingMethodPool(runtime);
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
442 }
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
443 return pool;
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8484
diff changeset
444 }
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
445 }