8269530: runtime/ParallelLoad/ParallelSuperTest.java timeout
Reviewed-by: dholmes, coleenp
This commit is contained in:
parent
3f2c372396
commit
e238cbd596
test/hotspot/jtreg/runtime/ParallelLoad
@ -21,14 +21,16 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
class ClassLoadingThread extends Thread {
|
||||
|
||||
private ClassLoader ldr = null;
|
||||
private Object thread_sync = null;
|
||||
private Semaphore mainSync = null;
|
||||
|
||||
public ClassLoadingThread(ClassLoader loader, Object sync) {
|
||||
public ClassLoadingThread(ClassLoader loader, Semaphore sem) {
|
||||
ldr = loader;
|
||||
thread_sync = sync;
|
||||
mainSync = sem;
|
||||
}
|
||||
|
||||
private boolean success = true;
|
||||
@ -47,9 +49,9 @@ class ClassLoadingThread extends Thread {
|
||||
success = false;
|
||||
} finally {
|
||||
ThreadPrint.println("Finished");
|
||||
// Wake up the second thread
|
||||
synchronized (thread_sync) {
|
||||
thread_sync.notify();
|
||||
// Signal main thread to start t2.
|
||||
if (mainSync != null) {
|
||||
mainSync.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
import java.io.*;
|
||||
import jdk.test.lib.classloader.ClassUnloadCommon;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
// This class loader will deadlock where one thread has a lock for A, trying to get a lock for B
|
||||
// and the other thread has a lock for B, trying to get a lock for A in the case of
|
||||
@ -60,16 +61,15 @@ class MyLoader extends ClassLoader {
|
||||
|
||||
private static boolean parallel = false;
|
||||
private Object sync = new Object();
|
||||
private Object thread_sync = new Object();
|
||||
private static volatile boolean waiting = false;
|
||||
private static Semaphore mainSem = new Semaphore(0);
|
||||
|
||||
private void makeThreadWait() {
|
||||
if (!parallel) { return; }
|
||||
|
||||
// Wake up the second thread here.
|
||||
synchronized (thread_sync) {
|
||||
thread_sync.notify();
|
||||
}
|
||||
// Signal main thread to start t2.
|
||||
mainSem.release();
|
||||
|
||||
if (isRegisteredAsParallelCapable()) {
|
||||
synchronized(sync) {
|
||||
try {
|
||||
@ -136,18 +136,16 @@ class MyLoader extends ClassLoader {
|
||||
void startLoading() {
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
threads[i] = new ClassLoadingThread(this, thread_sync);
|
||||
threads[i] = new ClassLoadingThread(this, parallel ? null : mainSem);
|
||||
threads[i].setName("Loading Thread #" + (i + 1));
|
||||
threads[i].start();
|
||||
System.out.println("Thread " + (i + 1) + " was started...");
|
||||
// wait to start the second thread if not concurrent
|
||||
if (i == 0) {
|
||||
synchronized(thread_sync) {
|
||||
try {
|
||||
ThreadPrint.println("t2 waits");
|
||||
thread_sync.wait();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
try {
|
||||
ThreadPrint.println("Main thread calls mainSem.acquire()");
|
||||
mainSem.acquire();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user