annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java @ 15163:e5265dc8762f

Truffle: Clean ups around optimized call target.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 15 Apr 2014 15:31:01 +0200
parents 64dcb92ee75a
children d59f48be0ed6
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 /*
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
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import static com.oracle.graal.phases.GraalOptions.*;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
27 import java.lang.reflect.*;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 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
29 import java.util.Map.Entry;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.api.code.*;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.api.meta.*;
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.*;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 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
41 import com.oracle.graal.nodes.java.*;
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.MethodCallTargetNode.InvokeKind;
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.*;
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
47 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
48 import com.oracle.graal.phases.util.*;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 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
50 import com.oracle.graal.virtual.phases.ea.*;
10687
d2055a110396 Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10682
diff changeset
51 import com.oracle.truffle.api.*;
10614
f84ea5453961 Fixes for Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10613
diff changeset
52 import com.oracle.truffle.api.nodes.*;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
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 * 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
56 */
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
57 public final class TruffleCacheImpl implements TruffleCache {
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
59 private final Providers providers;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 private final GraphBuilderConfiguration config;
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
61 private final GraphBuilderConfiguration configForRootGraph;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 private final OptimisticOptimizations optimisticOptimizations;
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
64 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
65 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
66 private final StructuredGraph markerGraph = new StructuredGraph();
11813
9af8b109ec0f Truffle: force slow path on StringBuilder methods.
Andreas Woess <andreas.woess@jku.at>
parents: 11812
diff changeset
67 private final ResolvedJavaType stringBuilderClass;
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
68 private final ResolvedJavaMethod executeHelperMethod;
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
69 private long counter;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
71 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
72 this.providers = providers;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 this.config = config;
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
74 this.configForRootGraph = configForRootGraph;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 this.optimisticOptimizations = optimisticOptimizations;
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
76 this.stringBuilderClass = providers.getMetaAccess().lookupJavaType(StringBuilder.class);
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
77 try {
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14984
diff changeset
78 executeHelperMethod = providers.getMetaAccess().lookupJavaMethod(OptimizedCallTarget.class.getDeclaredMethod("executeHelper", Object[].class));
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
79 } catch (NoSuchMethodException ex) {
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
80 throw new RuntimeException(ex);
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
81 }
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
82 }
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
83
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
84 public StructuredGraph createRootGraph() {
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
85 StructuredGraph graph = new StructuredGraph(executeHelperMethod);
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
86 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
87 return graph;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 }
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89
11681
39f98ffd187f Fix compiler warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11680
diff changeset
90 @SuppressWarnings("unused")
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
91 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
92 boolean ignoreSlowPath) {
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93
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
94 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
95 return null;
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
96 }
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14826
diff changeset
97
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
98 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
99 key.add(method);
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
100 for (ValueNode v : arguments) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14624
diff changeset
101 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
102 key.add(v.stamp());
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 }
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 }
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
105 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
106 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
107 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
108 return resultGraph;
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
109 }
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
111 if (resultGraph == markerGraph) {
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
112 // Avoid recursive inline.
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
113 return null;
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
114 }
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
115
13991
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
116 if (lastUsed.values().size() >= TruffleCompilerOptions.TruffleMaxCompilationCacheSize.getValue()) {
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
117 List<Long> lastUsedList = new ArrayList<>();
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
118 for (long l : lastUsed.values()) {
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
119 lastUsedList.add(l);
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 Collections.sort(lastUsedList);
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
122 long mid = lastUsedList.get(lastUsedList.size() / 2);
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
123
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
124 List<List<Object>> toRemoveList = new ArrayList<>();
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
125 for (Entry<List<Object>, Long> entry : lastUsed.entrySet()) {
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
126 if (entry.getValue() < mid) {
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
127 toRemoveList.add(entry.getKey());
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
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
131 for (List<Object> entry : toRemoveList) {
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
132 cache.remove(entry);
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
133 lastUsed.remove(entry);
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
134 }
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
135 }
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
136
25b86e465365 Turn Truffle cache into least recently used cache with maximum size.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13615
diff changeset
137 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
138 cache.put(key, markerGraph);
14624
f3510d0dcf67 removed use of varargs from Debug.scope() API
Doug Simon <doug.simon@oracle.com>
parents: 14158
diff changeset
139 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
140
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
141 final StructuredGraph graph = new StructuredGraph(method);
13597
565bf188d39b Fix graph mark comparison in TruffleCache
Andreas Woess <andreas.woess@jku.at>
parents: 13585
diff changeset
142 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
143 Mark mark = graph.getMark();
13585
f4f0a8a01ce0 remove PhasePlan
Lukas Stadler <lukas.stadler@jku.at>
parents: 13584
diff changeset
144 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
145
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13597
diff changeset
146 for (ParameterNode param : graph.getNodes(ParameterNode.class)) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14624
diff changeset
147 if (param.getKind() == Kind.Object) {
13614
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13597
diff changeset
148 ValueNode actualArgument = arguments.get(param.index());
0774f3303c2e rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 13597
diff changeset
149 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
150 }
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 }
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
152
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 // 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
154 new ReplaceIntrinsicsPhase(providers.getReplacements()).apply(graph);
10614
f84ea5453961 Fixes for Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10613
diff changeset
155
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
156 // 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
157 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
158
13378
16d99e9d77ad Options: rename flag (AOTCompilation -> ImmutableCode)
Bernhard Urban <bernhard.urban@jku.at>
parents: 13197
diff changeset
159 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
160 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
161
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 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
163
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 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
165
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 // Conditional elimination.
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 ConditionalEliminationPhase conditionalEliminationPhase = new ConditionalEliminationPhase(phaseContext.getMetaAccess());
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
168 conditionalEliminationPhase.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
169
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 // 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
171 canonicalizerPhase.apply(graph, phaseContext);
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
172
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
173 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
174 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
175 if (!graph.getMark().equals(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
176 // Make sure macro substitutions such as
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
177 // CompilerDirectives.transferToInterpreter get processed first.
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
178 for (Node newNode : graph.getNewNodes(mark)) {
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
179 if (newNode instanceof MethodCallTargetNode) {
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 MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) newNode;
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
181 Class<? extends FixedWithNextNode> macroSubstitution = providers.getReplacements().getMacroSubstitution(methodCallTargetNode.targetMethod());
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 (macroSubstitution != null) {
13601
fd522e725ee5 inliningutils: minor refactor
Bernhard Urban <bernhard.urban@jku.at>
parents: 13597
diff changeset
183 InliningUtil.inlineMacroNode(methodCallTargetNode.invoke(), methodCallTargetNode.targetMethod(), macroSubstitution);
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
184 } else {
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 tryCutOffRuntimeExceptions(methodCallTargetNode);
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
186 }
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 }
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 }
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 mark = graph.getMark();
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 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
192 inliningProgress = 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
193 List<Node> canonicalizerUsages = new ArrayList<Node>();
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 for (Node n : methodCallTarget.invoke().asNode().usages()) {
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
195 if (n instanceof Canonicalizable) {
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
196 canonicalizerUsages.add(n);
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
197 }
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
198 }
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
199 List<ValueNode> argumentSnapshot = methodCallTarget.arguments().snapshot();
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
200 Mark beforeInvokeMark = graph.getMark();
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 expandInvoke(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
202 for (Node arg : argumentSnapshot) {
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 if (arg != null && arg.recordsUsages()) {
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 for (Node argUsage : arg.usages()) {
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 if (graph.isNew(beforeInvokeMark, argUsage) && argUsage instanceof Canonicalizable) {
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 canonicalizerUsages.add(argUsage);
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 }
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 }
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
209 }
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
210 }
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
211 canonicalizerPhase.applyIncremental(graph, phaseContext, canonicalizerUsages);
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
212 }
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
213 }
11707
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
214
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
215 // Convert deopt to guards.
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
216 new ConvertDeoptimizeToGuardPhase().apply(graph);
f6f5fceef2ce Simpler but more efficient version of Truffle graph cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11681
diff changeset
217
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
218 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
219
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
220 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
221 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
222 }
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
223 }
11712
0d16339188ef Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11707
diff changeset
224
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
225 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
226 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
227 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
228 }
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
229 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
230 } 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
231 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
232 }
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
233
11268
ac59bdde1194 TruffleCache: do not expand assertion paths by default.
Andreas Woess <andreas.woess@jku.at>
parents: 11265
diff changeset
234 }
ac59bdde1194 TruffleCache: do not expand assertion paths by default.
Andreas Woess <andreas.woess@jku.at>
parents: 11265
diff changeset
235
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
236 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
237 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
238 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
239 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
240 }
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
241 if (inlineGraph == this.markerGraph) {
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
242 // 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
243 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
244 ", 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
245 }
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
246 Invoke invoke = methodCallTargetNode.invoke();
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
247 InliningUtil.inline(invoke, inlineGraph, true);
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
248 }
10687
d2055a110396 Introduce CompilerDirectives.SlowPath annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10682
diff changeset
249
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
250 private boolean tryCutOffRuntimeExceptions(MethodCallTargetNode methodCallTargetNode) {
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
251 if (methodCallTargetNode.targetMethod().isConstructor()) {
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
252 ResolvedJavaType runtimeException = providers.getMetaAccess().lookupJavaType(RuntimeException.class);
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
253 ResolvedJavaType controlFlowException = providers.getMetaAccess().lookupJavaType(ControlFlowException.class);
11801
63ee8dea4b80 TruffleCache: do not cut off ControlFlowException constructors.
Andreas Woess <andreas.woess@jku.at>
parents: 11728
diff changeset
254 ResolvedJavaType exceptionType = Objects.requireNonNull(ObjectStamp.typeOrNull(methodCallTargetNode.receiver().stamp()));
63ee8dea4b80 TruffleCache: do not cut off ControlFlowException constructors.
Andreas Woess <andreas.woess@jku.at>
parents: 11728
diff changeset
255 if (runtimeException.isAssignableFrom(methodCallTargetNode.targetMethod().getDeclaringClass()) && !controlFlowException.isAssignableFrom(exceptionType)) {
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
256 DeoptimizeNode deoptNode = methodCallTargetNode.graph().add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.UnreachedCode));
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
257 FixedNode invokeNode = methodCallTargetNode.invoke().asNode();
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
258 invokeNode.replaceAtPredecessor(deoptNode);
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
259 GraphUtil.killCFG(invokeNode);
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
260 return true;
10612
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
261 }
549a7568ce14 Introduce new Truffle compiler options: TruffleOperationCacheMaxNodes and TraceTruffleCompilationExceptions
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10611
diff changeset
262 }
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
263 return false;
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
264 }
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
265
11813
9af8b109ec0f Truffle: force slow path on StringBuilder methods.
Andreas Woess <andreas.woess@jku.at>
parents: 11812
diff changeset
266 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
267 boolean result = (methodCallTargetNode.invokeKind() == InvokeKind.Special || methodCallTargetNode.invokeKind() == InvokeKind.Static) && methodCallTargetNode.targetMethod().canBeInlined() &&
11728
7778a0f2999a Run partial escape analysis on Truffle cache methods.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11712
diff changeset
268 !Modifier.isNative(methodCallTargetNode.targetMethod().getModifiers()) && 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
269 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
270 !methodCallTargetNode.targetMethod().getDeclaringClass().equals(stringBuilderClass);
15163
e5265dc8762f Truffle: Clean ups around optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14991
diff changeset
271 return result;
10611
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 }
1546866ebb8d First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
273 }