Mercurial > hg > truffle
annotate graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 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.
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Mon, 08 Oct 2012 19:34:32 -0700 |
parents | ee651c726397 |
children | 2463eb24b644 |
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 */ |
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
|
23 package com.oracle.graal.snippets; |
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.*; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
27 import java.util.Map.Entry; |
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
|
28 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
|
29 |
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.*; |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
36 import com.oracle.graal.nodes.extended.*; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
37 import com.oracle.graal.nodes.java.*; |
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.*; |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5531
diff
changeset
|
41 import com.oracle.graal.snippets.Snippet.ConstantParameter; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
42 import com.oracle.graal.snippets.Snippet.Parameter; |
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
|
43 import com.oracle.graal.snippets.Snippet.Varargs; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
44 import com.oracle.graal.snippets.Snippet.VarargsParameter; |
5466
af07e798947d
lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5428
diff
changeset
|
45 import com.oracle.graal.snippets.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
|
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 /** |
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
|
48 * A snippet template is a graph created by parsing a snippet method and then |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5531
diff
changeset
|
49 * specialized by binding constants to the snippet's {@link ConstantParameter} parameters. |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
50 * |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
51 * Snippet templates can be managed in a {@link Cache}. |
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 /** |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
56 * A snippet template key encapsulates the method from which a snippet was built |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
57 * and the arguments used to specialized the snippet. |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
58 * |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
59 * @see Cache |
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
|
60 */ |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
61 public static class Key implements Iterable<Map.Entry<String, Object>> { |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
62 public final ResolvedJavaMethod method; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
63 private final HashMap<String, Object> map = new HashMap<>(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
64 private int hash; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
65 |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
66 public Key(ResolvedJavaMethod method) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
67 this.method = method; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
68 this.hash = method.hashCode(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
69 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
70 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
71 public Key add(String name, Object value) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
72 assert !map.containsKey(name); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
73 map.put(name, value); |
5574
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
74 hash = hash ^ name.hashCode(); |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
75 if (value != null) { |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
76 hash *= (value.hashCode() + 1); |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
77 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
78 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
|
79 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
80 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
81 public int length() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
82 return map.size(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
83 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
84 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
85 public Object get(String name) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
86 return map.get(name); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
87 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
88 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
89 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
90 public Iterator<Entry<String, Object>> iterator() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
91 return map.entrySet().iterator(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
92 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
93 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
94 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
95 public boolean equals(Object obj) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
96 if (obj instanceof Key) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
97 Key other = (Key) obj; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
98 return other.method == method && other.map.equals(map); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
99 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
100 return false; |
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 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
103 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
104 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
|
105 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
|
106 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
107 |
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
|
108 @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
|
109 public String toString() { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5681
diff
changeset
|
110 return MetaUtil.format("%h.%n", method) + map.toString(); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
111 } |
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
|
112 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
113 public Set<String> names() { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
114 return map.keySet(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
115 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
116 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
117 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
118 /** |
5484
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
119 * Arguments used to instantiate a template. |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
120 */ |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
121 public static class Arguments implements Iterable<Map.Entry<String, Object>> { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
122 private final HashMap<String, Object> map = new HashMap<>(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
123 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
124 public static Arguments arguments(String name, Object value) { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
125 return new Arguments().add(name, value); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
126 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
127 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
128 public Arguments add(String name, Object value) { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
129 assert !map.containsKey(name); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
130 map.put(name, value); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
131 return this; |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
132 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
133 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
134 public int length() { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
135 return map.size(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
136 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
137 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
138 @Override |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
139 public Iterator<Entry<String, Object>> iterator() { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
140 return map.entrySet().iterator(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
141 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
142 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
143 @Override |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
144 public String toString() { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
145 return map.toString(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
146 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
147 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
148 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
149 /** |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
150 * A collection of snippet templates accessed by a {@link Key} instance. |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
151 */ |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
152 public static class Cache { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
153 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
154 private final ConcurrentHashMap<SnippetTemplate.Key, SnippetTemplate> templates = new ConcurrentHashMap<>(); |
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
|
155 private final MetaAccessProvider runtime; |
5481
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 |
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
|
158 public Cache(MetaAccessProvider runtime) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
159 this.runtime = runtime; |
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
|
160 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
161 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
162 /** |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
163 * 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
|
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 public SnippetTemplate get(final SnippetTemplate.Key key) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
166 SnippetTemplate template = templates.get(key); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
167 if (template == null) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
168 template = Debug.scope("SnippetSpecialization", key.method, new Callable<SnippetTemplate>() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
169 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
170 public SnippetTemplate call() throws Exception { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
171 return new SnippetTemplate(runtime, key); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
172 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
173 }); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
174 //System.out.println(key + " -> " + template); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
175 templates.put(key, template); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
176 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
177 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
|
178 } |
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
|
179 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
180 |
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
|
181 public abstract static class AbstractTemplates<T extends SnippetsInterface> { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
182 protected final Cache cache; |
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
|
183 protected final MetaAccessProvider runtime; |
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
|
184 protected Class<T> snippetsClass; |
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
|
185 public AbstractTemplates(MetaAccessProvider runtime, Class<T> snippetsClass) { |
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
|
186 this.runtime = 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
|
187 this.snippetsClass = snippetsClass; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
188 this.cache = new Cache(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
|
189 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
190 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
191 protected ResolvedJavaMethod snippet(String name, Class<?>... parameterTypes) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
192 try { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
193 ResolvedJavaMethod snippet = runtime.getResolvedJavaMethod(snippetsClass.getDeclaredMethod(name, parameterTypes)); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
194 assert snippet.getAnnotation(Snippet.class) != null : "snippet is not annotated with @" + Snippet.class.getSimpleName(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
195 return 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
|
196 } catch (NoSuchMethodException e) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
197 throw new GraalInternalError(e); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
198 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
199 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
200 } |
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
|
201 |
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
|
202 /** |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
203 * 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
|
204 */ |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
205 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
|
206 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
|
207 if (p != null) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
208 return true; |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
209 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
210 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
211 return false; |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
212 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
213 |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
214 /** |
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
|
215 * 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
|
216 */ |
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
|
217 public SnippetTemplate(MetaAccessProvider runtime, SnippetTemplate.Key key) { |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
218 ResolvedJavaMethod method = key.method; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
219 assert Modifier.isStatic(method.accessFlags()) : "snippet method must be static: " + method; |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
220 Signature signature = method.signature(); |
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
|
221 |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
222 // 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
|
223 StructuredGraph snippetGraph = (StructuredGraph) method.compilerStorage().get(Graph.class); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
224 StructuredGraph snippetCopy = new StructuredGraph(snippetGraph.name, snippetGraph.method()); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
225 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
226 replacements.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
|
227 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
228 int parameterCount = signature.argumentCount(false); |
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
|
229 assert checkTemplate(key, parameterCount, method, signature); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
230 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
231 Parameter[] parameterAnnotations = new Parameter[parameterCount]; |
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
|
232 VarargsParameter[] varargsParameterAnnotations = new VarargsParameter[parameterCount]; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
233 ConstantNode[] placeholders = new ConstantNode[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
|
234 for (int i = 0; i < parameterCount; i++) { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5681
diff
changeset
|
235 ConstantParameter c = MetaUtil.getParameterAnnotation(ConstantParameter.class, i, method); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
236 if (c != null) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
237 String name = c.value(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
238 Object arg = key.get(name); |
5540
a891c53a295b
Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5538
diff
changeset
|
239 Kind kind = signature.argumentKindAt(i); |
5572
8f9c9d372e31
small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5547
diff
changeset
|
240 replacements.put(snippetGraph.getLocal(i), ConstantNode.forConstant(Constant.forBoxed(kind, arg), runtime, 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
|
241 } else { |
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
|
242 VarargsParameter vp = MetaUtil.getParameterAnnotation(VarargsParameter.class, i, 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
|
243 if (vp != 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
|
244 String name = vp.value(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
245 Object array = ((Varargs) key.get(name)).array; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
246 ConstantNode placeholder = ConstantNode.forObject(array, runtime, snippetCopy); |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
247 replacements.put(snippetGraph.getLocal(i), placeholder); |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
248 placeholders[i] = placeholder; |
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
|
249 varargsParameterAnnotations[i] = vp; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
250 } else { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
251 parameterAnnotations[i] = MetaUtil.getParameterAnnotation(Parameter.class, i, 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
|
252 } |
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 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
254 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
255 snippetCopy.addDuplicates(snippetGraph.getNodes(), 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
|
256 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
257 Debug.dump(snippetCopy, "Before specialization"); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
258 if (!replacements.isEmpty()) { |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
259 // Do deferred intrinsification of node intrinsics |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
260 new SnippetIntrinsificationPhase(runtime, new BoxingMethodPool(runtime), false).apply(snippetCopy); |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
261 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
262 new CanonicalizerPhase(null, runtime, null, 0, null).apply(snippetCopy); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
263 } |
5466
af07e798947d
lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5428
diff
changeset
|
264 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
265 // Gather the template parameters |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
266 parameters = new HashMap<>(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
267 for (int i = 0; i < parameterCount; 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
|
268 VarargsParameter vp = varargsParameterAnnotations[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
|
269 if (vp != 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
|
270 assert snippetCopy.getLocal(i) == 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
|
271 Object array = ((Varargs) key.get(vp.value())).array; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
272 int length = Array.getLength(array); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
273 LocalNode[] locals = new LocalNode[length]; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
274 Stamp stamp = StampFactory.forKind(runtime.getResolvedJavaType(array.getClass().getComponentType()).kind()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
281 parameters.put(vp.value(), locals); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
282 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 } |
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
|
293 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
294 } else { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
295 Parameter p = parameterAnnotations[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
|
296 if (p != null) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
297 LocalNode local = snippetCopy.getLocal(i); |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
298 assert local != null; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
299 parameters.put(p.value(), 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
|
300 } |
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
|
301 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
302 } |
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
|
303 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
304 // 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
|
305 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
|
306 do { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
307 exploded = false; |
5490 | 308 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first(); |
309 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop altogether | |
310 LoopBeginNode loopBegin = explodeLoop.findLoopBegin(); | |
311 if (loopBegin != null) { | |
312 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin); | |
313 int mark = snippetCopy.getMark(); | |
5681
7482f7d08455
Don't try to fold conditions when there is no runtime available
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5670
diff
changeset
|
314 LoopTransformations.fullUnroll(loop, runtime); |
5490 | 315 new CanonicalizerPhase(null, runtime, null, 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
|
316 } |
5490 | 317 FixedNode explodeLoopNext = explodeLoop.next(); |
318 explodeLoop.clearSuccessors(); | |
319 explodeLoop.replaceAtPredecessor(explodeLoopNext); | |
320 explodeLoop.replaceAtUsages(null); | |
321 GraphUtil.killCFG(explodeLoop); | |
322 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
|
323 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
324 } 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
|
325 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
326 // 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
|
327 // of side-effects that prevent deoptimizing to a point before the snippet). |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
328 Node curSideEffectNode = null; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
329 Node curStampNode = null; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
330 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
|
331 if (node instanceof ValueNode && ((ValueNode) node).stamp() == StampFactory.forNodeIntrinsic()) { |
6496
16d1411409b4
moved AMD64 specific code into com.oracle.graal.compiler.amd64
Doug Simon <doug.simon@oracle.com>
parents:
6449
diff
changeset
|
332 assert curStampNode == null : "Currently limited to one stamp node (but this can be converted to a List if necessary)"; |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
333 curStampNode = node; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
334 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 if (stateSplit.hasSideEffect()) { |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
339 assert curSideEffectNode == null : "Currently limited to one side-effecting node (but this can be converted to a List if necessary)"; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
340 curSideEffectNode = node; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
341 } |
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 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
|
343 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
|
344 } |
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 } |
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
|
346 } |
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
|
347 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
348 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
|
349 |
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
|
350 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
|
351 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
356 Map<Integer, JumpNode[]> jumpsMap = new HashMap<>(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
357 for (JumpNode jump : snippet.getNodes().filter(JumpNode.class).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
|
358 FixedNode next = jump.next(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
359 |
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
|
360 // Remove the nodes after the jump |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
361 jump.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
|
362 GraphUtil.killCFG(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
|
363 JumpNode[] jumpsForIndex = jumpsMap.get(jump.successorIndex()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
364 if (jumpsForIndex == 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
|
365 jumpsMap.put(jump.successorIndex(), new JumpNode[] {jump}); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
366 } else { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
367 jumpsForIndex = Arrays.copyOf(jumpsForIndex, jumpsForIndex.length + 1); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
368 jumpsForIndex[jumpsForIndex.length - 1] = jump; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
369 jumpsMap.put(jump.successorIndex(), jumpsForIndex); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
370 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
371 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
372 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
373 this.jumps = new JumpNode[jumpsMap.size()][]; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
374 for (Map.Entry<Integer, JumpNode[]> e : jumpsMap.entrySet()) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
375 int successorIndex = e.getKey(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
376 assert successorIndex >= 0 && successorIndex < this.jumps.length; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
377 assert this.jumps[successorIndex] == 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
|
378 this.jumps[successorIndex] = e.getValue(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
379 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
380 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
381 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
|
382 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
383 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
|
384 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
|
385 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
|
386 // 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
|
387 } 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
|
388 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
|
389 if (node instanceof ReturnNode) { |
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
|
390 assert this.jumps.length == 0 : "snippet with Jump node(s) cannot have a return node"; |
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
|
391 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
|
392 } |
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
|
393 } |
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
|
394 } |
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
|
395 |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
396 this.sideEffectNode = curSideEffectNode; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
397 this.stampNode = curStampNode; |
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
|
398 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
|
399 } |
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
|
400 |
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
|
401 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
|
402 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
|
403 if (placeholders[i] != null) { |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
404 assert placeholders[i].isDeleted() : placeholders[i]; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
405 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
406 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
407 return true; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
408 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
409 |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
410 private static boolean checkConstantArgument(final ResolvedJavaMethod method, Signature signature, int i, String name, Object arg, Kind kind) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
411 if (kind.isObject()) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
412 Class<?> type = signature.argumentTypeAt(i, method.holder()).resolve(method.holder()).toJava(); |
5574
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
413 assert arg == null || type.isInstance(arg) : |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
414 method + ": wrong value type for " + name + ": expected " + type.getName() + ", got " + arg.getClass().getName(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
415 } else { |
5574
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
416 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() : |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
417 method + ": wrong value kind for " + name + ": expected " + kind + ", got " + (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
|
418 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
419 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
|
420 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
421 |
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
|
422 private static boolean checkVarargs(final ResolvedJavaMethod method, Signature signature, int i, String name, Varargs varargs) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
423 Object arg = varargs.array; |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
424 ResolvedJavaType type = (ResolvedJavaType) signature.argumentTypeAt(i, method.holder()); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
425 Class< ? > javaType = type.toJava(); |
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
|
426 assert javaType.isArray() : "varargs parameter must be an array type"; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
427 assert javaType.isInstance(arg) : "value for " + name + " is not a " + javaType.getName() + " instance: " + arg; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
428 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
|
429 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
430 |
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
|
431 /** |
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
|
432 * 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
|
433 */ |
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
|
434 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
|
435 |
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
|
436 /** |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
437 * The named parameters of this template that must be bound to values during instantiation. |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
438 * Each value in this map is either a {@link LocalNode} instance or a {@link LocalNode} array. |
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
|
439 */ |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
440 private final Map<String, 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
|
441 |
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
|
442 /** |
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
|
443 * 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
|
444 */ |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
445 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
|
446 |
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
|
447 /** |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
448 * Node that inherits the {@link StateSplit#stateAfter()} from the replacee during instantiation. |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
449 */ |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
450 private final Node sideEffectNode; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
451 |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
452 /** |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
453 * Node that inherits the {@link ValueNode#stamp()} from the replacee during instantiation. |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
454 */ |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
455 private final Node stampNode; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
456 |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
457 /** |
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
|
458 * 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
|
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 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
|
461 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
462 /** |
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
|
463 * The {@link JumpNode}s in the snippet, indexed by {@linkplain ControlSplitNode#blockSuccessor(int) successor} indexes. |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
464 * There may be more than one jump per successor index which explains why this is a 2-dimensional array. |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
465 */ |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
466 private final JumpNode[][] jumps; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
467 |
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 /** |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
469 * Gets the instantiation-time bindings to this template's parameters. |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
470 * |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
471 * @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
|
472 */ |
6407
46d426e79bed
Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6386
diff
changeset
|
473 private IdentityHashMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider runtime, SnippetTemplate.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
|
474 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>(); |
6449
de9c0c4b7c9b
added sanity assertion to snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
475 assert args.length() == parameters.size() : "number of args (" + args.length() + ") != number of parameters (" + parameters.size() + ")"; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
476 for (Map.Entry<String, Object> e : args) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
477 String name = e.getKey(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
478 Object parameter = parameters.get(name); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
479 assert parameter != null : this + " has no parameter named " + name; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
480 Object argument = e.getValue(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
481 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
|
482 if (argument instanceof ValueNode) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
483 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
|
484 } else { |
5540
a891c53a295b
Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5538
diff
changeset
|
485 Kind kind = ((LocalNode) parameter).kind(); |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
486 assert argument != null || kind.isObject() : this + " cannot accept null for non-object parameter named " + name; |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5531
diff
changeset
|
487 Constant constant = Constant.forBoxed(kind, argument); |
5572
8f9c9d372e31
small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5547
diff
changeset
|
488 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
|
489 } |
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 } else { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
491 assert parameter instanceof LocalNode[]; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
492 LocalNode[] locals = (LocalNode[]) parameter; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
493 Object array = argument; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
494 assert array != null && array.getClass().isArray(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
495 int length = locals.length; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
496 assert Array.getLength(array) == length : length + " != " + Array.getLength(array); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
497 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
|
498 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
|
499 assert local != null; |
6431
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
500 Object value = Array.get(array, j); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
501 if (value instanceof ValueNode) { |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
502 replacements.put(local, (ValueNode) value); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
503 } else { |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
504 Constant constant = Constant.forBoxed(local.kind(), value); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
505 ConstantNode element = ConstantNode.forConstant(constant, runtime, replaceeGraph); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
506 replacements.put(local, element); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
507 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
508 } |
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
|
509 } |
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
|
510 } |
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
|
511 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
|
512 } |
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
|
513 |
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
|
514 /** |
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
|
515 * Replaces a given fixed node with this specialized 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
|
516 * |
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
|
517 * @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
|
518 * @param replacee the node that will be replaced |
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
|
519 * @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
|
520 * @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
|
521 */ |
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
|
522 public Map<Node, Node> instantiate(MetaAccessProvider runtime, |
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
|
523 FixedWithNextNode replacee, SnippetTemplate.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
|
524 |
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 // 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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 |
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 // 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
|
536 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
|
537 replacee.replaceAtPredecessor(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
|
538 FixedNode next = replacee.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
|
539 replacee.setNext(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
|
540 |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
541 if (sideEffectNode != null) { |
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
|
542 assert ((StateSplit) replacee).hasSideEffect(); |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
543 Node sideEffectDup = duplicates.get(sideEffectNode); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
544 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
545 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
546 if (stampNode != null) { |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
547 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
|
548 ((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
|
549 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
550 |
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
|
551 // Replace all usages of the replacee with the value returned by 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
|
552 Node returnValue = 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
|
553 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
|
554 if (returnNode.result() instanceof LocalNode) { |
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 returnValue = replacements.get(returnNode.result()); |
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 } 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
|
557 returnValue = duplicates.get(returnNode.result()); |
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 } |
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
|
559 assert returnValue != null || replacee.usages().isEmpty(); |
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
|
560 replacee.replaceAtUsages(returnValue); |
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
|
561 |
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
|
562 Node returnDuplicate = duplicates.get(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
|
563 returnDuplicate.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
|
564 returnDuplicate.replaceAndDelete(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
|
565 } |
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
|
566 |
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
|
567 // 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
|
568 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
|
569 replacee.replaceAtUsages(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
|
570 GraphUtil.killCFG(replacee); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
571 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
572 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
|
573 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
|
574 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
575 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
576 /** |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
577 * Replaces a given floating node with this specialized 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
|
578 * |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
579 * @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
|
580 * @param replacee the node that will be replaced |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
581 * @param lastFixedNode the CFG of the snippet is inserted after this node |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
582 * @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
|
583 */ |
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
|
584 public void instantiate(MetaAccessProvider runtime, |
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
|
585 FloatingNode replacee, |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
586 FixedWithNextNode lastFixedNode, SnippetTemplate.Arguments 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
|
587 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
588 // 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
|
589 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
598 assert lastFixedNode != null : replaceeGraph; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 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
|
603 |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
604 if (sideEffectNode != null) { |
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
|
605 assert ((StateSplit) replacee).hasSideEffect(); |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
606 Node sideEffectDup = duplicates.get(sideEffectNode); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
607 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
608 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
609 if (stampNode != null) { |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
610 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
|
611 ((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
|
612 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
613 |
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
|
614 // 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
|
615 assert returnNode != null : replaceeGraph; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
616 Node returnValue = 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
|
617 if (returnNode.result() instanceof LocalNode) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
618 returnValue = 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
|
619 } else { |
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
|
620 returnValue = 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
|
621 } |
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
|
622 assert returnValue != null || replacee.usages().isEmpty(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
623 replacee.replaceAtUsages(returnValue); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
624 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
625 Node returnDuplicate = duplicates.get(returnNode); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
626 returnDuplicate.clearInputs(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
627 returnDuplicate.replaceAndDelete(next); |
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
|
628 |
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
|
629 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
|
630 } |
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
|
631 |
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
|
632 /** |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
633 * Replaces a given floating node that is an input to a {@link ControlSplitNode} with this specialized 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
|
634 * The {@linkplain JumpNode jumps} in the snippet are connected to the successors of the control split node. |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
635 * |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
636 * @param replacee the node that will be replaced |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
637 * @param controlSplitNode the node replaced by this wheCFG of the snippet is inserted after this node |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
638 * @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
|
639 */ |
6407
46d426e79bed
Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6386
diff
changeset
|
640 public void instantiate(MetaAccessProvider runtime, |
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
|
641 FloatingNode replacee, |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
642 ControlSplitNode controlSplitNode, |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
643 SnippetTemplate.Arguments 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
|
644 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
645 // 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
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
655 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
656 int successorIndex = 0; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
657 for (JumpNode[] jumpsForIndex : jumps) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
658 fixEdge(controlSplitNode, jumpsForIndex, successorIndex++, duplicates); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
659 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
660 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
661 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
|
662 controlSplitNode.replaceAtPredecessor(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
|
663 controlSplitNode.replaceAtUsages(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
|
664 |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
665 assert sideEffectNode == null; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
666 assert stampNode == 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
|
667 assert returnNode == null : replaceeGraph; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
668 GraphUtil.killCFG(controlSplitNode); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
669 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
670 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
671 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
672 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
673 private static void fixEdge(ControlSplitNode splitAnchor, JumpNode[] jumpsForIndex, int successorIndex, Map<Node, Node> duplicates) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
674 BeginNode blockSuccessor = splitAnchor.blockSuccessor(successorIndex); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
675 splitAnchor.setBlockSuccessor(successorIndex, 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
|
676 if (jumpsForIndex.length == 1) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
677 JumpNode jump = (JumpNode) duplicates.get(jumpsForIndex[0]); |
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 jump.replaceAtPredecessor(blockSuccessor); |
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 GraphUtil.killCFG(jump); |
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 } else { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
681 StructuredGraph graph = (StructuredGraph) splitAnchor.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
|
682 MergeNode merge = graph.add(new MergeNode()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
683 for (int i = 0; i < jumpsForIndex.length; 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
|
684 EndNode end = graph.add(new EndNode()); |
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 JumpNode jump = (JumpNode) duplicates.get(jumpsForIndex[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
|
686 jump.replaceAtPredecessor(end); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
687 merge.addForwardEnd(end); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
688 GraphUtil.killCFG(jump); |
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 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
690 merge.setNext(blockSuccessor); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
691 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
692 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
693 |
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
|
694 @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
|
695 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
|
696 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
|
697 String sep = ""; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
698 for (Map.Entry<String, Object> e : parameters.entrySet()) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
699 String name = e.getKey(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
700 Object value = e.getValue(); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
701 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
|
702 sep = ", "; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
703 if (value instanceof LocalNode) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
704 LocalNode local = (LocalNode) value; |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
705 buf.append(local.kind().javaName).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
|
706 } else { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
707 LocalNode[] locals = (LocalNode[]) value; |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
708 String kind = locals.length == 0 ? "?" : locals[0].kind().javaName; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
709 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
|
710 } |
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 } |
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 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
|
713 } |
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
|
714 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
715 private static boolean checkTemplate(SnippetTemplate.Key key, int parameterCount, ResolvedJavaMethod method, Signature signature) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
716 Set<String> expected = new HashSet<>(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
717 for (int i = 0; i < parameterCount; 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
|
718 ConstantParameter c = MetaUtil.getParameterAnnotation(ConstantParameter.class, i, 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
|
719 VarargsParameter vp = MetaUtil.getParameterAnnotation(VarargsParameter.class, i, 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
|
720 Parameter p = MetaUtil.getParameterAnnotation(Parameter.class, i, 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
|
721 if (c != 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
|
722 assert vp == null && p == 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
|
723 String name = c.value(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
724 expected.add(name); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
725 Kind kind = signature.argumentKindAt(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
|
726 assert key.names().contains(name) : "key for " + method + " is missing \"" + name + "\": " + key; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
727 assert checkConstantArgument(method, signature, i, c.value(), key.get(name), kind); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
728 } else if (vp != 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
|
729 assert p == 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
|
730 String name = vp.value(); |
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 expected.add(name); |
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 assert key.names().contains(name) : "key for " + method + " is missing \"" + name + "\": " + key; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
733 assert key.get(name) instanceof Varargs; |
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 Varargs varargs = (Varargs) key.get(name); |
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 assert checkVarargs(method, signature, i, name, varargs); |
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 } else { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
737 assert p != null : method + ": parameter " + i + " must be annotated with exactly one of " + |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
738 "@" + ConstantParameter.class.getSimpleName() + " or " + |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
739 "@" + VarargsParameter.class.getSimpleName() + " or " + |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
740 "@" + Parameter.class.getSimpleName(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
741 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
742 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
743 if (!key.names().containsAll(expected)) { |
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 expected.removeAll(key.names()); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
745 assert false : expected + " missing from key " + key; |
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 } |
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 if (!expected.containsAll(key.names())) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
748 Set<String> namesCopy = new HashSet<>(key.names()); |
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 namesCopy.removeAll(expected); |
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 assert false : "parameter(s) " + namesCopy + " should be annotated with @" + ConstantParameter.class.getSimpleName() + |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
751 " or @" + VarargsParameter.class.getSimpleName() + " in " + MetaUtil.format("%H.%n(%p)", 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
|
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 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
|
754 } |
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
|
755 } |