annotate graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 5574:13624e51918a

allow null for @ConstantParameter values
author Doug Simon <doug.simon@oracle.com>
date Tue, 12 Jun 2012 23:05:42 +0200
parents 8f9c9d372e31
children 29684ae5a194
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
30 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5503
diff changeset
31 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
32 import com.oracle.graal.compiler.loop.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.compiler.phases.*;
6ec0857cdf46 added support for snippet templates which are snippet 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.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
35 import com.oracle.graal.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
36 import com.oracle.graal.graph.Node.Verbosity;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.*;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
38 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
39 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
40 import com.oracle.graal.nodes.util.*;
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.Multiple;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
43 import com.oracle.graal.snippets.Snippet.Parameter;
5466
af07e798947d lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5428
diff changeset
44 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
45
6ec0857cdf46 added support for snippet templates which are snippet 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 * 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
48 * 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
49 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
50 * 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
51 */
6ec0857cdf46 added support for snippet templates which are snippet 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 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
53
6ec0857cdf46 added support for snippet templates which are snippet 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 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
55 * 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
56 * 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
57 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
58 * @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
59 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
60 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
61 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
62 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
63 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
64
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
65 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
66 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
67 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
68 }
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 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
71 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
72 map.put(name, value);
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
73 hash = hash ^ name.hashCode();
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
74 if (value != null) {
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
75 hash *= (value.hashCode() + 1);
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
76 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
77 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
78 }
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 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
81 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
82 }
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 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
85 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
86 }
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 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
89 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
90 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
91 }
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 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
94 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
95 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
96 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
97 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
98 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
99 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
100 }
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 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
103 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
104 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
105 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
106
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
107 @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
108 public String toString() {
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
109 return CodeUtil.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
110 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
111 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
112
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
113 /**
5484
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
114 * Arguments used to instantiate a template.
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
115 */
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
116 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
117 private final HashMap<String, Object> map = new HashMap<>();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
118
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
119 public static Arguments arguments(String name, Object value) {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
120 return new Arguments().add(name, value);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
121 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
122
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
123 public Arguments add(String name, Object value) {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
124 assert !map.containsKey(name);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
125 map.put(name, value);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
126 return this;
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
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
129 public int length() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
130 return map.size();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
131 }
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 @Override
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
134 public Iterator<Entry<String, Object>> iterator() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
135 return map.entrySet().iterator();
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 String toString() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
140 return map.toString();
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
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
144 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
145 * 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
146 */
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
147 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
148
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
149 private final ConcurrentHashMap<SnippetTemplate.Key, SnippetTemplate> templates = new ConcurrentHashMap<>();
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
150 private final CodeCacheProvider 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
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
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
153 public Cache(CodeCacheProvider 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
154 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
155 }
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 /**
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
158 * 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
159 */
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
160 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
161 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
162 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
163 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
164 @Override
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 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
166 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
167 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
168 });
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
169 //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
170 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
171 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
172 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
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
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
175 }
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
176
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
177 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
178 * 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
179 */
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
180 public SnippetTemplate(CodeCacheProvider runtime, SnippetTemplate.Key key) {
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
181 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
182 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
183 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
184
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
185 // Copy snippet graph, replacing @Constant parameters with given arguments
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
186 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
187 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
188 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
189 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
190
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
191 int parameterCount = signature.argumentCount(false);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
192 Parameter[] parameterAnnotations = new Parameter[parameterCount];
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
193 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
194 for (int i = 0; i < parameterCount; i++) {
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
195 ConstantParameter c = CodeUtil.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
196 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
197 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
198 Object arg = key.get(name);
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
199 Kind kind = signature.argumentKindAt(i);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
200 assert checkConstantArgument(method, signature, i, name, arg, kind);
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5547
diff changeset
201 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
202 } else {
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
203 Parameter p = CodeUtil.getParameterAnnotation(Parameter.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
204 assert p != null : method + ": parameter " + i + " must be annotated with either @Constant or @Parameter";
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
205 String name = p.value();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
206 if (p.multiple()) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
207 Object multiple = key.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
208 assert multiple != null : method + ": requires a Multiple 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
209 assert checkMultipleArgument(method, signature, i, name, multiple);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
210 Object array = ((Multiple) multiple).array;
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
211 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
212 replacements.put(snippetGraph.getLocal(i), placeholder);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
213 placeholders[i] = placeholder;
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
214 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
215 parameterAnnotations[i] = p;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
216 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
217 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
218 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
219
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
220 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
221 if (!replacements.isEmpty()) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
222 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
223 }
5466
af07e798947d lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5428
diff changeset
224
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
225 // 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
226 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
227 for (int i = 0; i < parameterCount; i++) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
228 Parameter p = parameterAnnotations[i];
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
229 if (p != null) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
230 if (p.multiple()) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
231 assert snippetCopy.getLocal(i) == null;
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
232 Object array = ((Multiple) key.get(p.value())).array;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
233 int length = Array.getLength(array);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
234 LocalNode[] locals = new LocalNode[length];
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
235 Stamp stamp = StampFactory.forKind(runtime.getResolvedJavaType(array.getClass().getComponentType()).kind());
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
236 for (int j = 0; j < length; j++) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
237 assert (parameterCount & 0xFFFF) == parameterCount;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
238 int idx = i << 16 | j;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
239 LocalNode local = snippetCopy.unique(new LocalNode(idx, stamp));
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
240 locals[j] = local;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
241 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
242 parameters.put(p.value(), locals);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
243
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
244 ConstantNode placeholder = placeholders[i];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
245 assert placeholder != null;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
246 for (Node usage : placeholder.usages().snapshot()) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
247 if (usage instanceof LoadIndexedNode) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
248 LoadIndexedNode loadIndexed = (LoadIndexedNode) usage;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
249 Debug.dump(snippetCopy, "Before replacing %s", loadIndexed);
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
250 LoadSnippetParameterNode loadSnippetParameter = snippetCopy.add(new LoadSnippetParameterNode(locals, loadIndexed.index(), loadIndexed.stamp()));
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
251 snippetCopy.replaceFixedWithFixed(loadIndexed, loadSnippetParameter);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
252 Debug.dump(snippetCopy, "After replacing %s", loadIndexed);
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
253 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
254 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
255 } else {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
256 LocalNode local = snippetCopy.getLocal(i);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
257 assert local != null;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
258 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
259 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
260 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
261 }
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
262
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
263 // 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
264 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
265 do {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
266 exploded = false;
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
267 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
268 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop altogether
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
269 LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
270 if (loopBegin != null) {
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
271 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
272 int mark = snippetCopy.getMark();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
273 LoopTransformations.fullUnroll(loop);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
274 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
275 }
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
276 FixedNode explodeLoopNext = explodeLoop.next();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
277 explodeLoop.clearSuccessors();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
278 explodeLoop.replaceAtPredecessor(explodeLoopNext);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
279 explodeLoop.replaceAtUsages(null);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
280 GraphUtil.killCFG(explodeLoop);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
281 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
282 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
283 } 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
284
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
285 // 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
286 // of side-effects that prevent deoptimizing to a point before 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
287 for (Node node : snippetCopy.getNodes()) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
288 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
289 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
290 FrameState frameState = stateSplit.stateAfter();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
291 assert !stateSplit.hasSideEffect() : "snippets cannot contain side-effecting node " + node + "\n " + frameState.toString(Verbosity.Debugger);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
292 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
293 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
294 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
295 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
296 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
297
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
298 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
299
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
300 assert checkAllMultipleParameterPlaceholdersAreDeleted(parameterCount, placeholders);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
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 this.graph = 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
303 nodes = new ArrayList<>(graph.getNodeCount());
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
304 ReturnNode retNode = 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
305 StartNode entryPointNode = graph.start();
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
306 for (Node node : graph.getNodes()) {
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
307 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
308 // 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
309 } 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
310 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
311 if (node instanceof ReturnNode) {
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
312 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
313 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
314 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
315 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
316 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
317 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
318
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
319 private static boolean checkAllMultipleParameterPlaceholdersAreDeleted(int parameterCount, ConstantNode[] placeholders) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
320 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
321 if (placeholders[i] != null) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
322 assert placeholders[i].isDeleted() : placeholders[i];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
323 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
324 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
325 return true;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
326 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
327
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
328 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
329 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
330 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
331 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
332 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
333 } else {
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
334 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() :
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
335 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
336 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
337 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
338 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
339
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
340 private static boolean checkMultipleArgument(final ResolvedJavaMethod method, Signature signature, int i, String name, Object multiple) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
341 assert multiple instanceof Multiple;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
342 Object arg = ((Multiple) multiple).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
343 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
344 Class< ? > javaType = type.toJava();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
345 assert javaType.isArray() : "multiple parameter must be an array type";
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
346 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
347 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
348 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
349
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
350 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
351 * 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
352 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
353 private final StructuredGraph graph;
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
354
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
355 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
356 * 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
357 * 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
358 */
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
359 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
360
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
361 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
362 * 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
363 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
364 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
365
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
366 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
367 * 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
368 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
369 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
370
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
371 /**
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
372 * 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
373 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
374 * @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
375 */
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
376 private IdentityHashMap<Node, Node> bind(StructuredGraph replaceeGraph, CodeCacheProvider 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
377 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
378
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
379 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
380 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
381 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
382 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
383 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
384 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
385 if (argument instanceof ValueNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
386 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
387 } else {
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
388 Kind kind = ((LocalNode) parameter).kind();
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5531
diff changeset
389 Constant constant = Constant.forBoxed(kind, argument);
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5547
diff changeset
390 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
391 }
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
392 } else {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
393 assert parameter instanceof LocalNode[];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
394 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
395 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
396 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
397 int length = locals.length;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
398 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
399 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
400 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
401 assert local != null;
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5531
diff changeset
402 Constant constant = Constant.forBoxed(local.kind(), Array.get(array, j));
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5547
diff changeset
403 ConstantNode element = 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
404 replacements.put(local, element);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
405 }
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
406 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
407 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
408 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
409 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
410
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
411 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
412 * Replaces a given node with this specialized 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
413 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
414 * @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
415 * @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
416 * @param anchor the control flow 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
417 * @param args the arguments to be bound to the flattened positional parameters 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
418 */
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
419 public void instantiate(CodeCacheProvider 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
420 Node replacee,
5484
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
421 FixedWithNextNode anchor, 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
422
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
423 // Inline the snippet nodes, replacing parameters with the given args in the process
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
424 String name = graph.name == null ? "{copy}" : graph.name + "{copy}";
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
425 StructuredGraph graphCopy = new StructuredGraph(name, graph.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
426 StartNode entryPointNode = graph.start();
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
427 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
428 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
429 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
430 Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, 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
431 Debug.dump(replaceeGraph, "After inlining snippet %s", graphCopy.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
432
6ec0857cdf46 added support for snippet templates which are snippet 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 // 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
434 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
5487
9743ae819f73 Move virtual chain help methods from SuperBlock to GraphUtil
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5467
diff changeset
435 anchor.replaceAtPredecessor(firstCFGNodeDuplicate);
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
436 FixedNode next = anchor.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
437 anchor.setNext(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
438
6ec0857cdf46 added support for snippet templates which are snippet 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 // 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
440 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
441 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
442 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
443 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
444 } 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
445 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
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 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
448 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
449
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
450 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
451 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
452 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
453 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
454
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
455 // 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
456 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
457 replacee.replaceAtUsages(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
458 if (replacee instanceof FixedNode) {
6ec0857cdf46 added support for snippet templates which are snippet 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 GraphUtil.killCFG((FixedNode) 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
460 } 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
461 replacee.safeDelete();
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
462 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
463
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
464 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
465 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
466
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
467 @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
468 public String 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
469 StringBuilder buf = new StringBuilder(graph.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
470 String sep = "";
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
471 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
472 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
473 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
474 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
475 sep = ", ";
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
476 if (value instanceof LocalNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
477 LocalNode local = (LocalNode) value;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
478 buf.append(local.kind().name()).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
479 } else {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
480 LocalNode[] locals = (LocalNode[]) value;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
481 String kind = locals.length == 0 ? "?" : locals[0].kind().name();
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
482 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
483 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
484 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
485 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
486 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
487 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
488