Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/MergeSpecializationsTest.java @ 21591:6c5327245831
LinearScan: fix intervals context.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Fri, 29 May 2015 10:59:03 +0200 |
parents | e773cc48d3e8 |
children |
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() { |
19785
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
87 for (int i = 0; i < 100; i++) { |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
88 multithreadedMerge(TestNodeFactory.getInstance(), new Executions(1, 1L << 32, 1.0), 1, 2, 3); |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
89 } |
19709
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
90 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
91 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
92 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
93 public void testMultithreadedMergeReverse() { |
19785
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
94 for (int i = 0; i < 100; i++) { |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
95 multithreadedMerge(TestNodeFactory.getInstance(), new Executions(1.0, 1L << 32, 1), 3, 2, 1); |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
96 } |
19709
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
97 } |
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 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
100 public void testMultithreadedMergeCachedInOrder() { |
19785
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
101 for (int i = 0; i < 100; i++) { |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
102 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 1L << 32, 1.0), 1, 2, 3); |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
103 } |
19709
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 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
106 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
107 public void testMultithreadedMergeCachedTwoEntries() { |
19785
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
108 for (int i = 0; i < 100; i++) { |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
109 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 2, 1.0), 1, 1, 3); |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
110 } |
19709
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
111 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
112 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
113 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
114 public void testMultithreadedMergeCachedThreeEntries() { |
19785
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
115 for (int i = 0; i < 100; i++) { |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
116 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 2, 3), 1, 1, 1); |
e773cc48d3e8
Truffle-DSL: make specialization types mergable with other specialization types.
Christian Humer <christian.humer@gmail.com>
parents:
19764
diff
changeset
|
117 } |
19709
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 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
120 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
|
121 assertEquals(3, order.length); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
122 final TestRootNode<T> node = createRoot(factory); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
123 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
124 final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
125 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
126 final CountDownLatch beforeFirst = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
127 final CountDownLatch executedFirst = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
128 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
129 final CountDownLatch beforeSecond = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
130 final CountDownLatch executedSecond = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
131 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
132 final CountDownLatch beforeThird = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
133 final CountDownLatch executedThird = new CountDownLatch(THREADS); |
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 Thread[] threads = new Thread[THREADS]; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
136 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
|
137 threads[i] = new Thread(new Runnable() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
138 public void run() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
139 threadsStarted.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
140 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
141 MergeSpecializationsTest.await(beforeFirst); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
142 executeWith(node, executions.firstValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
143 executedFirst.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
144 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
145 MergeSpecializationsTest.await(beforeSecond); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
146 executeWith(node, executions.secondValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
147 executedSecond.countDown(); |
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 MergeSpecializationsTest.await(beforeThird); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
150 executeWith(node, executions.thirdValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
151 executedThird.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
152 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
153 }); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
154 threads[i].start(); |
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 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
157 final SpecializedNode gen = (SpecializedNode) node.getNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
158 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
159 final SpecializationNode start0 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
160 assertEquals("UninitializedNode_", start0.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
161 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
162 await(threadsStarted); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
163 beforeFirst.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
164 await(executedFirst); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
165 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
166 final SpecializationNode start1 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
167 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
|
168 assertEquals("UninitializedNode_", nthChild(1, start1).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 beforeSecond.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
171 await(executedSecond); |
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 start2 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
174 Arrays.sort(order, 0, 2); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
175 assertEquals("PolymorphicNode_", start2.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, start2).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, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
178 assertEquals("UninitializedNode_", nthChild(3, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
179 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
180 beforeThird.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
181 await(executedThird); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
182 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
183 final SpecializationNode start3 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
184 Arrays.sort(order); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
185 assertEquals("PolymorphicNode_", start3.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 assertEquals("UninitializedNode_", nthChild(4, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
190 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
191 for (Thread thread : threads) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
192 try { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
193 thread.join(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
194 } catch (InterruptedException e) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
195 fail("interrupted"); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
196 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
197 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
198 } |
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 private static class Executions { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
201 public final Object firstValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
202 public final Object secondValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
203 public final Object thirdValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
204 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
205 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
|
206 this.firstValue = firstValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
207 this.secondValue = secondValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
208 this.thirdValue = thirdValue; |
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 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
211 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
212 private static void await(final CountDownLatch latch) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
213 try { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
214 latch.await(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
215 } catch (InterruptedException e) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
216 fail("interrupted"); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
217 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
218 } |
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 private static Node firstChild(Node node) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
221 return node.getChildren().iterator().next(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
222 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
223 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
224 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
|
225 if (n == 0) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
226 return node; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
227 } else { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
228 return nthChild(n - 1, firstChild(node)); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
229 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
230 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
231 } |