Mercurial > hg > truffle
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 16581:8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 22 Jul 2014 16:32:43 +0200 |
parents | a3b0a2d61e62 |
children | 70f47dbbcabd |
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 /* |
16511
aee02665e505
Truffle: NodeUtil fix for displaying null SourceSections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
2 * Copyright (c) 2012, 2014, 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:
10845
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:
10845
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:
10845
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.io.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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.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
|
29 import java.lang.reflect.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 import java.util.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 import sun.misc.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
34 import com.oracle.truffle.api.*; |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
35 import com.oracle.truffle.api.nodes.Node.Child; |
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
36 import com.oracle.truffle.api.nodes.Node.Children; |
16067
915ebb306fcc
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15834
diff
changeset
|
37 import com.oracle.truffle.api.source.*; |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
38 |
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
|
39 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 * Utility class that manages the special access methods for node instances. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 */ |
11636
136eaa90ef41
Truffle: make NodeUtil class final and its unsafe field private.
Andreas Woess <andreas.woess@jku.at>
parents:
11622
diff
changeset
|
42 public final class NodeUtil { |
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
|
43 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
44 /** |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
45 * Interface that allows the customization of field offsets used for {@link Unsafe} field |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
46 * accesses. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
47 */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
48 public interface FieldOffsetProvider { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
49 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
50 long objectFieldOffset(Field field); |
15834
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
51 |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
52 int getTypeSize(Class<?> clazz); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
53 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
54 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
55 private static final FieldOffsetProvider unsafeFieldOffsetProvider = new FieldOffsetProvider() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
56 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
57 @Override |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
58 public long objectFieldOffset(Field field) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
59 return unsafe.objectFieldOffset(field); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
60 } |
15834
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
61 |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
62 @Override |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
63 public int getTypeSize(Class<?> clazz) { |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
64 if (!clazz.isPrimitive()) { |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
65 return Unsafe.ARRAY_OBJECT_INDEX_SCALE; |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
66 } else if (clazz == int.class) { |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
67 return Unsafe.ARRAY_INT_INDEX_SCALE; |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
68 } else { |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
69 throw new UnsupportedOperationException("unsupported field type: " + clazz); |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
70 } |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
71 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
72 }; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
73 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
74 public static enum NodeFieldKind { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
75 /** The single {@link Node#getParent() parent} field. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
76 PARENT, |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
77 /** A field annotated with {@link Child}. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
78 CHILD, |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
79 /** A field annotated with {@link Children}. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
80 CHILDREN, |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
81 /** A normal non-child data field of the node. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
82 DATA |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
83 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
84 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
85 /** |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
86 * Information about a field in a {@link Node} class. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
87 */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
88 public static final class NodeField { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
89 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
90 private final NodeFieldKind kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
91 private final Class<?> type; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
92 private final String name; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
93 private long offset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
94 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
95 protected NodeField(NodeFieldKind kind, Class<?> type, String name, long offset) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
96 this.kind = kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
97 this.type = type; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
98 this.name = name; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
99 this.offset = offset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
100 } |
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
|
101 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
102 public NodeFieldKind getKind() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
103 return kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
104 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
105 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
106 public Class<?> getType() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
107 return type; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
108 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
109 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
110 public String getName() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
111 return name; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
112 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
113 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
114 public long getOffset() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
115 return offset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
116 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
117 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
118 public Object loadValue(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
119 if (type == boolean.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
120 return unsafe.getBoolean(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
121 } else if (type == byte.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
122 return unsafe.getByte(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
123 } else if (type == short.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
124 return unsafe.getShort(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
125 } else if (type == char.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
126 return unsafe.getChar(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
127 } else if (type == int.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
128 return unsafe.getInt(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
129 } else if (type == long.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
130 return unsafe.getLong(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
131 } else if (type == float.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
132 return unsafe.getFloat(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
133 } else if (type == double.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
134 return unsafe.getDouble(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
135 } else { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
136 return unsafe.getObject(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
137 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
138 } |
14743
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
139 |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
140 @Override |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
141 public int hashCode() { |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
142 return kind.hashCode() | type.hashCode() | name.hashCode() | ((Long) offset).hashCode(); |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
143 } |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
144 |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
145 @Override |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
146 public boolean equals(Object obj) { |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
147 if (obj instanceof NodeField) { |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
148 NodeField other = (NodeField) obj; |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
149 return offset == other.offset && name.equals(other.name) && type.equals(other.type) && kind.equals(other.kind); |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
150 } |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
151 return false; |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
152 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
153 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
154 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
155 /** |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
156 * Information about a {@link Node} class. A single instance of this class is allocated for |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
157 * every subclass of {@link Node} that is used. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
158 */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
159 public static final class NodeClass { |
16466
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
160 private static final ClassValue<NodeClass> nodeClasses = new ClassValue<NodeClass>() { |
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
161 @SuppressWarnings("unchecked") |
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
162 @Override |
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
163 protected NodeClass computeValue(Class<?> clazz) { |
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
164 assert Node.class.isAssignableFrom(clazz); |
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
165 return new NodeClass((Class<? extends Node>) clazz, unsafeFieldOffsetProvider); |
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
166 } |
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
167 }; |
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
|
168 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
169 // The comprehensive list of all fields. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
170 private final NodeField[] fields; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
171 // Separate arrays for the frequently accessed field offsets. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
172 private final long parentOffset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
173 private final long[] childOffsets; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
174 private final long[] childrenOffsets; |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
175 private final Class<? extends Node> clazz; |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
176 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
177 public static NodeClass get(Class<? extends Node> clazz) { |
16466
d41922beb512
Truffle: use ClassValue for NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16465
diff
changeset
|
178 return nodeClasses.get(clazz); |
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
|
179 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
180 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
181 public NodeClass(Class<? extends Node> clazz, FieldOffsetProvider fieldOffsetProvider) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
182 List<NodeField> fieldsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
183 List<Long> parentOffsetsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
184 List<Long> childOffsetsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
185 List<Long> childrenOffsetsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
186 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
187 for (Field field : getAllFields(clazz)) { |
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
|
188 if (Modifier.isStatic(field.getModifiers()) || field.isSynthetic()) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
189 continue; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
190 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
191 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
192 NodeFieldKind kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
193 if (Node.class.isAssignableFrom(field.getType()) && field.getName().equals("parent") && field.getDeclaringClass() == Node.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
194 kind = NodeFieldKind.PARENT; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
195 parentOffsetsList.add(fieldOffsetProvider.objectFieldOffset(field)); |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
196 } else if (Node.class.isAssignableFrom(field.getType()) && field.getAnnotation(Child.class) != null) { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
197 kind = NodeFieldKind.CHILD; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
198 childOffsetsList.add(fieldOffsetProvider.objectFieldOffset(field)); |
10756
7f6580db1e88
Truffle: add assertions to verify the finalness of child fields.
Andreas Woess <andreas.woess@jku.at>
parents:
10755
diff
changeset
|
199 assert !Modifier.isFinal(field.getModifiers()) : "child field must not be final (\"" + field.getName() + "\", " + clazz + ")"; |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
200 } else if (field.getType().isArray() && Node.class.isAssignableFrom(field.getType().getComponentType()) && field.getAnnotation(Children.class) != null) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
201 kind = NodeFieldKind.CHILDREN; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
202 childrenOffsetsList.add(fieldOffsetProvider.objectFieldOffset(field)); |
10756
7f6580db1e88
Truffle: add assertions to verify the finalness of child fields.
Andreas Woess <andreas.woess@jku.at>
parents:
10755
diff
changeset
|
203 assert Modifier.isFinal(field.getModifiers()) : "children array field must be final (\"" + field.getName() + "\", " + clazz + ")"; |
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
|
204 } else { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
205 kind = NodeFieldKind.DATA; |
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
|
206 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
207 fieldsList.add(new NodeField(kind, field.getType(), field.getName(), fieldOffsetProvider.objectFieldOffset(field))); |
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
|
208 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
209 this.fields = fieldsList.toArray(new NodeField[fieldsList.size()]); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
210 assert parentOffsetsList.size() == 1 : "must have exactly one parent field"; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
211 this.parentOffset = parentOffsetsList.get(0); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
212 this.childOffsets = toLongArray(childOffsetsList); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
213 this.childrenOffsets = toLongArray(childrenOffsetsList); |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
214 this.clazz = clazz; |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
215 } |
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
|
216 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
217 public NodeField[] getFields() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
218 return fields; |
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
|
219 } |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
220 |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
221 public long getParentOffset() { |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
222 return parentOffset; |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
223 } |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
224 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
225 public long[] getChildOffsets() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
226 return childOffsets; |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
227 } |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
228 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
229 public long[] getChildrenOffsets() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
230 return childrenOffsets; |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
231 } |
14743
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
232 |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
233 @Override |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
234 public int hashCode() { |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
235 return Arrays.hashCode(fields) ^ Arrays.hashCode(childOffsets) ^ Arrays.hashCode(childrenOffsets) ^ ((Long) parentOffset).hashCode(); |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
236 } |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
237 |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
238 @Override |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
239 public boolean equals(Object obj) { |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
240 if (obj instanceof NodeClass) { |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
241 NodeClass other = (NodeClass) obj; |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
242 return Arrays.equals(fields, other.fields) && Arrays.equals(childOffsets, other.childOffsets) && Arrays.equals(childrenOffsets, other.childrenOffsets) && |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
243 parentOffset == other.parentOffset; |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
244 } |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
245 return false; |
762c9aceb7d8
Add equals/hashCode methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14569
diff
changeset
|
246 } |
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
|
247 |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
248 public Iterator<Node> makeIterator(Node node) { |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
249 assert clazz.isInstance(node); |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
250 return new NodeIterator(node); |
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
|
251 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
252 |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
253 private final class NodeIterator implements Iterator<Node> { |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
254 private final Node node; |
16581
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
255 private final int childrenCount; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
256 private int index; |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
257 |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
258 protected NodeIterator(Node node) { |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
259 this.node = node; |
16581
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
260 this.index = 0; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
261 this.childrenCount = childrenCount(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
262 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
263 |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
264 private int childrenCount() { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
265 int nodeCount = childOffsets.length; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
266 for (long fieldOffset : childrenOffsets) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
267 Node[] children = ((Node[]) unsafe.getObject(node, fieldOffset)); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
268 if (children != null) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
269 nodeCount += children.length; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
270 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
271 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
272 return nodeCount; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
273 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
274 |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
275 private Node nodeAt(int idx) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
276 int nodeCount = childOffsets.length; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
277 if (idx < nodeCount) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
278 return (Node) unsafe.getObject(node, childOffsets[idx]); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
279 } else { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
280 for (long fieldOffset : childrenOffsets) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
281 Node[] nodeArray = (Node[]) unsafe.getObject(node, fieldOffset); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
282 if (idx < nodeCount + nodeArray.length) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
283 return nodeArray[idx - nodeCount]; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
284 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
285 nodeCount += nodeArray.length; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
286 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
287 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
288 return null; |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
289 } |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
290 |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
291 private void forward() { |
16581
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
292 if (index < childrenCount) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
293 index++; |
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
|
294 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
295 } |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
296 |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
297 public boolean hasNext() { |
16581
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
298 return index < childrenCount; |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
299 } |
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
|
300 |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
301 public Node next() { |
16581
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
302 try { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
303 return nodeAt(index); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
304 } finally { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
16548
diff
changeset
|
305 forward(); |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
306 } |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
307 } |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
308 |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
309 public void remove() { |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
310 throw new UnsupportedOperationException(); |
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
|
311 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
312 } |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
313 } |
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
|
314 |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
315 static Iterator<Node> makeIterator(Node node) { |
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
316 return NodeClass.get(node.getClass()).makeIterator(node); |
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
|
317 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
318 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
319 private static long[] toLongArray(List<Long> list) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
320 long[] array = new long[list.size()]; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
321 for (int i = 0; i < list.size(); i++) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
322 array[i] = list.get(i); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
323 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
324 return array; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
325 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
326 |
11636
136eaa90ef41
Truffle: make NodeUtil class final and its unsafe field private.
Andreas Woess <andreas.woess@jku.at>
parents:
11622
diff
changeset
|
327 private static final Unsafe unsafe = getUnsafe(); |
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
|
328 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
329 private static Unsafe getUnsafe() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
330 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
|
331 return Unsafe.getUnsafe(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
332 } catch (SecurityException e) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 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
|
335 Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 theUnsafeInstance.setAccessible(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
|
337 return (Unsafe) theUnsafeInstance.get(Unsafe.class); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } catch (Exception e) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 throw new RuntimeException("exception while trying to get Unsafe.theUnsafe via reflection:", e); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 @SuppressWarnings("unchecked") |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 public static <T extends Node> T cloneNode(T orig) { |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
345 final Node clone = orig.copy(); |
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
346 NodeClass nodeClass = NodeClass.get(clone.getClass()); |
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
|
347 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 unsafe.putObject(clone, nodeClass.parentOffset, 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
|
349 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
350 for (long fieldOffset : nodeClass.childOffsets) { |
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
|
351 Node child = (Node) unsafe.getObject(orig, fieldOffset); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 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
|
353 Node clonedChild = cloneNode(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
|
354 unsafe.putObject(clonedChild, nodeClass.parentOffset, 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
|
355 unsafe.putObject(clone, fieldOffset, clonedChild); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
358 for (long fieldOffset : nodeClass.childrenOffsets) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
359 Node[] children = (Node[]) unsafe.getObject(orig, fieldOffset); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
360 if (children != null) { |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
361 Node[] clonedChildren = (Node[]) Array.newInstance(children.getClass().getComponentType(), children.length); |
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
|
362 for (int i = 0; i < children.length; i++) { |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
363 if (children[i] != null) { |
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
364 Node clonedChild = cloneNode(children[i]); |
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
365 clonedChildren[i] = clonedChild; |
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
366 unsafe.putObject(clonedChild, nodeClass.parentOffset, clone); |
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
|
367 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
368 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
369 unsafe.putObject(clone, fieldOffset, clonedChildren); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
372 return (T) 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
|
373 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
374 |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
375 public static List<Node> findNodeChildren(Node node) { |
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
376 List<Node> nodes = new ArrayList<>(); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
377 NodeClass nodeClass = NodeClass.get(node.getClass()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
378 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
379 for (long fieldOffset : nodeClass.childOffsets) { |
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
|
380 Object child = unsafe.getObject(node, fieldOffset); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
381 if (child != null) { |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
382 nodes.add((Node) child); |
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 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
385 for (long fieldOffset : nodeClass.childrenOffsets) { |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
386 Node[] children = (Node[]) unsafe.getObject(node, fieldOffset); |
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
|
387 if (children != null) { |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
388 for (Node child : children) { |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
389 if (child != null) { |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
390 nodes.add(child); |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
391 } |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
392 } |
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
|
393 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
394 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
395 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
396 return 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
|
397 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
398 |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
399 public static boolean replaceChild(Node parent, Node oldChild, Node 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
|
400 NodeClass nodeClass = NodeClass.get(parent.getClass()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
401 |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
402 for (long fieldOffset : nodeClass.getChildOffsets()) { |
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
|
403 if (unsafe.getObject(parent, fieldOffset) == oldChild) { |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
404 assert assertAssignable(nodeClass, fieldOffset, 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
|
405 unsafe.putObject(parent, fieldOffset, newChild); |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
406 return true; |
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
|
407 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
408 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
409 |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
410 for (long fieldOffset : nodeClass.getChildrenOffsets()) { |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
411 Object arrayObject = unsafe.getObject(parent, fieldOffset); |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
412 if (arrayObject != null) { |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
413 assert arrayObject instanceof Node[] : "Children array must be instanceof Node[] "; |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
414 Node[] array = (Node[]) arrayObject; |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
415 for (int i = 0; i < array.length; i++) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
416 if (array[i] == oldChild) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
417 assert assertAssignable(nodeClass, fieldOffset, newChild); |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
418 array[i] = newChild; |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
419 return true; |
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
|
420 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
421 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
422 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
423 } |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
424 return false; |
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
|
425 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
426 |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
427 private static boolean assertAssignable(NodeClass clazz, long fieldOffset, Object newValue) { |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
428 if (newValue == null) { |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
429 return true; |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
430 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
431 for (NodeField field : clazz.getFields()) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
432 if (field.getOffset() == fieldOffset) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
433 if (field.getKind() == NodeFieldKind.CHILD) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
434 if (field.getType().isAssignableFrom(newValue.getClass())) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
435 return true; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
436 } else { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
437 assert false : "Child class " + newValue.getClass().getName() + " is not assignable to field \"" + field.getName() + "\" of type " + field.getType().getName(); |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
438 return false; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
439 } |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
440 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
441 if (field.getType().getComponentType().isAssignableFrom(newValue.getClass())) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
442 return true; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
443 } else { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
444 assert false : "Child class " + newValue.getClass().getName() + " is not assignable to field \"" + field.getName() + "\" of type " + field.getType().getName(); |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
445 return false; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
446 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
447 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
448 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
449 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
450 throw new IllegalArgumentException(); |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
451 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
452 |
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
|
453 /** Returns all declared fields in the class hierarchy. */ |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
454 private static Field[] getAllFields(Class<? extends Object> clazz) { |
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
|
455 Field[] declaredFields = clazz.getDeclaredFields(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
456 if (clazz.getSuperclass() != 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
|
457 return concat(getAllFields(clazz.getSuperclass()), declaredFields); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
458 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
459 return declaredFields; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
460 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
461 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
462 public static <T> T[] concat(T[] first, T[] second) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
463 T[] result = Arrays.copyOf(first, first.length + second.length); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
464 System.arraycopy(second, 0, result, first.length, second.length); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
465 return result; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
466 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
467 |
11622
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
468 /** |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
469 * Get the nth parent of a node, where the 0th parent is the node itself. Returns null if there |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
470 * are less than n ancestors. |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
471 */ |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
472 public static Node getNthParent(Node node, int n) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
473 Node parent = node; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
474 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
475 for (int i = 0; i < n; i++) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
476 parent = parent.getParent(); |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
477 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
478 if (parent == null) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
479 return null; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
480 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
481 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
482 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
483 return parent; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
484 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
485 |
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
|
486 /** find annotation in class/interface hierarchy. */ |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
487 public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) { |
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 if (clazz.getAnnotation(annotationClass) != 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
|
489 return clazz.getAnnotation(annotationClass); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } else { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
491 for (Class<?> intf : clazz.getInterfaces()) { |
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
|
492 if (intf.getAnnotation(annotationClass) != 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
|
493 return intf.getAnnotation(annotationClass); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 if (clazz.getSuperclass() != 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
|
497 return findAnnotation(clazz.getSuperclass(), annotationClass); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 return 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
|
501 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
503 public static <T> T findParent(Node start, Class<T> clazz) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
504 Node parent = start.getParent(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
505 if (parent == null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
506 return null; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
507 } else if (clazz.isInstance(parent)) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
508 return clazz.cast(parent); |
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
|
509 } else { |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
510 return findParent(parent, clazz); |
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
|
511 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
512 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
513 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
514 public static <T> List<T> findAllParents(Node start, Class<T> clazz) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
515 List<T> parents = new ArrayList<>(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
516 T parent = findParent(start, clazz); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
517 while (parent != null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
518 parents.add(parent); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
519 parent = findParent((Node) parent, clazz); |
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
|
520 } |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
521 return parents; |
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
|
522 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
523 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
524 public static List<Node> collectNodes(Node parent, Node child) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
525 List<Node> nodes = new ArrayList<>(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
526 Node current = child; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
527 while (current != null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
528 nodes.add(current); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
529 if (current == parent) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
530 return nodes; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
531 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
532 current = current.getParent(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
533 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
534 throw new IllegalArgumentException("Node " + parent + " is not a parent of " + child + "."); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
535 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
536 |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
537 public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) { |
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
538 for (Node childNode : findNodeChildren(root)) { |
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
|
539 if (clazz.isInstance(childNode)) { |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
540 return clazz.cast(childNode); |
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
|
541 } else { |
9487
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
542 T node = findFirstNodeInstance(childNode, clazz); |
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
543 if (node != null) { |
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
544 return node; |
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
545 } |
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
|
546 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
547 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
548 return 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
|
549 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
550 |
16465
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
551 public static <T> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { |
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
|
552 final List<T> nodeList = new ArrayList<>(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
553 root.accept(new 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
|
554 public boolean visit(Node 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
|
555 if (clazz.isInstance(node)) { |
16465
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
556 nodeList.add(clazz.cast(node)); |
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
|
557 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
558 return 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
|
559 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
560 }); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
561 return nodeList; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
562 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
563 |
16465
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
564 /** |
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
565 * Like {@link #findAllNodeInstances(Node, Class)} but do not visit children of found nodes. |
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
566 */ |
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
567 public static <T> List<T> findNodeInstancesShallow(final Node root, final Class<T> clazz) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
568 final List<T> nodeList = new ArrayList<>(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
569 root.accept(new 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
|
570 public boolean visit(Node 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
|
571 if (clazz.isInstance(node)) { |
16465
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
572 nodeList.add(clazz.cast(node)); |
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
|
573 return 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
|
574 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
575 return 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
|
576 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
577 }); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
578 return nodeList; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
579 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
580 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
581 public static int countNodes(Node root) { |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
582 return countNodes(root, null, false); |
13995
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
583 } |
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
584 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
585 public static int countNodes(Node root, NodeCountFilter filter) { |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
586 return countNodes(root, filter, false); |
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
587 } |
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
588 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
589 public static int countNodes(Node root, NodeCountFilter filter, boolean visitInlinedCallNodes) { |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
590 NodeCountVisitor nodeCount = new NodeCountVisitor(filter, visitInlinedCallNodes); |
13995
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
591 root.accept(nodeCount); |
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
592 return nodeCount.nodeCount; |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
593 } |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
594 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
595 public interface NodeCountFilter { |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
596 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
597 boolean isCounted(Node node); |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
598 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
599 } |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
600 |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
601 private static final class NodeCountVisitor implements NodeVisitor { |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
602 |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
603 private final boolean visitInlinedCallNodes; |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
604 int nodeCount; |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
605 private final NodeCountFilter filter; |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
606 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
607 private NodeCountVisitor(NodeCountFilter filter, boolean visitInlinedCallNodes) { |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
608 this.filter = filter; |
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
609 this.visitInlinedCallNodes = visitInlinedCallNodes; |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
610 } |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
611 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
612 @Override |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
613 public boolean visit(Node node) { |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
614 if (filter == null || filter.isCounted(node)) { |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
615 nodeCount++; |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
616 } |
13811
641f22b1c6b8
Truffle: further fixes to the new CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
12666
diff
changeset
|
617 |
15093
5634b199c4da
Truffle: API-change: renamed CallNode to DirectCallNode and added IndirectCallNode.
Christian Humer <christian.humer@gmail.com>
parents:
15090
diff
changeset
|
618 if (visitInlinedCallNodes && node instanceof DirectCallNode) { |
5634b199c4da
Truffle: API-change: renamed CallNode to DirectCallNode and added IndirectCallNode.
Christian Humer <christian.humer@gmail.com>
parents:
15090
diff
changeset
|
619 DirectCallNode call = (DirectCallNode) node; |
15090
07e7aae05983
Truffle: context sensitive inlining cleanup
Christian Humer <christian.humer@gmail.com>
parents:
15089
diff
changeset
|
620 if (call.isInlined()) { |
14073
c5411233cdf8
Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents:
14067
diff
changeset
|
621 Node target = ((RootCallTarget) call.getCurrentCallTarget()).getRootNode(); |
c5411233cdf8
Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents:
14067
diff
changeset
|
622 if (target != null) { |
c5411233cdf8
Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents:
14067
diff
changeset
|
623 target.accept(this); |
c5411233cdf8
Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents:
14067
diff
changeset
|
624 } |
13811
641f22b1c6b8
Truffle: further fixes to the new CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
12666
diff
changeset
|
625 } |
641f22b1c6b8
Truffle: further fixes to the new CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
12666
diff
changeset
|
626 } |
641f22b1c6b8
Truffle: further fixes to the new CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
12666
diff
changeset
|
627 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
628 return true; |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
629 } |
13995
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
630 |
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
631 } |
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
632 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
633 public static String printCompactTreeToString(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
634 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
635 printCompactTree(new PrintWriter(out), null, node, 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
636 return out.toString(); |
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
|
637 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
638 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
639 public static void printCompactTree(OutputStream out, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
640 printCompactTree(new PrintWriter(out), null, node, 1); |
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
|
641 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
642 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
643 private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) { |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
644 if (node == null) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
645 return; |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
646 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
647 for (int i = 0; i < level; i++) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
648 p.print(" "); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
649 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
650 if (parent == null) { |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
651 p.println(nodeName(node)); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
652 } else { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
653 String fieldName = "unknownField"; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
654 NodeField[] fields = NodeClass.get(parent.getClass()).fields; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
655 for (NodeField field : fields) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
656 Object value = field.loadValue(parent); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
657 if (value == node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
658 fieldName = field.getName(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
659 break; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
660 } else if (value instanceof Node[]) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
661 int index = 0; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
662 for (Node arrayNode : (Node[]) value) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
663 if (arrayNode == node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
664 fieldName = field.getName() + "[" + index + "]"; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
665 break; |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
666 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
667 index++; |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
668 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
669 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
670 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
671 p.print(fieldName); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
672 p.print(" = "); |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
673 p.println(nodeName(node)); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
674 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
675 |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
676 for (Node child : node.getChildren()) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
677 printCompactTree(p, node, child, level + 1); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
678 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
679 p.flush(); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
680 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
681 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
682 public static String printSourceAttributionTree(Node node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
683 StringWriter out = new StringWriter(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
684 printSourceAttributionTree(new PrintWriter(out), null, node, 1); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
685 return out.toString(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
686 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
687 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
688 public static void printSourceAttributionTree(OutputStream out, Node node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
689 printSourceAttributionTree(new PrintWriter(out), null, node, 1); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
690 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
691 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
692 private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
693 if (node == null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
694 return; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
695 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
696 if (parent == null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
697 // Add some preliminary information before starting with the root node |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
698 final SourceSection sourceSection = node.getSourceSection(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
699 if (sourceSection != null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
700 final String txt = sourceSection.getSource().getCode(); |
11907
873da100d113
Truffle: another minor tweak to NodeUtil.printSourceAttributionTree
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11850
diff
changeset
|
701 p.println("Full source len=(" + txt.length() + ") ___" + txt + "___"); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
702 p.println("AST source attribution:"); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
703 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
704 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
705 final StringBuilder sb = new StringBuilder(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
706 for (int i = 0; i < level; i++) { |
11850
e68922869732
Truffle: minor legibility improvement in NodeUtil.printSourceAttributionTree()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11848
diff
changeset
|
707 sb.append("| "); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
708 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
709 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
710 if (parent != null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
711 String childName = ""; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
712 NodeField[] fields = NodeClass.get(parent.getClass()).fields; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
713 for (NodeField field : fields) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
714 Object value = field.loadValue(parent); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
715 if (value == node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
716 childName = field.getName(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
717 break; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
718 } else if (value instanceof Node[]) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
719 int index = 0; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
720 for (Node arrayNode : (Node[]) value) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
721 if (arrayNode == node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
722 childName = field.getName() + "[" + index + "]"; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
723 break; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
724 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
725 index++; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
726 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
727 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
728 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
729 sb.append(childName); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
730 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
731 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
732 sb.append(" (" + node.getClass().getSimpleName() + ") "); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
733 sb.append(displaySourceAttribution(node)); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
734 p.println(sb.toString()); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
735 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
736 for (Node child : node.getChildren()) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
737 printSourceAttributionTree(p, node, child, level + 1); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
738 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
739 p.flush(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
740 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
741 |
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
|
742 /** |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
743 * Prints a human readable form of a {@link Node} AST to the given {@link PrintStream}. This |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
744 * print method does not check for cycles in the node structure. |
15090
07e7aae05983
Truffle: context sensitive inlining cleanup
Christian Humer <christian.humer@gmail.com>
parents:
15089
diff
changeset
|
745 * |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
746 * @param out the stream to print to. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
747 * @param node the root node to write |
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
|
748 */ |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
749 public static void printTree(OutputStream out, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
750 printTree(new PrintWriter(out), node); |
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
|
751 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
752 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
753 public static String printTreeToString(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
754 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
755 printTree(new PrintWriter(out), node); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
756 return out.toString(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
757 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
758 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
759 public static void printTree(PrintWriter p, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
760 printTree(p, node, 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
761 p.println(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
762 p.flush(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
763 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
764 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
765 private static void printTree(PrintWriter p, Node node, int level) { |
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
|
766 if (node == 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
|
767 p.print("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
|
768 return; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
769 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
770 |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
771 p.print(nodeName(node)); |
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
|
772 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
773 ArrayList<NodeField> childFields = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
774 String sep = ""; |
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
|
775 p.print("("); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
776 for (NodeField field : NodeClass.get(node.getClass()).fields) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
777 if (field.getKind() == NodeFieldKind.CHILD || field.getKind() == NodeFieldKind.CHILDREN) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
778 childFields.add(field); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
779 } else if (field.getKind() == NodeFieldKind.DATA) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
780 p.print(sep); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
781 sep = ", "; |
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
|
782 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
783 p.print(field.getName()); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
784 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
785 p.print(field.loadValue(node)); |
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
|
786 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
787 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
788 p.print(")"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
789 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
790 if (childFields.size() != 0) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
791 p.print(" {"); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
792 for (NodeField field : childFields) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
793 printNewLine(p, level); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
794 p.print(field.getName()); |
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
|
795 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
796 Object value = field.loadValue(node); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
797 if (value == null) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
798 p.print(" = null "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
799 } else if (field.getKind() == NodeFieldKind.CHILD) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
800 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
801 printTree(p, (Node) value, level + 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
802 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
803 printChildren(p, level, value); |
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
|
804 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
805 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
806 printNewLine(p, level - 1); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
807 p.print("}"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
808 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
809 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
810 |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
811 private static void printChildren(PrintWriter p, int level, Object value) { |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
812 String sep; |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
813 Node[] children = (Node[]) value; |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
814 p.print(" = ["); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
815 sep = ""; |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
816 for (Node child : children) { |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
817 p.print(sep); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
818 sep = ", "; |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
819 printTree(p, child, level + 1); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
820 } |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
821 p.print("]"); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
822 } |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
823 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
824 private static void printNewLine(PrintWriter p, int level) { |
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
|
825 p.println(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
826 for (int i = 0; i < level; i++) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
827 p.print(" "); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
828 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
829 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
830 |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
831 private static String nodeName(Node node) { |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
832 return node.getClass().getSimpleName(); |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
833 } |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
834 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
835 private static String displaySourceAttribution(Node node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
836 final SourceSection section = node.getSourceSection(); |
16511
aee02665e505
Truffle: NodeUtil fix for displaying null SourceSections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
837 if (section instanceof NullSourceSection) { |
aee02665e505
Truffle: NodeUtil fix for displaying null SourceSections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
838 return "source: " + section.getShortDescription(); |
aee02665e505
Truffle: NodeUtil fix for displaying null SourceSections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
839 } |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
840 if (section != null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
841 final String srcText = section.getCode(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
842 final StringBuilder sb = new StringBuilder(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
843 sb.append("source: len=" + srcText.length()); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
844 sb.append(" (" + section.getCharIndex() + "," + (section.getCharEndIndex() - 1) + ")"); |
11907
873da100d113
Truffle: another minor tweak to NodeUtil.printSourceAttributionTree
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11850
diff
changeset
|
845 sb.append(" ___" + srcText + "___"); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
846 return sb.toString(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
847 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
848 return ""; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
849 } |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
850 |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
851 public static boolean verify(Node root) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
852 Iterable<Node> children = root.getChildren(); |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
853 for (Node child : children) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
854 if (child != null) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
855 if (child.getParent() != root) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
856 throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root)); |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
857 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
858 verify(child); |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
859 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
860 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
861 return true; |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
862 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
863 |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
864 private static String toStringWithClass(Object obj) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
865 return obj == null ? "null" : obj + "(" + obj.getClass().getName() + ")"; |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
866 } |
16464
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
867 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
868 static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
869 if (TruffleOptions.TraceRewritesFilterFromCost != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
870 if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
871 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
872 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
873 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
874 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
875 if (TruffleOptions.TraceRewritesFilterToCost != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
876 if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
877 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
878 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
879 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
880 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
881 String filter = TruffleOptions.TraceRewritesFilterClass; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
882 Class<? extends Node> from = oldNode.getClass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
883 Class<? extends Node> to = newNode.getClass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
884 if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
885 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
886 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
887 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
888 final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
889 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
890 PrintStream out = System.out; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
891 out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s%s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode), |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
892 reason != null && reason.length() > 0 ? reason : "unknown", reportedSourceSection != null ? " at " + reportedSourceSection.getShortDescription() : ""); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
893 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
894 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
895 private static String formatNodeInfo(Node node) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
896 String cost = "?"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
897 switch (node.getCost()) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
898 case NONE: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
899 cost = "G"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
900 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
901 case MONOMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
902 cost = "M"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
903 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
904 case POLYMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
905 cost = "P"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
906 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
907 case MEGAMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
908 cost = "G"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
909 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
910 default: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
911 cost = "?"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
912 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
913 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
914 return cost + " " + node.getClass().getSimpleName(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
915 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
916 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
917 private static boolean filterByKind(Node node, NodeCost cost) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
918 return node.getCost() == cost; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
919 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
920 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
921 private static boolean filterByContainsClassName(Class<? extends Node> from, String filter) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
922 Class<?> currentFrom = from; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
923 while (currentFrom != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
924 if (currentFrom.getName().contains(filter)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
925 return false; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
926 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
927 currentFrom = currentFrom.getSuperclass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
928 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
929 return true; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
930 } |
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
|
931 } |