annotate truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDispatchNode.java @ 22003:5bc7f7b867ab

Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Sat, 18 Jul 2015 18:03:36 +0200
parents c07e64ecb528
children 503529c65456
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
5 * The Universal Permissive License (UPL), Version 1.0
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
6 *
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
7 * Subject to the condition set forth below, permission is hereby granted to any
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
8 * person obtaining a copy of this software, associated documentation and/or
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
9 * data (collectively the "Software"), free of charge and under any and all
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
10 * copyright rights in the Software, and any and all patent rights owned or
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
11 * freely licensable by each licensor hereunder covering either (i) the
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
12 * unmodified Software as contributed to or provided by such licensor, or (ii)
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
13 * the Larger Works (as defined below), to deal in both
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
14 *
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
15 * (a) the Software, and
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
16 *
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
17 * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
18 * one is included with the Software each a "Larger Work" to which the Software
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
19 * is contributed by such licensors),
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
20 *
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
21 * without restriction, including without limitation the rights to copy, create
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
22 * derivative works of, display, perform, and distribute the Software and make,
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
23 * use, sell, offer for sale, import, export, have made, and have sold the
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
24 * Software and the Larger Work(s), and to sublicense the foregoing rights on
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
25 * either these or other terms.
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
26 *
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
27 * This license is subject to the following condition:
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
28 *
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
29 * The above copyright notice and either this complete permission notice or at a
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
30 * minimum a reference to the UPL must be included in all copies or substantial
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
31 * portions of the Software.
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
32 *
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
39 * SOFTWARE.
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 */
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 package com.oracle.truffle.sl.nodes.call;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 import com.oracle.truffle.api.*;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 import com.oracle.truffle.api.dsl.*;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 import com.oracle.truffle.api.frame.*;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 import com.oracle.truffle.api.nodes.*;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 import com.oracle.truffle.sl.runtime.*;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 public abstract class SLDispatchNode extends Node {
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 protected static final int INLINE_CACHE_SIZE = 2;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 public abstract Object executeDispatch(VirtualFrame frame, SLFunction function, Object[] arguments);
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54
21493
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
55 @Specialization(guards = "function.getCallTarget() == null")
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
56 protected Object doUndefinedFunction(SLFunction function, @SuppressWarnings("unused") Object[] arguments) {
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
57 throw new SLUndefinedFunctionException(function.getName());
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
58 }
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
59
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 /**
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 * Inline cached specialization of the dispatch.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 *
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 * <p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 * Since SL is a quite simple language, the benefit of the inline cache is quite small: after
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 * checking that the actual function to be executed is the same as the cachedFuntion, we can
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 * safely execute the cached call target. You can reasonably argue that caching the call target
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 * is overkill, since we could just retrieve it via {@code function.getCallTarget()}. However,
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 * in a more complex language the lookup of the call target is usually much more complicated
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 * than in SL. In addition, caching the call target allows method inlining.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 * </p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 *
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 * <p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 * {@code limit = "INLINE_CACHE_SIZE"} Specifies the limit number of inline cache specialization
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 * instantiations.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 * </p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 * <p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 * {@code guards = "function == cachedFunction"} The inline cache check. Note that
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 * cachedFunction is a final field so that the compiler can optimize the check.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 * </p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 * <p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 * {@code assumptions = "cachedFunction.getCallTargetStable()"} Support for function
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 * redefinition: When a function is redefined, the call target maintained by the SLFunction
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 * object is change. To avoid a check for that, we use an Assumption that is invalidated by the
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 * SLFunction when the change is performed. Since checking an assumption is a no-op in compiled
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 * code, the assumption check performed by the DSL does not add any overhead during optimized
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 * execution.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 * </p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88 *
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 * @see Cached
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 * @see Specialization
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 *
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 * @param function the dynamically provided function
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 * @param cachedFunction the cached function of the specialization instance
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 * @param callNode the {@link DirectCallNode} specifically created for the {@link CallTarget} in
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 * cachedFunction.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 */
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 @Specialization(limit = "INLINE_CACHE_SIZE", guards = "function == cachedFunction", assumptions = "cachedFunction.getCallTargetStable()")
22003
5bc7f7b867ab Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21997
diff changeset
98 protected static Object doDirect(VirtualFrame frame, SLFunction function, Object[] arguments, //
5bc7f7b867ab Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21997
diff changeset
99 @Cached("function") SLFunction cachedFunction, //
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 @Cached("create(cachedFunction.getCallTarget())") DirectCallNode callNode) {
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 /* Inline cache hit, we are safe to execute the cached call target. */
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 return callNode.call(frame, arguments);
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 }
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 /**
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 * Slow-path code for a call, used when the polymorphic inline cache exceeded its maximum size
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 * specified in <code>INLINE_CACHE_SIZE</code>. Such calls are not optimized any further, e.g.,
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108 * no method inlining is performed.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 */
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
110 @Specialization(contains = "doDirect")
22003
5bc7f7b867ab Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21997
diff changeset
111 protected static Object doIndirect(VirtualFrame frame, SLFunction function, Object[] arguments, //
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 @Cached("create()") IndirectCallNode callNode) {
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113 /*
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114 * SL has a quite simple call lookup: just ask the function for the current call target, and
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 * call it.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
116 */
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117 return callNode.call(frame, function.getCallTarget(), arguments);
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 }
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 }