Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java
48795 views
1
/*
2
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test LFMultiThreadCachingTest
26
* @bug 8046703
27
* @summary Test verifies that lambda forms are cached when run with multiple threads
28
* @author kshefov
29
* @library /lib/testlibrary/jsr292 /lib/testlibrary
30
* @build TestMethods
31
* @build LambdaFormTestCase
32
* @build LFCachingTestCase
33
* @build LFMultiThreadCachingTest
34
* @run main/othervm LFMultiThreadCachingTest
35
*/
36
37
import java.lang.invoke.MethodHandle;
38
import java.util.Collections;
39
import java.util.EnumSet;
40
import java.util.HashMap;
41
import java.util.Map;
42
import java.util.concurrent.BrokenBarrierException;
43
import java.util.concurrent.ConcurrentLinkedQueue;
44
import java.util.concurrent.CountDownLatch;
45
import java.util.concurrent.CyclicBarrier;
46
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
47
48
/**
49
* Multiple threaded lambda forms caching test class.
50
*/
51
public final class LFMultiThreadCachingTest extends LFCachingTestCase {
52
53
private static final TestMethods.Kind[] KINDS;
54
55
static {
56
EnumSet<TestMethods.Kind> set = EnumSet.complementOf(EnumSet.of(TestMethods.Kind.EXCEPT));
57
KINDS = set.toArray(new TestMethods.Kind[set.size()]);
58
if (KINDS.length < 2) {
59
throw new Error("TESTBUG: KINDS.length[" + KINDS.length + "] should be at least 2");
60
}
61
}
62
private static final int CORES = Math.max(KINDS.length, Runtime.getRuntime().availableProcessors());
63
64
/**
65
* Constructor a for multiple threaded lambda forms caching test case.
66
*
67
* @param testMethod A method from {@code j.l.i.MethodHandles} class that
68
* returns a {@code j.l.i.MethodHandle} instance.
69
*/
70
public LFMultiThreadCachingTest(TestMethods testMethod) {
71
super(testMethod);
72
}
73
74
@Override
75
public void doTest() {
76
Map<String, Object> data = getTestMethod().getTestCaseData();
77
ConcurrentLinkedQueue<MethodHandle> adapters = new ConcurrentLinkedQueue<>();
78
CyclicBarrier begin = new CyclicBarrier(CORES);
79
CountDownLatch end = new CountDownLatch(CORES);
80
final Map<Thread, Throwable> threadUncaughtExceptions
81
= Collections.synchronizedMap(new HashMap<Thread, Throwable>(CORES));
82
for (int i = 0; i < CORES; ++i) {
83
TestMethods.Kind kind = KINDS[i % KINDS.length];
84
Thread t = new Thread(() -> {
85
try {
86
begin.await();
87
adapters.add(getTestMethod().getTestCaseMH(data, kind));
88
} catch (Throwable ex) {
89
threadUncaughtExceptions.put(Thread.currentThread(), ex);
90
} finally {
91
end.countDown();
92
}
93
});
94
t.start();
95
}
96
try {
97
end.await();
98
boolean vmeThrown = false;
99
boolean nonVmeThrown = false;
100
Throwable vme = null;
101
for (Map.Entry<Thread,
102
Throwable> entry : threadUncaughtExceptions.entrySet()) {
103
Thread t = entry.getKey();
104
Throwable e = entry.getValue();
105
System.err.printf("%nA thread with name \"%s\" of %d threads"
106
+ " has thrown exception:%n", t.getName(), CORES);
107
e.printStackTrace();
108
if (CodeCacheOverflowProcessor.isThrowableCausedByVME(e)) {
109
vmeThrown = true;
110
vme = e;
111
} else {
112
nonVmeThrown = true;
113
}
114
if (nonVmeThrown) {
115
throw new Error("One ore more threads have"
116
+ " thrown unexpected exceptions. See log.");
117
}
118
if (vmeThrown) {
119
throw new Error("One ore more threads have"
120
+ " thrown VirtualMachineError caused by"
121
+ " code cache overflow. See log.", vme);
122
}
123
}
124
} catch (InterruptedException ex) {
125
throw new Error("Unexpected exception: ", ex);
126
}
127
if (adapters.size() < CORES) {
128
throw new Error("adapters size[" + adapters.size() + "] is less than " + CORES);
129
}
130
MethodHandle prev = adapters.poll();
131
for (MethodHandle current : adapters) {
132
checkLFCaching(prev, current);
133
prev = current;
134
}
135
}
136
137
/**
138
* Main routine for multiple threaded lambda forms caching test.
139
*
140
* @param args Accepts no arguments.
141
*/
142
public static void main(String[] args) {
143
LambdaFormTestCase.runTests(LFMultiThreadCachingTest::new, EnumSet.allOf(TestMethods.class));
144
}
145
}
146
147