From d45fc76b0d7d3a8ab71e985a3306659d281f1ea4 Mon Sep 17 00:00:00 2001 From: Anton Artemov Date: Tue, 2 Dec 2025 11:24:14 +0100 Subject: [PATCH] 8366659: Fixed semi-broken tests --- .../SuspendWithObjectMonitorWait1.java | 4 +- .../SuspendWithObjectMonitorWait2.java | 4 +- .../SuspendWithObjectMonitorWait3.java | 4 +- .../SuspendWithObjectMonitorWaitBase.java | 55 ++++++++++++++++++- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait1.java b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait1.java index b9eb6e2e31c..9242f799996 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait1.java +++ b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait1.java @@ -28,7 +28,7 @@ * @requires vm.jvmti * @library /test/lib * @compile SuspendWithObjectMonitorWait1.java - * @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait1 + * @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait1 1 */ import java.io.PrintStream; @@ -70,7 +70,7 @@ public class SuspendWithObjectMonitorWait1 extends SuspendWithObjectMonitorWaitB SuspendWithObjectMonitorWaitWorker waiter; // waiter thread SuspendWithObjectMonitorWaitWorker resumer; // resumer thread - System.out.println("About to execute for " + timeMax + " seconds."); + System.out.println("Test 1: About to execute for " + timeMax + " seconds."); long start_time = System.currentTimeMillis(); while (System.currentTimeMillis() < start_time + (timeMax * 1000)) { diff --git a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait2.java b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait2.java index 33bd349ae6e..6781abe76f5 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait2.java +++ b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait2.java @@ -28,7 +28,7 @@ * @requires vm.jvmti * @library /test/lib * @compile SuspendWithObjectMonitorWait2.java - * @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait2 + * @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait2 2 */ import java.io.PrintStream; @@ -79,7 +79,7 @@ public class SuspendWithObjectMonitorWait2 extends SuspendWithObjectMonitorWaitB SuspendWithObjectMonitorWaitWorker waiter; // waiter thread SuspendWithObjectMonitorWaitWorker resumer; // resumer thread - System.out.println("About to execute for " + timeMax + " seconds."); + System.out.println("Test 2: About to execute for " + timeMax + " seconds."); long start_time = System.currentTimeMillis(); while (System.currentTimeMillis() < start_time + (timeMax * 1000)) { diff --git a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait3.java b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait3.java index 88faeeb2767..c8ee87e4a21 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait3.java +++ b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWait3.java @@ -28,7 +28,7 @@ * @requires vm.jvmti * @library /test/lib * @compile SuspendWithObjectMonitorWait3.java - * @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait3 + * @run main/othervm/native -agentlib:SuspendWithObjectMonitorWait SuspendWithObjectMonitorWait3 3 */ import java.io.PrintStream; @@ -85,7 +85,7 @@ public class SuspendWithObjectMonitorWait3 extends SuspendWithObjectMonitorWaitB SuspendWithObjectMonitorWaitWorker waiter; // waiter thread SuspendWithObjectMonitorWaitWorker resumer; // resumer thread - System.out.println("About to execute for " + timeMax + " seconds."); + System.out.println("Test 3: About to execute for " + timeMax + " seconds."); long start_time = System.currentTimeMillis(); while (System.currentTimeMillis() < start_time + (timeMax * 1000)) { diff --git a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWaitBase.java b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWaitBase.java index 25cdbc5039d..252402fd8bd 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWaitBase.java +++ b/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/SuspendWithObjectMonitorWaitBase.java @@ -145,7 +145,12 @@ public class SuspendWithObjectMonitorWaitBase { } public static void main(String[] args) throws Exception { - if (args.length > 2) { + if (args.length == 0) { + System.err.println("Invalid number of arguments, there should be at least a test_case given."); + usage(); + } + + if (args.length > 3) { System.err.println("Invalid number of arguments, there are too many arguments."); usage(); } @@ -159,14 +164,32 @@ public class SuspendWithObjectMonitorWaitBase { throw ule; } + int testCase = 0; int timeMax = 0; for (int argIndex = 0; argIndex < args.length; argIndex++) { - if ("-p".equals(args[argIndex])) { + if (args[argIndex].equals("-p")) { // Handle optional -p arg regardless of position. printDebug = true; continue; } + if (testCase == 0) { + try { + // testCase must be the first non-optional arg. + testCase = Integer.parseUnsignedInt(args[argIndex]); + log("testCase = " + testCase); + } catch (NumberFormatException nfe) { + System.err.println("'" + args[argIndex] + + "': invalid test_case value."); + usage(); + } + if (testCase < 1 || testCase > 3) { + System.err.println("Invalid test_case value: '" + testCase + "'"); + usage(); + } + continue; + } + if (argIndex < args.length) { // timeMax is an optional arg. try { @@ -180,7 +203,33 @@ public class SuspendWithObjectMonitorWaitBase { timeMax = DEF_TIME_MAX; } } - SuspendWithObjectMonitorWaitBase test = new SuspendWithObjectMonitorWaitBase(); + + if (timeMax == 0) { + timeMax = DEF_TIME_MAX; + } + log("timeMax = " + timeMax); + + if (testCase == 0) { + // Just -p was given. + System.err.println("Invalid number of arguments, no test_case given."); + usage(); + } + + SuspendWithObjectMonitorWaitBase test = null; + switch (testCase) { + case 1: + test = new SuspendWithObjectMonitorWait1(); + break; + case 2: + test = new SuspendWithObjectMonitorWait2(); + break; + case 3: + test = new SuspendWithObjectMonitorWait3(); + break; + default: + // Impossible + break; + } int result = test.run(timeMax, System.out); System.exit(result + exit_delta); }