Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/MergeSpecializationsTest.java @ 19764:e8d2f3f95dcd
Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 10 Mar 2015 19:28:26 +0100 |
parents | 678a3de139ad |
children | e773cc48d3e8 |
rev | line source |
---|---|
19709
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
1 /* |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
4 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
8 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
14 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
18 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
21 * questions. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
22 */ |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
24 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
27 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
28 import java.util.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
29 import java.util.concurrent.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
30 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
31 import org.junit.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
32 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.dsl.internal.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.dsl.test.MergeSpecializationsTestFactory.TestCachedNodeFactory; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.dsl.test.MergeSpecializationsTestFactory.TestNodeFactory; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
37 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
38 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
39 import com.oracle.truffle.api.nodes.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
40 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
41 public class MergeSpecializationsTest { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
42 |
19764
e8d2f3f95dcd
Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents:
19709
diff
changeset
|
43 private static final int THREADS = 50; |
19709
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
44 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
45 @NodeChild |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
46 @SuppressWarnings("unused") |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
47 abstract static class TestNode extends ValueNode { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
48 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
49 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
50 int s1(int a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
51 return 1; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
52 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
53 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
54 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
55 int s2(long a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
56 return 2; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
57 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
58 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
59 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
60 int s3(double a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
61 return 3; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
62 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
63 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
64 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
65 @NodeChild |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
66 @SuppressWarnings("unused") |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
67 abstract static class TestCachedNode extends ValueNode { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
68 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
69 @Specialization(guards = "a == cachedA", limit = "3") |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
70 int s1(int a, @Cached("a") int cachedA) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
71 return 1; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
72 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
73 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
74 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
75 int s2(long a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
76 return 2; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
77 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
78 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
79 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
80 int s3(double a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
81 return 3; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
82 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
83 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
84 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
85 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
86 public void testMultithreadedMergeInOrder() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
87 multithreadedMerge(TestNodeFactory.getInstance(), new Executions(1, 1L << 32, 1.0), 1, 2, 3); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
88 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
89 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
90 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
91 public void testMultithreadedMergeReverse() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
92 multithreadedMerge(TestNodeFactory.getInstance(), new Executions(1.0, 1L << 32, 1), 3, 2, 1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
93 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
94 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
95 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
96 public void testMultithreadedMergeCachedInOrder() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
97 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 1L << 32, 1.0), 1, 2, 3); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
98 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
99 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
100 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
101 public void testMultithreadedMergeCachedTwoEntries() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
102 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 2, 1.0), 1, 1, 3); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
103 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
104 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
105 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
106 public void testMultithreadedMergeCachedThreeEntries() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
107 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 2, 3), 1, 1, 1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
108 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
109 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
110 private static <T extends ValueNode> void multithreadedMerge(NodeFactory<T> factory, final Executions executions, int... order) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
111 assertEquals(3, order.length); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
112 final TestRootNode<T> node = createRoot(factory); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
113 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
114 final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
115 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
116 final CountDownLatch beforeFirst = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
117 final CountDownLatch executedFirst = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
118 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
119 final CountDownLatch beforeSecond = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
120 final CountDownLatch executedSecond = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
121 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
122 final CountDownLatch beforeThird = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
123 final CountDownLatch executedThird = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
124 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
125 Thread[] threads = new Thread[THREADS]; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
126 for (int i = 0; i < threads.length; i++) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
127 threads[i] = new Thread(new Runnable() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
128 public void run() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
129 threadsStarted.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
130 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
131 MergeSpecializationsTest.await(beforeFirst); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
132 executeWith(node, executions.firstValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
133 executedFirst.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
134 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
135 MergeSpecializationsTest.await(beforeSecond); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
136 executeWith(node, executions.secondValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
137 executedSecond.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
138 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
139 MergeSpecializationsTest.await(beforeThird); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
140 executeWith(node, executions.thirdValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
141 executedThird.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
142 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
143 }); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
144 threads[i].start(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
145 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
146 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
147 final SpecializedNode gen = (SpecializedNode) node.getNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
148 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
149 final SpecializationNode start0 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
150 assertEquals("UninitializedNode_", start0.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
151 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
152 await(threadsStarted); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
153 beforeFirst.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
154 await(executedFirst); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
155 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
156 final SpecializationNode start1 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
157 assertEquals("S" + order[0] + "Node_", start1.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
158 assertEquals("UninitializedNode_", nthChild(1, start1).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
159 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
160 beforeSecond.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
161 await(executedSecond); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
162 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
163 final SpecializationNode start2 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
164 Arrays.sort(order, 0, 2); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
165 assertEquals("PolymorphicNode_", start2.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
166 assertEquals("S" + order[0] + "Node_", nthChild(1, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
167 assertEquals("S" + order[1] + "Node_", nthChild(2, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
168 assertEquals("UninitializedNode_", nthChild(3, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
169 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
170 beforeThird.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
171 await(executedThird); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
172 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
173 final SpecializationNode start3 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
174 Arrays.sort(order); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
175 assertEquals("PolymorphicNode_", start3.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
176 assertEquals("S" + order[0] + "Node_", nthChild(1, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
177 assertEquals("S" + order[1] + "Node_", nthChild(2, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
178 assertEquals("S" + order[2] + "Node_", nthChild(3, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
179 assertEquals("UninitializedNode_", nthChild(4, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
180 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
181 for (Thread thread : threads) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
182 try { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
183 thread.join(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
184 } catch (InterruptedException e) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
185 fail("interrupted"); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
186 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
187 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
188 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
189 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
190 private static class Executions { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
191 public final Object firstValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
192 public final Object secondValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
193 public final Object thirdValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
194 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
195 public Executions(Object firstValue, Object secondValue, Object thirdValue) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
196 this.firstValue = firstValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
197 this.secondValue = secondValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
198 this.thirdValue = thirdValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
199 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
200 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
201 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
202 private static void await(final CountDownLatch latch) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
203 try { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
204 latch.await(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
205 } catch (InterruptedException e) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
206 fail("interrupted"); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
207 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
208 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
209 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
210 private static Node firstChild(Node node) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
211 return node.getChildren().iterator().next(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
212 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
213 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
214 private static Node nthChild(int n, Node node) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
215 if (n == 0) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
216 return node; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
217 } else { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
218 return nthChild(n - 1, firstChild(node)); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
219 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
220 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
221 } |