annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsInstaller.java @ 8420:5d3fa6f949fb

created com.oracle.graal.api.replacements project and moved ClassSubstitution and MethodSubstitution there
author Doug Simon <doug.simon@oracle.com>
date Thu, 21 Mar 2013 12:14:09 +0100
parents 11bada5f81a6
children 24608582da70
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
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
49 /**
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8414
diff changeset
50 * Utility for managing the pre-processing and installation of replacements. Replacements are either
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8414
diff changeset
51 * {@linkplain Snippets snippets}, {@linkplain MethodSubstitution method substitutions} or
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8414
diff changeset
52 * {@link MacroSubstitution macro substitutions}.
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
53 */
8410
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
54 public class ReplacementsInstaller {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
55
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
56 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
57 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
58 protected final Assumptions assumptions;
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
59 protected final BoxingMethodPool pool;
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
60 private final Thread owner;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
61
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
62 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
63 * A graph cache used by this installer to avoid using the compiler storage for each method
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
64 * processed during snippet installation. Without this, all processed methods are to be
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
65 * determined as {@linkplain InliningUtil#canIntrinsify intrinsifiable}.
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
66 */
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
67 private final Map<ResolvedJavaMethod, StructuredGraph> graphCache;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
68
8410
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
69 public ReplacementsInstaller(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target) {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
70 this.runtime = runtime;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
71 this.target = target;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
72 this.assumptions = assumptions;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
73 this.pool = new BoxingMethodPool(runtime);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
74 this.graphCache = new HashMap<>();
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
75 this.owner = Thread.currentThread();
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
76 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
77
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
78 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
79 * Finds all the snippet methods in a given class, builds a graph for them and installs the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
80 * graph with the key value of {@code Graph.class} in the
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
81 * {@linkplain ResolvedJavaMethod#getCompilerStorage() compiler storage} of each method.
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
82 */
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8410
diff changeset
83 public void installSnippets(Class<? extends Snippets> snippets) {
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8410
diff changeset
84 for (Method method : snippets.getDeclaredMethods()) {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
85 if (method.getAnnotation(Snippet.class) != null) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
86 int modifiers = method.getModifiers();
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
87 if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
88 throw new RuntimeException("Snippet must not be abstract or native");
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
89 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
90 ResolvedJavaMethod snippet = runtime.lookupJavaMethod(method);
7220
fcae6d960acd added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7096
diff changeset
91 assert snippet.getCompilerStorage().get(Graph.class) == null : method;
7901
93a133fc03ce clear frame states in snippets and replace with sentries
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
92 StructuredGraph graph = makeGraph(snippet, inliningPolicy(snippet));
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
93 // System.out.println("snippet: " + graph);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
94 snippet.getCompilerStorage().put(Graph.class, graph);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
95 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
96 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
97 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
98
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
99 /**
8410
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
100 * Finds all the methods in a given class annotated with {@link MethodSubstitution} or
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
101 * {@link MacroSubstitution}. It builds graphs for the former and installs them in the
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
102 * {@linkplain ResolvedJavaMethod#getCompilerStorage() compiler storage} of the original (i.e.,
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
103 * substituted) method with a key of {@code Graph.class}. For the latter, the denoted
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
104 * {@linkplain MacroSubstitution#macro() macro} node type is install in the compiler storage
e996a732c740 renamings as part of a move away from the overloading of the "snippet" term for various code replacement/substitution mechanisms towards it being solely for the concept of IR lowering
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
105 * with a key of {@code Node.class}.
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
106 */
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
107 public void installSubstitutions(Class<?> substitutions) {
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
108 assert owner == Thread.currentThread() : "substitution installation must be single threaded";
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
109 ClassSubstitution classSubstitution = substitutions.getAnnotation(ClassSubstitution.class);
7545
b30b33d9da80 sanity checks for SnippetInstaller.installSubstitutions()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
110 assert classSubstitution != null;
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8410
diff changeset
111 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
112 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
113 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
114 MacroSubstitution macroSubstitution = substituteMethod.getAnnotation(MacroSubstitution.class);
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
115 if (methodSubstitution == null && macroSubstitution == null) {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
116 continue;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
117 }
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
118
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
119 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
120 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
121 throw new RuntimeException("Substitution methods must be static: " + substituteMethod);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
122 }
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
123
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
124 if (methodSubstitution != null) {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
125 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
126 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
127 }
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
128 String originalName = originalName(substituteMethod, methodSubstitution.value());
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
129 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
130 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
131 if (originalMethod != 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
132 installMethodSubstitution(originalMethod, substituteMethod);
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 }
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
134 }
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
135 if (macroSubstitution != null) {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
136 String originalName = originalName(substituteMethod, macroSubstitution.value());
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
137 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
138 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
139 if (originalMethod != 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
140 installMacroSubstitution(originalMethod, macroSubstitution.macro());
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
141 }
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
142 }
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
143 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
144 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
145
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
146 // These fields are used to detect calls from the substitute method to the original method.
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
147 ResolvedJavaMethod substitute;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
148 ResolvedJavaMethod original;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
149 boolean substituteCallsOriginal;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
150
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
151 /**
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
152 * Installs a method substitution.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
153 *
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
154 * @param originalMethod 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
155 * @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
156 */
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
157 protected void installMethodSubstitution(Member originalMethod, Method substituteMethod) {
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
158 substitute = runtime.lookupJavaMethod(substituteMethod);
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
159 if (originalMethod instanceof Method) {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
160 original = runtime.lookupJavaMethod((Method) originalMethod);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
161 } else {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
162 original = runtime.lookupJavaConstructor((Constructor) originalMethod);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
163 }
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
164 try {
8377
40eaf9970bff removed unused code
Doug Simon <doug.simon@oracle.com>
parents: 8373
diff changeset
165 Debug.log("substitution: " + MetaUtil.format("%H.%n(%p)", original) + " --> " + MetaUtil.format("%H.%n(%p)", substitute));
7901
93a133fc03ce clear frame states in snippets and replace with sentries
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
166 StructuredGraph graph = makeGraph(substitute, inliningPolicy(substitute));
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
167 Object oldValue = original.getCompilerStorage().put(Graph.class, graph);
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
168 assert oldValue == null;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
169 } finally {
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
170 substitute = null;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
171 original = null;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
172 substituteCallsOriginal = false;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
173 }
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
174 }
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
175
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
176 /**
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
177 * Installs a macro substitution.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
178 *
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
179 * @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
180 * @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
181 */
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
182 protected void installMacroSubstitution(Member originalMethod, Class<? extends FixedWithNextNode> macro) {
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 }
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
189 Object oldValue = originalJavaMethod.getCompilerStorage().put(Node.class, macro);
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
190 assert oldValue == null;
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
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
195 Snippet snippet = method.getAnnotation(Snippet.class);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
196 if (snippet != null) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
197 policyClass = snippet.inlining();
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
198 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
199 if (policyClass == SnippetInliningPolicy.class) {
7134
3de18d9cd04e Remove a usasge of getMirrorOrFail
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7096
diff changeset
200 return new DefaultSnippetInliningPolicy(runtime, pool);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
201 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
202 try {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
203 return policyClass.getConstructor().newInstance();
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
204 } catch (Exception e) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
205 throw new GraalInternalError(e);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
206 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
207 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
208
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
209 /**
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
210 * Does final processing of a snippet graph.
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
211 */
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
212 protected void finalizeGraph(ResolvedJavaMethod method, StructuredGraph graph) {
8409
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8377
diff changeset
213 new NodeIntrinsificationPhase(runtime, pool).apply(graph);
8414
8f274684c123 rename: SnippetIntrinsificationVerificationPhase -> NodeIntrinsificationVerificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
214 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
215
8419
11bada5f81a6 refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
216 if (substitute == null) {
11bada5f81a6 refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
217 new SnippetFrameStateCleanupPhase().apply(graph);
11bada5f81a6 refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
218 new DeadCodeEliminationPhase().apply(graph);
11bada5f81a6 refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
219 new InsertStateAfterPlaceholderPhase().apply(graph);
11bada5f81a6 refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
220 } else {
11bada5f81a6 refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
221 new DeadCodeEliminationPhase().apply(graph);
11bada5f81a6 refactored MethodSubstitution and MacroSubstitution into top level classes
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
222 }
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
223 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
224
7901
93a133fc03ce clear frame states in snippets and replace with sentries
Lukas Stadler <lukas.stadler@jku.at>
parents: 7827
diff changeset
225 public StructuredGraph makeGraph(final ResolvedJavaMethod method, final SnippetInliningPolicy policy) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
226 return Debug.scope("BuildSnippetGraph", new Object[]{method}, new Callable<StructuredGraph>() {
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7510
diff changeset
227
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
228 @Override
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
229 public StructuredGraph call() throws Exception {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
230 StructuredGraph graph = parseGraph(method, policy);
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
231
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 finalizeGraph(method, graph);
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
233
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
234 Debug.dump(graph, "%s: Final", method.getName());
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
235
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
236 return graph;
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
237 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
238 });
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
239 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
240
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
241 private StructuredGraph parseGraph(final ResolvedJavaMethod method, final SnippetInliningPolicy policy) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
242 StructuredGraph graph = graphCache.get(method);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
243 if (graph == null) {
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
244 graph = buildGraph(method, policy == null ? inliningPolicy(method) : policy);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
245 graphCache.put(method, graph);
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
246 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
247 return graph;
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
248 }
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
249
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 /**
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
251 * Builds the initial graph for a snippet.
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
252 */
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
253 protected StructuredGraph buildInitialGraph(final ResolvedJavaMethod method) {
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
254 final StructuredGraph graph = new StructuredGraph(method);
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
255 GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault();
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
256 GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config, OptimisticOptimizations.NONE);
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
257 graphBuilder.apply(graph);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
258
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
259 Debug.dump(graph, "%s: %s", method.getName(), GraphBuilderPhase.class.getSimpleName());
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
260
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7295
diff changeset
261 new WordTypeVerificationPhase(runtime, target.wordKind).apply(graph);
8409
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8377
diff changeset
262 new NodeIntrinsificationPhase(runtime, pool).apply(graph);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
263
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
264 return graph;
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
265 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
266
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
267 /**
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
268 * Called after a graph is inlined.
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
269 *
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
270 * @param caller the graph into which {@code callee} was inlined
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
271 * @param callee the graph that was inlined into {@code caller}
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
272 */
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
273 protected void afterInline(StructuredGraph caller, StructuredGraph callee) {
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
274 if (GraalOptions.OptCanonicalizer) {
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
275 new WordTypeRewriterPhase(runtime, target.wordKind).apply(caller);
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
276 new CanonicalizerPhase(runtime, assumptions).apply(caller);
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
277 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
278 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
279
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
280 /**
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
281 * Called after all inlining for a given graph is complete.
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
282 */
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
283 protected void afterInlining(StructuredGraph graph) {
8409
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8377
diff changeset
284 new NodeIntrinsificationPhase(runtime, pool).apply(graph);
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
285
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
286 new WordTypeRewriterPhase(runtime, target.wordKind).apply(graph);
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
287
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
288 new DeadCodeEliminationPhase().apply(graph);
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
289 if (GraalOptions.OptCanonicalizer) {
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
290 new CanonicalizerPhase(runtime, assumptions).apply(graph);
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
291 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
292 }
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
293
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
294 private StructuredGraph buildGraph(final ResolvedJavaMethod method, final SnippetInliningPolicy policy) {
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
295 assert !Modifier.isAbstract(method.getModifiers()) && !Modifier.isNative(method.getModifiers()) : method;
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
296 final StructuredGraph graph = buildInitialGraph(method);
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
297
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
298 for (Invoke invoke : graph.getInvokes()) {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
299 MethodCallTargetNode callTarget = invoke.methodCallTarget();
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
300 ResolvedJavaMethod callee = callTarget.targetMethod();
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
301 if (callee == substitute) {
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
302 final StructuredGraph originalGraph = new StructuredGraph(original);
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
303 new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault(), OptimisticOptimizations.NONE).apply(originalGraph);
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
304 InliningUtil.inline(invoke, originalGraph, true);
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
305
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
306 Debug.dump(graph, "after inlining %s", callee);
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
307 afterInline(graph, originalGraph);
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
308 substituteCallsOriginal = true;
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
309 } else {
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
310 if ((callTarget.invokeKind() == InvokeKind.Static || callTarget.invokeKind() == InvokeKind.Special) && policy.shouldInline(callee, method)) {
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
311 StructuredGraph targetGraph = parseGraph(callee, policy);
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
312 InliningUtil.inline(invoke, targetGraph, true);
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
313 Debug.dump(graph, "after inlining %s", callee);
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
314 afterInline(graph, targetGraph);
7383
36474f315a8a added support for substitute methods to call the original/substituted methods
Doug Simon <doug.simon@oracle.com>
parents: 7373
diff changeset
315 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
316 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
317 }
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
318
8199
a68310b2b8b8 made GraphBuilderPhase and SnippetInstaller more extensible (inspired by patch from Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
319 afterInlining(graph);
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
320
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
321 for (LoopEndNode end : graph.getNodes(LoopEndNode.class)) {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
322 end.disableSafepoint();
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
323 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
324
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
325 if (GraalOptions.ProbabilityAnalysis) {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
326 new DeadCodeEliminationPhase().apply(graph);
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
327 new ComputeProbabilityPhase().apply(graph);
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
328 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7229
diff changeset
329 return graph;
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
330 }
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
331
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
332 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
333 if (methodSubstitution.isEmpty()) {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
334 return substituteMethod.getName();
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
335 } else {
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
336 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
337 }
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
338 }
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
339
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
340 /**
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
341 * 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
342 *
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
343 * @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
344 * @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
345 * @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
346 */
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
347 private 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
348 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
349 // 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
350 // 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
351 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
352 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
353 } 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
354 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
355 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
356 }
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
357 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
358 }
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
359 }
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
360
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
361 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
362 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
363 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
364 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
365 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
366 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
367 }
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
368
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
369 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
370 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
371 }
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
372
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
373 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
374 Class[] parameters;
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
375 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
376 parameters = substituteMethod.getParameterTypes();
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
377 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
378 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
379 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
380 }
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
381 } else {
7510
225002aba5a5 added new macro node facility, removed ArrayCopyIntrinsificationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 7383
diff changeset
382 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
383 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
384 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
385 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
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 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
389 }
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
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
391 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
392 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
393 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
394 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
395 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
396 // 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
397 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
398 }
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
399 }
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
400 try {
8360
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
401 if (name.equals("<init>")) {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
402 return originalClass.getDeclaredConstructor(parameters);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
403 } else {
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
404 return originalClass.getDeclaredMethod(name, parameters);
fa5a670a1682 added support for substituting constructors
Doug Simon <doug.simon@oracle.com>
parents: 8199
diff changeset
405 }
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
406 } 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
407 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
408 }
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 }
7076
32408bd16b91 fixes after merge
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7075
diff changeset
410 }