Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java @ 19050:75da87c96605
initial commit of GraphBuilderPhase plugins
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 31 Jan 2015 00:30:00 +0100 |
parents | a720bf2e2f43 |
children |
rev | line source |
---|---|
16766
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
1 /* |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
4 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
10 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
15 * accompanied this code). |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
16 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
20 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
23 * questions. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
24 */ |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
25 package com.oracle.truffle.api.dsl.internal; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
26 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
27 import java.util.*; |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
28 import java.util.concurrent.*; |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
29 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
30 import com.oracle.truffle.api.nodes.*; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
31 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
32 /** Contains utility classes shared across generated DSLNode implementations. */ |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
33 public class DSLShare { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
34 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
35 public static boolean isExcluded(Node currentNode, DSLMetadata otherMetadata) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
36 assert otherMetadata.getExcludedBy().length > 0 : "At least one exclude must be defined for isIncluded."; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
37 Node cur = findRoot(currentNode); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
38 while (cur != null) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
39 Class<?> curClass = cur.getClass(); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
40 if (curClass == otherMetadata.getSpecializationClass()) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
41 return true; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
42 } else if (containsClass(otherMetadata.getExcludedBy(), cur)) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
43 return true; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
44 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
45 cur = getNext(cur); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
46 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
47 return false; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
48 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
49 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
50 private static boolean includes(Node oldNode, DSLNode newNode) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
51 return containsClass(newNode.getMetadata0().getIncludes(), oldNode); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
52 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
53 |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
54 public static <T extends Node & DSLNode> T rewrite(final Node thisNode, final T newNode, final String message) { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
55 return thisNode.atomic(new Callable<T>() { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
56 public T call() { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
57 assert newNode != null; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
58 if (getNext(thisNode) != null || getPrevious(thisNode) != null) { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
59 // already polymorphic -> append |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
60 return appendPolymorphic(findUninitialized(thisNode), newNode); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
61 } else if (includes(thisNode, newNode)) { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
62 // included -> remains monomorphic |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
63 newNode.adoptChildren0(thisNode, null); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
64 return thisNode.replace(newNode, message); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
65 } else { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
66 // goto polymorphic |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
67 return null; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
68 } |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
69 } |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
70 }); |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
71 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
72 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
73 @SuppressWarnings("unchecked") |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
74 public static <T extends Node> T findRoot(T node) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
75 Node prev = node; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
76 Node cur; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
77 do { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
78 cur = prev; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
79 prev = getPrevious(cur); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
80 } while (prev != null); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
81 return (T) cur; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
82 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
83 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
84 private static Node findUninitialized(Node node) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
85 Node next = node; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
86 Node cur; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
87 do { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
88 cur = next; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
89 next = getNext(cur); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
90 } while (next != null); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
91 return cur; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
92 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
93 |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
94 public static <T extends Node & DSLNode> T rewriteUninitialized(final Node uninitialized, final T newNode) { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
95 return uninitialized.atomic(new Callable<T>() { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
96 public T call() { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
97 Node prev = getPrevious(uninitialized); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
98 if (prev == null) { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
99 newNode.adoptChildren0(uninitialized, null); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
100 return uninitialized.replace(newNode, "Uninitialized monomorphic"); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
101 } else { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
102 return appendPolymorphic(uninitialized, newNode); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
103 } |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
104 } |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
105 }); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
106 |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
107 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
108 |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
109 public static <T extends Node & DSLNode> T rewriteToPolymorphic(final Node oldNode, final DSLNode uninitializedDSL, final T polymorphic, final DSLNode currentCopy, final DSLNode newNodeDSL, |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
110 final String message) { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
111 return oldNode.atomic(new Callable<T>() { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
112 public T call() { |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
113 assert getNext(oldNode) == null; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
114 assert getPrevious(oldNode) == null; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
115 assert newNodeDSL != null; |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
116 |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
117 Node uninitialized = (Node) uninitializedDSL; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
118 Node newNode = (Node) newNodeDSL; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
119 polymorphic.adoptChildren0(oldNode, (Node) currentCopy); |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
120 |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
121 updateSourceSection(oldNode, uninitialized); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
122 // new specialization |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
123 updateSourceSection(oldNode, newNode); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
124 newNodeDSL.adoptChildren0(null, uninitialized); |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
125 currentCopy.adoptChildren0(null, newNode); |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
126 |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
127 oldNode.replace(polymorphic, message); |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
128 |
17252
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
129 assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
130 assert uninitializedDSL.getNext0() == null; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
131 return polymorphic; |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
132 } |
1680a4ddc2a7
Truffle-DSL: added thread-safety for DSL rewrites.
Christian Humer <christian.humer@gmail.com>
parents:
16922
diff
changeset
|
133 }); |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
134 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
135 |
16921
f5541b01f374
Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
136 private static void updateSourceSection(Node oldNode, Node newNode) { |
f5541b01f374
Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
137 if (newNode.getSourceSection() == null) { |
f5541b01f374
Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
138 newNode.assignSourceSection(oldNode.getSourceSection()); |
f5541b01f374
Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
139 } |
f5541b01f374
Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
140 } |
f5541b01f374
Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
141 |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
142 private static Class<?>[] mergeTypes(DSLNode node, Class<?>[] types) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
143 Class<?>[] specializedTypes = node.getMetadata0().getSpecializedTypes(); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
144 if (specializedTypes.length == 0) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
145 return null; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
146 } else if (types == null) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
147 return Arrays.copyOf(specializedTypes, specializedTypes.length); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
148 } else { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
149 for (int i = 0; i < specializedTypes.length; i++) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
150 if (specializedTypes[i] != types[i]) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
151 types[i] = Object.class; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
152 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
153 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
154 return types; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
155 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
156 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
157 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
158 private static <T extends Node & DSLNode> T appendPolymorphic(Node uninitialized, T newNode) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
159 Class<?>[] includes = newNode.getMetadata0().getIncludes(); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
160 Node cur = getPrevious(uninitialized); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
161 Node prev = uninitialized; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
162 int depth = 0; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
163 Class<?>[] types = null; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
164 while (cur != null) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
165 if (containsClass(includes, cur)) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
166 cur.replace(prev, "Included in other specialization"); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
167 cur = prev; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
168 } else { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
169 depth++; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
170 types = mergeTypes((DSLNode) cur, types); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
171 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
172 prev = cur; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
173 cur = getPrevious(cur); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
174 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
175 assert prev.getCost() == NodeCost.POLYMORPHIC; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
176 |
16921
f5541b01f374
Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
177 updateSourceSection(prev, newNode); |
16922
0ea0c4133b78
Truffle-DSL: fixed polymorphic to monomorphic transition. It remained polymorphic in some cases.
Christian Humer <christian.humer@gmail.com>
parents:
16921
diff
changeset
|
178 if (depth <= 1) { |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
179 newNode.adoptChildren0(prev, null); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
180 return prev.replace(newNode, "Polymorphic to monomorphic."); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
181 } else { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
182 newNode.adoptChildren0(null, uninitialized); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
183 ((DSLNode) prev).updateTypes0(mergeTypes(newNode, types)); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
184 return uninitialized.replace(newNode, "Appended polymorphic"); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
185 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
186 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
187 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
188 private static boolean containsClass(Class<?>[] classList, Node node) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
189 Class<?> nodeClass = node.getClass(); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
190 for (Class<?> toCheck : classList) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
191 if (nodeClass == toCheck) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
192 if (node.getCost() == NodeCost.UNINITIALIZED) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
193 /* |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
194 * In case a specialization is excluded by the fallback specialization the |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
195 * uninitialized class is used as exclusion class. Because the fallback field in |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
196 * the uninitialized specialization is not accessible we use the costs to check |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
197 * if the fallback was reached or not. In case the fallback was reached in the |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
198 * uninitialized version the cost is MONOMORPHIC, otherwise it is UNINITIALIZED. |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
199 */ |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
200 continue; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
201 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
202 return true; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
203 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
204 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
205 return false; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
206 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
207 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
208 private static Node getNext(Node node) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
209 return ((DSLNode) node).getNext0(); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
210 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
211 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
212 private static Node getPrevious(Node node) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
213 Node parent = node.getParent(); |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
214 if (parent instanceof DSLNode && getNext(parent) == node) { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
215 return parent; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
216 } else { |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
217 return null; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
218 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
219 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16751
diff
changeset
|
220 |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
17252
diff
changeset
|
221 } |