Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java @ 16895:06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 18 Aug 2014 14:04:21 +0200 |
parents | cbd42807a31f |
children | 3c54a098455f |
rev | line source |
---|---|
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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 |
15259
d90e5c22ba55
Move GraalOptions to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15216
diff
changeset
|
25 import static com.oracle.graal.compiler.common.GraalOptions.*; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 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
|
28 import java.util.Map.Entry; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.code.*; |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.api.meta.*; |
16544
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
32 import com.oracle.graal.compiler.common.*; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 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
|
34 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
|
35 import com.oracle.graal.graph.Graph.Mark; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 import com.oracle.graal.graph.*; |
11712
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11707
diff
changeset
|
37 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
|
38 import com.oracle.graal.graph.spi.*; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 import com.oracle.graal.java.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
40 import com.oracle.graal.nodes.CallTargetNode.InvokeKind; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 import com.oracle.graal.nodes.*; |
10612
549a7568ce14
Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10611
diff
changeset
|
42 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
|
43 import com.oracle.graal.nodes.type.*; |
11712
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11707
diff
changeset
|
44 import com.oracle.graal.nodes.util.*; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 import com.oracle.graal.phases.*; |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 import com.oracle.graal.phases.util.*; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 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
|
51 import com.oracle.graal.virtual.phases.ea.*; |
10687
d2055a110396
Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10682
diff
changeset
|
52 import com.oracle.truffle.api.*; |
10614
f84ea5453961
Fixes for Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10613
diff
changeset
|
53 import com.oracle.truffle.api.nodes.*; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 /** |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 * 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
|
57 */ |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
58 public final class TruffleCacheImpl implements TruffleCache { |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
60 private final Providers providers; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 private final GraphBuilderConfiguration config; |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
62 private final GraphBuilderConfiguration configForRootGraph; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 private final OptimisticOptimizations optimisticOptimizations; |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 |
11707
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
65 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
|
66 private final HashMap<List<Object>, Long> lastUsed = new HashMap<>(); |
11707
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
67 private final StructuredGraph markerGraph = new StructuredGraph(); |
16267
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
68 |
11813
9af8b109ec0f
Truffle: force slow path on StringBuilder methods.
Andreas Woess <andreas.woess@jku.at>
parents:
11812
diff
changeset
|
69 private final ResolvedJavaType stringBuilderClass; |
16267
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
70 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
|
71 private final ResolvedJavaType errorClass; |
16267
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
72 private final ResolvedJavaType controlFlowExceptionClass; |
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
73 |
15216
d59f48be0ed6
Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15163
diff
changeset
|
74 private final ResolvedJavaMethod callBoundaryMethod; |
13991
25b86e465365
Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13615
diff
changeset
|
75 private long counter; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
77 public TruffleCacheImpl(Providers providers, GraphBuilderConfiguration config, GraphBuilderConfiguration configForRootGraph, OptimisticOptimizations optimisticOptimizations) { |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
78 this.providers = providers; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 this.config = config; |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
80 this.configForRootGraph = configForRootGraph; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
81 this.optimisticOptimizations = optimisticOptimizations; |
16267
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
82 |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
83 this.stringBuilderClass = providers.getMetaAccess().lookupJavaType(StringBuilder.class); |
16267
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
84 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
|
85 this.errorClass = providers.getMetaAccess().lookupJavaType(Error.class); |
16267
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
86 this.controlFlowExceptionClass = providers.getMetaAccess().lookupJavaType(ControlFlowException.class); |
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
87 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
88 try { |
15216
d59f48be0ed6
Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15163
diff
changeset
|
89 callBoundaryMethod = providers.getMetaAccess().lookupJavaMethod(OptimizedCallTarget.class.getDeclaredMethod("callRoot", Object[].class)); |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
90 } catch (NoSuchMethodException ex) { |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
91 throw new RuntimeException(ex); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
92 } |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
93 } |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
94 |
15287
e3b5fdeb304a
pass CallTarget name to Truffle-generated StructuredGraphs
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15260
diff
changeset
|
95 public StructuredGraph createRootGraph(String name) { |
e3b5fdeb304a
pass CallTarget name to Truffle-generated StructuredGraphs
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15260
diff
changeset
|
96 StructuredGraph graph = new StructuredGraph(name, callBoundaryMethod); |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
97 new GraphBuilderPhase.Instance(providers.getMetaAccess(), configForRootGraph, TruffleCompilerImpl.Optimizations).apply(graph); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
98 return graph; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
99 } |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
100 |
14984
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14866
diff
changeset
|
101 public StructuredGraph lookup(final ResolvedJavaMethod method, final NodeInputList<ValueNode> arguments, final Assumptions assumptions, final CanonicalizerPhase finalCanonicalizer, |
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14866
diff
changeset
|
102 boolean ignoreSlowPath) { |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
103 |
14984
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14866
diff
changeset
|
104 if (!ignoreSlowPath && method.getAnnotation(CompilerDirectives.SlowPath.class) != null) { |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
105 return null; |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
106 } |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14826
diff
changeset
|
107 |
11707
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
108 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
|
109 key.add(method); |
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
110 for (ValueNode v : arguments) { |
14633
da2431cc1506
Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents:
14624
diff
changeset
|
111 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
|
112 key.add(v.stamp()); |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
113 } |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
114 } |
11707
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
115 StructuredGraph resultGraph = cache.get(key); |
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
116 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
|
117 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
|
118 return resultGraph; |
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
119 } |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
120 |
11707
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
121 if (resultGraph == markerGraph) { |
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
122 // Avoid recursive inline. |
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
123 return null; |
10612
549a7568ce14
Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10611
diff
changeset
|
124 } |
549a7568ce14
Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10611
diff
changeset
|
125 |
13991
25b86e465365
Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13615
diff
changeset
|
126 if (lastUsed.values().size() >= TruffleCompilerOptions.TruffleMaxCompilationCacheSize.getValue()) { |
16544
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
127 lookupExceedsMaxSize(); |
13991
25b86e465365
Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13615
diff
changeset
|
128 } |
25b86e465365
Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13615
diff
changeset
|
129 |
25b86e465365
Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13615
diff
changeset
|
130 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
|
131 cache.put(key, markerGraph); |
14624
f3510d0dcf67
removed use of varargs from Debug.scope() API
Doug Simon <doug.simon@oracle.com>
parents:
14158
diff
changeset
|
132 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
|
133 |
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
|
134 final StructuredGraph graph = new StructuredGraph(method); |
13597
565bf188d39b
Fix graph mark comparison in TruffleCache
Andreas Woess <andreas.woess@jku.at>
parents:
13585
diff
changeset
|
135 final PhaseContext phaseContext = new PhaseContext(providers, new Assumptions(false)); |
565bf188d39b
Fix graph mark comparison in TruffleCache
Andreas Woess <andreas.woess@jku.at>
parents:
13585
diff
changeset
|
136 Mark mark = graph.getMark(); |
13585 | 137 new GraphBuilderPhase.Instance(phaseContext.getMetaAccess(), config, optimisticOptimizations).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
|
138 |
13614
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13597
diff
changeset
|
139 for (ParameterNode param : graph.getNodes(ParameterNode.class)) { |
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. |
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
|
150 new ConvertDeoptimizeToGuardPhase().apply(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
|
151 |
13378
16d99e9d77ad
Options: rename flag (AOTCompilation -> ImmutableCode)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13197
diff
changeset
|
152 CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase(!ImmutableCode.getValue()); |
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 PartialEscapePhase partialEscapePhase = new PartialEscapePhase(false, canonicalizerPhase); |
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
|
154 |
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. |
15390
fb014b3cf001
part 2, disabling flow-sensitive reductions
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
15388
diff
changeset
|
160 ConditionalEliminationPhase conditionalEliminationPhase = new ConditionalEliminationPhase(phaseContext.getMetaAccess()); |
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. |
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
|
164 canonicalizerPhase.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; |
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
|
167 for (MethodCallTargetNode methodCallTarget : graph.getNodes(MethodCallTargetNode.class)) { |
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; |
16544
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
173 lookupDoInline(graph, phaseContext, canonicalizerPhase, 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. |
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
178 new ConvertDeoptimizeToGuardPhase().apply(graph); |
f6f5fceef2ce
Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11681
diff
changeset
|
179 |
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
|
180 new EarlyReadEliminationPhase(canonicalizerPhase).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 |
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
|
187 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
|
188 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
|
189 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
|
190 } |
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
|
191 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
|
192 } 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
|
193 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
|
194 } |
16544
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
195 } |
11728
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
196 |
16544
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
197 private void lookupExceedsMaxSize() { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
198 List<Long> lastUsedList = new ArrayList<>(); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
199 for (long l : lastUsed.values()) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
200 lastUsedList.add(l); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
201 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
202 Collections.sort(lastUsedList); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
203 long mid = lastUsedList.get(lastUsedList.size() / 2); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
204 |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
205 List<List<Object>> toRemoveList = new ArrayList<>(); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
206 for (Entry<List<Object>, Long> entry : lastUsed.entrySet()) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
207 if (entry.getValue() < mid) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
208 toRemoveList.add(entry.getKey()); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
209 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
210 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
211 |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
212 for (List<Object> entry : toRemoveList) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
213 cache.remove(entry); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
214 lastUsed.remove(entry); |
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 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
217 |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
218 private Mark lookupProcessMacroSubstitutions(final StructuredGraph graph, Mark mark) throws GraalInternalError { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
219 // Make sure macro substitutions such as |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
220 // CompilerDirectives.transferToInterpreter get processed first. |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
221 for (Node newNode : graph.getNewNodes(mark)) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
222 if (newNode instanceof MethodCallTargetNode) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
223 MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) newNode; |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
224 Class<? extends FixedWithNextNode> macroSubstitution = providers.getReplacements().getMacroSubstitution(methodCallTargetNode.targetMethod()); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
225 if (macroSubstitution != null) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
226 InliningUtil.inlineMacroNode(methodCallTargetNode.invoke(), methodCallTargetNode.targetMethod(), macroSubstitution); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
227 } else { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
228 tryCutOffRuntimeExceptionsAndErrors(methodCallTargetNode); |
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 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
232 return graph.getMark(); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
233 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
234 |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
235 private void lookupDoInline(final StructuredGraph graph, final PhaseContext phaseContext, CanonicalizerPhase canonicalizerPhase, MethodCallTargetNode methodCallTarget) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
236 List<Node> canonicalizerUsages = new ArrayList<>(); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
237 for (Node n : methodCallTarget.invoke().asNode().usages()) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
238 if (n instanceof Canonicalizable) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
239 canonicalizerUsages.add(n); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
240 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
241 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
242 List<ValueNode> argumentSnapshot = methodCallTarget.arguments().snapshot(); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
243 Mark beforeInvokeMark = graph.getMark(); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
244 expandInvoke(methodCallTarget); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
245 for (Node arg : argumentSnapshot) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
246 if (arg != null && arg.recordsUsages()) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
247 for (Node argUsage : arg.usages()) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
248 if (graph.isNew(beforeInvokeMark, argUsage) && argUsage instanceof Canonicalizable) { |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
249 canonicalizerUsages.add(argUsage); |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
250 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
251 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
252 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
253 } |
1e8b758800fb
extract methods in TruffleCacheImpl
Christian Wirth <christian.wirth@oracle.com>
parents:
16432
diff
changeset
|
254 canonicalizerPhase.applyIncremental(graph, phaseContext, canonicalizerUsages); |
11268
ac59bdde1194
TruffleCache: do not expand assertion paths by default.
Andreas Woess <andreas.woess@jku.at>
parents:
11265
diff
changeset
|
255 } |
ac59bdde1194
TruffleCache: do not expand assertion paths by default.
Andreas Woess <andreas.woess@jku.at>
parents:
11265
diff
changeset
|
256 |
11728
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
257 private void expandInvoke(MethodCallTargetNode methodCallTargetNode) { |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
258 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
|
259 if (inlineGraph == null) { |
14984
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14866
diff
changeset
|
260 inlineGraph = TruffleCacheImpl.this.lookup(methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), null, null, false); |
11728
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
261 } |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
262 if (inlineGraph == this.markerGraph) { |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
263 // 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
|
264 throw GraphUtil.approxSourceException(methodCallTargetNode, new IllegalStateException("Found illegal recursive call to " + methodCallTargetNode.targetMethod() + |
4937347fa343
Truffle: approximate source location for "illegal recursive call".
Andreas Woess <andreas.woess@jku.at>
parents:
11801
diff
changeset
|
265 ", must annotate such calls with @CompilerDirectives.SlowPath!")); |
11728
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
266 } |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
267 Invoke invoke = methodCallTargetNode.invoke(); |
16176
5785eca138b0
improve tracking of nodes to canonicalize after inlining
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15470
diff
changeset
|
268 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
|
269 } |
10687
d2055a110396
Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10682
diff
changeset
|
270 |
16432
78cbe3d93bc1
truffle compiler: be a bit more aggressive on cutting exceptions/errors
Bernhard Urban <bernhard.urban@jku.at>
parents:
16431
diff
changeset
|
271 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
|
272 if (methodCallTargetNode.targetMethod().isConstructor()) { |
16267
c04bdca850a9
truffle compiler: small cleanup
Bernhard Urban <bernhard.urban@jku.at>
parents:
16266
diff
changeset
|
273 ResolvedJavaType declaringClass = methodCallTargetNode.targetMethod().getDeclaringClass(); |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15259
diff
changeset
|
274 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
|
275 |
16432
78cbe3d93bc1
truffle compiler: be a bit more aggressive on cutting exceptions/errors
Bernhard Urban <bernhard.urban@jku.at>
parents:
16431
diff
changeset
|
276 boolean removeAllocation = runtimeExceptionClass.isAssignableFrom(declaringClass) || errorClass.isAssignableFrom(declaringClass); |
16431
99fa6bd5d27b
truffle compiler: rename
Bernhard Urban <bernhard.urban@jku.at>
parents:
16267
diff
changeset
|
277 boolean isControlFlowException = controlFlowExceptionClass.isAssignableFrom(exceptionType); |
99fa6bd5d27b
truffle compiler: rename
Bernhard Urban <bernhard.urban@jku.at>
parents:
16267
diff
changeset
|
278 if (removeAllocation && !isControlFlowException) { |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
279 DeoptimizeNode deoptNode = methodCallTargetNode.graph().add(DeoptimizeNode.create(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.UnreachedCode)); |
11728
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
280 FixedNode invokeNode = methodCallTargetNode.invoke().asNode(); |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
281 invokeNode.replaceAtPredecessor(deoptNode); |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
282 GraphUtil.killCFG(invokeNode); |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
283 return true; |
10612
549a7568ce14
Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10611
diff
changeset
|
284 } |
549a7568ce14
Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10611
diff
changeset
|
285 } |
11728
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
286 return false; |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
287 } |
7778a0f2999a
Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11712
diff
changeset
|
288 |
11813
9af8b109ec0f
Truffle: force slow path on StringBuilder methods.
Andreas Woess <andreas.woess@jku.at>
parents:
11812
diff
changeset
|
289 private boolean shouldInline(final MethodCallTargetNode methodCallTargetNode) { |
15163
e5265dc8762f
Truffle: Clean ups around optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14991
diff
changeset
|
290 boolean result = (methodCallTargetNode.invokeKind() == InvokeKind.Special || methodCallTargetNode.invokeKind() == InvokeKind.Static) && methodCallTargetNode.targetMethod().canBeInlined() && |
15311
820c6d353358
added ModifiersProvider as superinterface for ResolvedJava[Method|Field|Type] and implemented all checks against modifiers as default methods
Doug Simon <doug.simon@oracle.com>
parents:
15287
diff
changeset
|
291 !methodCallTargetNode.targetMethod().isNative() && methodCallTargetNode.targetMethod().getAnnotation(ExplodeLoop.class) == null && |
14158
fd7fcd2d2072
replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents:
13993
diff
changeset
|
292 methodCallTargetNode.targetMethod().getAnnotation(CompilerDirectives.SlowPath.class) == null && |
fd7fcd2d2072
replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents:
13993
diff
changeset
|
293 !methodCallTargetNode.targetMethod().getDeclaringClass().equals(stringBuilderClass); |
15163
e5265dc8762f
Truffle: Clean ups around optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14991
diff
changeset
|
294 return result; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
295 } |
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
296 } |