annotate truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDispatchNode.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 503529c65456
children
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
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22003
diff changeset
6 *
21997
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
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22003
diff changeset
14 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
15 * (a) the Software, and
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22003
diff changeset
16 *
21997
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),
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22003
diff changeset
20 *
21997
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.
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22003
diff changeset
26 *
21997
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:
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22003
diff changeset
28 *
21997
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.
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22003
diff changeset
32 *
21997
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
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
43 import com.oracle.truffle.api.CallTarget;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
44 import com.oracle.truffle.api.dsl.Cached;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
45 import com.oracle.truffle.api.dsl.Specialization;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
46 import com.oracle.truffle.api.frame.VirtualFrame;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
47 import com.oracle.truffle.api.nodes.DirectCallNode;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
48 import com.oracle.truffle.api.nodes.IndirectCallNode;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
49 import com.oracle.truffle.api.nodes.Node;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
50 import com.oracle.truffle.sl.runtime.SLFunction;
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 public abstract class SLDispatchNode extends Node {
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 protected static final int INLINE_CACHE_SIZE = 2;
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 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
57
21493
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
58 @Specialization(guards = "function.getCallTarget() == null")
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
59 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
60 throw new SLUndefinedFunctionException(function.getName());
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
61 }
99e3f4c5c853 SL: handle undefined functions gracefully.
Christian Humer <christian.humer@gmail.com>
parents: 20956
diff changeset
62
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 /**
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 * Inline cached specialization of the dispatch.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 *
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 * <p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 * 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
68 * 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
69 * 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
70 * 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
71 * 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
72 * 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
73 * </p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 *
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 * {@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
77 * instantiations.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 * </p>
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 * {@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
81 * 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
82 * </p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 * <p>
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 * {@code assumptions = "cachedFunction.getCallTargetStable()"} Support for function
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 * 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
86 * 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
87 * 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
88 * 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
89 * execution.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 * </p>
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 * @see Cached
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 * @see Specialization
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 *
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 * @param function the dynamically provided function
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 * @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
97 * @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
98 * cachedFunction.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 */
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 @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
101 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
102 @Cached("function") SLFunction cachedFunction, //
20956
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 @Cached("create(cachedFunction.getCallTarget())") DirectCallNode callNode) {
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 /* 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
105 return callNode.call(frame, arguments);
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 }
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108 /**
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 * 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
110 * 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
111 * no method inlining is performed.
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 */
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113 @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
114 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
115 @Cached("create()") IndirectCallNode callNode) {
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 * 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
118 * call it.
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 return callNode.call(frame, function.getCallTarget(), arguments);
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 }
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122
2170de9acab0 SL: use DSL for call dispatches.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
123 }