annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUninitializedDispatchNode.java @ 18311:3343ed66de79

Truffle: RootNode#getExecutionContext.
author Chris Seaton <chris.seaton@oracle.com>
date Sun, 09 Nov 2014 00:54:15 +0000
parents 64dcb92ee75a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
4 *
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
8 *
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
14 *
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
18 *
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
21 * questions.
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
22 */
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.sl.nodes.call;
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
25 import com.oracle.truffle.api.*;
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
26 import com.oracle.truffle.api.frame.*;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
27 import com.oracle.truffle.api.nodes.*;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
28 import com.oracle.truffle.sl.*;
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29 import com.oracle.truffle.sl.runtime.*;
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
30
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
31 /**
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
32 * The last entry of a polymorphic inline cache.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
33 */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
34 final class SLUninitializedDispatchNode extends SLAbstractDispatchNode {
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
35
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
36 /**
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
37 * When we reach this method, all the previous cache entries did not match the function. If the
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
38 * cache is still small enough, we extend it by adding another {@link SLDirectDispatchNode}. If
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
39 * the cache reached its maximum size, we replace the whole dispatch chain with a
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
40 * {@link SLGenericDispatchNode}.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
41 */
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
42 @Override
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13959
diff changeset
43 protected Object executeDispatch(VirtualFrame frame, SLFunction function, Object[] arguments) {
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
44 /* The following code modifies the AST, so compiled code must be invalidated. */
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
45 CompilerDirectives.transferToInterpreterAndInvalidate();
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
46
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
47 /*
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
48 * Count the number of SLDirectDispatchNodes we already have in the cache. We walk the chain
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
49 * of parent nodes until we hit the SLCallNode. We know that a SLCallNode is always present.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
50 */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
51 Node cur = this;
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
52 int depth = 0;
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
53 while (cur.getParent() instanceof SLAbstractDispatchNode) {
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
54 cur = cur.getParent();
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
55 depth++;
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
56 }
13943
89ac75425681 SL: small cleanups
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13836
diff changeset
57 SLInvokeNode invokeNode = (SLInvokeNode) cur.getParent();
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
58
13959
96bd95f62d92 SL: small cleanups
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13943
diff changeset
59 SLAbstractDispatchNode replacement;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
60 if (function.getCallTarget() == null) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
61 /* Corner case: the function is not defined, so report an error to the user. */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
62 throw new SLException("Call of undefined function: " + function.getName());
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
63
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
64 } else if (depth < INLINE_CACHE_SIZE) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
65 /* Extend the inline cache. Allocate the new cache entry, and the new end of the cache. */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
66 SLAbstractDispatchNode next = new SLUninitializedDispatchNode();
13959
96bd95f62d92 SL: small cleanups
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13943
diff changeset
67 replacement = new SLDirectDispatchNode(next, function);
13836
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
68 /* Replace ourself with the new cache entry. */
13959
96bd95f62d92 SL: small cleanups
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13943
diff changeset
69 replace(replacement);
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
70
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
71 } else {
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
72 /* Cache size exceeded, fall back to a single generic dispatch node. */
13959
96bd95f62d92 SL: small cleanups
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13943
diff changeset
73 replacement = new SLGenericDispatchNode();
13836
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
74 /* Replace the whole chain, not just ourself, with the new generic node. */
13959
96bd95f62d92 SL: small cleanups
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13943
diff changeset
75 invokeNode.dispatchNode.replace(replacement);
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
76 }
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
77
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
78 /*
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
79 * Execute the newly created node perform the actual dispatch. That saves us from
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
80 * duplicating the actual call logic here.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13807
diff changeset
81 */
13959
96bd95f62d92 SL: small cleanups
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13943
diff changeset
82 return replacement.executeDispatch(frame, function, arguments);
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
83 }
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
84 }