Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 20130:8dc73c226c63
Truffle: cache NodeClass lookup in Node.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 02 Apr 2015 01:26:31 +0200 |
parents | f792b4270cb1 |
children | 4b12d5355811 |
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 |
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
|
27 import java.lang.annotation.*; |
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
|
28 import java.util.*; |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
29 import java.util.concurrent.*; |
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
|
30 |
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
|
31 import com.oracle.truffle.api.*; |
17382
e1da729b3e4e
make Truffle Node source section @CompilationFinal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16912
diff
changeset
|
32 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; |
18985
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
33 import com.oracle.truffle.api.instrument.*; |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
34 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; |
16067
915ebb306fcc
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15775
diff
changeset
|
35 import com.oracle.truffle.api.source.*; |
16151
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
36 import com.oracle.truffle.api.utilities.*; |
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
|
37 |
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
|
38 /** |
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
|
39 * 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
|
40 */ |
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
|
41 public abstract class Node implements NodeInterface, Cloneable { |
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
|
42 |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
19979
diff
changeset
|
43 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
|
44 @CompilationFinal private Node parent; |
17382
e1da729b3e4e
make Truffle Node source section @CompilationFinal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16912
diff
changeset
|
45 @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
|
46 |
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
|
47 /** |
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
|
48 * 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
|
49 */ |
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 @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
|
51 @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
|
52 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
|
53 } |
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
|
54 |
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
|
55 /** |
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
|
56 * 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
|
57 */ |
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 @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
|
59 @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
|
60 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
|
61 } |
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 |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
63 protected Node() { |
16151
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
64 this(null); |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
65 } |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
66 |
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
|
67 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
|
68 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
|
69 this.sourceSection = sourceSection; |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
19979
diff
changeset
|
70 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
|
71 if (TruffleOptions.TraceASTJSON) { |
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
72 JSONHelper.dumpNewNode(this); |
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
73 } |
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
|
74 } |
8f0fb0ade839
Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11279
diff
changeset
|
75 |
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
|
76 /** |
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
|
77 * 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
|
78 * |
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
|
79 * @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
|
80 */ |
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
|
81 public final void assignSourceSection(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
|
82 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
|
83 // 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
|
84 // 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
|
85 // 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
|
86 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
|
87 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
|
88 } |
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
|
89 } |
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 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
|
91 } |
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
|
92 |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
19979
diff
changeset
|
93 NodeClass getNodeClass() { |
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
19979
diff
changeset
|
94 return nodeClass; |
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
19979
diff
changeset
|
95 } |
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
19979
diff
changeset
|
96 |
14566
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
97 /** |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
98 * 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
|
99 * 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
|
100 * 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
|
101 * {@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
|
102 * {@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
|
103 * default value. |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
104 */ |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14073
diff
changeset
|
105 public NodeCost getCost() { |
13994
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
106 NodeInfo info = getClass().getAnnotation(NodeInfo.class); |
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
107 if (info != null) { |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14073
diff
changeset
|
108 return info.cost(); |
13994
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
109 } |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14073
diff
changeset
|
110 return NodeCost.MONOMORPHIC; |
13994
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
111 } |
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
112 |
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
|
113 /** |
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
|
114 * 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
|
115 */ |
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
|
116 public final void clearSourceSection() { |
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
|
117 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
|
118 } |
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
|
119 |
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
|
120 /** |
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
|
121 * Retrieves the guest language source code section that is currently assigned 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
|
122 * |
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
|
123 * @return the assigned source code 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
|
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 public final SourceSection getSourceSection() { |
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 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
|
127 } |
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 |
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 /** |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
130 * Retrieves the guest language source code section that is currently assigned 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
|
131 * |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
132 * @return the assigned source code section |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
133 */ |
17389
763a34f283f9
make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents:
17382
diff
changeset
|
134 @ExplodeLoop |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
135 public final 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 } |
763a34f283f9
make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents:
17382
diff
changeset
|
141 current = current.parent; |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
142 } |
17389
763a34f283f9
make Truffle Node parent @CompilationFinal, let getEncapsulatingSourceSection evaluate at compile time
Lukas Stadler <lukas.stadler@oracle.com>
parents:
17382
diff
changeset
|
143 return null; |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
144 } |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
145 |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
146 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
147 * 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
|
148 * node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
149 * |
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
|
150 * @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
|
151 * @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
|
152 */ |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
153 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
|
154 CompilerDirectives.transferToInterpreterAndInvalidate(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
155 assert newChildren != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
156 for (Node newChild : newChildren) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
157 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
|
158 } |
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
|
159 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
|
160 } |
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
|
161 |
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
|
162 /** |
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 * 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
|
164 * |
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
|
165 * @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
|
166 * @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
|
167 */ |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
168 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
|
169 CompilerDirectives.transferToInterpreterAndInvalidate(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
170 assert newChild != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
171 adoptHelper(newChild); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
172 return newChild; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
173 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
174 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
175 public final void adoptChildren() { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
176 CompilerDirectives.transferToInterpreterAndInvalidate(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
177 adoptHelper(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
178 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
179 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
180 private void adoptHelper(final Node newChild) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
181 assert newChild != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
182 if (newChild == this) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
183 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
|
184 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
185 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
|
186 if (TruffleOptions.TraceASTJSON) { |
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
187 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
|
188 } |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
189 newChild.adoptHelper(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
190 } |
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 private void adoptHelper() { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
193 Iterable<Node> children = this.getChildren(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
194 for (Node child : children) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
195 if (child != null && child.getParent() != this) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
196 this.adoptHelper(child); |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
197 } |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
198 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
199 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
200 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
201 private void adoptUnadoptedHelper(final Node newChild) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
202 assert newChild != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
203 if (newChild == this) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
204 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
|
205 } |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
206 newChild.parent = this; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
207 newChild.adoptUnadoptedHelper(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
208 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
209 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
210 private void adoptUnadoptedHelper() { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
211 Iterable<Node> children = this.getChildren(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
212 for (Node child : children) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
213 if (child != null && child.getParent() == null) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
214 this.adoptUnadoptedHelper(child); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
215 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
216 } |
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
|
217 } |
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 |
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
|
219 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
220 * 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
|
221 * 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
|
222 * |
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
|
223 * @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
|
224 */ |
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
|
225 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
|
226 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
|
227 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
|
228 } |
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
|
229 |
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 * 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
|
232 * |
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
|
233 * @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
|
234 */ |
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
|
235 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
|
236 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
|
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 |
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 /** |
9256
9640bb930327
Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9255
diff
changeset
|
240 * 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
|
241 * {@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
|
242 * |
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
|
243 * @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
|
244 * @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
|
245 * @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
|
246 */ |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
247 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
|
248 CompilerDirectives.transferToInterpreterAndInvalidate(); |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
249 atomic(new Runnable() { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
250 public void run() { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
251 replaceHelper(newNode, reason); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
252 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
253 }); |
12494
57b8a41c0e18
Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents:
11951
diff
changeset
|
254 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
|
255 } |
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 |
12494
57b8a41c0e18
Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents:
11951
diff
changeset
|
257 /** |
9256
9640bb930327
Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9255
diff
changeset
|
258 * 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
|
259 * {@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
|
260 * |
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
|
261 * @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
|
262 * @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
|
263 */ |
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
|
264 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
|
265 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
|
266 } |
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
|
267 |
19765
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:
19613
diff
changeset
|
268 final void replaceHelper(Node newNode, CharSequence reason) { |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
269 CompilerAsserts.neverPartOfCompilation(); |
19783
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:
19765
diff
changeset
|
270 assert inAtomicBlock(); |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
271 if (this.getParent() == null) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
272 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
|
273 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
274 if (sourceSection != null && newNode.getSourceSection() == null) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
275 // Pass on the source section to the new node. |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
276 newNode.assignSourceSection(sourceSection); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
277 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
278 // (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
|
279 // will always find the root node |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
280 newNode.parent = this.parent; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
281 if (NodeUtil.replaceChild(this.parent, this, newNode)) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
282 this.parent.adoptHelper(newNode); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
283 } else { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
284 this.parent.adoptUnadoptedHelper(newNode); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
285 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
286 reportReplace(this, newNode, reason); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
287 onReplace(newNode, reason); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
288 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
289 |
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
|
290 /** |
19141
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19038
diff
changeset
|
291 * 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
|
292 */ |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
293 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
|
294 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
|
295 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
296 |
14584
6189c1983cd3
Truffle: make Node#replace accept any CharSequence as reason
Andreas Woess <andreas.woess@jku.at>
parents:
14566
diff
changeset
|
297 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
|
298 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
|
299 while (node != null) { |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
300 if (node instanceof ReplaceObserver) { |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
301 ((ReplaceObserver) node).nodeReplaced(oldNode, newNode, reason); |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
302 } 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
|
303 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
|
304 if (target instanceof ReplaceObserver) { |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
305 ((ReplaceObserver) target).nodeReplaced(oldNode, newNode, reason); |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
306 } |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
307 } |
16912
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
308 node = node.getParent(); |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
309 } |
16464
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
310 if (TruffleOptions.TraceRewrites) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
311 NodeUtil.traceRewrite(this, newNode, reason); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
312 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
313 if (TruffleOptions.TraceASTJSON) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
314 JSONHelper.dumpReplaceChild(this, newNode, reason); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
315 } |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
316 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
317 |
10846
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
318 /** |
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
|
319 * 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
|
320 * 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
|
321 * |
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
|
322 * @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
|
323 * @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
|
324 */ |
14584
6189c1983cd3
Truffle: make Node#replace accept any CharSequence as reason
Andreas Woess <andreas.woess@jku.at>
parents:
14566
diff
changeset
|
325 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
|
326 // empty default |
10590
6eb8d63cea34
Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents:
10481
diff
changeset
|
327 } |
6eb8d63cea34
Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents:
10481
diff
changeset
|
328 |
15346
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
329 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
330 * 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
|
331 * 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
|
332 * |
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
|
333 * @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
|
334 */ |
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
|
335 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
|
336 if (nodeVisitor.visit(this)) { |
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
|
337 for (Node child : this.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
|
338 if (child != null) { |
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
|
339 child.accept(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
|
340 } |
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
|
341 } |
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
|
342 } |
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
|
343 } |
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
|
344 |
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
|
345 /** |
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
|
346 * 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
|
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 * @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
|
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 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
|
351 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
|
352 public Iterator<Node> iterator() { |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
19979
diff
changeset
|
353 return nodeClass.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
|
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 |
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
|
358 /** |
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 * 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
|
360 * |
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
|
361 * @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
|
362 */ |
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 Node 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
|
364 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
|
365 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
|
366 } catch (CloneNotSupportedException e) { |
18509
7bf2965140de
Truffle: Node#clone(): throw assertion error on CloneNotSupportedException
Andreas Woess <andreas.woess@jku.at>
parents:
18332
diff
changeset
|
367 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
|
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 |
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
|
371 /** |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
372 * 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
|
373 * |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
374 * @return the new deep copy |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
375 */ |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
376 public Node deepCopy() { |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
377 return NodeUtil.deepCopyImpl(this); |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
378 } |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
379 |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18509
diff
changeset
|
380 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
381 * 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
|
382 * 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
|
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 @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
|
385 @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
|
386 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
|
387 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
|
388 } |
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
|
389 |
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
|
390 /** |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
391 * 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
|
392 * |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
393 * @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
|
394 */ |
13983
f46cab39a9a2
Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents:
13915
diff
changeset
|
395 public final RootNode getRootNode() { |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
396 Node rootNode = this; |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
397 while (rootNode.getParent() != null) { |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
398 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
|
399 rootNode = rootNode.getParent(); |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
400 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
401 if (rootNode instanceof RootNode) { |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
402 return (RootNode) rootNode; |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
403 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
404 return null; |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
405 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
406 |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
407 /** |
18985
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
408 * 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
|
409 * 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
|
410 * 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
|
411 * 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
|
412 * <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
|
413 * <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
|
414 * 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
|
415 * |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
416 * @see Instrument |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
417 */ |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
418 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
|
419 return false; |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
420 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
421 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
422 /** |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
423 * 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
|
424 * <ol> |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
425 * <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
|
426 * <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
|
427 * <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
|
428 * </ol> |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
429 * |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
430 * @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
|
431 */ |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
432 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
|
433 return null; |
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 /** |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
437 * Enables {@linkplain Instrument instrumentation} of a node, where the node is presumed to be |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
438 * part of a well-formed Truffle AST that is not being executed. If this node has not already |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
439 * been probed, modifies the AST by inserting a {@linkplain WrapperNode wrapper node} between |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
440 * the node and its parent; the wrapper node must be provided by implementations of |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
441 * {@link #createWrapperNode()}. No more than one {@link Probe} may be associated with a node, |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
442 * so a {@linkplain WrapperNode wrapper} may not wrap another {@linkplain WrapperNode wrapper}. |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
443 * |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
444 * @return a (possibly newly created) {@link Probe} associated with this node. |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
445 * @throws ProbeException (unchecked) when a probe cannot be created, leaving the AST unchanged |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
446 */ |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
447 public final Probe probe() { |
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 if (this instanceof WrapperNode) { |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
450 throw new ProbeException(ProbeFailure.Reason.WRAPPER_NODE, null, this, null); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
451 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
452 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
453 if (parent == null) { |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
454 throw new ProbeException(ProbeFailure.Reason.NO_PARENT, null, this, null); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
455 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
456 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
457 if (parent instanceof WrapperNode) { |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
458 return ((WrapperNode) parent).getProbe(); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
459 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
460 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
461 if (!isInstrumentable()) { |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
462 throw new ProbeException(ProbeFailure.Reason.NOT_INSTRUMENTABLE, parent, this, null); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
463 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
464 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
465 // Create a new wrapper/probe with this node as its child. |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
466 final WrapperNode wrapper = createWrapperNode(); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
467 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
468 if (wrapper == null || !(wrapper instanceof Node)) { |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
469 throw new ProbeException(ProbeFailure.Reason.NO_WRAPPER, parent, this, wrapper); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
470 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
471 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
472 final Node wrapperNode = (Node) wrapper; |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
473 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
474 if (!this.isSafelyReplaceableBy(wrapperNode)) { |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
475 throw new ProbeException(ProbeFailure.Reason.WRAPPER_TYPE, parent, this, wrapper); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
476 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
477 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
478 // Connect it to a Probe |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
479 final Probe probe = ProbeNode.insertProbe(wrapper); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
480 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
481 // Replace this node in the AST with the wrapper |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
482 this.replace(wrapperNode); |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
483 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
484 return probe; |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
485 } |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
486 |
867058575979
Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18750
diff
changeset
|
487 /** |
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
|
488 * 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
|
489 */ |
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
|
490 @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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 } |
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
|
500 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
|
501 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
|
502 } |
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
|
503 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
|
504 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
|
505 } |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
506 |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
507 public final void atomic(Runnable closure) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
508 RootNode rootNode = getRootNode(); |
19613
d344d76b7b6d
Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
19247
diff
changeset
|
509 synchronized (rootNode != null ? rootNode : GIL) { |
19783
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:
19765
diff
changeset
|
510 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:
19765
diff
changeset
|
511 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:
19765
diff
changeset
|
512 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:
19765
diff
changeset
|
513 } 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:
19765
diff
changeset
|
514 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:
19765
diff
changeset
|
515 } |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
516 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
517 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
518 |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
519 public final <T> T atomic(Callable<T> closure) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
520 try { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
521 RootNode rootNode = getRootNode(); |
19613
d344d76b7b6d
Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
19247
diff
changeset
|
522 synchronized (rootNode != null ? rootNode : GIL) { |
19783
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:
19765
diff
changeset
|
523 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:
19765
diff
changeset
|
524 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:
19765
diff
changeset
|
525 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:
19765
diff
changeset
|
526 } 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:
19765
diff
changeset
|
527 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:
19765
diff
changeset
|
528 } |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
529 } |
19613
d344d76b7b6d
Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
19247
diff
changeset
|
530 } catch (RuntimeException | Error e) { |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
531 throw e; |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
532 } catch (Exception e) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
533 throw new RuntimeException(e); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
534 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
535 } |
15775
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
536 |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
537 /** |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
538 * 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
|
539 * available. |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
540 */ |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
541 public String getDescription() { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
542 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
|
543 if (info != null) { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
544 return info.description(); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
545 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
546 return ""; |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
547 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
548 |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
549 /** |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
550 * 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
|
551 * language is unknown, returns "". |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
552 */ |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
553 public String getLanguage() { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
554 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
|
555 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
|
556 return info.language(); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
557 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
558 if (parent != null) { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
559 return parent.getLanguage(); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
560 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
561 return ""; |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
562 } |
19613
d344d76b7b6d
Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
19247
diff
changeset
|
563 |
d344d76b7b6d
Truffle: Node cleanup
Andreas Woess <andreas.woess@oracle.com>
parents:
19247
diff
changeset
|
564 private static final Object GIL = new Object(); |
19783
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:
19765
diff
changeset
|
565 |
19979
f792b4270cb1
Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents:
19975
diff
changeset
|
566 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
|
567 @Override |
f792b4270cb1
Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents:
19975
diff
changeset
|
568 protected Integer initialValue() { |
f792b4270cb1
Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents:
19975
diff
changeset
|
569 return 0; |
f792b4270cb1
Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents:
19975
diff
changeset
|
570 } |
f792b4270cb1
Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents:
19975
diff
changeset
|
571 }; |
19783
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:
19765
diff
changeset
|
572 |
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:
19765
diff
changeset
|
573 private static boolean inAtomicBlock() { |
19979
f792b4270cb1
Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents:
19975
diff
changeset
|
574 return IN_ATOMIC_BLOCK.get() > 0; |
19783
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:
19765
diff
changeset
|
575 } |
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:
19765
diff
changeset
|
576 |
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:
19765
diff
changeset
|
577 private static boolean enterAtomic() { |
19979
f792b4270cb1
Truffle: simplify inAtomicBlock assertion.
Christian Humer <christian.humer@oracle.com>
parents:
19975
diff
changeset
|
578 IN_ATOMIC_BLOCK.set(IN_ATOMIC_BLOCK.get() + 1); |
19783
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:
19765
diff
changeset
|
579 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:
19765
diff
changeset
|
580 } |
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:
19765
diff
changeset
|
581 |
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:
19765
diff
changeset
|
582 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:
19765
diff
changeset
|
583 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:
19765
diff
changeset
|
584 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:
19765
diff
changeset
|
585 } |
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
|
586 } |