annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 22219:1c0f490984d5

Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 16 Sep 2015 15:36:22 -0700
parents dc83cc1f94f2 3aad794eec0e
children 20380d1d41f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
11279
494b818b527c Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10862
diff changeset
7 * published by the Free Software Foundation. Oracle designates this
494b818b527c Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10862
diff changeset
8 * particular file as subject to the "Classpath" exception as provided
494b818b527c Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10862
diff changeset
9 * by Oracle in the LICENSE file that accompanied this code.
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 *
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * This code is distributed in the hope that it will be useful, but WITHOUT
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 * version 2 for more details (a copy is included in the LICENSE file that
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * accompanied this code).
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 *
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License version
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 * 2 along with this work; if not, write to the Free Software Foundation,
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 *
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 * or visit www.oracle.com if you need additional information or have any
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 * questions.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 package com.oracle.truffle.api.nodes;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
27 import java.lang.annotation.ElementType;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
28 import java.lang.annotation.Retention;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
29 import java.lang.annotation.RetentionPolicy;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
30 import java.lang.annotation.Target;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
31 import java.util.HashMap;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
32 import java.util.Iterator;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
33 import java.util.Map;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
34 import java.util.concurrent.Callable;
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
36 import com.oracle.truffle.api.CallTarget;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
37 import com.oracle.truffle.api.CompilerAsserts;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
38 import com.oracle.truffle.api.CompilerDirectives;
17382
e1da729b3e4e make Truffle Node source section @CompilationFinal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16912
diff changeset
39 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
40 import com.oracle.truffle.api.ReplaceObserver;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
41 import com.oracle.truffle.api.TruffleLanguage;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
42 import com.oracle.truffle.api.TruffleOptions;
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: 21966
diff changeset
43 import com.oracle.truffle.api.impl.Accessor;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
44 import com.oracle.truffle.api.instrument.Instrument;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
45 import com.oracle.truffle.api.instrument.Probe;
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
46 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
47 import com.oracle.truffle.api.source.SourceSection;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
48 import com.oracle.truffle.api.utilities.JSONHelper;
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
49
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 * Abstract base class for all Truffle nodes.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 */
18332
65a160d9d259 Truffle: add NodeInterface and require that all child fields be of this type
Andreas Woess <andreas.woess@jku.at>
parents: 17389
diff changeset
53 public abstract class Node implements NodeInterface, Cloneable {
20130
8dc73c226c63 Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents: 19979
diff changeset
54 private final NodeClass nodeClass;
17389
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
55 @CompilationFinal private Node parent;
17382
e1da729b3e4e make Truffle Node source section @CompilationFinal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16912
diff changeset
56 @CompilationFinal private SourceSection sourceSection;
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
57
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 * Marks array fields that are children of this node.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 @Retention(RetentionPolicy.RUNTIME)
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 @Target({ElementType.FIELD})
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 public @interface Children {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 * Marks fields that represent child nodes of this node.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 @Retention(RetentionPolicy.RUNTIME)
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 @Target({ElementType.FIELD})
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 public @interface Child {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
74 protected Node() {
16151
76895499bc88 Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents: 16067
diff changeset
75 this(null);
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
76 }
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
77
11535
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
78 protected Node(SourceSection sourceSection) {
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
79 CompilerAsserts.neverPartOfCompilation();
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
80 this.sourceSection = sourceSection;
20130
8dc73c226c63 Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents: 19979
diff changeset
81 this.nodeClass = NodeClass.get(getClass());
16151
76895499bc88 Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents: 16067
diff changeset
82 if (TruffleOptions.TraceASTJSON) {
76895499bc88 Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents: 16067
diff changeset
83 JSONHelper.dumpNewNode(this);
76895499bc88 Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents: 16067
diff changeset
84 }
11535
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
85 }
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
86
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 /**
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
88 * Assigns a link to a guest language source section to this node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
89 *
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
90 * @param section the object representing a section in guest language source code
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
91 */
22035
100d2d3250d5 remove final from key SourceSection methods
Mick Jordan <mick.jordan@oracle.com>
parents: 21966
diff changeset
92 public void assignSourceSection(SourceSection section) {
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
93 if (sourceSection != null) {
11610
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
94 // Patch this test during the transition to constructor-based
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
95 // source attribution, which would otherwise trigger this
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
96 // exception. This method will eventually be deprecated.
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
97 if (getSourceSection() != section) {
11648
4ab1f371adc8 Do not assign new source section if replacing node already has source section assigned.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11610
diff changeset
98 throw new IllegalStateException("Source section is already assigned. Old: " + getSourceSection() + ", new: " + section);
11610
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
99 }
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
100 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
101 this.sourceSection = section;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
102 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
103
20130
8dc73c226c63 Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents: 19979
diff changeset
104 NodeClass getNodeClass() {
8dc73c226c63 Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents: 19979
diff changeset
105 return nodeClass;
8dc73c226c63 Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents: 19979
diff changeset
106 }
8dc73c226c63 Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents: 19979
diff changeset
107
14566
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
108 /**
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
109 * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
110 * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
111 * is intended to be overridden by subclasses. The default implementation returns the value of
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
112 * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
113 * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
114 * default value.
6681b9eb3f4c Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 14564
diff changeset
115 */
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14073
diff changeset
116 public NodeCost getCost() {
13994
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
117 NodeInfo info = getClass().getAnnotation(NodeInfo.class);
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
118 if (info != null) {
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14073
diff changeset
119 return info.cost();
13994
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
120 }
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14073
diff changeset
121 return NodeCost.MONOMORPHIC;
13994
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
122 }
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
123
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
124 /**
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
125 * Clears any previously assigned guest language source code from this node.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
126 */
22037
494b5e7094d0 remove final on clearSourceSection
Mick Jordan <mick.jordan@oracle.com>
parents: 22035
diff changeset
127 public void clearSourceSection() {
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
128 this.sourceSection = null;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
129 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
130
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
131 /**
21117
f6f3f44a1830 Truffle/Instrumentation: Javadoc corrections on Node.{getSourceSection,getEncapsulatingSourceSection}
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 20131
diff changeset
132 * Retrieves the segment of guest language source code that is represented by this Node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
133 *
21117
f6f3f44a1830 Truffle/Instrumentation: Javadoc corrections on Node.{getSourceSection,getEncapsulatingSourceSection}
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 20131
diff changeset
134 * @return the source code represented by this Node
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
135 */
22035
100d2d3250d5 remove final from key SourceSection methods
Mick Jordan <mick.jordan@oracle.com>
parents: 21966
diff changeset
136 public SourceSection getSourceSection() {
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
137 return sourceSection;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
138 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
139
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
140 /**
21117
f6f3f44a1830 Truffle/Instrumentation: Javadoc corrections on Node.{getSourceSection,getEncapsulatingSourceSection}
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 20131
diff changeset
141 * Retrieves the segment of guest language source code that is represented by this Node, if
f6f3f44a1830 Truffle/Instrumentation: Javadoc corrections on Node.{getSourceSection,getEncapsulatingSourceSection}
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 20131
diff changeset
142 * present; otherwise retrieves the segment represented by the nearest AST ancestor that has
f6f3f44a1830 Truffle/Instrumentation: Javadoc corrections on Node.{getSourceSection,getEncapsulatingSourceSection}
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 20131
diff changeset
143 * this information.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
144 *
21117
f6f3f44a1830 Truffle/Instrumentation: Javadoc corrections on Node.{getSourceSection,getEncapsulatingSourceSection}
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 20131
diff changeset
145 * @return an approximation of the source code represented by this Node
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
146 */
17389
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
147 @ExplodeLoop
22035
100d2d3250d5 remove final from key SourceSection methods
Mick Jordan <mick.jordan@oracle.com>
parents: 21966
diff changeset
148 public SourceSection getEncapsulatingSourceSection() {
17389
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
149 Node current = this;
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
150 while (current != null) {
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
151 if (current.sourceSection != null) {
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
152 return current.sourceSection;
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
153 }
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
154 current = current.parent;
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
155 }
17389
763a34f283f9 make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17382
diff changeset
156 return null;
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
157 }
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
158
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
159 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
160 * Method that updates the link to the parent in the array of specified new child nodes to this
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
161 * node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
162 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 * @param newChildren the array of new children whose parent should be updated
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 * @return the array of new children
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 */
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
166 protected final <T extends Node> T[] insert(final T[] newChildren) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
167 CompilerDirectives.transferToInterpreterAndInvalidate();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
168 assert newChildren != null;
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
169 for (Node newChild : newChildren) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
170 adoptHelper(newChild);
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 return newChildren;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 * Method that updates the link to the parent in the specified new child node to this node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
177 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 * @param newChild the new child whose parent should be updated
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 * @return the new child
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 */
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
181 protected final <T extends Node> T insert(final T newChild) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
182 CompilerDirectives.transferToInterpreterAndInvalidate();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
183 assert newChild != null;
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
184 adoptHelper(newChild);
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
185 return newChild;
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
186 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
187
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
188 public final void adoptChildren() {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
189 CompilerDirectives.transferToInterpreterAndInvalidate();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
190 adoptHelper();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
191 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
192
22080
65e9fbb40e51 avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents: 22066
diff changeset
193 void adoptHelper(final Node newChild) {
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
194 assert newChild != null;
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
195 if (newChild == this) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
196 throw new IllegalStateException("The parent of a node can never be the node itself.");
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
197 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
198 newChild.parent = this;
16151
76895499bc88 Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents: 16067
diff changeset
199 if (TruffleOptions.TraceASTJSON) {
76895499bc88 Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents: 16067
diff changeset
200 JSONHelper.dumpNewChild(this, newChild);
76895499bc88 Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents: 16067
diff changeset
201 }
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
202 newChild.adoptHelper();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
203 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
204
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
205 private void adoptHelper() {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
206 Iterable<Node> children = this.getChildren();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
207 for (Node child : children) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
208 if (child != null && child.getParent() != this) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
209 this.adoptHelper(child);
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
210 }
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
211 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
212 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
213
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
214 private void adoptUnadoptedHelper(final Node newChild) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
215 assert newChild != null;
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
216 if (newChild == this) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
217 throw new IllegalStateException("The parent of a node can never be the node itself.");
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 }
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
219 newChild.parent = this;
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
220 newChild.adoptUnadoptedHelper();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
221 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
222
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
223 private void adoptUnadoptedHelper() {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
224 Iterable<Node> children = this.getChildren();
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
225 for (Node child : children) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
226 if (child != null && child.getParent() == null) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
227 this.adoptUnadoptedHelper(child);
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
228 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
229 }
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
230 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
233 * Returns properties of this node interesting for debugging and can be overwritten by
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
234 * subclasses to add their own custom properties.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
235 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
236 * @return the properties as a key/value hash map
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238 public Map<String, Object> getDebugProperties() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 Map<String, Object> properties = new HashMap<>();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240 return properties;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
241 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
244 * The current parent node of this node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
245 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
246 * @return the parent node
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
247 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 public final Node getParent() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 return parent;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
250 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
252 /**
9256
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
253 * Replaces this node with another node. If there is a source section (see
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
254 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
255 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
256 * @param newNode the new node that is the replacement
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
257 * @param reason a description of the reason for the replacement
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
258 * @return the new node
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
259 */
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
260 public final <T extends Node> T replace(final T newNode, final CharSequence reason) {
13915
d6b340b757a2 Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents: 13811
diff changeset
261 CompilerDirectives.transferToInterpreterAndInvalidate();
14629
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
262 atomic(new Runnable() {
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
263 public void run() {
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
264 replaceHelper(newNode, reason);
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
265 }
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
266 });
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
267 return newNode;
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
270 /**
9256
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
271 * Replaces this node with another node. If there is a source section (see
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
272 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
273 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
274 * @param newNode the new node that is the replacement
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
275 * @return the new node
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
276 */
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
277 public final <T extends Node> T replace(T newNode) {
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
278 return replace(newNode, "");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
279 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
280
19758
f682b9e6ca07 Truffle: expose non-atomic replace API to Truffle DSL to avoid multiple RootNode lookups for multiple replaces in one atomic block.
Christian Humer <christian.humer@gmail.com>
parents: 19606
diff changeset
281 final void replaceHelper(Node newNode, CharSequence reason) {
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
282 CompilerAsserts.neverPartOfCompilation();
19767
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
283 assert inAtomicBlock();
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
284 if (this.getParent() == null) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
285 throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent.");
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
286 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
287 if (sourceSection != null && newNode.getSourceSection() == null) {
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
288 // Pass on the source section to the new node.
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
289 newNode.assignSourceSection(sourceSection);
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
290 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
291 // (aw) need to set parent *before* replace, so that (unsynchronized) getRootNode()
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
292 // will always find the root node
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
293 newNode.parent = this.parent;
22080
65e9fbb40e51 avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents: 22066
diff changeset
294 if (!NodeUtil.replaceChild(this.parent, this, newNode, true)) {
14628
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
295 this.parent.adoptUnadoptedHelper(newNode);
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
296 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
297 reportReplace(this, newNode, reason);
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
298 onReplace(newNode, reason);
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
299 }
a08b8694f556 Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents: 14584
diff changeset
300
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
301 /**
19141
67d9e635102f Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19038
diff changeset
302 * Checks if this node can be replaced by another node: tree structure & type.
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
303 */
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
304 public final boolean isSafelyReplaceableBy(Node newNode) {
19141
67d9e635102f Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19038
diff changeset
305 return NodeUtil.isReplacementSafe(getParent(), this, newNode);
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
306 }
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
307
14584
6189c1983cd3 Truffle: make Node#replace accept any CharSequence as reason
Andreas Woess <andreas.woess@jku.at>
parents: 14566
diff changeset
308 private void reportReplace(Node oldNode, Node newNode, CharSequence reason) {
16912
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
309 Node node = this;
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
310 while (node != null) {
21204
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 21117
diff changeset
311 boolean consumed = false;
16912
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
312 if (node instanceof ReplaceObserver) {
21204
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 21117
diff changeset
313 consumed = ((ReplaceObserver) node).nodeReplaced(oldNode, newNode, reason);
16912
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
314 } else if (node instanceof RootNode) {
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
315 CallTarget target = ((RootNode) node).getCallTarget();
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
316 if (target instanceof ReplaceObserver) {
21204
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 21117
diff changeset
317 consumed = ((ReplaceObserver) target).nodeReplaced(oldNode, newNode, reason);
16912
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
318 }
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
319 }
21204
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 21117
diff changeset
320 if (consumed) {
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 21117
diff changeset
321 break;
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 21117
diff changeset
322 }
16912
f8998c828bed Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 16467
diff changeset
323 node = node.getParent();
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
324 }
16464
76081918079d Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents: 16151
diff changeset
325 if (TruffleOptions.TraceRewrites) {
76081918079d Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents: 16151
diff changeset
326 NodeUtil.traceRewrite(this, newNode, reason);
76081918079d Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents: 16151
diff changeset
327 }
76081918079d Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents: 16151
diff changeset
328 if (TruffleOptions.TraceASTJSON) {
76081918079d Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents: 16151
diff changeset
329 JSONHelper.dumpReplaceChild(this, newNode, reason);
76081918079d Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents: 16151
diff changeset
330 }
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
331 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
332
10846
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
333 /**
9782
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
334 * Intended to be implemented by subclasses of {@link Node} to receive a notification when the
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
335 * node is rewritten. This method is invoked before the actual replace has happened.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
336 *
9782
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
337 * @param newNode the replacement node
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
338 * @param reason the reason the replace supplied
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
339 */
14584
6189c1983cd3 Truffle: make Node#replace accept any CharSequence as reason
Andreas Woess <andreas.woess@jku.at>
parents: 14566
diff changeset
340 protected void onReplace(Node newNode, CharSequence reason) {
16464
76081918079d Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents: 16151
diff changeset
341 // empty default
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
342 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
343
15346
1cd02b4d90d1 onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents: 14991
diff changeset
344 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
345 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
346 * child nodes.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
347 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
348 * @param nodeVisitor the visitor
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
349 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
350 public final void accept(NodeVisitor nodeVisitor) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
351 if (nodeVisitor.visit(this)) {
20131
4b12d5355811 Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
352 NodeUtil.forEachChildRecursive(this, nodeVisitor);
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
353 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
355
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
356 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
357 * Iterator over the children of this node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
358 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
359 * @return the iterator
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
360 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
361 public final Iterable<Node> getChildren() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
362 return new Iterable<Node>() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
363 public Iterator<Node> iterator() {
21650
45ed86c4d127 Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents: 21204
diff changeset
364 return getNodeClass().makeIterator(Node.this);
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
365 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
366 };
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
367 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
368
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
369 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
370 * Creates a shallow copy of this node.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
371 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
372 * @return the new copy
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
373 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
374 public Node copy() {
21966
5023b913e2ba Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21951
diff changeset
375 CompilerAsserts.neverPartOfCompilation();
5023b913e2ba Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21951
diff changeset
376
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
377 try {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
378 return (Node) super.clone();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
379 } catch (CloneNotSupportedException e) {
18509
7bf2965140de Truffle: Node#clone(): throw assertion error on CloneNotSupportedException
Andreas Woess <andreas.woess@jku.at>
parents: 18332
diff changeset
380 throw new AssertionError(e);
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
381 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
382 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
383
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
384 /**
18750
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
385 * Creates a deep copy of this node.
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
386 *
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
387 * @return the new deep copy
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
388 */
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
389 public Node deepCopy() {
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
390 return NodeUtil.deepCopyImpl(this);
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
391 }
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
392
8a758dce7d80 Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents: 18509
diff changeset
393 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
394 * This method must never be called. It enforces that {@link Object#clone} is not directly
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
395 * called by subclasses. Use the {@link #copy()} method instead.
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
396 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
397 @Override
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
398 @Deprecated
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
399 protected final Object clone() throws CloneNotSupportedException {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
400 throw new IllegalStateException("This method should never be called, use the copy method instead!");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
401 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
403 /**
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
404 * Get the root node of the tree a node belongs to.
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14629
diff changeset
405 *
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
406 * @return the {@link RootNode} or {@code null} if there is none.
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
407 */
13983
f46cab39a9a2 Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
408 public final RootNode getRootNode() {
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
409 Node rootNode = this;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
410 while (rootNode.getParent() != null) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
411 assert !(rootNode instanceof RootNode) : "root node must not have a parent";
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
412 rootNode = rootNode.getParent();
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
413 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
414 if (rootNode instanceof RootNode) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
415 return (RootNode) rootNode;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
416 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
417 return null;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
418 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
419
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
420 /**
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
421 * Any node for which this is {@code true} can be "instrumented" by installing a {@link Probe}
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
422 * that intercepts execution events at the node and routes them to any {@link Instrument}s that
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
423 * have been attached to the {@link Probe}. Only one {@link Probe} may be installed at each
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
424 * node; subsequent calls return the one already installed.
19038
c7e57dffc5ad Truffle/Instrumentation: comments and minor code cleanup post-review
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18985
diff changeset
425 * <p>
c7e57dffc5ad Truffle/Instrumentation: comments and minor code cleanup post-review
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18985
diff changeset
426 * <b>Note:</b> instrumentation requires a appropriate {@link WrapperNode}, which must be
c7e57dffc5ad Truffle/Instrumentation: comments and minor code cleanup post-review
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18985
diff changeset
427 * provided by {@link #createWrapperNode()}.
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
428 *
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
429 * @see Instrument
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
430 */
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
431 public boolean isInstrumentable() {
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
432 return false;
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
433 }
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
434
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
435 /**
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
436 * For any node that {@link #isInstrumentable()}, this method must return a {@link Node} that:
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
437 * <ol>
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
438 * <li>implements {@link WrapperNode}</li>
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
439 * <li>has {@code this} as it's child, and</li>
19038
c7e57dffc5ad Truffle/Instrumentation: comments and minor code cleanup post-review
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18985
diff changeset
440 * <li>whose type is safe for replacement of {@code this} in the parent.</li>
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
441 * </ol>
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
442 *
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
443 * @return an appropriately typed {@link WrapperNode} if {@link #isInstrumentable()}.
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
444 */
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
445 public WrapperNode createWrapperNode() {
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
446 return null;
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
447 }
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
448
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18750
diff changeset
449 /**
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
450 * Converts this node to a textual representation useful for debugging.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
451 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
452 @Override
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
453 public String toString() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
454 StringBuilder sb = new StringBuilder(getClass().getSimpleName());
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
455 Map<String, Object> properties = getDebugProperties();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
456 boolean hasProperties = false;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
457 for (Map.Entry<String, Object> entry : properties.entrySet()) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
458 sb.append(hasProperties ? "," : "<");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
459 hasProperties = true;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
460 sb.append(entry.getKey()).append("=").append(entry.getValue());
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
461 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
462 if (hasProperties) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
463 sb.append(">");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
464 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
465 sb.append("@").append(Integer.toHexString(hashCode()));
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
466 return sb.toString();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
467 }
14629
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
468
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
469 public final void atomic(Runnable closure) {
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
470 RootNode rootNode = getRootNode();
19606
d344d76b7b6d Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents: 19247
diff changeset
471 synchronized (rootNode != null ? rootNode : GIL) {
19767
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
472 assert enterAtomic();
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
473 try {
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
474 closure.run();
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
475 } finally {
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
476 assert exitAtomic();
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
477 }
14629
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
478 }
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
479 }
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
480
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
481 public final <T> T atomic(Callable<T> closure) {
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
482 try {
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
483 RootNode rootNode = getRootNode();
19606
d344d76b7b6d Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents: 19247
diff changeset
484 synchronized (rootNode != null ? rootNode : GIL) {
19767
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
485 assert enterAtomic();
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
486 try {
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
487 return closure.call();
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
488 } finally {
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
489 assert exitAtomic();
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
490 }
14629
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
491 }
19606
d344d76b7b6d Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents: 19247
diff changeset
492 } catch (RuntimeException | Error e) {
14629
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
493 throw e;
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
494 } catch (Exception e) {
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
495 throw new RuntimeException(e);
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
496 }
ba52fbec5b6c Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents: 14628
diff changeset
497 }
15775
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
498
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
499 /**
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
500 * Returns a user-readable description of the purpose of the Node, or "" if no description is
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
501 * available.
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
502 */
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
503 public String getDescription() {
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
504 NodeInfo info = getClass().getAnnotation(NodeInfo.class);
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
505 if (info != null) {
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
506 return info.description();
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
507 }
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
508 return "";
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
509 }
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
510
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
511 /**
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
512 * Returns a string representing the language this node has been implemented for. If the
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
513 * language is unknown, returns "".
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
514 */
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
515 public String getLanguage() {
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
516 NodeInfo info = getClass().getAnnotation(NodeInfo.class);
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
517 if (info != null && info.language() != null && info.language().length() > 0) {
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
518 return info.language();
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
519 }
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
520 if (parent != null) {
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
521 return parent.getLanguage();
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
522 }
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
523 return "";
4293efaaab76 Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents: 15474
diff changeset
524 }
19606
d344d76b7b6d Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents: 19247
diff changeset
525
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
526 protected void applyInstrumentation(Node node) {
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
527 ACCESSOR.applyInstrumentation(node);
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
528 }
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
529
19606
d344d76b7b6d Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents: 19247
diff changeset
530 private static final Object GIL = new Object();
19767
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
531
19979
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
532 private static final ThreadLocal<Integer> IN_ATOMIC_BLOCK = new ThreadLocal<Integer>() {
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
533 @Override
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
534 protected Integer initialValue() {
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
535 return 0;
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
536 }
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
537 };
19767
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
538
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
539 private static boolean inAtomicBlock() {
19979
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
540 return IN_ATOMIC_BLOCK.get() > 0;
19767
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
541 }
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
542
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
543 private static boolean enterAtomic() {
19979
f792b4270cb1 Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents: 19975
diff changeset
544 IN_ATOMIC_BLOCK.set(IN_ATOMIC_BLOCK.get() + 1);
19767
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
545 return true;
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
546 }
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
547
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
548 private static boolean exitAtomic() {
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
549 IN_ATOMIC_BLOCK.set(IN_ATOMIC_BLOCK.get() - 1);
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
550 return true;
e6a4ba0980dd Truffle: add assertion to always be in atomic blocks for replaces as it now may be violated by NodeUtil#nonAtomicReplace.
Christian Humer <christian.humer@gmail.com>
parents: 19758
diff changeset
551 }
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: 21966
diff changeset
552
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: 21966
diff changeset
553 private static final class AccessorNodes extends Accessor {
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22051
diff changeset
554 @SuppressWarnings("rawtypes")
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: 21966
diff changeset
555 @Override
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: 21966
diff changeset
556 protected Class<? extends TruffleLanguage> findLanguage(RootNode n) {
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: 21966
diff changeset
557 return n.language;
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: 21966
diff changeset
558 }
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
559
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
560 @Override
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
561 protected void applyInstrumentation(Node node) {
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
562 super.applyInstrumentation(node);
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
563 }
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: 21966
diff changeset
564 }
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: 21966
diff changeset
565
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: 21966
diff changeset
566 // registers into Accessor.NODES
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22080
diff changeset
567 private static final AccessorNodes ACCESSOR = new AccessorNodes();
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
568 }