author | dl |
Tue, 10 Jul 2018 10:24:08 -0700 | |
changeset 51035 | 0484b16ef437 |
parent 50229 | 6b29ef846c5c |
permissions | -rw-r--r-- |
20882 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
6 |
* published by the Free Software Foundation. |
|
7 |
* |
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
12 |
* accompanied this code). |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License version |
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 |
* |
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
19 |
* or visit www.oracle.com if you need additional information or have any |
|
20 |
* questions. |
|
21 |
*/ |
|
22 |
||
23 |
/* |
|
24 |
* This file is available under and governed by the GNU General Public |
|
25 |
* License version 2 only, as published by the Free Software Foundation. |
|
26 |
* However, the following notice accompanied the original version of this |
|
27 |
* file: |
|
28 |
* |
|
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
29 |
* Written by Doug Lea and Martin Buchholz with assistance from |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
30 |
* members of JCP JSR-166 Expert Group and released to the public |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
31 |
* domain, as explained at |
20882 | 32 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
33 |
*/ |
|
34 |
||
35 |
/* |
|
36 |
* @test |
|
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
37 |
* @bug 8004138 8205576 |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40279
diff
changeset
|
38 |
* @modules java.base/java.util.concurrent:open |
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
39 |
* @run testng FJExceptionTableLeak |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
40 |
* @summary Checks that ForkJoinTask thrown exceptions are not leaked. |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
41 |
* This whitebox test is sensitive to forkjoin implementation details. |
20882 | 42 |
*/ |
34347 | 43 |
|
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
44 |
import static org.testng.Assert.*; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
45 |
import org.testng.annotations.Test; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
46 |
|
50229
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
47 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
48 |
|
50229
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
49 |
import java.lang.ref.ReferenceQueue; |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
50 |
import java.lang.ref.WeakReference; |
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
51 |
import java.lang.invoke.MethodHandles; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
52 |
import java.lang.invoke.VarHandle; |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
53 |
import java.util.ArrayList; |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
54 |
import java.util.concurrent.CountDownLatch; |
34347 | 55 |
import java.util.concurrent.ForkJoinPool; |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
56 |
import java.util.concurrent.ForkJoinTask; |
34347 | 57 |
import java.util.concurrent.RecursiveAction; |
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
58 |
import java.util.concurrent.ThreadLocalRandom; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
59 |
import java.util.concurrent.locks.ReentrantLock; |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
60 |
import java.util.function.BooleanSupplier; |
20882 | 61 |
|
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
62 |
@Test |
20882 | 63 |
public class FJExceptionTableLeak { |
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
64 |
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
65 |
final VarHandle NEXT, EX; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
66 |
final Object[] exceptionTable; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
67 |
final ReentrantLock exceptionTableLock; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
68 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
69 |
FJExceptionTableLeak() throws ReflectiveOperationException { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
70 |
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn( |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
71 |
ForkJoinTask.class, MethodHandles.lookup()); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
72 |
Class<?> nodeClass = Class.forName( |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
73 |
ForkJoinTask.class.getName() + "$ExceptionNode"); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
74 |
VarHandle exceptionTableHandle = lookup.findStaticVarHandle( |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
75 |
ForkJoinTask.class, "exceptionTable", arrayClass(nodeClass)); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
76 |
VarHandle exceptionTableLockHandle = lookup.findStaticVarHandle( |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
77 |
ForkJoinTask.class, "exceptionTableLock", ReentrantLock.class); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
78 |
exceptionTable = (Object[]) exceptionTableHandle.get(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
79 |
exceptionTableLock = (ReentrantLock) exceptionTableLockHandle.get(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
80 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
81 |
NEXT = lookup.findVarHandle(nodeClass, "next", nodeClass); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
82 |
EX = lookup.findVarHandle(nodeClass, "ex", Throwable.class); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
83 |
} |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
84 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
85 |
static <T> Class<T[]> arrayClass(Class<T> klazz) { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
86 |
try { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
87 |
return (Class<T[]>) Class.forName("[L" + klazz.getName() + ";"); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
88 |
} catch (ReflectiveOperationException ex) { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
89 |
throw new Error(ex); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
90 |
} |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
91 |
} |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
92 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
93 |
Object next(Object node) { return NEXT.get(node); } |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
94 |
Throwable ex(Object node) { return (Throwable) EX.get(node); } |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
95 |
|
20882 | 96 |
static class FailingTaskException extends RuntimeException {} |
97 |
static class FailingTask extends RecursiveAction { |
|
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
98 |
public void compute() { throw new FailingTaskException(); } |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
99 |
} |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
100 |
|
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
101 |
/** Counts all FailingTaskExceptions still recorded in exceptionTable. */ |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
102 |
int retainedExceptions() { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
103 |
exceptionTableLock.lock(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
104 |
try { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
105 |
int count = 0; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
106 |
for (Object node : exceptionTable) |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
107 |
for (; node != null; node = next(node)) |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
108 |
if (ex(node) instanceof FailingTaskException) |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
109 |
count++; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
110 |
return count; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
111 |
} finally { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
112 |
exceptionTableLock.unlock(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
113 |
} |
20882 | 114 |
} |
115 |
||
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
116 |
@Test |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
117 |
public void exceptionTableCleanup() throws Exception { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
118 |
ArrayList<FailingTask> failedTasks = failedTasks(); |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
119 |
|
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
120 |
// Retain a strong ref to one last failing task |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
121 |
FailingTask lastTask = failedTasks.get(rnd.nextInt(failedTasks.size())); |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
122 |
|
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
123 |
// Clear all other strong refs, making exception table cleanable |
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
124 |
failedTasks.clear(); |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
125 |
|
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
126 |
BooleanSupplier exceptionTableIsClean = () -> { |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
127 |
try { |
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
128 |
// Trigger exception table expunging as side effect |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
129 |
lastTask.join(); |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
130 |
throw new AssertionError("should throw"); |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
131 |
} catch (FailingTaskException expected) {} |
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
132 |
int count = retainedExceptions(); |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
133 |
if (count == 0) |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
134 |
throw new AssertionError("expected to find last task"); |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
135 |
return count == 1; |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
136 |
}; |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
137 |
gcAwait(exceptionTableIsClean); |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
138 |
} |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
139 |
|
51035
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
140 |
/** Sequestered into a separate method to inhibit GC retention. */ |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
141 |
ArrayList<FailingTask> failedTasks() |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
142 |
throws Exception { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
143 |
final ForkJoinPool pool = new ForkJoinPool(rnd.nextInt(1, 4)); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
144 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
145 |
assertEquals(0, retainedExceptions()); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
146 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
147 |
final ArrayList<FailingTask> tasks = new ArrayList<>(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
148 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
149 |
for (int i = exceptionTable.length; i--> 0; ) { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
150 |
FailingTask task = new FailingTask(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
151 |
pool.execute(task); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
152 |
tasks.add(task); // retain strong refs to all tasks, for now |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
153 |
task = null; // excessive GC retention paranoia |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
154 |
} |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
155 |
for (FailingTask task : tasks) { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
156 |
try { |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
157 |
task.join(); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
158 |
throw new AssertionError("should throw"); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
159 |
} catch (FailingTaskException success) {} |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
160 |
task = null; // excessive GC retention paranoia |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
161 |
} |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
162 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
163 |
if (rnd.nextBoolean()) |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
164 |
gcAwait(() -> retainedExceptions() == tasks.size()); |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
165 |
|
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
166 |
return tasks; |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
167 |
} |
0484b16ef437
8205576: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"
dl
parents:
50229
diff
changeset
|
168 |
|
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
169 |
// --------------- GC finalization infrastructure --------------- |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
170 |
|
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
171 |
/** No guarantees, but effective in practice. */ |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
172 |
static void forceFullGc() { |
50229
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
173 |
long timeoutMillis = 1000L; |
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
174 |
CountDownLatch finalized = new CountDownLatch(1); |
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
175 |
ReferenceQueue<Object> queue = new ReferenceQueue<>(); |
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
176 |
WeakReference<Object> ref = new WeakReference<>( |
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
177 |
new Object() { protected void finalize() { finalized.countDown(); }}, |
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
178 |
queue); |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
179 |
try { |
50229
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
180 |
for (int tries = 3; tries--> 0; ) { |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
181 |
System.gc(); |
50229
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
182 |
if (finalized.await(timeoutMillis, MILLISECONDS) |
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
183 |
&& queue.remove(timeoutMillis) != null |
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
184 |
&& ref.get() == null) { |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
185 |
System.runFinalization(); // try to pick up stragglers |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
186 |
return; |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
187 |
} |
50229
6b29ef846c5c
8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents:
47216
diff
changeset
|
188 |
timeoutMillis *= 4; |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
189 |
} |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
190 |
} catch (InterruptedException unexpected) { |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
191 |
throw new AssertionError("unexpected InterruptedException"); |
20882 | 192 |
} |
40279
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
193 |
throw new AssertionError("failed to do a \"full\" gc"); |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
194 |
} |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
195 |
|
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
196 |
static void gcAwait(BooleanSupplier s) { |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
197 |
for (int i = 0; i < 10; i++) { |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
198 |
if (s.getAsBoolean()) |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
199 |
return; |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
200 |
forceFullGc(); |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
201 |
} |
7a1e94e544d6
8151158: [TESTBUG] java/util/concurrent/forkjoin/FJExceptionTableLeak.java fails due to out of memory
dl
parents:
39744
diff
changeset
|
202 |
throw new AssertionError("failed to satisfy condition"); |
20882 | 203 |
} |
204 |
} |