author | shurailine |
Mon, 08 Feb 2016 18:14:48 -0800 | |
changeset 35768 | 7066da300a08 |
parent 32991 | b27c76b82713 |
permissions | -rw-r--r-- |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
1 |
/* |
35768
7066da300a08
8149391: Fix module dependences in java/util tests
shurailine
parents:
32991
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
4 |
* |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
8 |
* |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
13 |
* accompanied this code). |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
14 |
* |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
18 |
* |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
21 |
* questions. |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
22 |
*/ |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
23 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
24 |
import org.testng.annotations.Test; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
25 |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
26 |
import java.lang.management.ManagementFactory; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
27 |
import java.lang.management.ThreadInfo; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
28 |
import java.lang.management.ThreadMXBean; |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
29 |
import java.util.HashMap; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
30 |
import java.util.Map; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
31 |
import java.util.concurrent.CompletableFuture; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
32 |
import java.util.concurrent.ConcurrentHashMap; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
33 |
import java.util.concurrent.ConcurrentMap; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
34 |
import java.util.concurrent.CountDownLatch; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
35 |
import java.util.concurrent.ThreadLocalRandom; |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
36 |
import java.util.concurrent.TimeUnit; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
37 |
import java.util.concurrent.TimeoutException; |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
38 |
import java.util.function.BiConsumer; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
39 |
import java.util.function.Supplier; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
40 |
import java.util.stream.IntStream; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
41 |
import java.util.stream.Stream; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
42 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
43 |
/** |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
44 |
* @test |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
45 |
* @bug 8028564 |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
46 |
* @run testng/timeout=1200 ConcurrentAssociateTest |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
47 |
* @summary Test that association operations, such as put and compute, |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
48 |
* place entries in the map |
35768
7066da300a08
8149391: Fix module dependences in java/util tests
shurailine
parents:
32991
diff
changeset
|
49 |
* @modules java.management |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
50 |
*/ |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
51 |
@Test |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
52 |
public class ConcurrentAssociateTest { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
53 |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
54 |
/** Maximum time (in seconds) to wait for a test method to complete. */ |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
55 |
private static final int TIMEOUT = Integer.getInteger("timeout", 200); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
56 |
|
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
57 |
/** The number of entries for each thread to place in a map. */ |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
58 |
private static final int N = Integer.getInteger("n", 128); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
59 |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
60 |
/** The number of iterations of the test. */ |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
61 |
private static final int I = Integer.getInteger("i", 64); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
62 |
|
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
63 |
/** Objects to be placed in the concurrent map. */ |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
64 |
static class X { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
65 |
// Limit the hash code to trigger collisions |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
66 |
final int hc = ThreadLocalRandom.current().nextInt(1, 9); |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
67 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
68 |
public int hashCode() { return hc; } |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
69 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
70 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
71 |
@Test |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
72 |
public void testPut() throws Throwable { |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
73 |
test("CHM.put", (m, o) -> m.put(o, o)); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
74 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
75 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
76 |
@Test |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
77 |
public void testCompute() throws Throwable { |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
78 |
test("CHM.compute", (m, o) -> m.compute(o, (k, v) -> o)); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
79 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
80 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
81 |
@Test |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
82 |
public void testComputeIfAbsent() throws Throwable { |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
83 |
test("CHM.computeIfAbsent", (m, o) -> m.computeIfAbsent(o, (k) -> o)); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
84 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
85 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
86 |
@Test |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
87 |
public void testMerge() throws Throwable { |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
88 |
test("CHM.merge", (m, o) -> m.merge(o, o, (v1, v2) -> v1)); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
89 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
90 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
91 |
@Test |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
92 |
public void testPutAll() throws Throwable { |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
93 |
test("CHM.putAll", (m, o) -> { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
94 |
Map<Object, Object> hm = new HashMap<>(); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
95 |
hm.put(o, o); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
96 |
m.putAll(hm); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
97 |
}); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
98 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
99 |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
100 |
private static void test(String desc, BiConsumer<ConcurrentMap<Object, Object>, Object> associator) throws Throwable { |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
101 |
for (int i = 0; i < I; i++) { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
102 |
testOnce(desc, associator); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
103 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
104 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
105 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
106 |
static class AssociationFailure extends RuntimeException { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
107 |
AssociationFailure(String message) { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
108 |
super(message); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
109 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
110 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
111 |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
112 |
private static void testOnce(String desc, BiConsumer<ConcurrentMap<Object, Object>, Object> associator) throws Throwable { |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
113 |
ConcurrentHashMap<Object, Object> m = new ConcurrentHashMap<>(); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
114 |
CountDownLatch s = new CountDownLatch(1); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
115 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
116 |
Supplier<Runnable> sr = () -> () -> { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
117 |
try { |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
118 |
if (!s.await(TIMEOUT, TimeUnit.SECONDS)) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
119 |
dumpTestThreads(); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
120 |
throw new AssertionError("timed out"); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
121 |
} |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
122 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
123 |
catch (InterruptedException e) { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
124 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
125 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
126 |
for (int i = 0; i < N; i++) { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
127 |
Object o = new X(); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
128 |
associator.accept(m, o); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
129 |
if (!m.containsKey(o)) { |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
130 |
throw new AssociationFailure(desc + " failed: entry does not exist"); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
131 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
132 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
133 |
}; |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
134 |
|
31807
3bd38a739ea1
8081734: ConcurrentHashMap/ConcurrentAssociateTest.java, times out 90% of time on sparc with 256 cpu.
darcy
parents:
21981
diff
changeset
|
135 |
// Bound concurrency to avoid degenerate performance |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
136 |
int ps = Math.min(Runtime.getRuntime().availableProcessors(), 8); |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
137 |
Stream<CompletableFuture> runners = IntStream.range(0, ps) |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
138 |
.mapToObj(i -> sr.get()) |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
139 |
.map(CompletableFuture::runAsync); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
140 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
141 |
CompletableFuture all = CompletableFuture.allOf( |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
142 |
runners.toArray(CompletableFuture[]::new)); |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
143 |
|
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
144 |
// Trigger the runners to start associating |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
145 |
s.countDown(); |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
146 |
|
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
147 |
try { |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
148 |
all.get(TIMEOUT, TimeUnit.SECONDS); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
149 |
} catch (TimeoutException e) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
150 |
dumpTestThreads(); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
151 |
throw e; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
152 |
} catch (Throwable e) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
153 |
dumpTestThreads(); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
154 |
Throwable cause = e.getCause(); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
155 |
if (cause instanceof AssociationFailure) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
156 |
throw cause; |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
157 |
} |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
158 |
throw e; |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
159 |
} |
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
160 |
} |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
161 |
|
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
162 |
/** |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
163 |
* A debugging tool to print stack traces of most threads, as jstack does. |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
164 |
* Uninteresting threads are filtered out. |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
165 |
*/ |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
166 |
static void dumpTestThreads() { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
167 |
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
168 |
System.err.println("------ stacktrace dump start ------"); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
169 |
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
170 |
String name = info.getThreadName(); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
171 |
if ("Signal Dispatcher".equals(name)) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
172 |
continue; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
173 |
if ("Reference Handler".equals(name) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
174 |
&& info.getLockName().startsWith("java.lang.ref.Reference$Lock")) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
175 |
continue; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
176 |
if ("Finalizer".equals(name) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
177 |
&& info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock")) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
178 |
continue; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
179 |
System.err.print(info); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
180 |
} |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
181 |
System.err.println("------ stacktrace dump end ------"); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31807
diff
changeset
|
182 |
} |
21981
48b31d370bc9
8028564: Concurrent calls to CHM.put can fail to add the key/value to the map
psandoz
parents:
diff
changeset
|
183 |
} |