From a8450b37ee6ea83c5354ba0892ac71df19e5a1cc Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Wed, 26 Oct 2022 17:28:44 +0000 Subject: [PATCH] 8295713: runtime/ParallelLoad/SuperWait/SuperWaitTest.java fails intermittently on Windows Reviewed-by: pchilanomate, dholmes --- .../SuperWait/ClassLoadingThread.java | 18 ++++------- .../ParallelLoad/SuperWait/SuperWaitTest.java | 30 ++++++++----------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/ClassLoadingThread.java b/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/ClassLoadingThread.java index d5ecf350309..898ab51bffc 100644 --- a/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/ClassLoadingThread.java +++ b/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/ClassLoadingThread.java @@ -23,14 +23,12 @@ class ClassLoadingThread extends Thread { - private ClassLoader ldr1; - private ClassLoader ldr2; - private int which; + private String className; + private ClassLoader ldr; - public ClassLoadingThread(ClassLoader loader1, ClassLoader loader2, int i) { - ldr1 = loader1; - ldr2 = loader2; - which = i; + public ClassLoadingThread(String name, ClassLoader loader) { + className = name; + ldr = loader; } private boolean success = true; @@ -50,10 +48,6 @@ class ClassLoadingThread extends Thread { } public void run() { - if (which == 0) { - callForName("A",ldr1); - } else { - callForName("C", ldr2); - } + callForName(className, ldr); } } diff --git a/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/SuperWaitTest.java b/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/SuperWaitTest.java index 51ee2c8636f..b93e4151418 100644 --- a/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/SuperWaitTest.java +++ b/test/hotspot/jtreg/runtime/ParallelLoad/SuperWait/SuperWaitTest.java @@ -36,19 +36,17 @@ import java.util.concurrent.Semaphore; public class SuperWaitTest { - private static Semaphore mainSync = null; - // Loads classes A and D, delegates for A's super class B private static class MyLoaderOne extends ClassLoader { + private static boolean dIsLoading = false; + ClassLoader parent; ClassLoader baseLoader; - int count; MyLoaderOne(ClassLoader parent) { this.parent = parent; this.baseLoader = null; - this.count = 0; } public void setBaseLoader(ClassLoader ldr) { @@ -61,13 +59,15 @@ public class SuperWaitTest { if (name.equals("A") || name.equals("D")) { ThreadPrint.println("Loading " + name); if (name.equals("A")) { - try { - ThreadPrint.println("Waiting for " + name); - mainSync.acquire(); // wait until other thread gets here - wait(); // let the other thread have this lock. - } catch (InterruptedException ie) {} + ThreadPrint.println("Waiting for " + name); + while (!dIsLoading) { // guard against spurious wakeup + try { + wait(); // let the other thread have this lock. + } catch (InterruptedException ie) {} + } } else { - notify(); // reacquire lock when superclass loading is done + dIsLoading = true; + notify(); // notify lock when superclass loading is done } byte[] classfile = ClassUnloadCommon.getClassData(name); return defineClass(name, classfile, 0, classfile.length); @@ -85,12 +85,10 @@ public class SuperWaitTest { ClassLoader parent; ClassLoader baseLoader; - int count; MyLoaderTwo(ClassLoader parent) { this.parent = parent; this.baseLoader = null; - this.count = 0; } public void setBaseLoader(ClassLoader ldr) { @@ -102,9 +100,6 @@ public class SuperWaitTest { if (loadedClass != null) return loadedClass; if (name.equals("C") || name.equals("B")) { ThreadPrint.println("Loading " + name); - if (name.equals("C")) { - mainSync.release(); - } byte[] classfile = ClassUnloadCommon.getClassData(name); return defineClass(name, classfile, 0, classfile.length); } else if (name.equals("D")) { @@ -131,7 +126,6 @@ public class SuperWaitTest { public static void main(java.lang.String[] unused) { // t1 loads (A,CL1) extends (B,CL2); t2 loads (C,CL2) extends (D,CL1) - mainSync = new Semaphore(0); ClassLoader appLoader = SuperWaitTest.class.getClassLoader(); MyLoaderOne ldr1 = new MyLoaderOne(appLoader); @@ -139,12 +133,14 @@ public class SuperWaitTest { ldr1.setBaseLoader(ldr2); ldr2.setBaseLoader(ldr1); + threads[0] = new ClassLoadingThread("A", ldr1); + threads[1] = new ClassLoadingThread("C", ldr2); for (int i = 0; i < 2; i++) { - threads[i] = new ClassLoadingThread(ldr1, ldr2, i); threads[i].setName("Loading Thread #" + (i + 1)); threads[i].start(); System.out.println("Thread " + (i + 1) + " was started..."); } + if (report_success()) { System.out.println("PASSED"); } else {