annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java @ 19540:9a749d774c73

Refactor ConvertDeoptimizeToGuardPhase.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 22 Feb 2015 19:31:57 +0100
parents 61d3cb8e1280
children 69b7ad0a3fda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
18208
abe9758da9d9 Truffle: add headers for new compilation listener files.
Christian Humer <christian.humer@gmail.com>
parents: 18204
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.truffle;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.util.*;
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
26 import java.util.Map.Entry;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.api.meta.*;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 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: 12686
diff changeset
30 import com.oracle.graal.debug.Debug.Scope;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
31 import com.oracle.graal.graph.Graph.Mark;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.graph.*;
11712
0d16339188ef Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11707
diff changeset
33 import com.oracle.graal.graph.Node;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11813
diff changeset
34 import com.oracle.graal.graph.spi.*;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.java.*;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.nodes.*;
19306
a0a760b0fb5f pulled method evolution dependencies out of Assumptions and directly into StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19250
diff changeset
37 import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions;
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
38 import com.oracle.graal.nodes.java.*;
11801
63ee8dea4b80 TruffleCache: do not cut off ControlFlowException constructors.
Andreas Woess <andreas.woess@jku.at>
parents: 11728
diff changeset
39 import com.oracle.graal.nodes.type.*;
11712
0d16339188ef Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11707
diff changeset
40 import com.oracle.graal.nodes.util.*;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 import com.oracle.graal.phases.*;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.phases.common.*;
15470
c55f44b3c5e5 remove NodesToDoubles, refactoring of node probability and inlining relevance computation
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15390
diff changeset
43 import com.oracle.graal.phases.common.inlining.*;
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
44 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
45 import com.oracle.graal.phases.util.*;
18204
a1873eefea65 Truffle: refactor TraceTrufflePerformanceWarnings into separate class.
Christian Humer <christian.humer@gmail.com>
parents: 18146
diff changeset
46 import com.oracle.graal.truffle.debug.*;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 import com.oracle.graal.truffle.phases.*;
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
48 import com.oracle.graal.virtual.phases.ea.*;
10687
d2055a110396 Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10682
diff changeset
49 import com.oracle.truffle.api.*;
10614
f84ea5453961 Fixes for Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10613
diff changeset
50 import com.oracle.truffle.api.nodes.*;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 /**
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 * Implementation of a cache for Truffle graphs for improving partial evaluation time.
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 */
17192
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
55 public class TruffleCacheImpl implements TruffleCache {
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
57 private final Providers providers;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 private final GraphBuilderConfiguration config;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 private final OptimisticOptimizations optimisticOptimizations;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
61 private final HashMap<List<Object>, StructuredGraph> cache = new HashMap<>();
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
62 private final HashMap<List<Object>, Long> lastUsed = new HashMap<>();
19306
a0a760b0fb5f pulled method evolution dependencies out of Assumptions and directly into StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19250
diff changeset
63 private final StructuredGraph markerGraph = new StructuredGraph(AllowAssumptions.NO);
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
64
11813
9af8b109ec0f Truffle: force slow path on StringBuilder methods.
Andreas Woess <andreas.woess@jku.at>
parents: 11812
diff changeset
65 private final ResolvedJavaType stringBuilderClass;
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
66 private final ResolvedJavaType runtimeExceptionClass;
16432
78cbe3d93bc1 truffle compiler: be a bit more aggressive on cutting exceptions/errors
Bernhard Urban <bernhard.urban@jku.at>
parents: 16431
diff changeset
67 private final ResolvedJavaType errorClass;
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
68 private final ResolvedJavaType controlFlowExceptionClass;
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
69
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
70 private long counter;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71
19107
46544f51cde4 Move some logic from TruffleCache to PartialEvaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19050
diff changeset
72 public TruffleCacheImpl(Providers providers, GraphBuilderConfiguration config, OptimisticOptimizations optimisticOptimizations) {
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
73 this.providers = providers;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 this.config = config;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 this.optimisticOptimizations = optimisticOptimizations;
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
76
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
77 this.stringBuilderClass = providers.getMetaAccess().lookupJavaType(StringBuilder.class);
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
78 this.runtimeExceptionClass = providers.getMetaAccess().lookupJavaType(RuntimeException.class);
16432
78cbe3d93bc1 truffle compiler: be a bit more aggressive on cutting exceptions/errors
Bernhard Urban <bernhard.urban@jku.at>
parents: 16431
diff changeset
79 this.errorClass = providers.getMetaAccess().lookupJavaType(Error.class);
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
80 this.controlFlowExceptionClass = providers.getMetaAccess().lookupJavaType(ControlFlowException.class);
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17203
diff changeset
81 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17203
diff changeset
82
18146
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
83 private static List<Object> computeCacheKey(ResolvedJavaMethod method, NodeInputList<ValueNode> arguments) {
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
84 List<Object> key = new ArrayList<>(arguments.size() + 1);
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
85 key.add(method);
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
86 for (ValueNode v : arguments) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14624
diff changeset
87 if (v.getKind() == Kind.Object) {
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
88 key.add(v.stamp());
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 }
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 }
18146
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
91 return key;
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
92 }
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
93
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
94 public StructuredGraph lookup(ResolvedJavaMethod method, NodeInputList<ValueNode> arguments, CanonicalizerPhase canonicalizer) {
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
95 List<Object> key = computeCacheKey(method, arguments);
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
96 StructuredGraph resultGraph = cache.get(key);
18143
0e1c92b8b267 TruffleCache: avoid publishing invalid cache state.
Bernhard Urban <bernhard.urban@jku.at>
parents: 18141
diff changeset
97 if (resultGraph == markerGraph) {
18146
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
98 // compilation failed previously, don't try again
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
99 return null;
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
100 }
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
101 StructuredGraph graph = cacheLookup(method, arguments, canonicalizer);
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
102 assert graph != markerGraph : "markerGraph should not leak out";
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
103 return graph;
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
104 }
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
105
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
106 private StructuredGraph cacheLookup(ResolvedJavaMethod method, NodeInputList<ValueNode> arguments, CanonicalizerPhase canonicalizer) {
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
107 if (method.getAnnotation(CompilerDirectives.TruffleBoundary.class) != null) {
18143
0e1c92b8b267 TruffleCache: avoid publishing invalid cache state.
Bernhard Urban <bernhard.urban@jku.at>
parents: 18141
diff changeset
108 return null;
0e1c92b8b267 TruffleCache: avoid publishing invalid cache state.
Bernhard Urban <bernhard.urban@jku.at>
parents: 18141
diff changeset
109 }
0e1c92b8b267 TruffleCache: avoid publishing invalid cache state.
Bernhard Urban <bernhard.urban@jku.at>
parents: 18141
diff changeset
110
18146
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
111 List<Object> key = computeCacheKey(method, arguments);
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
112 StructuredGraph resultGraph = cache.get(key);
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
113 if (resultGraph != null) {
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
114 lastUsed.put(key, counter++);
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
115 return resultGraph;
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
116 }
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
118 if (lastUsed.values().size() >= TruffleCompilerOptions.TruffleMaxCompilationCacheSize.getValue()) {
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
119 lookupExceedsMaxSize();
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
120 }
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
121
19306
a0a760b0fb5f pulled method evolution dependencies out of Assumptions and directly into StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19250
diff changeset
122 StructuredGraph graph = new StructuredGraph(method, AllowAssumptions.NO);
19250
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19116
diff changeset
123 PhaseContext phaseContext = new PhaseContext(providers);
14624
f3510d0dcf67 removed use of varargs from Debug.scope() API
Doug Simon <doug.simon@oracle.com>
parents: 14160
diff changeset
124 try (Scope s = Debug.scope("TruffleCache", providers.getMetaAccess(), method)) {
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: 12686
diff changeset
125
19250
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19116
diff changeset
126 graph = parseGraph(graph, phaseContext);
17192
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
127 if (graph == null) {
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
128 return null;
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
129 }
18550
bbf27a6ffb52 add graph to context in TruffleCacheImpl.cacheLookup
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18487
diff changeset
130 } catch (Throwable e) {
bbf27a6ffb52 add graph to context in TruffleCacheImpl.cacheLookup
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18487
diff changeset
131 throw Debug.handle(e);
bbf27a6ffb52 add graph to context in TruffleCacheImpl.cacheLookup
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18487
diff changeset
132 }
bbf27a6ffb52 add graph to context in TruffleCacheImpl.cacheLookup
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18487
diff changeset
133
bbf27a6ffb52 add graph to context in TruffleCacheImpl.cacheLookup
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18487
diff changeset
134 try (Scope s = Debug.scope("TruffleCache", providers.getMetaAccess(), method, graph)) {
17192
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
135
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
136 lastUsed.put(key, counter++);
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
137 cache.put(key, markerGraph);
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: 12686
diff changeset
138
19403
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19306
diff changeset
139 for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14624
diff changeset
140 if (param.getKind() == Kind.Object) {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13597
diff changeset
141 ValueNode actualArgument = arguments.get(param.index());
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13597
diff changeset
142 param.setStamp(param.stamp().join(actualArgument.stamp()));
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: 12686
diff changeset
143 }
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
144 }
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
145
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
146 // Intrinsify methods.
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
147 new ReplaceIntrinsicsPhase(providers.getReplacements()).apply(graph);
10614
f84ea5453961 Fixes for Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10613
diff changeset
148
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: 12686
diff changeset
149 // Convert deopt to guards.
19540
9a749d774c73 Refactor ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19403
diff changeset
150 new ConvertDeoptimizeToGuardPhase().apply(graph, 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: 12686
diff changeset
151
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
152 PartialEscapePhase partialEscapePhase = new PartialEscapePhase(false, canonicalizer);
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: 12686
diff changeset
153
18550
bbf27a6ffb52 add graph to context in TruffleCacheImpl.cacheLookup
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18487
diff changeset
154 Mark mark = null;
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: 12686
diff changeset
155 while (true) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
156
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
157 partialEscapePhase.apply(graph, phaseContext);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
158
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
159 // Conditional elimination.
18487
0f4813e0b4a9 Use asConstant() instead of asJavaConstant() where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 18208
diff changeset
160 ConditionalEliminationPhase conditionalEliminationPhase = new ConditionalEliminationPhase();
15390
fb014b3cf001 part 2, disabling flow-sensitive reductions
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15388
diff changeset
161 conditionalEliminationPhase.apply(graph);
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: 12686
diff changeset
162
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
163 // Canonicalize / constant propagate.
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
164 canonicalizer.apply(graph, phaseContext);
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
165
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: 12686
diff changeset
166 boolean inliningProgress = false;
19403
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19306
diff changeset
167 for (MethodCallTargetNode methodCallTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
13597
565bf188d39b Fix graph mark comparison in TruffleCache
Andreas Woess <andreas.woess@jku.at>
parents: 13585
diff changeset
168 if (!graph.getMark().equals(mark)) {
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
169 mark = lookupProcessMacroSubstitutions(graph, mark);
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: 12686
diff changeset
170 }
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
171 if (methodCallTarget.isAlive() && methodCallTarget.invoke() != null && shouldInline(methodCallTarget)) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
172 inliningProgress = true;
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
173 lookupDoInline(graph, phaseContext, canonicalizer, methodCallTarget);
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
174 }
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
175 }
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
176
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
177 // Convert deopt to guards.
19540
9a749d774c73 Refactor ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19403
diff changeset
178 new ConvertDeoptimizeToGuardPhase().apply(graph, phaseContext);
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
179
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
180 new EarlyReadEliminationPhase(canonicalizer).apply(graph, phaseContext);
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
181
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: 12686
diff changeset
182 if (!inliningProgress) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
183 break;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
184 }
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
185 }
11712
0d16339188ef Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11707
diff changeset
186
17407
c4cdee8566a4 Truffle: rename PrintTrufflePerformanceWarnings to TraceTrufflePerformanceWarnings.
Christian Humer <christian.humer@gmail.com>
parents: 17307
diff changeset
187 if (TruffleCompilerOptions.TraceTrufflePerformanceWarnings.getValue()) {
17273
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
188 int warnNodeCount = TruffleCompilerOptions.TrufflePerformanceWarningGraalNodeCount.getValue();
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
189 if (graph.getNodeCount() > warnNodeCount) {
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
190 Map<String, Object> map = new LinkedHashMap<>();
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
191 map.put("nodeCount", graph.getNodeCount());
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
192 map.put("method", method.toString());
18204
a1873eefea65 Truffle: refactor TraceTrufflePerformanceWarnings into separate class.
Christian Humer <christian.humer@gmail.com>
parents: 18146
diff changeset
193 TracePerformanceWarningsListener.logPerformanceWarning(String.format("Method on fast path contains more than %d graal nodes.", warnNodeCount), map);
18978
9110e3065561 dump graphs for performance warnings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18964
diff changeset
194
9110e3065561 dump graphs for performance warnings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18964
diff changeset
195 try (Scope s2 = Debug.scope("TrufflePerformanceWarnings")) {
9110e3065561 dump graphs for performance warnings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18964
diff changeset
196 Debug.dump(graph, "performance warning");
9110e3065561 dump graphs for performance warnings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18964
diff changeset
197 }
17273
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
198 }
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
199 }
43655130d0ab Truffle: added a performance warning for number of nodes in a single Truffle cache entry.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
200
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: 12686
diff changeset
201 cache.put(key, graph);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
202 if (TruffleCompilerOptions.TraceTruffleCacheDetails.getValue()) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
203 TTY.println(String.format("[truffle] added to graph cache method %s with %d nodes.", method, graph.getNodeCount()));
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
204 }
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
205 return graph;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12686
diff changeset
206 } 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: 12686
diff changeset
207 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: 12686
diff changeset
208 }
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
209 }
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
210
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
211 private void lookupExceedsMaxSize() {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
212 List<Long> lastUsedList = new ArrayList<>();
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
213 for (long l : lastUsed.values()) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
214 lastUsedList.add(l);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
215 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
216 Collections.sort(lastUsedList);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
217 long mid = lastUsedList.get(lastUsedList.size() / 2);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
218
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
219 List<List<Object>> toRemoveList = new ArrayList<>();
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
220 for (Entry<List<Object>, Long> entry : lastUsed.entrySet()) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
221 if (entry.getValue() < mid) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
222 toRemoveList.add(entry.getKey());
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
223 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
224 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
225
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
226 for (List<Object> entry : toRemoveList) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
227 cache.remove(entry);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
228 lastUsed.remove(entry);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
229 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
230 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
231
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
232 private Mark lookupProcessMacroSubstitutions(StructuredGraph graph, Mark mark) {
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
233 // Make sure macro substitutions such as
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
234 // CompilerDirectives.transferToInterpreter get processed first.
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
235 for (Node newNode : graph.getNewNodes(mark)) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
236 if (newNode instanceof MethodCallTargetNode) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
237 MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) newNode;
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
238 Class<? extends FixedWithNextNode> macroSubstitution = providers.getReplacements().getMacroSubstitution(methodCallTargetNode.targetMethod());
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
239 if (macroSubstitution != null) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
240 InliningUtil.inlineMacroNode(methodCallTargetNode.invoke(), methodCallTargetNode.targetMethod(), macroSubstitution);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
241 } else {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
242 tryCutOffRuntimeExceptionsAndErrors(methodCallTargetNode);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
243 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
244 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
245 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
246 return graph.getMark();
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
247 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
248
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
249 private void lookupDoInline(StructuredGraph graph, PhaseContext phaseContext, CanonicalizerPhase canonicalizer, MethodCallTargetNode methodCallTarget) {
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
250 List<Node> canonicalizerUsages = new ArrayList<>();
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
251 for (Node n : methodCallTarget.invoke().asNode().usages()) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
252 if (n instanceof Canonicalizable) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
253 canonicalizerUsages.add(n);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
254 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
255 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
256 List<ValueNode> argumentSnapshot = methodCallTarget.arguments().snapshot();
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
257 Mark beforeInvokeMark = graph.getMark();
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
258 expandInvoke(methodCallTarget, canonicalizer);
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
259 for (Node arg : argumentSnapshot) {
17064
3c54a098455f removed Node.recordsUsages()
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
260 if (arg != null) {
16544
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
261 for (Node argUsage : arg.usages()) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
262 if (graph.isNew(beforeInvokeMark, argUsage) && argUsage instanceof Canonicalizable) {
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
263 canonicalizerUsages.add(argUsage);
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
264 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
265 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
266 }
1e8b758800fb extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents: 16432
diff changeset
267 }
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
268 canonicalizer.applyIncremental(graph, phaseContext, canonicalizerUsages);
11268
ac59bdde1194 TruffleCache: do not expand assertion paths by default.
Andreas Woess <andreas.woess@jku.at>
parents: 11265
diff changeset
269 }
ac59bdde1194 TruffleCache: do not expand assertion paths by default.
Andreas Woess <andreas.woess@jku.at>
parents: 11265
diff changeset
270
19250
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19116
diff changeset
271 protected StructuredGraph parseGraph(StructuredGraph graph, final PhaseContext phaseContext) {
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19116
diff changeset
272 new GraphBuilderPhase.Instance(phaseContext.getMetaAccess(), phaseContext.getStampProvider(), null, config, optimisticOptimizations).apply(graph);
17192
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
273 return graph;
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
274 }
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
275
17170
fe5d4383b505 use supplied canonicalizer in TruffleCacheImpl
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17064
diff changeset
276 private void expandInvoke(MethodCallTargetNode methodCallTargetNode, CanonicalizerPhase canonicalizer) {
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
277 StructuredGraph inlineGraph = providers.getReplacements().getMethodSubstitution(methodCallTargetNode.targetMethod());
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
278 if (inlineGraph == null) {
18146
9db0af368bb4 truffleCache: refactor in order to fix recursive inlining warning
Bernhard Urban <bernhard.urban@jku.at>
parents: 18143
diff changeset
279 inlineGraph = cacheLookup(methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), canonicalizer);
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
280 }
17192
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
281 if (inlineGraph == null) {
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
282 return;
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
283 }
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
284 if (inlineGraph == this.markerGraph) {
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
285 // Can happen for recursive calls.
11812
4937347fa343 Truffle: approximate source location for "illegal recursive call".
Andreas Woess <andreas.woess@jku.at>
parents: 11801
diff changeset
286 throw GraphUtil.approxSourceException(methodCallTargetNode, new IllegalStateException("Found illegal recursive call to " + methodCallTargetNode.targetMethod() +
18138
4c49f062d136 Truffle: corrected references to @SlowPath (now @TruffleBoundary).
Danilo Ansaloni <danilo.ansaloni@oracle.com>
parents: 18130
diff changeset
287 ", must annotate such calls with @TruffleBoundary!"));
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
288 }
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
289 Invoke invoke = methodCallTargetNode.invoke();
16176
5785eca138b0 improve tracking of nodes to canonicalize after inlining
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15470
diff changeset
290 InliningUtil.inline(invoke, inlineGraph, true, null);
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
291 }
10687
d2055a110396 Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10682
diff changeset
292
16432
78cbe3d93bc1 truffle compiler: be a bit more aggressive on cutting exceptions/errors
Bernhard Urban <bernhard.urban@jku.at>
parents: 16431
diff changeset
293 private boolean tryCutOffRuntimeExceptionsAndErrors(MethodCallTargetNode methodCallTargetNode) {
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
294 if (methodCallTargetNode.targetMethod().isConstructor()) {
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
295 ResolvedJavaType declaringClass = methodCallTargetNode.targetMethod().getDeclaringClass();
15260
61363577a184 Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents: 15259
diff changeset
296 ResolvedJavaType exceptionType = Objects.requireNonNull(StampTool.typeOrNull(methodCallTargetNode.receiver().stamp()));
16267
c04bdca850a9 truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents: 16266
diff changeset
297
16432
78cbe3d93bc1 truffle compiler: be a bit more aggressive on cutting exceptions/errors
Bernhard Urban <bernhard.urban@jku.at>
parents: 16431
diff changeset
298 boolean removeAllocation = runtimeExceptionClass.isAssignableFrom(declaringClass) || errorClass.isAssignableFrom(declaringClass);
16431
99fa6bd5d27b truffle compiler: rename
Bernhard Urban <bernhard.urban@jku.at>
parents: 16267
diff changeset
299 boolean isControlFlowException = controlFlowExceptionClass.isAssignableFrom(exceptionType);
99fa6bd5d27b truffle compiler: rename
Bernhard Urban <bernhard.urban@jku.at>
parents: 16267
diff changeset
300 if (removeAllocation && !isControlFlowException) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18834
diff changeset
301 DeoptimizeNode deoptNode = methodCallTargetNode.graph().add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.UnreachedCode));
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
302 FixedNode invokeNode = methodCallTargetNode.invoke().asNode();
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
303 invokeNode.replaceAtPredecessor(deoptNode);
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
304 GraphUtil.killCFG(invokeNode);
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
305 return true;
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
306 }
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
307 }
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
308 return false;
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
309 }
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
310
17192
d0d76deeacb9 Make more Truffle code HotSpot independent, and allow more customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17170
diff changeset
311 protected boolean shouldInline(MethodCallTargetNode methodCallTargetNode) {
18834
21de06b3f429 Respect canBeInlined in Truffle partial evaluation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18829
diff changeset
312 boolean result = methodCallTargetNode.invokeKind().isDirect() && methodCallTargetNode.targetMethod().hasBytecodes() && methodCallTargetNode.targetMethod().canBeInlined() &&
18822
fad37aaed6d2 Add utilities isDirect and isIndirect to InvokeKind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18550
diff changeset
313 methodCallTargetNode.targetMethod().getAnnotation(ExplodeLoop.class) == null &&
18130
b4e38f4ca414 Truffle: rename @SlowPath to @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 17427
diff changeset
314 methodCallTargetNode.targetMethod().getAnnotation(CompilerDirectives.TruffleBoundary.class) == null &&
14160
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 13993
diff changeset
315 !methodCallTargetNode.targetMethod().getDeclaringClass().equals(stringBuilderClass);
15163
e5265dc8762f Truffle: Clean ups around optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14991
diff changeset
316 return result;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
317 }
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
318 }