Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java @ 9099:ed81c74f92ff
Cache boolean flags instead of full Annotation objects
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Fri, 12 Apr 2013 16:05:56 -0700 |
parents | 6d376d09880b |
children | cd2600a2336e |
rev | line source |
---|---|
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
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; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import java.lang.reflect.*; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import java.util.*; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import java.util.concurrent.*; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
29 import com.oracle.graal.api.code.*; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5503
diff
changeset
|
30 import com.oracle.graal.api.meta.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.debug.*; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.graph.*; |
6523
c8763a2deb0c
rename packages in graal.loop to match project name
Doug Simon <doug.simon@oracle.com>
parents:
6521
diff
changeset
|
33 import com.oracle.graal.loop.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.*; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
35 import com.oracle.graal.nodes.calc.*; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
36 import com.oracle.graal.nodes.java.*; |
8178
67ee3325c285
added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
37 import com.oracle.graal.nodes.spi.*; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
38 import com.oracle.graal.nodes.type.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 import com.oracle.graal.nodes.util.*; |
6526
ee651c726397
split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents:
6525
diff
changeset
|
40 import com.oracle.graal.phases.common.*; |
8642
1093255fd0d4
simplified registration of snippets
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
41 import com.oracle.graal.replacements.Snippet.ConstantParameter; |
1093255fd0d4
simplified registration of snippets
Doug Simon <doug.simon@oracle.com>
parents:
8637
diff
changeset
|
42 import com.oracle.graal.replacements.Snippet.VarargsParameter; |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
8414
diff
changeset
|
43 import com.oracle.graal.replacements.nodes.*; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
44 import com.oracle.graal.word.*; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
45 import com.oracle.graal.word.phases.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
48 * A snippet template is a graph created by parsing a snippet method and then specialized by binding |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
49 * constants to the snippet's {@link ConstantParameter} parameters. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
50 * |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
51 * Snippet templates can be managed in a cache maintained by {@link AbstractTemplates}. |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 */ |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 public class SnippetTemplate { |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 /** |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
56 * Holds the {@link ResolvedJavaMethod} of the snippet, together with some information about the |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
57 * method that needs to be computed only once. The {@link SnippetInfo} should be created once |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
58 * per snippet an then cached. |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
60 public static class SnippetInfo { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
61 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
62 protected final ResolvedJavaMethod method; |
9099
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
63 protected final boolean[] constantParameters; |
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
64 protected final boolean[] varargsParameters; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
65 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
66 /** |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
67 * The parameter names, taken from the local variables table. Only used for assertion |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
68 * checking, so use only within an assert statement. |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
69 */ |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
70 protected final String[] names; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
71 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
72 protected SnippetInfo(ResolvedJavaMethod method) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
73 this.method = method; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
74 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
75 assert Modifier.isStatic(method.getModifiers()) : "snippet method must be static: " + MetaUtil.format("%H.%n", method); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
76 int count = method.getSignature().getParameterCount(false); |
9099
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
77 constantParameters = new boolean[count]; |
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
78 varargsParameters = new boolean[count]; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
79 for (int i = 0; i < count; i++) { |
9099
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
80 constantParameters[i] = MetaUtil.getParameterAnnotation(ConstantParameter.class, i, method) != null; |
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
81 varargsParameters[i] = MetaUtil.getParameterAnnotation(VarargsParameter.class, i, method) != null; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
82 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
83 assert !isConstantParameter(i) || !isVarargsParameter(i) : "Parameter cannot be annotated with both @" + ConstantParameter.class.getSimpleName() + " and @" + |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
84 VarargsParameter.class.getSimpleName(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
85 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
86 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
87 names = new String[count]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
88 // Retrieve the names only when assertions are turned on. |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
89 assert initNames(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
90 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
91 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
92 private boolean initNames() { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
93 int slotIdx = 0; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
94 for (int i = 0; i < names.length; i++) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
95 names[i] = method.getLocalVariableTable().getLocal(slotIdx, 0).getName(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
96 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
97 Kind kind = method.getSignature().getParameterKind(i); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
98 slotIdx += kind == Kind.Long || kind == Kind.Double ? 2 : 1; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
99 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
100 return true; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
101 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
102 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
103 public ResolvedJavaMethod getMethod() { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
104 return method; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
105 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
106 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
107 public int getParameterCount() { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
108 return constantParameters.length; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
109 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
110 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
111 public boolean isConstantParameter(int paramIdx) { |
9099
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
112 return constantParameters[paramIdx]; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
113 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
114 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
115 public boolean isVarargsParameter(int paramIdx) { |
9099
ed81c74f92ff
Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9049
diff
changeset
|
116 return varargsParameters[paramIdx]; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
117 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
118 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
119 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
120 /** |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
121 * Values that are bound to the snippet method parameters. The methods {@link #add}, |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
122 * {@link #addConst}, and {@link #addVarargs} must be called in the same order as in the |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
123 * signature of the snippet method. The parameter name is passed to the add methods for |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
124 * assertion checking, i.e., to enforce that the order matches. Which method needs to be called |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
125 * depends on the annotation of the snippet method parameter: |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
126 * <ul> |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
127 * <li>Use {@link #add} for a parameter without an annotation. The value is bound when the |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
128 * {@link SnippetTemplate} is {@link SnippetTemplate#instantiate instantiated}. |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
129 * <li>Use {@link #addConst} for a parameter annotated with {@link ConstantParameter}. The value |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
130 * is bound when the {@link SnippetTemplate} is {@link SnippetTemplate#SnippetTemplate created}. |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
131 * <li>Use {@link #addVarargs} for an array parameter annotated with {@link VarargsParameter}. A |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
132 * separate {@link SnippetTemplate} is {@link SnippetTemplate#SnippetTemplate created} for every |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
133 * distinct array length. The actual values are bound when the {@link SnippetTemplate} is |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
134 * {@link SnippetTemplate#instantiate instantiated} |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
135 * </ul> |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
136 */ |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
137 public static class Arguments { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
138 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
139 protected final SnippetInfo info; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
140 protected final CacheKey cacheKey; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
141 protected final Object[] values; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
142 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
143 protected int nextParamIdx; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
144 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
145 public Arguments(SnippetInfo info) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
146 this.info = info; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
147 this.cacheKey = new CacheKey(info); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
148 this.values = new Object[info.getParameterCount()]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
149 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
150 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
151 public Arguments add(String name, Object value) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
152 assert check(name, false, false); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
153 values[nextParamIdx] = value; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
154 nextParamIdx++; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
155 return this; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
156 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
157 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
158 public Arguments addConst(String name, Object value) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
159 assert check(name, true, false); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
160 values[nextParamIdx] = value; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
161 cacheKey.setParam(nextParamIdx, value); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
162 nextParamIdx++; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
163 return this; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
164 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
165 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
166 public Arguments addVarargs(String name, Class componentType, Stamp argStamp, Object value) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
167 assert check(name, false, true); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
168 Varargs varargs = new Varargs(componentType, argStamp, value); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
169 values[nextParamIdx] = varargs; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
170 // A separate template is necessary for every distinct array length |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
171 cacheKey.setParam(nextParamIdx, varargs.length); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
172 nextParamIdx++; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
173 return this; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
174 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
175 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
176 private boolean check(String name, boolean constParam, boolean varargsParam) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
177 assert nextParamIdx < info.getParameterCount() : "too many parameters: " + name + " " + this; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
178 assert info.names[nextParamIdx].equals(name) : "wrong parameter name: " + name + " " + this; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
179 assert constParam == info.isConstantParameter(nextParamIdx) : "Parameter " + (constParam ? "not " : "") + "annotated with @" + ConstantParameter.class.getSimpleName() + ": " + name + |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
180 " " + this; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
181 assert varargsParam == info.isVarargsParameter(nextParamIdx) : "Parameter " + (varargsParam ? "not " : "") + "annotated with @" + VarargsParameter.class.getSimpleName() + ": " + name + |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
182 " " + this; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
183 return true; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
184 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
185 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
186 @Override |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
187 public String toString() { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
188 StringBuilder result = new StringBuilder(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
189 result.append("Parameters<").append(MetaUtil.format("%H.%n", info.method)).append(" ["); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
190 String sep = ""; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
191 for (int i = 0; i < info.getParameterCount(); i++) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
192 result.append(sep); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
193 if (info.isConstantParameter(i)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
194 result.append("const "); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
195 } else if (info.isVarargsParameter(i)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
196 result.append("varargs "); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
197 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
198 result.append(info.names[i]).append(" = ").append(values[i]); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
199 sep = ", "; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
200 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
201 result.append(">"); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
202 return result.toString(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
203 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
204 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
205 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
206 /** |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
207 * Wrapper for the prototype value of a {@linkplain VarargsParameter varargs} parameter. |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
208 */ |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
209 static class Varargs { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
210 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
211 protected final Class componentType; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
212 protected final Stamp stamp; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
213 protected final Object value; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
214 protected final int length; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
215 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
216 protected Varargs(Class componentType, Stamp stamp, Object value) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
217 this.componentType = componentType; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
218 this.stamp = stamp; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
219 this.value = value; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
220 if (value instanceof List) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
221 this.length = ((List) value).size(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
222 } else { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
223 this.length = Array.getLength(value); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
224 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
225 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
226 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
227 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
228 static class CacheKey { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
229 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
230 private final ResolvedJavaMethod method; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
231 private final Object[] values; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
232 private int hash; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
233 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
234 protected CacheKey(SnippetInfo info) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
235 this.method = info.method; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
236 this.values = new Object[info.getParameterCount()]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
237 this.hash = info.method.hashCode(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
238 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
239 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
240 protected void setParam(int paramIdx, Object value) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
241 values[paramIdx] = value; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
242 hash = (hash * 31) ^ (value == null ? 0 : value.hashCode()); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
243 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
244 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
245 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
246 public boolean equals(Object obj) { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
247 if (!(obj instanceof CacheKey)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
248 return false; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
249 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
250 CacheKey other = (CacheKey) obj; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
251 if (method != other.method) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
252 return false; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
253 } |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
254 for (int i = 0; i < values.length; i++) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
255 if (values[i] != null && !values[i].equals(other.values[i])) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
256 return false; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
257 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
258 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
259 return true; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
260 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
261 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
262 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
263 public int hashCode() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
264 return hash; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
265 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
266 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
267 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
268 /** |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
269 * Base class for snippet classes. It provides a cache for {@link SnippetTemplate}s. |
5484
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
270 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
271 public abstract static class AbstractTemplates { |
5484
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
272 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
273 protected final MetaAccessProvider runtime; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
274 protected final Replacements replacements; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
275 protected final TargetDescription target; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
276 private final ConcurrentHashMap<CacheKey, SnippetTemplate> templates; |
5484
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
277 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
278 protected AbstractTemplates(MetaAccessProvider runtime, Replacements replacements, TargetDescription target) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
279 this.runtime = runtime; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8606
diff
changeset
|
280 this.replacements = replacements; |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
281 this.target = target; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
282 this.templates = new ConcurrentHashMap<>(); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
283 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
284 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
285 protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
286 Method found = null; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
287 for (Method method : declaringClass.getDeclaredMethods()) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
288 if (method.getAnnotation(Snippet.class) != null && method.getName().equals(methodName)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
289 assert found == null : "found more than one @" + Snippet.class.getSimpleName() + " method " + methodName + " in " + declaringClass; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
290 found = method; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
291 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
292 } |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
293 assert found != null : "did not find @" + Snippet.class.getSimpleName() + " method " + methodName + " in " + declaringClass; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
294 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
295 return new SnippetInfo(runtime.lookupJavaMethod(found)); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
296 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
297 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
298 /** |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
299 * Gets a template for a given key, creating it first if necessary. |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
300 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
301 protected SnippetTemplate template(final Arguments args) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
302 SnippetTemplate template = templates.get(args.cacheKey); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
303 if (template == null) { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
304 template = Debug.scope("SnippetSpecialization", args.info.method, new Callable<SnippetTemplate>() { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
305 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
306 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
307 public SnippetTemplate call() throws Exception { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
308 return new SnippetTemplate(runtime, replacements, target, args); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
309 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
310 }); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
311 templates.put(args.cacheKey, template); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
312 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
313 return template; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
314 } |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
315 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
316 |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7141
diff
changeset
|
317 private static final Object UNUSED_PARAMETER = "DEAD PARAMETER"; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
318 private static final Object CONSTANT_PARAMETER = "CONSTANT"; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
319 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
320 /** |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
321 * Determines if any parameter of a given method is annotated with {@link ConstantParameter}. |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
322 */ |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
323 public static boolean hasConstantParameter(ResolvedJavaMethod method) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
324 for (ConstantParameter p : MetaUtil.getParameterAnnotations(ConstantParameter.class, method)) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
325 if (p != null) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
326 return true; |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
327 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
328 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
329 return false; |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
330 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
331 |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
332 /** |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
333 * Creates a snippet template. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
334 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
335 protected SnippetTemplate(MetaAccessProvider runtime, Replacements replacements, TargetDescription target, Arguments args) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
336 StructuredGraph snippetGraph = replacements.getSnippet(args.info.method); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
337 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
338 ResolvedJavaMethod method = snippetGraph.method(); |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6534
diff
changeset
|
339 Signature signature = method.getSignature(); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
340 |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
341 // Copy snippet graph, replacing constant parameters with given arguments |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
342 StructuredGraph snippetCopy = new StructuredGraph(snippetGraph.name, snippetGraph.method()); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8606
diff
changeset
|
343 IdentityHashMap<Node, Node> nodeReplacements = new IdentityHashMap<>(); |
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8606
diff
changeset
|
344 nodeReplacements.put(snippetGraph.start(), snippetCopy.start()); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
345 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
346 assert checkTemplate(runtime, args, method, signature); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
347 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
348 int parameterCount = args.info.getParameterCount(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
349 ConstantNode[] placeholders = new ConstantNode[parameterCount]; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
350 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
351 for (int i = 0; i < parameterCount; i++) { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
352 if (args.info.isConstantParameter(i)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
353 Object arg = args.values[i]; |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6534
diff
changeset
|
354 Kind kind = signature.getParameterKind(i); |
7141
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
355 Constant constantArg; |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
356 if (arg instanceof Constant) { |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
357 constantArg = (Constant) arg; |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
358 } else { |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
359 constantArg = Constant.forBoxed(kind, arg); |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
360 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8606
diff
changeset
|
361 nodeReplacements.put(snippetGraph.getLocal(i), ConstantNode.forConstant(constantArg, runtime, snippetCopy)); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
362 } else if (args.info.isVarargsParameter(i)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
363 Varargs varargs = (Varargs) args.values[i]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
364 Object array = Array.newInstance(varargs.componentType, varargs.length); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
365 ConstantNode placeholder = ConstantNode.forObject(array, runtime, snippetCopy); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
366 nodeReplacements.put(snippetGraph.getLocal(i), placeholder); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
367 placeholders[i] = placeholder; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
368 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
369 } |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8606
diff
changeset
|
370 snippetCopy.addDuplicates(snippetGraph.getNodes(), nodeReplacements); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
371 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
372 Debug.dump(snippetCopy, "Before specialization"); |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8606
diff
changeset
|
373 if (!nodeReplacements.isEmpty()) { |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
374 // Do deferred intrinsification of node intrinsics |
8913
653110156f8a
refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents:
8627
diff
changeset
|
375 new NodeIntrinsificationPhase(runtime).apply(snippetCopy); |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
376 new WordTypeRewriterPhase(runtime, target.wordKind).apply(snippetCopy); |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
377 |
9049
6d376d09880b
Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9038
diff
changeset
|
378 new CanonicalizerPhase.Instance(runtime, replacements.getAssumptions(), 0, null).apply(snippetCopy); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
379 } |
8414
8f274684c123
rename: SnippetIntrinsificationVerificationPhase -> NodeIntrinsificationVerificationPhase
Doug Simon <doug.simon@oracle.com>
parents:
8413
diff
changeset
|
380 assert NodeIntrinsificationVerificationPhase.verify(snippetCopy); |
5466
af07e798947d
lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5428
diff
changeset
|
381 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
382 // Gather the template parameters |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
383 parameters = new Object[parameterCount]; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
384 for (int i = 0; i < parameterCount; i++) { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
385 if (args.info.isConstantParameter(i)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
386 parameters[i] = CONSTANT_PARAMETER; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
387 } else if (args.info.isVarargsParameter(i)) { |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
388 assert snippetCopy.getLocal(i) == null; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
389 Varargs varargs = (Varargs) args.values[i]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
390 int length = varargs.length; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
391 LocalNode[] locals = new LocalNode[length]; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
392 Stamp stamp = varargs.stamp; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
393 for (int j = 0; j < length; j++) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
394 assert (parameterCount & 0xFFFF) == parameterCount; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
395 int idx = i << 16 | j; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
396 LocalNode local = snippetCopy.unique(new LocalNode(idx, stamp)); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
397 locals[j] = local; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
398 } |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
399 parameters[i] = locals; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
400 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
401 ConstantNode placeholder = placeholders[i]; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
402 assert placeholder != null; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
403 for (Node usage : placeholder.usages().snapshot()) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
404 if (usage instanceof LoadIndexedNode) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
405 LoadIndexedNode loadIndexed = (LoadIndexedNode) usage; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
406 Debug.dump(snippetCopy, "Before replacing %s", loadIndexed); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
407 LoadSnippetVarargParameterNode loadSnippetParameter = snippetCopy.add(new LoadSnippetVarargParameterNode(locals, loadIndexed.index(), loadIndexed.stamp())); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
408 snippetCopy.replaceFixedWithFixed(loadIndexed, loadSnippetParameter); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
409 Debug.dump(snippetCopy, "After replacing %s", loadIndexed); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
410 } |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
411 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
412 } else { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
413 LocalNode local = snippetCopy.getLocal(i); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
414 if (local == null) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
415 // Parameter value was eliminated |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
416 parameters[i] = UNUSED_PARAMETER; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
417 } else { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
418 parameters[i] = local; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
419 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
420 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
421 } |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
422 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
423 // Do any required loop explosion |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
424 boolean exploded = false; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
425 do { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
426 exploded = false; |
5490 | 427 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first(); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
428 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
429 // altogether |
5490 | 430 LoopBeginNode loopBegin = explodeLoop.findLoopBegin(); |
431 if (loopBegin != null) { | |
432 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin); | |
433 int mark = snippetCopy.getMark(); | |
7064
8d16b9b2c51e
first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6653
diff
changeset
|
434 LoopTransformations.fullUnroll(loop, runtime, null); |
9049
6d376d09880b
Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9038
diff
changeset
|
435 new CanonicalizerPhase.Instance(runtime, replacements.getAssumptions(), mark, null).apply(snippetCopy); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
436 } |
5490 | 437 FixedNode explodeLoopNext = explodeLoop.next(); |
438 explodeLoop.clearSuccessors(); | |
439 explodeLoop.replaceAtPredecessor(explodeLoopNext); | |
440 explodeLoop.replaceAtUsages(null); | |
441 GraphUtil.killCFG(explodeLoop); | |
442 exploded = true; | |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
443 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
444 } while (exploded); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
445 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
446 // Remove all frame states from inlined snippet graph. Snippets must be atomic (i.e. free |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
447 // of side-effects that prevent deoptimizing to a point before the snippet). |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
448 ArrayList<StateSplit> curSideEffectNodes = new ArrayList<>(); |
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
449 ArrayList<ValueNode> curStampNodes = new ArrayList<>(); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
450 for (Node node : snippetCopy.getNodes()) { |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
451 if (node instanceof ValueNode && ((ValueNode) node).stamp() == StampFactory.forNodeIntrinsic()) { |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
452 curStampNodes.add((ValueNode) node); |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
453 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
454 if (node instanceof StateSplit) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
455 StateSplit stateSplit = (StateSplit) node; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
456 FrameState frameState = stateSplit.stateAfter(); |
6534
feb579677b58
SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6526
diff
changeset
|
457 if (stateSplit.hasSideEffect()) { |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
458 curSideEffectNodes.add((StateSplit) node); |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
459 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
460 if (frameState != null) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
461 stateSplit.setStateAfter(null); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
462 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
463 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
464 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
465 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
466 new DeadCodeEliminationPhase().apply(snippetCopy); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
467 |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
468 assert checkAllVarargPlaceholdersAreDeleted(parameterCount, placeholders); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
469 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
470 this.snippet = snippetCopy; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
471 ReturnNode retNode = null; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
472 StartNode entryPointNode = snippet.start(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
473 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
474 new DeadCodeEliminationPhase().apply(snippetCopy); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
475 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
476 nodes = new ArrayList<>(snippet.getNodeCount()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
477 for (Node node : snippet.getNodes()) { |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
478 if (node == entryPointNode || node == entryPointNode.stateAfter()) { |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
479 // Do nothing. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
480 } else { |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
481 nodes.add(node); |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
482 if (node instanceof ReturnNode) { |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
483 retNode = (ReturnNode) node; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
484 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
485 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
486 } |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
487 |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
488 this.sideEffectNodes = curSideEffectNodes; |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
489 this.stampNodes = curStampNodes; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
490 this.returnNode = retNode; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
491 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
492 |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
493 private static boolean checkAllVarargPlaceholdersAreDeleted(int parameterCount, ConstantNode[] placeholders) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
494 for (int i = 0; i < parameterCount; i++) { |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
495 if (placeholders[i] != null) { |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
496 assert placeholders[i].isDeleted() : placeholders[i]; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
497 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
498 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
499 return true; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
500 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
501 |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
502 private static boolean checkConstantArgument(MetaAccessProvider runtime, final ResolvedJavaMethod method, Signature signature, int i, String name, Object arg, Kind kind) { |
7141
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
503 ResolvedJavaType type = signature.getParameterType(i, method.getDeclaringClass()).resolve(method.getDeclaringClass()); |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
504 if (runtime.lookupJavaType(WordBase.class).isAssignableFrom(type)) { |
7141
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
505 assert arg instanceof Constant : method + ": word constant parameters must be passed boxed in a Constant value: " + arg; |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
506 return true; |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
507 } |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7081
diff
changeset
|
508 if (kind == Kind.Object) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
509 assert arg == null || type.isInstance(Constant.forObject(arg)) : method + ": wrong value type for " + name + ": expected " + type.getName() + ", got " + arg.getClass().getName(); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
510 } else { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
511 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() : method + ": wrong value kind for " + name + ": expected " + kind + ", got " + |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
512 (arg == null ? "null" : arg.getClass().getSimpleName()); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
513 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
514 return true; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
515 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
516 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
517 private static boolean checkVarargs(MetaAccessProvider runtime, final ResolvedJavaMethod method, Signature signature, int i, String name, Varargs varargs) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6534
diff
changeset
|
518 ResolvedJavaType type = (ResolvedJavaType) signature.getParameterType(i, method.getDeclaringClass()); |
7060
06d5f450f32b
rename: ResolvedJavaType.isArrayClass() -> ResolvedJavaType.isArray()
Doug Simon <doug.simon@oracle.com>
parents:
7034
diff
changeset
|
519 assert type.isArray() : "varargs parameter must be an array type"; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
520 assert type.getComponentType().isAssignableFrom(runtime.lookupJavaType(varargs.componentType)) : "componentType for " + name + " not matching " + MetaUtil.toJavaName(type) + " instance: " + |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
521 varargs.componentType; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
522 return true; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
523 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
524 |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
525 /** |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
526 * The graph built from the snippet method. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
527 */ |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
528 private final StructuredGraph snippet; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
529 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
530 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
531 * The named parameters of this template that must be bound to values during instantiation. For |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
532 * a parameter that is still live after specialization, the value in this map is either a |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
533 * {@link LocalNode} instance or a {@link LocalNode} array. For an eliminated parameter, the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
534 * value is identical to the key. |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
535 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
536 private final Object[] parameters; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
537 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
538 /** |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
539 * The return node (if any) of the snippet. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
540 */ |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
541 private final ReturnNode returnNode; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
542 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
543 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
544 * Nodes that inherit the {@link StateSplit#stateAfter()} from the replacee during |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
545 * instantiation. |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
546 */ |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
547 private final ArrayList<StateSplit> sideEffectNodes; |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
548 |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
549 /** |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
550 * The nodes that inherit the {@link ValueNode#stamp()} from the replacee during instantiation. |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
551 */ |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
552 private final ArrayList<ValueNode> stampNodes; |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
553 |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
554 /** |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
555 * The nodes to be inlined when this specialization is instantiated. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
556 */ |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
557 private final ArrayList<Node> nodes; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
558 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
559 /** |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
560 * Gets the instantiation-time bindings to this template's parameters. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
561 * |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
562 * @return the map that will be used to bind arguments to parameters when inlining this template |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
563 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
564 private IdentityHashMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider runtime, Arguments args) { |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
565 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>(); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
566 assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")"; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
567 for (int i = 0; i < parameters.length; i++) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
568 Object parameter = parameters[i]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
569 assert parameter != null : this + " has no parameter named " + args.info.names[i]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
570 Object argument = args.values[i]; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
571 if (parameter instanceof LocalNode) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
572 if (argument instanceof ValueNode) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
573 replacements.put((LocalNode) parameter, (ValueNode) argument); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
574 } else { |
5540
a891c53a295b
Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5538
diff
changeset
|
575 Kind kind = ((LocalNode) parameter).kind(); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
576 assert argument != null || kind == Kind.Object : this + " cannot accept null for non-object parameter named " + args.info.names[i]; |
8908
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
577 Constant constant = forBoxed(argument, kind); |
5572
8f9c9d372e31
small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5547
diff
changeset
|
578 replacements.put((LocalNode) parameter, ConstantNode.forConstant(constant, runtime, replaceeGraph)); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
579 } |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7141
diff
changeset
|
580 } else if (parameter instanceof LocalNode[]) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
581 LocalNode[] locals = (LocalNode[]) parameter; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
582 Varargs varargs = (Varargs) argument; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
583 int length = locals.length; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
584 List list = null; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
585 Object array = null; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
586 if (varargs.value instanceof List) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
587 list = (List) varargs.value; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
588 assert list.size() == length : length + " != " + list.size(); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
589 } else { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
590 array = varargs.value; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
591 assert array != null && array.getClass().isArray(); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
592 assert Array.getLength(array) == length : length + " != " + Array.getLength(array); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
593 } |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
594 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
595 for (int j = 0; j < length; j++) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
596 LocalNode local = locals[j]; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
597 assert local != null; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7271
diff
changeset
|
598 Object value = list != null ? list.get(j) : Array.get(array, j); |
6431
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
599 if (value instanceof ValueNode) { |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
600 replacements.put(local, (ValueNode) value); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
601 } else { |
8908
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
602 Constant constant = forBoxed(value, local.kind()); |
6431
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
603 ConstantNode element = ConstantNode.forConstant(constant, runtime, replaceeGraph); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
604 replacements.put(local, element); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
605 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
606 } |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7141
diff
changeset
|
607 } else { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
608 assert parameter == CONSTANT_PARAMETER || parameter == UNUSED_PARAMETER : "unexpected entry for parameter: " + args.info.names[i] + " -> " + parameter; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
609 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
610 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
611 return replacements; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
612 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
613 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
614 /** |
8908
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
615 * Converts a Java boxed value to a {@link Constant} of the right kind. This adjusts for the |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
616 * limitation that a {@link Local}'s kind is a {@linkplain Kind#getStackKind() stack kind} and |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
617 * so cannot be used for re-boxing primitives smaller than an int. |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
618 * |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
619 * @param argument a Java boxed value |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
620 * @param localKind the kind of the {@link Local} to which {@code argument} will be bound |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
621 */ |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
622 protected Constant forBoxed(Object argument, Kind localKind) { |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
623 assert localKind == localKind.getStackKind(); |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
624 if (localKind == Kind.Int && !(argument instanceof Integer)) { |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
625 if (argument instanceof Boolean) { |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
626 return Constant.forBoxed(Kind.Boolean, argument); |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
627 } |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
628 if (argument instanceof Byte) { |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
629 return Constant.forBoxed(Kind.Byte, argument); |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
630 } |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
631 if (argument instanceof Short) { |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
632 return Constant.forBoxed(Kind.Short, argument); |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
633 } |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
634 assert argument instanceof Character; |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
635 return Constant.forBoxed(Kind.Char, argument); |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
636 } |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
637 return Constant.forBoxed(localKind, argument); |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
638 } |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
639 |
b9fb1ecaad92
convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents:
8642
diff
changeset
|
640 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
641 * Logic for replacing a snippet-lowered node at its usages with the return value of the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
642 * snippet. An alternative to the {@linkplain SnippetTemplate#DEFAULT_REPLACER default} |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
643 * replacement logic can be used to handle mismatches between the stamp of the node being |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
644 * lowered and the stamp of the snippet's return value. |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
645 */ |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
646 public interface UsageReplacer { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
647 |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
648 /** |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
649 * Replaces all usages of {@code oldNode} with direct or indirect usages of {@code newNode}. |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
650 */ |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
651 void replace(ValueNode oldNode, ValueNode newNode); |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
652 } |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
653 |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
654 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
655 * Represents the default {@link UsageReplacer usage replacer} logic which simply delegates to |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
656 * {@link Node#replaceAtUsages(Node)}. |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
657 */ |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
658 public static final UsageReplacer DEFAULT_REPLACER = new UsageReplacer() { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
659 |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
660 @Override |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
661 public void replace(ValueNode oldNode, ValueNode newNode) { |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
662 oldNode.replaceAtUsages(newNode); |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
663 } |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
664 }; |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
665 |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
666 /** |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
667 * Replaces a given fixed node with this specialized snippet. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
668 * |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
669 * @param runtime |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
670 * @param replacee the node that will be replaced |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
671 * @param replacer object that replaces the usages of {@code replacee} |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
672 * @param args the arguments to be bound to the flattened positional parameters of the snippet |
6386
abeeb57b655d
added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
6302
diff
changeset
|
673 * @return the map of duplicated nodes (original -> duplicate) |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
674 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
675 public Map<Node, Node> instantiate(MetaAccessProvider runtime, FixedNode replacee, UsageReplacer replacer, Arguments args) { |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
676 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
677 // Inline the snippet nodes, replacing parameters with the given args in the process |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
678 String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}"; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
679 StructuredGraph snippetCopy = new StructuredGraph(name, snippet.method()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
680 StartNode entryPointNode = snippet.start(); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
681 FixedNode firstCFGNode = entryPointNode.next(); |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
682 StructuredGraph replaceeGraph = (StructuredGraph) replacee.graph(); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
683 IdentityHashMap<Node, Node> replacements = bind(replaceeGraph, runtime, args); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
684 Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, replacements); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
685 Debug.dump(replaceeGraph, "After inlining snippet %s", snippetCopy.method()); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
686 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
687 // Re-wire the control flow graph around the replacee |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
688 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
689 replacee.replaceAtPredecessor(firstCFGNodeDuplicate); |
8357
5fbb2df2b47f
Allow lowering of UnwindNode and ExceptionObjectNode. The HotSpot code still uses the old LIR lowering.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8178
diff
changeset
|
690 FixedNode next = null; |
5fbb2df2b47f
Allow lowering of UnwindNode and ExceptionObjectNode. The HotSpot code still uses the old LIR lowering.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8178
diff
changeset
|
691 if (replacee instanceof FixedWithNextNode) { |
5fbb2df2b47f
Allow lowering of UnwindNode and ExceptionObjectNode. The HotSpot code still uses the old LIR lowering.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8178
diff
changeset
|
692 FixedWithNextNode fwn = (FixedWithNextNode) replacee; |
5fbb2df2b47f
Allow lowering of UnwindNode and ExceptionObjectNode. The HotSpot code still uses the old LIR lowering.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8178
diff
changeset
|
693 next = fwn.next(); |
5fbb2df2b47f
Allow lowering of UnwindNode and ExceptionObjectNode. The HotSpot code still uses the old LIR lowering.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8178
diff
changeset
|
694 fwn.setNext(null); |
5fbb2df2b47f
Allow lowering of UnwindNode and ExceptionObjectNode. The HotSpot code still uses the old LIR lowering.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8178
diff
changeset
|
695 } |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
696 |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
697 if (replacee instanceof StateSplit) { |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
698 for (StateSplit sideEffectNode : sideEffectNodes) { |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
699 assert ((StateSplit) replacee).hasSideEffect(); |
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
700 Node sideEffectDup = duplicates.get(sideEffectNode); |
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
701 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); |
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
702 } |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
703 } |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
704 for (ValueNode stampNode : stampNodes) { |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
705 Node stampDup = duplicates.get(stampNode); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
706 ((ValueNode) stampDup).setStamp(((ValueNode) replacee).stamp()); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
707 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
708 |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
709 // Replace all usages of the replacee with the value returned by the snippet |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
710 ValueNode returnValue = null; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
711 if (returnNode != null) { |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
712 if (returnNode.result() instanceof LocalNode) { |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
713 returnValue = (ValueNode) replacements.get(returnNode.result()); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
714 } else { |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
715 returnValue = (ValueNode) duplicates.get(returnNode.result()); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
716 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
717 assert returnValue != null || replacee.usages().isEmpty(); |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
718 replacer.replace(replacee, returnValue); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
719 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
720 Node returnDuplicate = duplicates.get(returnNode); |
6653
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
721 if (returnDuplicate.isAlive()) { |
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
722 returnDuplicate.clearInputs(); |
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
723 returnDuplicate.replaceAndDelete(next); |
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
724 } |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
725 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
726 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
727 // Remove the replacee from its graph |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
728 replacee.clearInputs(); |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
729 replacee.replaceAtUsages(null); |
6588
b89b5038ad7e
removed _'s from method names in CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
6574
diff
changeset
|
730 GraphUtil.killCFG(replacee); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
731 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
732 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this); |
6386
abeeb57b655d
added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
6302
diff
changeset
|
733 return duplicates; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
734 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
735 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
736 /** |
7141
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
737 * Gets a copy of the specialized graph. |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
738 */ |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
739 public StructuredGraph copySpecializedGraph() { |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
740 return snippet.copy(); |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
741 } |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
742 |
c85aecfee9e4
made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents:
7099
diff
changeset
|
743 /** |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
744 * Replaces a given floating node with this specialized snippet. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7313
diff
changeset
|
745 * |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
746 * @param runtime |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
747 * @param replacee the node that will be replaced |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
748 * @param replacer object that replaces the usages of {@code replacee} |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
749 * @param args the arguments to be bound to the flattened positional parameters of the snippet |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
750 */ |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
751 public void instantiate(MetaAccessProvider runtime, FloatingNode replacee, UsageReplacer replacer, LoweringTool tool, Arguments args) { |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
752 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
753 // Inline the snippet nodes, replacing parameters with the given args in the process |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
754 String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}"; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
755 StructuredGraph snippetCopy = new StructuredGraph(name, snippet.method()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
756 StartNode entryPointNode = snippet.start(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
757 FixedNode firstCFGNode = entryPointNode.next(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
758 StructuredGraph replaceeGraph = (StructuredGraph) replacee.graph(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
759 IdentityHashMap<Node, Node> replacements = bind(replaceeGraph, runtime, args); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
760 Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, replacements); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
761 Debug.dump(replaceeGraph, "After inlining snippet %s", snippetCopy.method()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
762 |
8178
67ee3325c285
added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
763 FixedWithNextNode lastFixedNode = tool.lastFixedNode(); |
67ee3325c285
added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
764 assert lastFixedNode != null && lastFixedNode.isAlive() : replaceeGraph; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
765 FixedNode next = lastFixedNode.next(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
766 lastFixedNode.setNext(null); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
767 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
768 replaceeGraph.addAfterFixed(lastFixedNode, firstCFGNodeDuplicate); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
769 |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
770 if (replacee instanceof StateSplit) { |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
771 for (StateSplit sideEffectNode : sideEffectNodes) { |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
772 assert ((StateSplit) replacee).hasSideEffect(); |
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
773 Node sideEffectDup = duplicates.get(sideEffectNode); |
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
774 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); |
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
775 } |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
776 } |
7546
727e869891fc
let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
777 for (ValueNode stampNode : stampNodes) { |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
778 Node stampDup = duplicates.get(stampNode); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
779 ((ValueNode) stampDup).setStamp(((ValueNode) replacee).stamp()); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
780 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
781 |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
782 // Replace all usages of the replacee with the value returned by the snippet |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
783 assert returnNode != null : replaceeGraph; |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
784 ValueNode returnValue = null; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
785 if (returnNode.result() instanceof LocalNode) { |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
786 returnValue = (ValueNode) replacements.get(returnNode.result()); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
787 } else { |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
788 returnValue = (ValueNode) duplicates.get(returnNode.result()); |
5670
29684ae5a194
Make sure snippet instentiation doesn't produce dead nodes and remove redundant DCE
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5574
diff
changeset
|
789 } |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
790 assert returnValue != null || replacee.usages().isEmpty(); |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
791 replacer.replace(replacee, returnValue); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
792 |
8178
67ee3325c285
added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
793 tool.setLastFixedNode(null); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
794 Node returnDuplicate = duplicates.get(returnNode); |
6653
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
795 if (returnDuplicate.isAlive()) { |
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
796 returnDuplicate.clearInputs(); |
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
797 returnDuplicate.replaceAndDelete(next); |
8178
67ee3325c285
added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
798 if (next != null && next.predecessor() instanceof FixedWithNextNode) { |
67ee3325c285
added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
799 tool.setLastFixedNode((FixedWithNextNode) next.predecessor()); |
67ee3325c285
added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents:
8175
diff
changeset
|
800 } |
6653
2d5407ae1ac4
intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents:
6588
diff
changeset
|
801 } |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
802 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
803 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this); |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
804 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
805 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
806 @Override |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
807 public String toString() { |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
808 StringBuilder buf = new StringBuilder(snippet.toString()).append('('); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
809 String sep = ""; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
810 for (int i = 0; i < parameters.length; i++) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
811 String name = "[" + i + "]"; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
812 Object value = parameters[i]; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
813 buf.append(sep); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
814 sep = ", "; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
815 if (value == null) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
816 buf.append("<null> ").append(name); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
817 } else if (value == UNUSED_PARAMETER) { |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7141
diff
changeset
|
818 buf.append("<unused> ").append(name); |
9038
8802f66cba62
Fix bug in graph dumping.
Roland Schatz <roland.schatz@oracle.com>
parents:
9015
diff
changeset
|
819 } else if (value == CONSTANT_PARAMETER) { |
8802f66cba62
Fix bug in graph dumping.
Roland Schatz <roland.schatz@oracle.com>
parents:
9015
diff
changeset
|
820 buf.append("<constant> ").append(name); |
7271
9c06e8bd8769
added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents:
7141
diff
changeset
|
821 } else if (value instanceof LocalNode) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
822 LocalNode local = (LocalNode) value; |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6534
diff
changeset
|
823 buf.append(local.kind().getJavaName()).append(' ').append(name); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
824 } else { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
825 LocalNode[] locals = (LocalNode[]) value; |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6534
diff
changeset
|
826 String kind = locals.length == 0 ? "?" : locals[0].kind().getJavaName(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
827 buf.append(kind).append('[').append(locals.length).append("] ").append(name); |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
828 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
829 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
830 return buf.append(')').toString(); |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
831 } |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
832 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
833 private static boolean checkTemplate(MetaAccessProvider runtime, Arguments args, ResolvedJavaMethod method, Signature signature) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
834 for (int i = 0; i < args.info.getParameterCount(); i++) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
835 if (args.info.isConstantParameter(i)) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6534
diff
changeset
|
836 Kind kind = signature.getParameterKind(i); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
837 assert checkConstantArgument(runtime, method, signature, i, args.info.names[i], args.values[i], kind); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
838 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
839 } else if (args.info.isVarargsParameter(i)) { |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
840 assert args.values[i] instanceof Varargs; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
841 Varargs varargs = (Varargs) args.values[i]; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8959
diff
changeset
|
842 assert checkVarargs(runtime, method, signature, i, args.info.names[i], varargs); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
843 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
844 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
845 return true; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
846 } |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
847 } |