annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java @ 14589:90b43a808eb0

use lazy names for snippet and replacements related debug values
author Doug Simon <doug.simon@oracle.com>
date Tue, 18 Mar 2014 18:02:45 +0100
parents e1a2302a42bc
children aa7bcf1fa423
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 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8414
diff changeset
23 package com.oracle.graal.replacements;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
25 import static com.oracle.graal.api.meta.LocationIdentity.*;
12733
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
26 import static com.oracle.graal.api.meta.MetaUtil.*;
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
27
12733
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
28 import java.io.*;
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
29 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
30 import java.util.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 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
32
7034
89df4e71940a More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7015
diff changeset
33 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
34 import com.oracle.graal.api.meta.*;
9187
cd2600a2336e Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents: 9099
diff changeset
35 import com.oracle.graal.api.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
36 import com.oracle.graal.debug.*;
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
37 import com.oracle.graal.debug.Debug.Scope;
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
38 import com.oracle.graal.debug.internal.*;
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
39 import com.oracle.graal.graph.*;
12728
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
40 import com.oracle.graal.graph.Graph.Mark;
6523
c8763a2deb0c rename packages in graal.loop to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6521
diff changeset
41 import com.oracle.graal.loop.*;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.nodes.*;
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
43 import com.oracle.graal.nodes.StructuredGraph.GuardsStage;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
44 import com.oracle.graal.nodes.calc.*;
9879
bf6943c12840 allow for late lowering of MemoryCheckpoints (handle usages by FloatingReads in SnippetTemplate)
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
45 import com.oracle.graal.nodes.extended.*;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
46 import com.oracle.graal.nodes.java.*;
8178
67ee3325c285 added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents: 8175
diff changeset
47 import com.oracle.graal.nodes.spi.*;
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
48 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
49 import com.oracle.graal.nodes.util.*;
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
50 import com.oracle.graal.phases.common.*;
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
51 import com.oracle.graal.phases.common.FloatingReadPhase.MemoryMapImpl;
11569
2f6734f8126a Avoid direct usage of CanonicalizerPhase.Instance in replacements processing.
Roland Schatz <roland.schatz@oracle.com>
parents: 11550
diff changeset
52 import com.oracle.graal.phases.tiers.*;
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
53 import com.oracle.graal.phases.util.*;
8642
1093255fd0d4 simplified registration of snippets
Doug Simon <doug.simon@oracle.com>
parents: 8637
diff changeset
54 import com.oracle.graal.replacements.Snippet.ConstantParameter;
1093255fd0d4 simplified registration of snippets
Doug Simon <doug.simon@oracle.com>
parents: 8637
diff changeset
55 import com.oracle.graal.replacements.Snippet.VarargsParameter;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8414
diff changeset
56 import com.oracle.graal.replacements.nodes.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
57 import com.oracle.graal.word.*;
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
58
6ec0857cdf46 added support for snippet templates which are snippet 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 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
60 * A snippet template is a graph created by parsing a snippet method and then specialized by binding
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
61 * constants to the snippet's {@link ConstantParameter} parameters.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
62 *
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
63 * Snippet templates can be managed in a cache maintained by {@link AbstractTemplates}.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 */
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 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
66
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 /**
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
68 * Holds the {@link ResolvedJavaMethod} of the snippet, together with some information about the
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
69 * method that needs to be computed only once. The {@link SnippetInfo} should be created once
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
70 * per snippet and then cached.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 */
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
72 public static class SnippetInfo {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
73
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
74 protected final ResolvedJavaMethod method;
9099
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
75 protected final boolean[] constantParameters;
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
76 protected final boolean[] varargsParameters;
12716
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
77
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
78 /**
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
79 * Times instantiations of all templates derived form this snippet.
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
80 *
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
81 * @see SnippetTemplate#instantiationTimer
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
82 */
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
83 private final DebugTimer instantiationTimer;
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
84
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
85 /**
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
86 * Counts instantiations of all templates derived from this snippet.
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
87 *
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
88 * @see SnippetTemplate#instantiationCounter
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
89 */
12507
d72864a2886e moved snippet timers/metrics from SnippetTemplate to SnippetInfo and added new metric for number of snippet specializations (i.e. number of SnippetTemplate objects created)
Doug Simon <doug.simon@oracle.com>
parents: 12362
diff changeset
90 private final DebugMetric instantiationCounter;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
91
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
92 /**
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
93 * The parameter names, taken from the local variables table. Only used for assertion
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
94 * checking, so use only within an assert statement.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
95 */
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
96 protected final String[] names;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
97
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
98 protected SnippetInfo(ResolvedJavaMethod method) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
99 this.method = method;
14589
90b43a808eb0 use lazy names for snippet and replacements related debug values
Doug Simon <doug.simon@oracle.com>
parents: 14548
diff changeset
100 instantiationCounter = Debug.metric(new MethodDebugValueName("SnippetInstantiationCount", method));
90b43a808eb0 use lazy names for snippet and replacements related debug values
Doug Simon <doug.simon@oracle.com>
parents: 14548
diff changeset
101 instantiationTimer = Debug.timer(new MethodDebugValueName("SnippetInstantiationTime", method));
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
102 assert Modifier.isStatic(method.getModifiers()) : "snippet method must be static: " + MetaUtil.format("%H.%n", method);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
103 int count = method.getSignature().getParameterCount(false);
9099
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
104 constantParameters = new boolean[count];
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
105 varargsParameters = new boolean[count];
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
106 for (int i = 0; i < count; i++) {
9099
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
107 constantParameters[i] = MetaUtil.getParameterAnnotation(ConstantParameter.class, i, method) != null;
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
108 varargsParameters[i] = MetaUtil.getParameterAnnotation(VarargsParameter.class, i, method) != null;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
109
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
110 assert !isConstantParameter(i) || !isVarargsParameter(i) : "Parameter cannot be annotated with both @" + ConstantParameter.class.getSimpleName() + " and @" +
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
111 VarargsParameter.class.getSimpleName();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
112 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
113
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
114 names = new String[count];
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
115 // Retrieve the names only when assertions are turned on.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
116 assert initNames();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
117 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
118
12733
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
119 private int templateCount;
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
120
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
121 void notifyNewTemplate() {
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
122 templateCount++;
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
123 if (UseSnippetTemplateCache && templateCount > MaxTemplatesPerSnippet) {
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
124 PrintStream err = System.err;
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
125 err.printf("WARNING: Exceeded %d templates for snippet %s%n" + " Adjust maximum with %s system property%n", MaxTemplatesPerSnippet, format("%h.%n(%p)", method),
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
126 MAX_TEMPLATES_PER_SNIPPET_PROPERTY_NAME);
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
127 }
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
128 }
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
129
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
130 private boolean initNames() {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
131 int slotIdx = 0;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
132 for (int i = 0; i < names.length; i++) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
133 names[i] = method.getLocalVariableTable().getLocal(slotIdx, 0).getName();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
134
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
135 Kind kind = method.getSignature().getParameterKind(i);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
136 slotIdx += kind == Kind.Long || kind == Kind.Double ? 2 : 1;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
137 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
138 return true;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
139 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
140
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
141 public ResolvedJavaMethod getMethod() {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
142 return method;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
143 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
144
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
145 public int getParameterCount() {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
146 return constantParameters.length;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
147 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
148
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
149 public boolean isConstantParameter(int paramIdx) {
9099
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
150 return constantParameters[paramIdx];
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
151 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
152
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
153 public boolean isVarargsParameter(int paramIdx) {
9099
ed81c74f92ff Cache boolean flags instead of full Annotation objects
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9049
diff changeset
154 return varargsParameters[paramIdx];
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
155 }
9417
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
156
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
157 public String getParameterName(int paramIdx) {
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
158 return names[paramIdx];
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
159 }
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
160 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
161
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
162 /**
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
163 * Values that are bound to the snippet method parameters. The methods {@link #add},
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
164 * {@link #addConst}, and {@link #addVarargs} must be called in the same order as in the
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
165 * signature of the snippet method. The parameter name is passed to the add methods for
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
166 * assertion checking, i.e., to enforce that the order matches. Which method needs to be called
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
167 * depends on the annotation of the snippet method parameter:
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
168 * <ul>
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
169 * <li>Use {@link #add} for a parameter without an annotation. The value is bound when the
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
170 * {@link SnippetTemplate} is {@link SnippetTemplate#instantiate instantiated}.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
171 * <li>Use {@link #addConst} for a parameter annotated with {@link ConstantParameter}. The value
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
172 * is bound when the {@link SnippetTemplate} is {@link SnippetTemplate#SnippetTemplate created}.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
173 * <li>Use {@link #addVarargs} for an array parameter annotated with {@link VarargsParameter}. A
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
174 * separate {@link SnippetTemplate} is {@link SnippetTemplate#SnippetTemplate created} for every
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
175 * distinct array length. The actual values are bound when the {@link SnippetTemplate} is
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
176 * {@link SnippetTemplate#instantiate instantiated}
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
177 * </ul>
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
178 */
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
179 public static class Arguments {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
180
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
181 protected final SnippetInfo info;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
182 protected final CacheKey cacheKey;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
183 protected final Object[] values;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
184
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
185 protected int nextParamIdx;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
186
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13287
diff changeset
187 public Arguments(SnippetInfo info, GuardsStage guardsStage, LoweringTool.LoweringStage loweringStage) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
188 this.info = info;
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13287
diff changeset
189 this.cacheKey = new CacheKey(info, guardsStage, loweringStage);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
190 this.values = new Object[info.getParameterCount()];
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
191 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
192
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
193 public Arguments add(String name, Object value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
194 assert check(name, false, false);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
195 values[nextParamIdx] = value;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
196 nextParamIdx++;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
197 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
198 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
199
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
200 public Arguments addConst(String name, Object value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
201 assert check(name, true, false);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
202 values[nextParamIdx] = value;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
203 cacheKey.setParam(nextParamIdx, value);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
204 nextParamIdx++;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
205 return this;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
206 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
207
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
208 public Arguments addVarargs(String name, Class componentType, Stamp argStamp, Object value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
209 assert check(name, false, true);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
210 Varargs varargs = new Varargs(componentType, argStamp, value);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
211 values[nextParamIdx] = varargs;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
212 // A separate template is necessary for every distinct array length
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
213 cacheKey.setParam(nextParamIdx, varargs.length);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
214 nextParamIdx++;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
215 return this;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
216 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
217
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
218 private boolean check(String name, boolean constParam, boolean varargsParam) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
219 assert nextParamIdx < info.getParameterCount() : "too many parameters: " + name + " " + this;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
220 assert info.names[nextParamIdx].equals(name) : "wrong parameter name: " + name + " " + this;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
221 assert constParam == info.isConstantParameter(nextParamIdx) : "Parameter " + (constParam ? "not " : "") + "annotated with @" + ConstantParameter.class.getSimpleName() + ": " + name +
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
222 " " + this;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
223 assert varargsParam == info.isVarargsParameter(nextParamIdx) : "Parameter " + (varargsParam ? "not " : "") + "annotated with @" + VarargsParameter.class.getSimpleName() + ": " + name +
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
224 " " + this;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
225 return true;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
226 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
227
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
228 @Override
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
229 public String toString() {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
230 StringBuilder result = new StringBuilder();
10001
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
231 result.append("Parameters<").append(MetaUtil.format("%h.%n", info.method)).append(" [");
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
232 String sep = "";
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
233 for (int i = 0; i < info.getParameterCount(); i++) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
234 result.append(sep);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
235 if (info.isConstantParameter(i)) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
236 result.append("const ");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
237 } else if (info.isVarargsParameter(i)) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
238 result.append("varargs ");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
239 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
240 result.append(info.names[i]).append(" = ").append(values[i]);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
241 sep = ", ";
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
242 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
243 result.append(">");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
244 return result.toString();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
245 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
246 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
247
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
248 /**
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
249 * Wrapper for the prototype value of a {@linkplain VarargsParameter varargs} parameter.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
250 */
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
251 static class Varargs {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
252
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
253 protected final Class componentType;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
254 protected final Stamp stamp;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
255 protected final Object value;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
256 protected final int length;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
257
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
258 protected Varargs(Class componentType, Stamp stamp, Object value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
259 this.componentType = componentType;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
260 this.stamp = stamp;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
261 this.value = value;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
262 if (value instanceof List) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
263 this.length = ((List) value).size();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
264 } else {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
265 this.length = Array.getLength(value);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
266 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
267 }
10001
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
268
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
269 @Override
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
270 public String toString() {
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
271 if (value instanceof boolean[]) {
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
272 return Arrays.toString((boolean[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
273 }
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
274 if (value instanceof byte[]) {
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
275 return Arrays.toString((byte[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
276 }
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
277 if (value instanceof char[]) {
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
278 return Arrays.toString((char[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
279 }
10007
10b8973ac372 fixed copy-and-paste errors
Doug Simon <doug.simon@oracle.com>
parents: 10001
diff changeset
280 if (value instanceof short[]) {
10001
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
281 return Arrays.toString((short[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
282 }
10007
10b8973ac372 fixed copy-and-paste errors
Doug Simon <doug.simon@oracle.com>
parents: 10001
diff changeset
283 if (value instanceof int[]) {
10001
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
284 return Arrays.toString((int[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
285 }
10007
10b8973ac372 fixed copy-and-paste errors
Doug Simon <doug.simon@oracle.com>
parents: 10001
diff changeset
286 if (value instanceof long[]) {
10001
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
287 return Arrays.toString((long[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
288 }
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
289 if (value instanceof float[]) {
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
290 return Arrays.toString((float[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
291 }
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
292 if (value instanceof double[]) {
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
293 return Arrays.toString((double[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
294 }
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
295 if (value instanceof Object[]) {
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
296 return Arrays.toString((Object[]) value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
297 }
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
298 return String.valueOf(value);
38d7b55f87b0 added instanceof snippets that for a profile with 100% precise coverage of seen types.
Doug Simon <doug.simon@oracle.com>
parents: 9917
diff changeset
299 }
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
300 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
301
12570
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
302 static class VarargsPlaceholderNode extends FloatingNode implements ArrayLengthProvider {
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
303
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
304 final Varargs varargs;
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
305
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
306 public VarargsPlaceholderNode(Varargs varargs, MetaAccessProvider metaAccess) {
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
307 super(StampFactory.exactNonNull(metaAccess.lookupJavaType(varargs.componentType).getArrayClass()));
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
308 this.varargs = varargs;
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
309 }
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
310
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
311 public ValueNode length() {
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
312 return ConstantNode.forInt(varargs.length, graph());
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
313 }
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
314 }
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
315
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
316 static class CacheKey {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
317
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
318 private final ResolvedJavaMethod method;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
319 private final Object[] values;
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
320 private final GuardsStage guardsStage;
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13287
diff changeset
321 private final LoweringTool.LoweringStage loweringStage;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
322 private int hash;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
323
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13287
diff changeset
324 protected CacheKey(SnippetInfo info, GuardsStage guardsStage, LoweringTool.LoweringStage loweringStage) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
325 this.method = info.method;
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
326 this.guardsStage = guardsStage;
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13287
diff changeset
327 this.loweringStage = loweringStage;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
328 this.values = new Object[info.getParameterCount()];
13282
dc4128904f0b Make the guardsStage part of the hash for SnippetTemplate.CacheKey
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13222
diff changeset
329 this.hash = info.method.hashCode() + 31 * guardsStage.hashCode();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
330 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
331
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
332 protected void setParam(int paramIdx, Object value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
333 values[paramIdx] = value;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
334 hash = (hash * 31) ^ (value == null ? 0 : value.hashCode());
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
335 }
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 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
338 public boolean equals(Object obj) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
339 if (!(obj instanceof CacheKey)) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
340 return false;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
341 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
342 CacheKey other = (CacheKey) obj;
14160
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 13932
diff changeset
343 if (!method.equals(other.method)) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
344 return false;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
345 }
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13287
diff changeset
346 if (guardsStage != other.guardsStage || loweringStage != other.loweringStage) {
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
347 return false;
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
348 }
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
349 for (int i = 0; i < values.length; i++) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
350 if (values[i] != null && !values[i].equals(other.values[i])) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
351 return false;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
352 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
353 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
354 return true;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
355 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
356
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
357 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
358 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
359 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
360 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
361 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
362
12716
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
363 private static final DebugTimer SnippetTemplateCreationTime = Debug.timer("SnippetTemplateCreationTime");
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
364 private static final DebugMetric SnippetTemplates = Debug.metric("SnippetTemplateCount");
12707
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
365
12733
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
366 private static final String MAX_TEMPLATES_PER_SNIPPET_PROPERTY_NAME = "graal.maxTemplatesPerSnippet";
12707
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
367 private static final boolean UseSnippetTemplateCache = Boolean.parseBoolean(System.getProperty("graal.useSnippetTemplateCache", "true"));
12733
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
368 private static final int MaxTemplatesPerSnippet = Integer.getInteger(MAX_TEMPLATES_PER_SNIPPET_PROPERTY_NAME, 50);
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
369
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
370 /**
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
371 * Base class for snippet classes. It provides a cache for {@link SnippetTemplate}s.
5484
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
372 */
9187
cd2600a2336e Store snippet templates in Replacements object.
Roland Schatz <roland.schatz@oracle.com>
parents: 9099
diff changeset
373 public abstract static class AbstractTemplates implements SnippetTemplateCache {
5484
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
374
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
375 protected final Providers providers;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
376 protected final TargetDescription target;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
377 private final ConcurrentHashMap<CacheKey, SnippetTemplate> templates;
5484
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
378
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
379 protected AbstractTemplates(Providers providers, TargetDescription target) {
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
380 this.providers = providers;
7034
89df4e71940a More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7015
diff changeset
381 this.target = target;
12707
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
382 if (UseSnippetTemplateCache) {
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
383 this.templates = new ConcurrentHashMap<>();
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
384 } else {
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
385 this.templates = null;
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
386 }
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
387 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
388
9417
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
389 /**
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
390 * Finds the method in {@code declaringClass} annotated with {@link Snippet} named
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
391 * {@code methodName}. If {@code methodName} is null, then there must be exactly one snippet
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
392 * method in {@code declaringClass}.
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
393 */
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
394 protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
395 Method found = null;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
396 for (Method method : declaringClass.getDeclaredMethods()) {
9417
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
397 if (method.getAnnotation(Snippet.class) != null && (methodName == null || method.getName().equals(methodName))) {
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
398 assert found == null : "found more than one @" + Snippet.class.getSimpleName() + " method in " + declaringClass + (methodName == null ? "" : " named " + methodName);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
399 found = method;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
400 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
401 }
9417
ffa27c3058e9 minor simplifications for writing compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9302
diff changeset
402 assert found != null : "did not find @" + Snippet.class.getSimpleName() + " method in " + declaringClass + (methodName == null ? "" : " named " + methodName);
13146
ffbfc3e78746 extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13131
diff changeset
403 ResolvedJavaMethod javaMethod = providers.getMetaAccess().lookupJavaMethod(found);
ffbfc3e78746 extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13131
diff changeset
404 providers.getReplacements().registerSnippet(javaMethod);
ffbfc3e78746 extend replacements API to support svm specific snippet handling
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13131
diff changeset
405 return new SnippetInfo(javaMethod);
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 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
407
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
408 /**
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
409 * 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
410 */
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
411 protected SnippetTemplate template(final Arguments args) {
12707
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
412 SnippetTemplate template = UseSnippetTemplateCache ? templates.get(args.cacheKey) : null;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
413 if (template == null) {
12716
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
414 SnippetTemplates.increment();
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
415 try (TimerCloseable a = SnippetTemplateCreationTime.start(); Scope s = Debug.scope("SnippetSpecialization", args.info.method)) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
416 template = new SnippetTemplate(providers, args);
12707
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
417 if (UseSnippetTemplateCache) {
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
418 templates.put(args.cacheKey, template);
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
419 }
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
420 } catch (Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
421 throw Debug.handle(e);
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
422 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
423 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
424 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
425 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
426 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
427
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
428 private static final Object UNUSED_PARAMETER = "DEAD PARAMETER";
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
429 private static final Object CONSTANT_PARAMETER = "CONSTANT";
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
430
6ec0857cdf46 added support for snippet templates which are snippet 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 /**
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
432 * Determines if any parameter of a given method is annotated with {@link ConstantParameter}.
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
433 */
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
434 public static boolean hasConstantParameter(ResolvedJavaMethod method) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
435 for (ConstantParameter p : MetaUtil.getParameterAnnotations(ConstantParameter.class, method)) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
436 if (p != null) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
437 return true;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
438 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
439 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
440 return false;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
441 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
442
12731
8e862906e2e4 removed hash code from name of SnippetTemplate metrics (blows up DebugValueMaps when template caching is disabled)
Doug Simon <doug.simon@oracle.com>
parents: 12728
diff changeset
443 private static String debugValueName(String category, Arguments args) {
12728
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
444 if (Debug.isEnabled()) {
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
445 StringBuilder result = new StringBuilder(category).append('[');
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
446 SnippetInfo info = args.info;
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
447 result.append(info.method.getName()).append('(');
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
448 String sep = "";
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
449 for (int i = 0; i < info.getParameterCount(); i++) {
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
450 if (info.isConstantParameter(i)) {
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
451 result.append(sep);
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
452 if (info.names[i] != null) {
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
453 result.append(info.names[i]);
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
454 } else {
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
455 result.append(i);
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
456 }
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
457 result.append('=').append(args.values[i]);
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
458 sep = ", ";
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
459 }
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
460 }
12731
8e862906e2e4 removed hash code from name of SnippetTemplate metrics (blows up DebugValueMaps when template caching is disabled)
Doug Simon <doug.simon@oracle.com>
parents: 12728
diff changeset
461 result.append(")]");
12728
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
462 return result.toString();
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
463
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
464 }
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
465 return null;
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
466 }
3e88ee655612 per SnippetTemplate metrics now include the details of the specialization in their name
Doug Simon <doug.simon@oracle.com>
parents: 12722
diff changeset
467
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
468 /**
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
469 * 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
470 */
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
471 protected SnippetTemplate(final Providers providers, Arguments args) {
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
472 StructuredGraph snippetGraph = providers.getReplacements().getSnippet(args.info.method);
12731
8e862906e2e4 removed hash code from name of SnippetTemplate metrics (blows up DebugValueMaps when template caching is disabled)
Doug Simon <doug.simon@oracle.com>
parents: 12728
diff changeset
473 instantiationTimer = Debug.timer(debugValueName("SnippetTemplateInstantiationTime", args));
8e862906e2e4 removed hash code from name of SnippetTemplate metrics (blows up DebugValueMaps when template caching is disabled)
Doug Simon <doug.simon@oracle.com>
parents: 12728
diff changeset
474 instantiationCounter = Debug.metric(debugValueName("SnippetTemplateInstantiationCount", args));
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
475
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
476 ResolvedJavaMethod method = snippetGraph.method();
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
477 Signature signature = method.getSignature();
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
478
13286
a3c559c0e460 SnippetTemplates does not use assumptions any more
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13282
diff changeset
479 PhaseContext phaseContext = new PhaseContext(providers, new Assumptions(false));
11572
a63b63822183 Pass canonicalizer into loop transformations.
Roland Schatz <roland.schatz@oracle.com>
parents: 11569
diff changeset
480
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
481 // Copy snippet graph, replacing constant parameters with given arguments
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11768
diff changeset
482 final StructuredGraph snippetCopy = new StructuredGraph(snippetGraph.name, snippetGraph.method());
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8606
diff changeset
483 IdentityHashMap<Node, Node> nodeReplacements = new IdentityHashMap<>();
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8606
diff changeset
484 nodeReplacements.put(snippetGraph.start(), snippetCopy.start());
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
485
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
486 MetaAccessProvider metaAccess = providers.getMetaAccess();
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
487 assert checkTemplate(metaAccess, args, method, signature);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
488
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
489 int parameterCount = args.info.getParameterCount();
12570
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
490 VarargsPlaceholderNode[] placeholders = new VarargsPlaceholderNode[parameterCount];
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
491
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
492 for (int i = 0; i < parameterCount; i++) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
493 if (args.info.isConstantParameter(i)) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
494 Object arg = args.values[i];
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
495 Kind kind = signature.getParameterKind(i);
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
496 Constant constantArg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
497 if (arg instanceof Constant) {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
498 constantArg = (Constant) arg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
499 } else {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
500 constantArg = Constant.forBoxed(kind, arg);
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
501 }
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
502 nodeReplacements.put(snippetGraph.getParameter(i), ConstantNode.forConstant(constantArg, metaAccess, snippetCopy));
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
503 } else if (args.info.isVarargsParameter(i)) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
504 Varargs varargs = (Varargs) args.values[i];
12570
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
505 VarargsPlaceholderNode placeholder = snippetCopy.unique(new VarargsPlaceholderNode(varargs, providers.getMetaAccess()));
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
506 nodeReplacements.put(snippetGraph.getParameter(i), placeholder);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
507 placeholders[i] = placeholder;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
508 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
509 }
11675
77d9f12797c5 Use NodeMap in inlining utility when number of nodes is high.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11572
diff changeset
510 snippetCopy.addDuplicates(snippetGraph.getNodes(), snippetGraph, snippetGraph.getNodeCount(), nodeReplacements);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
511
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
512 Debug.dump(snippetCopy, "Before specialization");
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8606
diff changeset
513 if (!nodeReplacements.isEmpty()) {
13222
de8f74d49690 rename Replacements.prepareSnippetCopyAfterInstantiation
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13197
diff changeset
514 providers.getReplacements().notifyAfterConstantsBound(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
515 }
5466
af07e798947d lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5428
diff changeset
516
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
517 // Gather the template parameters
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
518 parameters = new Object[parameterCount];
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
519 for (int i = 0; i < parameterCount; i++) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
520 if (args.info.isConstantParameter(i)) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
521 parameters[i] = CONSTANT_PARAMETER;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
522 } else if (args.info.isVarargsParameter(i)) {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
523 assert snippetCopy.getParameter(i) == null;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
524 Varargs varargs = (Varargs) args.values[i];
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
525 int length = varargs.length;
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
526 ParameterNode[] params = new ParameterNode[length];
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
527 Stamp stamp = varargs.stamp;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
528 for (int j = 0; j < length; j++) {
13932
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
529 // Use a decimal friendly numbering make it more obvious how values map
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
530 assert parameterCount < 10000;
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
531 int idx = (i + 1) * 10000 + j;
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
532 assert idx >= parameterCount : "collision in parameter numbering";
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
533 ParameterNode local = snippetCopy.unique(new ParameterNode(idx, stamp));
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
534 params[j] = local;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
535 }
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
536 parameters[i] = params;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
537
12570
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
538 VarargsPlaceholderNode placeholder = placeholders[i];
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
539 assert placeholder != null;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
540 for (Node usage : placeholder.usages().snapshot()) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
541 if (usage instanceof LoadIndexedNode) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
542 LoadIndexedNode loadIndexed = (LoadIndexedNode) usage;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
543 Debug.dump(snippetCopy, "Before replacing %s", loadIndexed);
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
544 LoadSnippetVarargParameterNode loadSnippetParameter = snippetCopy.add(new LoadSnippetVarargParameterNode(params, loadIndexed.index(), loadIndexed.stamp()));
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
545 snippetCopy.replaceFixedWithFixed(loadIndexed, loadSnippetParameter);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
546 Debug.dump(snippetCopy, "After replacing %s", loadIndexed);
13932
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
547 } else if (usage instanceof StoreIndexedNode) {
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
548 // The template lowering doesn't really treat this as an array so you can't
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
549 // store back into the varargs. Allocate your own array if you really need
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
550 // this and EA should eliminate it.
0e7841cf749c a few stronger asserts in snipppet expansion
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 13794
diff changeset
551 throw new GraalInternalError("Can't store into VarargsParameter array");
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
552 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
553 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
554 } else {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
555 ParameterNode local = snippetCopy.getParameter(i);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
556 if (local == null) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
557 // Parameter value was eliminated
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
558 parameters[i] = UNUSED_PARAMETER;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
559 } else {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
560 parameters[i] = local;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
561 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
562 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
563 }
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
564
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
565 // 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
566 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
567 do {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
568 exploded = false;
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
569 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
570 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
571 // altogether
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
572 LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
573 if (loopBegin != null) {
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
574 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12570
diff changeset
575 Mark mark = snippetCopy.getMark();
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
576 LoopTransformations.fullUnroll(loop, phaseContext, new CanonicalizerPhase(true));
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
577 new CanonicalizerPhase(true).applyIncremental(snippetCopy, phaseContext, mark);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
578 }
13794
2eb56f87b01e add GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@jku.at>
parents: 13692
diff changeset
579 GraphUtil.removeFixedWithUnusedInputs(explodeLoop);
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
580 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
581 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
582 } 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
583
13287
9b053d478a4e Use the appropriate phases in order to change the guards stage
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13286
diff changeset
584 GuardsStage guardsStage = args.cacheKey.guardsStage;
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
585 // Perform lowering on the snippet
13287
9b053d478a4e Use the appropriate phases in order to change the guards stage
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13286
diff changeset
586 if (guardsStage.ordinal() >= GuardsStage.FIXED_DEOPTS.ordinal()) {
9b053d478a4e Use the appropriate phases in order to change the guards stage
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13286
diff changeset
587 new GuardLoweringPhase().apply(snippetCopy, null);
9b053d478a4e Use the appropriate phases in order to change the guards stage
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13286
diff changeset
588 }
9b053d478a4e Use the appropriate phases in order to change the guards stage
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 13286
diff changeset
589 snippetCopy.setGuardsStage(guardsStage);
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
590 try (Scope s = Debug.scope("LoweringSnippetTemplate", snippetCopy)) {
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13287
diff changeset
591 new LoweringPhase(new CanonicalizerPhase(true), args.cacheKey.loweringStage).apply(snippetCopy, phaseContext);
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
592 } catch (Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
593 throw Debug.handle(e);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13153
diff changeset
594 }
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
595
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
596 // Remove all frame states from snippet graph. Snippets must be atomic (i.e. free
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
597 // of side-effects that prevent deoptimizing to a point before the snippet).
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
598 ArrayList<StateSplit> curSideEffectNodes = new ArrayList<>();
10667
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
599 ArrayList<DeoptimizingNode> curDeoptNodes = new ArrayList<>();
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
600 ArrayList<ValueNode> curStampNodes = new ArrayList<>();
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
601 for (Node node : snippetCopy.getNodes()) {
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
602 if (node instanceof ValueNode && ((ValueNode) node).stamp() == StampFactory.forNodeIntrinsic()) {
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
603 curStampNodes.add((ValueNode) node);
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
604 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
605 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
606 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
607 FrameState frameState = stateSplit.stateAfter();
6534
feb579677b58 SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
608 if (stateSplit.hasSideEffect()) {
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
609 curSideEffectNodes.add((StateSplit) node);
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
610 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
611 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
612 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
613 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
614 }
10667
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
615 if (node instanceof DeoptimizingNode) {
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
616 DeoptimizingNode deoptNode = (DeoptimizingNode) node;
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
617 if (deoptNode.canDeoptimize()) {
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
618 curDeoptNodes.add(deoptNode);
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
619 }
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
620 }
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
621 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
622
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
623 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
624
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
625 assert checkAllVarargPlaceholdersAreDeleted(parameterCount, placeholders);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
626
11767
ac252c4c920b FloatingReadPhase: use enum for describing the execution mode of the phase
Bernhard Urban <bernhard.urban@jku.at>
parents: 11766
diff changeset
627 new FloatingReadPhase(FloatingReadPhase.ExecutionMode.ANALYSIS_ONLY).apply(snippetCopy);
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
628
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
629 this.snippet = snippetCopy;
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
630 List<ReturnNode> returnNodes = new ArrayList<>(4);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
631 List<MemoryMapNode> memMaps = new ArrayList<>(4);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
632 StartNode entryPointNode = snippet.start();
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
633 for (ReturnNode retNode : snippet.getNodes(ReturnNode.class)) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
634 MemoryMapNode memMap = retNode.getMemoryMap();
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
635 memMaps.add(memMap);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
636 retNode.setMemoryMap(null);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
637 returnNodes.add(retNode);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
638 if (memMap.usages().isEmpty()) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
639 memMap.safeDelete();
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
640 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
641 }
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
642 assert snippet.getNodes().filter(MemoryMapNode.class).isEmpty();
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
643 if (returnNodes.isEmpty()) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
644 this.returnNode = null;
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
645 this.memoryMap = null;
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
646 } else if (returnNodes.size() == 1) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
647 this.returnNode = returnNodes.get(0);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
648 this.memoryMap = memMaps.get(0);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
649 } else {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
650 MergeNode merge = snippet.add(new MergeNode());
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
651 ValueNode returnValue = InliningUtil.mergeReturns(merge, returnNodes);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
652 this.returnNode = snippet.add(new ReturnNode(returnValue));
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
653 this.memoryMap = FloatingReadPhase.mergeMemoryMaps(merge, memMaps);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
654 merge.setNext(this.returnNode);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
655 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
656
7034
89df4e71940a More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7015
diff changeset
657 this.sideEffectNodes = curSideEffectNodes;
10667
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
658 this.deoptNodes = curDeoptNodes;
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
659 this.stampNodes = curStampNodes;
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
660
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
661 nodes = new ArrayList<>(snippet.getNodeCount());
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
662 for (Node node : snippet.getNodes()) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
663 if (node != entryPointNode && node != entryPointNode.stateAfter()) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
664 nodes.add(node);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
665 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
666 }
12707
3b2b8a71d10d added ability to disable snippet template cache (-Dgraal.useSnippetTemplateCache=false)
Doug Simon <doug.simon@oracle.com>
parents: 12703
diff changeset
667
12747
b5cf28c97430 replaced global snippet and template node metrics with per-snippet and per-template metrics
Doug Simon <doug.simon@oracle.com>
parents: 12745
diff changeset
668 Debug.metric(debugValueName("SnippetTemplateNodeCount", args)).add(nodes.size());
12733
8d8d9d0b04bb added check (with warning on System.err) if number of templates for a snippet exceeds a threshold (default is 50)
Doug Simon <doug.simon@oracle.com>
parents: 12731
diff changeset
669 args.info.notifyNewTemplate();
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
670 Debug.dump(snippet, "SnippetTemplate final state");
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
671 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
672
12570
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12549
diff changeset
673 private static boolean checkAllVarargPlaceholdersAreDeleted(int parameterCount, VarargsPlaceholderNode[] placeholders) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
674 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
675 if (placeholders[i] != null) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
676 assert placeholders[i].isDeleted() : placeholders[i];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
677 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
678 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
679 return true;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
680 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
681
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
682 private static boolean checkConstantArgument(MetaAccessProvider metaAccess, final ResolvedJavaMethod method, Signature signature, int i, String name, Object arg, Kind kind) {
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
683 ResolvedJavaType type = signature.getParameterType(i, method.getDeclaringClass()).resolve(method.getDeclaringClass());
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
684 if (metaAccess.lookupJavaType(WordBase.class).isAssignableFrom(type)) {
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
685 assert arg instanceof Constant : method + ": word constant parameters must be passed boxed in a Constant value: " + arg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
686 return true;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
687 }
7098
e23980f4a890 Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7081
diff changeset
688 if (kind == Kind.Object) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
689 assert arg == null || type.isInstance(Constant.forObject(arg)) : method + ": wrong value type for " + name + ": expected " + type.getName() + ", got " + arg.getClass().getName();
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
690 } else {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
691 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() : method + ": wrong value kind for " + name + ": expected " + kind + ", got " +
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
692 (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
693 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
694 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
695 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
696
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
697 private static boolean checkVarargs(MetaAccessProvider metaAccess, final ResolvedJavaMethod method, Signature signature, int i, String name, Varargs varargs) {
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
698 ResolvedJavaType type = (ResolvedJavaType) signature.getParameterType(i, method.getDeclaringClass());
7060
06d5f450f32b rename: ResolvedJavaType.isArrayClass() -> ResolvedJavaType.isArray()
Doug Simon <doug.simon@oracle.com>
parents: 7034
diff changeset
699 assert type.isArray() : "varargs parameter must be an array type";
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
700 assert type.getComponentType().isAssignableFrom(metaAccess.lookupJavaType(varargs.componentType)) : "componentType for " + name + " not matching " + MetaUtil.toJavaName(type) + " instance: " +
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
701 varargs.componentType;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
702 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
703 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
704
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
705 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
706 * 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
707 */
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
708 private final StructuredGraph snippet;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
709
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
710 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
711 * The named parameters of this template that must be bound to values during instantiation. For
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
712 * a parameter that is still live after specialization, the value in this map is either a
13616
6888c58b810b fix formatting
Lukas Stadler <lukas.stadler@jku.at>
parents: 13614
diff changeset
713 * {@link ParameterNode} instance or a {@link ParameterNode} array. For an eliminated parameter,
6888c58b810b fix formatting
Lukas Stadler <lukas.stadler@jku.at>
parents: 13614
diff changeset
714 * the value is identical to the key.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
715 */
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
716 private final Object[] parameters;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
717
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
718 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
719 * 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
720 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
721 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
722
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
723 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
724 * Nodes that inherit the {@link StateSplit#stateAfter()} from the replacee during
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
725 * instantiation.
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
726 */
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
727 private final ArrayList<StateSplit> sideEffectNodes;
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
728
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
729 /**
10667
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
730 * Nodes that inherit the {@link DeoptimizingNode#getDeoptimizationState()} from the replacee
13691
056d9d7dc061 expose memory map merging functionality in FloatingReadPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 13623
diff changeset
731 * during instantiation.
10667
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
732 */
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
733 private final ArrayList<DeoptimizingNode> deoptNodes;
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
734
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
735 /**
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
736 * The nodes that inherit the {@link ValueNode#stamp()} from the replacee during instantiation.
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
737 */
7546
727e869891fc let CheckCastSnippets insert UnsafeCastNodes (so that type stays visible during lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
738 private final ArrayList<ValueNode> stampNodes;
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
739
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
740 /**
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
741 * 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
742 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
743 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
744
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
745 /**
11802
82c4106741f7 SnippetTemplate: avoid two getNodes() in assertions. comment fix and renames
Bernhard Urban <bernhard.urban@jku.at>
parents: 11798
diff changeset
746 * map of killing locations to memory checkpoints (nodes).
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
747 */
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
748 private final MemoryMapNode memoryMap;
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
750 /**
12716
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
751 * Times instantiations of this template.
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
752 *
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
753 * @see SnippetInfo#instantiationTimer
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
754 */
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
755 private final DebugTimer instantiationTimer;
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
756
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
757 /**
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
758 * Counts instantiations of this template.
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
759 *
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
760 * @see SnippetInfo#instantiationCounter
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
761 */
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
762 private final DebugMetric instantiationCounter;
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
763
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
764 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
765 * Gets the instantiation-time bindings to this template's parameters.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
766 *
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
767 * @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
768 */
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
769 private IdentityHashMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider metaAccess, 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
770 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
771 assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")";
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
772 for (int i = 0; i < parameters.length; i++) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
773 Object parameter = parameters[i];
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
774 assert parameter != null : this + " has no parameter named " + args.info.names[i];
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
775 Object argument = args.values[i];
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
776 if (parameter instanceof ParameterNode) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
777 if (argument instanceof ValueNode) {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
778 replacements.put((ParameterNode) 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
779 } else {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
780 Kind kind = ((ParameterNode) parameter).kind();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
781 assert argument != null || kind == Kind.Object : this + " cannot accept null for non-object parameter named " + args.info.names[i];
8908
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
782 Constant constant = forBoxed(argument, kind);
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
783 replacements.put((ParameterNode) parameter, ConstantNode.forConstant(constant, metaAccess, 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
784 }
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
785 } else if (parameter instanceof ParameterNode[]) {
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
786 ParameterNode[] params = (ParameterNode[]) parameter;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
787 Varargs varargs = (Varargs) argument;
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
788 int length = params.length;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
789 List list = null;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
790 Object array = null;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
791 if (varargs.value instanceof List) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
792 list = (List) varargs.value;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
793 assert list.size() == length : length + " != " + list.size();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
794 } else {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
795 array = varargs.value;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
796 assert array != null && array.getClass().isArray();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
797 assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
798 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
799
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
800 for (int j = 0; j < length; j++) {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
801 ParameterNode param = params[j];
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
802 assert param != null;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
803 Object value = list != null ? list.get(j) : Array.get(array, j);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
804 if (value instanceof ValueNode) {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
805 replacements.put(param, (ValueNode) value);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
806 } else {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
807 Constant constant = forBoxed(value, param.kind());
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
808 ConstantNode element = ConstantNode.forConstant(constant, metaAccess, replaceeGraph);
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
809 replacements.put(param, element);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
810 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
811 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
812 } else {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
813 assert parameter == CONSTANT_PARAMETER || parameter == UNUSED_PARAMETER : "unexpected entry for parameter: " + args.info.names[i] + " -> " + parameter;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
814 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
815 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
816 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
817 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
818
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
819 /**
8908
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
820 * Converts a Java boxed value to a {@link Constant} of the right kind. This adjusts for the
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
821 * limitation that a {@link Local}'s kind is a {@linkplain Kind#getStackKind() stack kind} and
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
822 * so cannot be used for re-boxing primitives smaller than an int.
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
823 *
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
824 * @param argument a Java boxed value
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
825 * @param localKind the kind of the {@link Local} to which {@code argument} will be bound
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
826 */
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
827 protected Constant forBoxed(Object argument, Kind localKind) {
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
828 assert localKind == localKind.getStackKind();
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
829 if (localKind == Kind.Int && !(argument instanceof Integer)) {
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
830 if (argument instanceof Boolean) {
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
831 return Constant.forBoxed(Kind.Boolean, argument);
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
832 }
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
833 if (argument instanceof Byte) {
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
834 return Constant.forBoxed(Kind.Byte, argument);
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
835 }
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
836 if (argument instanceof Short) {
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
837 return Constant.forBoxed(Kind.Short, argument);
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
838 }
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
839 assert argument instanceof Character;
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
840 return Constant.forBoxed(Kind.Char, argument);
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
841 }
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
842 return Constant.forBoxed(localKind, argument);
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
843 }
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
844
b9fb1ecaad92 convert non-int boxed primitives whose stack kind is int to Constants of the right kind
Doug Simon <doug.simon@oracle.com>
parents: 8642
diff changeset
845 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
846 * Logic for replacing a snippet-lowered node at its usages with the return value of the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
847 * snippet. An alternative to the {@linkplain SnippetTemplate#DEFAULT_REPLACER default}
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
848 * replacement logic can be used to handle mismatches between the stamp of the node being
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
849 * lowered and the stamp of the snippet's return value.
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
850 */
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
851 public interface UsageReplacer {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
852
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
853 /**
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
854 * Replaces all usages of {@code oldNode} with direct or indirect usages of {@code newNode}.
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
855 */
11847
f5faf49a86dd remove MemoryState, make MemoryMap a node, add MemoryMap input to ReturnNode
Bernhard Urban <bernhard.urban@jku.at>
parents: 11844
diff changeset
856 void replace(ValueNode oldNode, ValueNode newNode, MemoryMapNode mmap);
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
857 }
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
858
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
859 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
860 * Represents the default {@link UsageReplacer usage replacer} logic which simply delegates to
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
861 * {@link Node#replaceAtUsages(Node)}.
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
862 */
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
863 public static final UsageReplacer DEFAULT_REPLACER = new UsageReplacer() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
864
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
865 private LocationIdentity getLocationIdentity(Node node) {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
866 if (node instanceof MemoryAccess) {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
867 return ((MemoryAccess) node).getLocationIdentity();
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
868 } else if (node instanceof MemoryProxy) {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
869 return ((MemoryProxy) node).getLocationIdentity();
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
870 } else if (node instanceof MemoryPhiNode) {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
871 return ((MemoryPhiNode) node).getLocationIdentity();
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
872 } else {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
873 return null;
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
874 }
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
875 }
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
876
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
877 @Override
11847
f5faf49a86dd remove MemoryState, make MemoryMap a node, add MemoryMap input to ReturnNode
Bernhard Urban <bernhard.urban@jku.at>
parents: 11844
diff changeset
878 public void replace(ValueNode oldNode, ValueNode newNode, MemoryMapNode mmap) {
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
879 if (mmap != null) {
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
880 for (Node usage : oldNode.usages().snapshot()) {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
881 LocationIdentity identity = getLocationIdentity(usage);
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
882 boolean usageReplaced = false;
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
883 if (identity != null && identity != FINAL_LOCATION) {
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
884 // lastLocationAccess points into the snippet graph. find a proper
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
885 // MemoryCheckPoint inside the snippet graph
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
886 MemoryNode lastAccess = mmap.getLastLocationAccess(identity);
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
887
13691
056d9d7dc061 expose memory map merging functionality in FloatingReadPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 13623
diff changeset
888 assert lastAccess != null : "no mapping found for lowerable node " + oldNode + ". (No node in the snippet kills the same location as the lowerable node?)";
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
889 if (usage instanceof MemoryAccess) {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
890 MemoryAccess access = (MemoryAccess) usage;
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
891 if (access.getLastLocationAccess() == oldNode) {
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
892 assert oldNode.graph().isAfterFloatingReadPhase();
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
893 access.setLastLocationAccess(lastAccess);
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
894 usageReplaced = true;
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
895 }
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
896 } else {
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
897 assert usage instanceof MemoryProxy || usage instanceof MemoryPhiNode;
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
898 usage.replaceFirstInput(oldNode, lastAccess.asNode());
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
899 usageReplaced = true;
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
900 }
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
901 }
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
902 if (!usageReplaced) {
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
903 assert newNode != null : "this branch is only valid if we have a newNode for replacement";
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
904 }
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
905 }
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
906 }
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
907 if (newNode == null) {
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
908 assert oldNode.usages().isEmpty();
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
909 } else {
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
910 oldNode.replaceAtUsages(newNode);
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
911 }
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
912 }
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
913 };
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
914
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
915 private boolean checkSnippetKills(ScheduledNode replacee) {
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
916 if (!replacee.graph().isAfterFloatingReadPhase()) {
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
917 // no floating reads yet, ignore locations created while lowering
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
918 return true;
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
919 }
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
920 if (memoryMap == null || ((MemoryMapImpl) memoryMap).isEmpty()) {
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
921 // there're no kills in the snippet graph
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
922 return true;
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
923 }
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
924
11844
1ce74467ab51 SnippetTemplate: remove canonicalizer. remove loop for return node. copy Set on user side
Bernhard Urban <bernhard.urban@jku.at>
parents: 11802
diff changeset
925 Set<LocationIdentity> kills = new HashSet<>(((MemoryMapImpl) memoryMap).getLocations());
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
926
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
927 if (replacee instanceof MemoryCheckpoint.Single) {
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
928 // check if some node in snippet graph also kills the same location
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
929 LocationIdentity locationIdentity = ((MemoryCheckpoint.Single) replacee).getLocationIdentity();
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
930 if (locationIdentity == ANY_LOCATION) {
12549
2df56730c5a6 UnsafeArrayCopyNode: try to be more precise about killed location
Bernhard Urban <bernhard.urban@jku.at>
parents: 12507
diff changeset
931 assert !(memoryMap.getLastLocationAccess(ANY_LOCATION) instanceof StartNode) : replacee + " kills ANY_LOCATION, but snippet does not";
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
932 }
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
933 assert kills.contains(locationIdentity) : replacee + " kills " + locationIdentity + ", but snippet doesn't contain a kill to this location";
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
934 return true;
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
935 }
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
936 assert !(replacee instanceof MemoryCheckpoint.Multi) : replacee + " multi not supported (yet)";
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
937
11802
82c4106741f7 SnippetTemplate: avoid two getNodes() in assertions. comment fix and renames
Bernhard Urban <bernhard.urban@jku.at>
parents: 11798
diff changeset
938 Debug.log("WARNING: %s is not a MemoryCheckpoint, but the snippet graph contains kills (%s). You might want %s to be a MemoryCheckpoint", replacee, kills, replacee);
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
939
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
940 // remove ANY_LOCATION if it's just a kill by the start node
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
941 if (memoryMap.getLastLocationAccess(ANY_LOCATION) instanceof StartNode) {
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
942 kills.remove(ANY_LOCATION);
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
943 }
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
944
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
945 // node can only lower to a ANY_LOCATION kill if the replacee also kills ANY_LOCATION
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
946 assert !kills.contains(ANY_LOCATION) : "snippet graph contains a kill to ANY_LOCATION, but replacee (" + replacee + ") doesn't kill ANY_LOCATION. kills: " + kills;
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
947
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
948 /*
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
949 * kills to other locations than ANY_LOCATION can be still inserted if there aren't any
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
950 * floating reads accessing this locations. Example: In HotSpot, InstanceOfNode is lowered
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
951 * to a snippet containing a write to SECONDARY_SUPER_CACHE_LOCATION. This is runtime
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
952 * specific, so the runtime independent InstanceOfNode can not kill this location. However,
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
953 * if no FloatingReadNode is reading from this location, the kill to this location is fine.
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
954 */
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
955 for (FloatingReadNode frn : replacee.graph().getNodes(FloatingReadNode.class)) {
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
956 assert !(kills.contains(frn.location().getLocationIdentity())) : frn + " reads from " + frn.location().getLocationIdentity() + " but " + replacee + " does not kill this location";
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
957 }
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
958 return true;
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
959 }
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
960
11847
f5faf49a86dd remove MemoryState, make MemoryMap a node, add MemoryMap input to ReturnNode
Bernhard Urban <bernhard.urban@jku.at>
parents: 11844
diff changeset
961 private class DuplicateMapper extends MemoryMapNode {
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
962
13131
5d4b75c35f59 Support lowering of control sink nodes; annotate parameters to make node class invariant checker happy
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12747
diff changeset
963 private final Map<Node, Node> duplicates;
5d4b75c35f59 Support lowering of control sink nodes; annotate parameters to make node class invariant checker happy
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12747
diff changeset
964 @Input private StartNode replaceeStart;
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
965
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
966 public DuplicateMapper(Map<Node, Node> duplicates, StartNode replaceeStart) {
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
967 this.duplicates = duplicates;
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
968 this.replaceeStart = replaceeStart;
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
969 }
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
970
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
971 @Override
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
972 public MemoryNode getLastLocationAccess(LocationIdentity locationIdentity) {
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
973 assert memoryMap != null : "no memory map stored for this snippet graph (snippet doesn't have a ReturnNode?)";
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
974 MemoryNode lastLocationAccess = memoryMap.getLastLocationAccess(locationIdentity);
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
975 assert lastLocationAccess != null;
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
976 if (lastLocationAccess instanceof StartNode) {
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
977 return replaceeStart;
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
978 } else {
13153
ae0001b445c0 Common base interface for nodes in the memory graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 13146
diff changeset
979 return (MemoryNode) duplicates.get(ValueNodeUtil.asNode(lastLocationAccess));
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
980 }
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
981 }
13691
056d9d7dc061 expose memory map merging functionality in FloatingReadPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 13623
diff changeset
982
056d9d7dc061 expose memory map merging functionality in FloatingReadPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 13623
diff changeset
983 @Override
056d9d7dc061 expose memory map merging functionality in FloatingReadPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 13623
diff changeset
984 public Set<LocationIdentity> getLocations() {
056d9d7dc061 expose memory map merging functionality in FloatingReadPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 13623
diff changeset
985 return memoryMap.getLocations();
056d9d7dc061 expose memory map merging functionality in FloatingReadPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 13623
diff changeset
986 }
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
987 }
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
988
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
989 /**
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
990 * Replaces a given fixed node with this specialized snippet.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
991 *
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
992 * @param metaAccess
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
993 * @param replacee the node that will be replaced
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
994 * @param replacer object that replaces the usages of {@code replacee}
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
995 * @param args the arguments to be bound to the flattened positional parameters of the snippet
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6302
diff changeset
996 * @return the map of duplicated nodes (original -> duplicate)
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
997 */
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
998 public Map<Node, Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, UsageReplacer replacer, Arguments args) {
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
999 assert checkSnippetKills(replacee);
12716
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
1000 try (TimerCloseable a = args.info.instantiationTimer.start(); TimerCloseable b = instantiationTimer.start()) {
12507
d72864a2886e moved snippet timers/metrics from SnippetTemplate to SnippetInfo and added new metric for number of snippet specializations (i.e. number of SnippetTemplate objects created)
Doug Simon <doug.simon@oracle.com>
parents: 12362
diff changeset
1001 args.info.instantiationCounter.increment();
12716
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
1002 instantiationCounter.increment();
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1003 // Inline the snippet nodes, replacing parameters with the given args in the process
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1004 StartNode entryPointNode = snippet.start();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1005 FixedNode firstCFGNode = entryPointNode.next();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1006 StructuredGraph replaceeGraph = replacee.graph();
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
1007 IdentityHashMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
12703
b6f66fb9f106 SnippetTemplate instantiation should replace snippet's start node with a valid anchor point not the caller's start node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
1008 replacements.put(entryPointNode, BeginNode.prevBegin(replacee));
11675
77d9f12797c5 Use NodeMap in inlining utility when number of nodes is high.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11572
diff changeset
1009 Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements);
11692
8b3a2258b368 Remove unused allocated graph in snippet instantiation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11675
diff changeset
1010 Debug.dump(replaceeGraph, "After inlining snippet %s", snippet.method());
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1011
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1012 // Re-wire the control flow graph around the replacee
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1013 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1014 replacee.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
1015
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1016 if (replacee instanceof StateSplit) {
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1017 for (StateSplit sideEffectNode : sideEffectNodes) {
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1018 assert ((StateSplit) replacee).hasSideEffect();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1019 Node sideEffectDup = duplicates.get(sideEffectNode);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1020 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter());
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1021 }
10667
5348b49b2a76 Assign framestates in snippet lowering after framestate assignment.
Roland Schatz <roland.schatz@oracle.com>
parents: 10422
diff changeset
1022 }
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
1023
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1024 if (replacee instanceof DeoptimizingNode) {
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1025 DeoptimizingNode replaceeDeopt = (DeoptimizingNode) replacee;
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1026 FrameState state = replaceeDeopt.getDeoptimizationState();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1027 for (DeoptimizingNode deoptNode : deoptNodes) {
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1028 DeoptimizingNode deoptDup = (DeoptimizingNode) duplicates.get(deoptNode);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1029 assert replaceeDeopt.canDeoptimize() || !deoptDup.canDeoptimize();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1030 deoptDup.setDeoptimizationState(state);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1031 }
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1032 }
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1033
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1034 updateStamps(replacee, duplicates);
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
1035
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1036 // Replace all usages of the replacee with the value returned by the snippet
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1037 ValueNode returnValue = null;
13131
5d4b75c35f59 Support lowering of control sink nodes; annotate parameters to make node class invariant checker happy
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12747
diff changeset
1038 if (returnNode != null && !(replacee instanceof ControlSinkNode)) {
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1039 ReturnNode returnDuplicate = (ReturnNode) duplicates.get(returnNode);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1040 returnValue = returnDuplicate.result();
11847
f5faf49a86dd remove MemoryState, make MemoryMap a node, add MemoryMap input to ReturnNode
Bernhard Urban <bernhard.urban@jku.at>
parents: 11844
diff changeset
1041 MemoryMapNode mmap = new DuplicateMapper(duplicates, replaceeGraph.start());
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1042 if (returnValue == null && replacee.usages().isNotEmpty() && replacee instanceof MemoryCheckpoint) {
14541
145b31ba9a57 SnippetTemplate: don't use dummy node for replace
Bernhard Urban <bernhard.urban@jku.at>
parents: 14160
diff changeset
1043 replacer.replace(replacee, null, mmap);
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1044 } else {
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1045 assert returnValue != null || replacee.usages().isEmpty();
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
1046 replacer.replace(replacee, returnValue, mmap);
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1047 }
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1048 if (returnDuplicate.isAlive()) {
14548
e1a2302a42bc Improve cleanup during snippet lowering where the snippet never returns normally (unwind, deopt...)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14541
diff changeset
1049 FixedNode next = null;
e1a2302a42bc Improve cleanup during snippet lowering where the snippet never returns normally (unwind, deopt...)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14541
diff changeset
1050 if (replacee instanceof FixedWithNextNode) {
e1a2302a42bc Improve cleanup during snippet lowering where the snippet never returns normally (unwind, deopt...)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14541
diff changeset
1051 FixedWithNextNode fwn = (FixedWithNextNode) replacee;
e1a2302a42bc Improve cleanup during snippet lowering where the snippet never returns normally (unwind, deopt...)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14541
diff changeset
1052 next = fwn.next();
e1a2302a42bc Improve cleanup during snippet lowering where the snippet never returns normally (unwind, deopt...)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14541
diff changeset
1053 fwn.setNext(null);
e1a2302a42bc Improve cleanup during snippet lowering where the snippet never returns normally (unwind, deopt...)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14541
diff changeset
1054 }
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1055 returnDuplicate.clearInputs();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1056 returnDuplicate.replaceAndDelete(next);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1057 }
9879
bf6943c12840 allow for late lowering of MemoryCheckpoints (handle usages by FloatingReads in SnippetTemplate)
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
1058 }
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
1059
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1060 // Remove the replacee from its graph
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1061 replacee.clearInputs();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1062 replacee.replaceAtUsages(null);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1063 GraphUtil.killCFG(replacee);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1064
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1065 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1066 return duplicates;
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1067 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1068 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1069
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1070 private void propagateStamp(Node node) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1071 if (node instanceof PhiNode) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1072 PhiNode phi = (PhiNode) node;
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1073 if (phi.inferPhiStamp()) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1074 for (Node usage : node.usages()) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1075 propagateStamp(usage);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1076 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1077 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1078 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1079 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1080
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1081 private void updateStamps(ValueNode replacee, Map<Node, Node> duplicates) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1082 for (ValueNode stampNode : stampNodes) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1083 Node stampDup = duplicates.get(stampNode);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1084 ((ValueNode) stampDup).setStamp(replacee.stamp());
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1085 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1086 for (ParameterNode paramNode : snippet.getNodes(ParameterNode.class)) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1087 for (Node usage : paramNode.usages()) {
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1088 Node usageDup = duplicates.get(usage);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1089 propagateStamp(usageDup);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1090 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1091 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1092 }
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1093
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1094 /**
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
1095 * Gets a copy of the specialized graph.
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
1096 */
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
1097 public StructuredGraph copySpecializedGraph() {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
1098 return snippet.copy();
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
1099 }
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
1100
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
1101 /**
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1102 * Replaces a given floating node with this specialized snippet.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7313
diff changeset
1103 *
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
1104 * @param metaAccess
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1105 * @param replacee the node that will be replaced
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
1106 * @param replacer object that replaces the usages of {@code replacee}
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1107 * @param args the arguments to be bound to the flattened positional parameters of the snippet
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1108 */
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
1109 public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, LoweringTool tool, Arguments args) {
11768
e53399f1b2cd SnippetTemplate: add assertions regarding memory kills
Bernhard Urban <bernhard.urban@jku.at>
parents: 11767
diff changeset
1110 assert checkSnippetKills(replacee);
12507
d72864a2886e moved snippet timers/metrics from SnippetTemplate to SnippetInfo and added new metric for number of snippet specializations (i.e. number of SnippetTemplate objects created)
Doug Simon <doug.simon@oracle.com>
parents: 12362
diff changeset
1111 try (TimerCloseable a = args.info.instantiationTimer.start()) {
d72864a2886e moved snippet timers/metrics from SnippetTemplate to SnippetInfo and added new metric for number of snippet specializations (i.e. number of SnippetTemplate objects created)
Doug Simon <doug.simon@oracle.com>
parents: 12362
diff changeset
1112 args.info.instantiationCounter.increment();
12716
c6b7f982e949 added per SnippetTemplate instantiation timer and counter
Doug Simon <doug.simon@oracle.com>
parents: 12707
diff changeset
1113 instantiationCounter.increment();
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1114
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1115 // Inline the snippet nodes, replacing parameters with the given args in the process
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1116 String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}";
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1117 StructuredGraph snippetCopy = new StructuredGraph(name, snippet.method());
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1118 StartNode entryPointNode = snippet.start();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1119 FixedNode firstCFGNode = entryPointNode.next();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1120 StructuredGraph replaceeGraph = replacee.graph();
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
1121 IdentityHashMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
12703
b6f66fb9f106 SnippetTemplate instantiation should replace snippet's start node with a valid anchor point not the caller's start node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
1122 replacements.put(entryPointNode, tool.getCurrentGuardAnchor().asNode());
11675
77d9f12797c5 Use NodeMap in inlining utility when number of nodes is high.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11572
diff changeset
1123 Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements);
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1124 Debug.dump(replaceeGraph, "After inlining snippet %s", snippetCopy.method());
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1125
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1126 FixedWithNextNode lastFixedNode = tool.lastFixedNode();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1127 assert lastFixedNode != null && lastFixedNode.isAlive() : replaceeGraph + " lastFixed=" + lastFixedNode;
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1128 FixedNode next = lastFixedNode.next();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1129 lastFixedNode.setNext(null);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1130 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1131 replaceeGraph.addAfterFixed(lastFixedNode, firstCFGNodeDuplicate);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1132
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1133 if (replacee instanceof StateSplit) {
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1134 for (StateSplit sideEffectNode : sideEffectNodes) {
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1135 assert ((StateSplit) replacee).hasSideEffect();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1136 Node sideEffectDup = duplicates.get(sideEffectNode);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1137 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter());
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1138 }
7034
89df4e71940a More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7015
diff changeset
1139 }
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1140 updateStamps(replacee, duplicates);
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
1141
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1142 // Replace all usages of the replacee with the value returned by the snippet
13692
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1143 ReturnNode returnDuplicate = (ReturnNode) duplicates.get(returnNode);
c215dec9d3cf allow multiple ReturnNodes per graph
Lukas Stadler <lukas.stadler@jku.at>
parents: 13691
diff changeset
1144 ValueNode returnValue = returnDuplicate.result();
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1145 assert returnValue != null || replacee.usages().isEmpty();
11749
a27fcd670725 SnippetTemplate: use FloatingReadPhase to store MemoryMap at ReturnNodes in order to connect the snippet graph properly when inlining it
Bernhard Urban <bernhard.urban@jku.at>
parents: 11732
diff changeset
1146 replacer.replace(replacee, returnValue, new DuplicateMapper(duplicates, replaceeGraph.start()));
11388
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1147
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1148 if (returnDuplicate.isAlive()) {
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1149 returnDuplicate.clearInputs();
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1150 returnDuplicate.replaceAndDelete(next);
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1151 }
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1152
f88427168d19 added counters and timers for snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 10667
diff changeset
1153 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);
5670
29684ae5a194 Make sure snippet instentiation doesn't produce dead nodes and remove redundant DCE
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5574
diff changeset
1154 }
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
1155 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1156
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1157 @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
1158 public String toString() {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1159 StringBuilder buf = new StringBuilder(snippet.toString()).append('(');
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
1160 String sep = "";
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1161 for (int i = 0; i < parameters.length; i++) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1162 String name = "[" + i + "]";
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1163 Object value = parameters[i];
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
1164 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
1165 sep = ", ";
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1166 if (value == null) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1167 buf.append("<null> ").append(name);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1168 } else if (value == UNUSED_PARAMETER) {
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
1169 buf.append("<unused> ").append(name);
9038
8802f66cba62 Fix bug in graph dumping.
Roland Schatz <roland.schatz@oracle.com>
parents: 9015
diff changeset
1170 } else if (value == CONSTANT_PARAMETER) {
8802f66cba62 Fix bug in graph dumping.
Roland Schatz <roland.schatz@oracle.com>
parents: 9015
diff changeset
1171 buf.append("<constant> ").append(name);
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
1172 } else if (value instanceof ParameterNode) {
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
1173 ParameterNode param = (ParameterNode) value;
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
1174 buf.append(param.kind().getJavaName()).append(' ').append(name);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1175 } else {
13623
c70dddf5ce4a fixed name clash
Doug Simon <doug.simon@oracle.com>
parents: 13616
diff changeset
1176 ParameterNode[] params = (ParameterNode[]) value;
c70dddf5ce4a fixed name clash
Doug Simon <doug.simon@oracle.com>
parents: 13616
diff changeset
1177 String kind = params.length == 0 ? "?" : params[0].kind().getJavaName();
c70dddf5ce4a fixed name clash
Doug Simon <doug.simon@oracle.com>
parents: 13616
diff changeset
1178 buf.append(kind).append('[').append(params.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
1179 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1180 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1181 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
1182 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1183
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
1184 private static boolean checkTemplate(MetaAccessProvider metaAccess, Arguments args, ResolvedJavaMethod method, Signature signature) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1185 for (int i = 0; i < args.info.getParameterCount(); i++) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1186 if (args.info.isConstantParameter(i)) {
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
1187 Kind kind = signature.getParameterKind(i);
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
1188 assert checkConstantArgument(metaAccess, method, signature, i, args.info.names[i], args.values[i], kind);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1189
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1190 } else if (args.info.isVarargsParameter(i)) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1191 assert args.values[i] instanceof Varargs;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8959
diff changeset
1192 Varargs varargs = (Varargs) args.values[i];
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11847
diff changeset
1193 assert checkVarargs(metaAccess, method, signature, i, args.info.names[i], varargs);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1194 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1195 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1196 return true;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
1197 }
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
1198 }