8266130: convert Thread-SMR stress tests from counter based to time based

Reviewed-by: cjplummer, dholmes
This commit is contained in:
Daniel D. Daugherty 2021-06-10 13:09:26 +00:00
parent 6c552a7b42
commit f677163b8a
21 changed files with 702 additions and 595 deletions

View File

@ -143,6 +143,8 @@ vmTestbase/nsk/jvmti/AttachOnDemand/attach045/TestDescription.java 8202971 gener
vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/TestDescription.java 8219652 aix-ppc64 vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/TestDescription.java 8219652 aix-ppc64
vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/TestDescription.java 8219652 aix-ppc64 vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/TestDescription.java 8219652 aix-ppc64
vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/TestDescription.java 8219652 aix-ppc64 vmTestbase/nsk/jvmti/SetJNIFunctionTable/setjniftab001/TestDescription.java 8219652 aix-ppc64
vmTestbase/nsk/jvmti/SuspendThread/suspendthrd003/TestDescription.java 8264605 generic-all
vmTestbase/nsk/jvmti/PopFrame/popframe011/TestDescription.java 8266593 generic-all
vmTestbase/gc/lock/jni/jnilock002/TestDescription.java 8192647 generic-all vmTestbase/gc/lock/jni/jnilock002/TestDescription.java 8192647 generic-all

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,16 @@
/** /**
* @test * @test
* @bug 8167108 * @bug 8167108 8266130
* @summary Stress test java.lang.Thread.interrupt() at thread exit. * @summary Stress test java.lang.Thread.interrupt() at thread exit.
* @run main/othervm -Xlog:thread+smr=debug InterruptAtExit * @run main/othervm InterruptAtExit
*/ */
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
public class InterruptAtExit extends Thread { public class InterruptAtExit extends Thread {
final static int N_THREADS = 32; private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int N_LATE_CALLS = 1000; private final static String PROG_NAME = "InterruptAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1); public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1); public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -42,32 +42,46 @@ public class InterruptAtExit extends Thread {
// Tell main thread we have started. // Tell main thread we have started.
startSyncObj.countDown(); startSyncObj.countDown();
try { try {
// Wait for main thread to interrupt us so we // Wait for main thread to tell us to race to the exit.
// can race to exit.
exitSyncObj.await(); exitSyncObj.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore because we expect one // Ignore because we are testing java.lang.Thread.interrupt()
// and one may arrive before we leave the 'try { }' block.
} }
} }
public static void main(String[] args) { public static void main(String[] args) {
InterruptAtExit threads[] = new InterruptAtExit[N_THREADS]; int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
for (int i = 0; i < N_THREADS; i++ ) { System.out.println("About to execute for " + timeMax + " seconds.");
threads[i] = new InterruptAtExit();
int late_count = 1; long count = 0;
threads[i].start(); long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
InterruptAtExit thread = new InterruptAtExit();
thread.start();
try { try {
// Wait for the worker thread to get going. // Wait for the worker thread to get going.
threads[i].startSyncObj.await(); thread.startSyncObj.await();
// Tell the worker thread to race to the exit and the
// Thread.interrupt() calls will come in during thread exit.
thread.exitSyncObj.countDown();
while (true) {
thread.interrupt();
// The first interrupt() call will break the if (!thread.isAlive()) {
// worker out of the exitSyncObj.await() call
// and the rest will come in during thread exit.
for (; late_count <= N_LATE_CALLS; late_count++) {
threads[i].interrupt();
if (!threads[i].isAlive()) {
// Done with Thread.interrupt() calls since // Done with Thread.interrupt() calls since
// thread is not alive. // thread is not alive.
break; break;
@ -77,30 +91,30 @@ public class InterruptAtExit extends Thread {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to java.lang.Thread.interrupt()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a Thread.interrupt() " +
"call after thread exit.");
try { try {
threads[i].join(); thread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
threads[i].interrupt(); thread.interrupt();
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
} }
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
String cmd = System.getProperty("sun.java.command"); String cmd = System.getProperty("sun.java.command");
if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) { if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) {
// Exit with success in a non-JavaTest environment: // Exit with success in a non-JavaTest environment:
System.exit(0); System.exit(0);
} }
} }
public static void usage() {
System.err.println("Usage: " + PROG_NAME + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,16 @@
/** /**
* @test * @test
* @bug 8167108 * @bug 8167108 8266130
* @summary Stress test java.lang.Thread.isInterrupted() at thread exit. * @summary Stress test java.lang.Thread.isInterrupted() at thread exit.
* @run main/othervm -Xlog:thread+smr=debug IsInterruptedAtExit * @run main/othervm IsInterruptedAtExit
*/ */
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
public class IsInterruptedAtExit extends Thread { public class IsInterruptedAtExit extends Thread {
final static int N_THREADS = 32; private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int N_LATE_CALLS = 2000; private final static String PROG_NAME = "IsInterruptedAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1); public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1); public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -42,33 +42,46 @@ public class IsInterruptedAtExit extends Thread {
// Tell main thread we have started. // Tell main thread we have started.
startSyncObj.countDown(); startSyncObj.countDown();
try { try {
// Wait for main thread to interrupt us so we // Wait for main thread to tell us to race to the exit.
// can race to exit.
exitSyncObj.await(); exitSyncObj.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore because we expect one throw new RuntimeException("Unexpected: " + e);
} }
} }
public static void main(String[] args) { public static void main(String[] args) {
IsInterruptedAtExit threads[] = new IsInterruptedAtExit[N_THREADS]; int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
for (int i = 0; i < N_THREADS; i++ ) { System.out.println("About to execute for " + timeMax + " seconds.");
threads[i] = new IsInterruptedAtExit();
int late_count = 1; long count = 0;
threads[i].start(); long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
IsInterruptedAtExit thread = new IsInterruptedAtExit();
thread.start();
try { try {
// Wait for the worker thread to get going. // Wait for the worker thread to get going.
threads[i].startSyncObj.await(); thread.startSyncObj.await();
// Tell the worker thread to race to the exit and the
// Thread.isInterrupted() calls will come in during
// thread exit.
thread.exitSyncObj.countDown();
while (true) {
thread.isInterrupted();
// This interrupt() call will break the worker out of if (!thread.isAlive()) {
// the exitSyncObj.await() call and the isInterrupted()
// calls will come in during thread exit.
threads[i].interrupt();
for (; late_count <= N_LATE_CALLS; late_count++) {
threads[i].isInterrupted();
if (!threads[i].isAlive()) {
// Done with Thread.isInterrupted() calls since // Done with Thread.isInterrupted() calls since
// thread is not alive. // thread is not alive.
break; break;
@ -78,30 +91,30 @@ public class IsInterruptedAtExit extends Thread {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to java.lang.Thread.isInterrupted()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a Thread.isInterrupted() " +
"call after thread exit.");
try { try {
threads[i].join(); thread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
threads[i].isInterrupted(); thread.isInterrupted();
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
} }
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
String cmd = System.getProperty("sun.java.command"); String cmd = System.getProperty("sun.java.command");
if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) { if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) {
// Exit with success in a non-JavaTest environment: // Exit with success in a non-JavaTest environment:
System.exit(0); System.exit(0);
} }
} }
public static void usage() {
System.err.println("Usage: " + PROG_NAME + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
} }

View File

@ -1,107 +0,0 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8167108
* @summary Stress test java.lang.Thread.resume() at thread exit.
* @run main/othervm -Xlog:thread+smr=debug ResumeAtExit
*/
import java.util.concurrent.CountDownLatch;
public class ResumeAtExit extends Thread {
final static int N_THREADS = 32;
final static int N_LATE_CALLS = 2000;
public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1);
@Override
public void run() {
// Tell main thread we have started.
startSyncObj.countDown();
try {
// Wait for main thread to interrupt us so we
// can race to exit.
exitSyncObj.await();
} catch (InterruptedException e) {
// ignore because we expect one
}
}
public static void main(String[] args) {
ResumeAtExit threads[] = new ResumeAtExit[N_THREADS];
for (int i = 0; i < N_THREADS; i++ ) {
threads[i] = new ResumeAtExit();
int late_count = 1;
threads[i].start();
try {
// Wait for the worker thread to get going.
threads[i].startSyncObj.await();
// This interrupt() call will break the worker out
// of the exitSyncObj.await() call and the resume()
// calls will come in during thread exit.
threads[i].interrupt();
for (; late_count <= N_LATE_CALLS; late_count++) {
threads[i].resume();
if (!threads[i].isAlive()) {
// Done with Thread.resume() calls since
// thread is not alive.
break;
}
}
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to java.lang.Thread.resume()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a Thread.resume() " +
"call after thread exit.");
try {
threads[i].join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
threads[i].resume();
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
}
String cmd = System.getProperty("sun.java.command");
if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) {
// Exit with success in a non-JavaTest environment:
System.exit(0);
}
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,16 @@
/** /**
* @test * @test
* @bug 8167108 * @bug 8167108 8266130
* @summary Stress test java.lang.Thread.setName() at thread exit. * @summary Stress test java.lang.Thread.setName() at thread exit.
* @run main/othervm -Xlog:thread+smr=debug SetNameAtExit * @run main/othervm SetNameAtExit
*/ */
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
public class SetNameAtExit extends Thread { public class SetNameAtExit extends Thread {
final static int N_THREADS = 32; private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int N_LATE_CALLS = 1000; private final static String PROG_NAME = "SetNameAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1); public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1); public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -42,33 +42,46 @@ public class SetNameAtExit extends Thread {
// Tell main thread we have started. // Tell main thread we have started.
startSyncObj.countDown(); startSyncObj.countDown();
try { try {
// Wait for main thread to interrupt us so we // Wait for main thread to tell us to race to the exit.
// can race to exit.
exitSyncObj.await(); exitSyncObj.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore because we expect one throw new RuntimeException("Unexpected: " + e);
} }
} }
public static void main(String[] args) { public static void main(String[] args) {
SetNameAtExit threads[] = new SetNameAtExit[N_THREADS]; int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
for (int i = 0; i < N_THREADS; i++ ) { System.out.println("About to execute for " + timeMax + " seconds.");
threads[i] = new SetNameAtExit();
int late_count = 1; long count = 0;
threads[i].start(); long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
SetNameAtExit thread = new SetNameAtExit();
thread.start();
try { try {
// Wait for the worker thread to get going. // Wait for the worker thread to get going.
threads[i].startSyncObj.await(); thread.startSyncObj.await();
// Tell the worker thread to race to the exit and the
// Thread.setName() calls will come in during thread exit.
thread.exitSyncObj.countDown();
long late_count = 0;
while (true) {
thread.setName("T" + count + "-" + late_count++);
// This interrupt() call will break the worker out if (!thread.isAlive()) {
// of the exitSyncObj.await() call and the setName()
// calls will come in during thread exit.
threads[i].interrupt();
for (; late_count <= N_LATE_CALLS; late_count++) {
threads[i].setName("T" + i + "-" + late_count);
if (!threads[i].isAlive()) {
// Done with Thread.setName() calls since // Done with Thread.setName() calls since
// thread is not alive. // thread is not alive.
break; break;
@ -78,30 +91,30 @@ public class SetNameAtExit extends Thread {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to java.lang.Thread.setName()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a Thread.setName() " +
"call after thread exit.");
try { try {
threads[i].join(); thread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
threads[i].setName("T" + i + "-done"); thread.setName("T" + count + "-done");
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
} }
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
String cmd = System.getProperty("sun.java.command"); String cmd = System.getProperty("sun.java.command");
if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) { if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) {
// Exit with success in a non-JavaTest environment: // Exit with success in a non-JavaTest environment:
System.exit(0); System.exit(0);
} }
} }
public static void usage() {
System.err.println("Usage: " + PROG_NAME + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,19 +23,19 @@
/** /**
* @test * @test
* @bug 8167108 * @bug 8167108 8266130
* @summary Stress test java.lang.Thread.setPriority() at thread exit. * @summary Stress test java.lang.Thread.setPriority() at thread exit.
* @run main/othervm -Xlog:thread+smr=debug SetPriorityAtExit * @run main/othervm SetPriorityAtExit
*/ */
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
public class SetPriorityAtExit extends Thread { public class SetPriorityAtExit extends Thread {
final static int N_THREADS = 32; private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int N_LATE_CALLS = 2000; private final static String PROG_NAME = "SetPriorityAtExit";
final static int MIN = java.lang.Thread.MIN_PRIORITY; private final static int MIN = java.lang.Thread.MIN_PRIORITY;
final static int NORM = java.lang.Thread.NORM_PRIORITY; private final static int NORM = java.lang.Thread.NORM_PRIORITY;
public CountDownLatch exitSyncObj = new CountDownLatch(1); public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1); public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -45,39 +45,51 @@ public class SetPriorityAtExit extends Thread {
// Tell main thread we have started. // Tell main thread we have started.
startSyncObj.countDown(); startSyncObj.countDown();
try { try {
// Wait for main thread to interrupt us so we // Wait for main thread to tell us to race to the exit.
// can race to exit.
exitSyncObj.await(); exitSyncObj.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore because we expect one throw new RuntimeException("Unexpected: " + e);
} }
} }
public static void main(String[] args) { public static void main(String[] args) {
SetPriorityAtExit threads[] = new SetPriorityAtExit[N_THREADS]; int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
int prio = MIN; int prio = MIN;
for (int i = 0; i < N_THREADS; i++ ) { long start_time = System.currentTimeMillis();
threads[i] = new SetPriorityAtExit(); while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
int late_count = 1; count++;
threads[i].start(); SetPriorityAtExit thread = new SetPriorityAtExit();
thread.start();
try { try {
// Wait for the worker thread to get going. // Wait for the worker thread to get going.
threads[i].startSyncObj.await(); thread.startSyncObj.await();
// Tell the worker thread to race to the exit and the
// This interrupt() call will break the worker out of // Thread.setPriority() calls will come in during
// the exitSyncObj.await() call and the setPriority() // thread exit.
// calls will come in during thread exit. thread.exitSyncObj.countDown();
threads[i].interrupt(); while (true) {
for (; late_count <= N_LATE_CALLS; late_count++) { thread.setPriority(prio);
threads[i].setPriority(prio);
if (prio == MIN) { if (prio == MIN) {
prio = NORM; prio = NORM;
} else { } else {
prio = MIN; prio = MIN;
} }
if (!threads[i].isAlive()) { if (!thread.isAlive()) {
// Done with Thread.setPriority() calls since // Done with Thread.setPriority() calls since
// thread is not alive. // thread is not alive.
break; break;
@ -86,31 +98,32 @@ public class SetPriorityAtExit extends Thread {
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
thread.setPriority(prio);
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to java.lang.Thread.setPriority()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a Thread.setPriority() " +
"call after thread exit.");
try { try {
threads[i].join(); thread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
threads[i].setPriority(prio); thread.setPriority(prio);
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
} }
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
String cmd = System.getProperty("sun.java.command"); String cmd = System.getProperty("sun.java.command");
if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) { if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) {
// Exit with success in a non-JavaTest environment: // Exit with success in a non-JavaTest environment:
System.exit(0); System.exit(0);
} }
} }
public static void usage() {
System.err.println("Usage: " + PROG_NAME + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,17 +23,17 @@
/** /**
* @test * @test
* @bug 8167108 * @bug 8167108 8266130
* @summary Stress test java.lang.Thread.stop() at thread exit. * @summary Stress test java.lang.Thread.stop() at thread exit.
* @run main/othervm -Xlog:thread+smr=debug StopAtExit * @run main/othervm StopAtExit
*/ */
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class StopAtExit extends Thread { public class StopAtExit extends Thread {
final static int N_THREADS = 32; private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int N_LATE_CALLS = 1000; private final static String PROG_NAME = "StopAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1); public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1); public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -44,11 +44,10 @@ public class StopAtExit extends Thread {
// Tell main thread we have started. // Tell main thread we have started.
startSyncObj.countDown(); startSyncObj.countDown();
try { try {
// Wait for main thread to interrupt us so we // Wait for main thread to tell us to race to the exit.
// can race to exit.
exitSyncObj.await(); exitSyncObj.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore because we expect one throw new RuntimeException("Unexpected: " + e);
} }
} catch (ThreadDeath td) { } catch (ThreadDeath td) {
// ignore because we're testing Thread.stop() which throws it // ignore because we're testing Thread.stop() which throws it
@ -58,24 +57,37 @@ public class StopAtExit extends Thread {
} }
public static void main(String[] args) { public static void main(String[] args) {
StopAtExit threads[] = new StopAtExit[N_THREADS]; int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
for (int i = 0; i < N_THREADS; i++ ) { System.out.println("About to execute for " + timeMax + " seconds.");
threads[i] = new StopAtExit();
int late_count = 1; long count = 0;
threads[i].start(); long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
StopAtExit thread = new StopAtExit();
thread.start();
try { try {
// Wait for the worker thread to get going. // Wait for the worker thread to get going.
threads[i].startSyncObj.await(); thread.startSyncObj.await();
// Tell the worker thread to race to the exit and the
// Thread.stop() calls will come in during thread exit.
thread.exitSyncObj.countDown();
while (true) {
thread.stop();
// This interrupt() call will break the worker out if (!thread.isAlive()) {
// of the exitSyncObj.await() call and the stop()
// calls will come in during thread exit.
threads[i].interrupt();
for (; late_count <= N_LATE_CALLS; late_count++) {
threads[i].stop();
if (!threads[i].isAlive()) {
// Done with Thread.stop() calls since // Done with Thread.stop() calls since
// thread is not alive. // thread is not alive.
break; break;
@ -90,30 +102,30 @@ public class StopAtExit extends Thread {
// main thread. // main thread.
} }
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to java.lang.Thread.stop()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a Thread.stop() " +
"call after thread exit.");
try { try {
threads[i].join(); thread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
threads[i].stop(); thread.stop();
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
} }
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
String cmd = System.getProperty("sun.java.command"); String cmd = System.getProperty("sun.java.command");
if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) { if (cmd != null && !cmd.startsWith("com.sun.javatest.regtest.agent.MainWrapper")) {
// Exit with success in a non-JavaTest environment: // Exit with success in a non-JavaTest environment:
System.exit(0); System.exit(0);
} }
} }
public static void usage() {
System.err.println("Usage: " + PROG_NAME + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,18 +27,17 @@ import nsk.share.Wicket;
import java.io.PrintStream; import java.io.PrintStream;
public class objmonusage006 { public class objmonusage006 {
private final static String AGENT_LIB = "objmonusage006";
private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int JCK_STATUS_BASE = 95; final static int JCK_STATUS_BASE = 95;
final static int WAIT_TIME = 100; final static int WAIT_TIME = 100;
final static int N_LATE_CHECKS = 1000;
final static int N_THREADS = 10;
static { static {
try { try {
System.loadLibrary("objmonusage006"); System.loadLibrary(AGENT_LIB);
} catch (UnsatisfiedLinkError ule) { } catch (UnsatisfiedLinkError ule) {
System.err.println("Could not load objmonusage006 library"); System.err.println("Could not load " + AGENT_LIB + " library");
System.err.println("java.library.path:" System.err.println("java.library.path:"
+ System.getProperty("java.library.path")); + System.getProperty("java.library.path"));
throw ule; throw ule;
@ -59,9 +58,25 @@ public class objmonusage006 {
} }
public static int run(String args[], PrintStream out) { public static int run(String args[], PrintStream out) {
int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
int res = -1; int res = -1;
for (int i = 0; i < N_THREADS; i++) { long start_time = System.currentTimeMillis();
System.out.println("Starting LockingThread #" + i + "."); while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
// Original objmonusage005 test block starts here: // Original objmonusage005 test block starts here:
// //
@ -86,23 +101,43 @@ public class objmonusage006 {
// lockCheck needs to be locked for JVM/TI // lockCheck needs to be locked for JVM/TI
// GetObjectMonitorUsage() to cover the right // GetObjectMonitorUsage() to cover the right
// code paths. // code paths.
System.out.println("LockingThread #" + i + " starting " while (true) {
+ N_LATE_CHECKS + " late checks.");
for (int j = 0; j < N_LATE_CHECKS; j++) {
check(lockCheck); check(lockCheck);
res = getRes(); res = getRes();
if (res != 0) { if (res != 0) {
return res; break;
} }
if (!thr.isAlive()) {
// Done with JVM/TI GetObjectMonitorUsage() calls
// since thread is not alive.
break;
} }
System.out.println("LockingThread #" + i + " ran "
+ N_LATE_CHECKS + " late checks.");
} }
} }
try {
thr.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
return res; return res;
} }
public static void usage() {
System.err.println("Usage: " + AGENT_LIB + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
static class LockingThread extends Thread { static class LockingThread extends Thread {
private volatile boolean flag = true; private volatile boolean flag = true;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/* /*
* @test * @test
* *
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/GetObjectMonitorUsage/objmonusage006. * @summary converted from VM Testbase nsk/jvmti/GetObjectMonitorUsage/objmonusage006.
* VM Testbase keywords: [jpda, jvmti, noras] * VM Testbase keywords: [jpda, jvmti, noras]
* VM Testbase readme: * VM Testbase readme:
@ -36,10 +37,10 @@
* COMMENTS * COMMENTS
* Derived from nsk/jvmti/GetObjectMonitorUsage/objmonusage005. * Derived from nsk/jvmti/GetObjectMonitorUsage/objmonusage005.
* *
* @requires vm.jvmti
* @library /vmTestbase * @library /vmTestbase
* /test/lib * /test/lib
* @run main/othervm/native * @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib:objmonusage006 * -agentlib:objmonusage006
* nsk.jvmti.GetObjectMonitorUsage.objmonusage006 * nsk.jvmti.GetObjectMonitorUsage.objmonusage006
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,22 +26,24 @@ package nsk.jvmti.InterruptThread;
import java.io.PrintStream; import java.io.PrintStream;
public class intrpthrd003 { public class intrpthrd003 {
private final static String AGENT_LIB = "intrpthrd003";
private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int THREADS_NUMBER = 32; final static int THREADS_NUMBER = 32;
final static int N_LATE_CALLS = 1000; final static int N_LATE_CALLS = 1000;
static { static {
try { try {
System.loadLibrary("intrpthrd003"); System.loadLibrary(AGENT_LIB);
} catch (UnsatisfiedLinkError ule) { } catch (UnsatisfiedLinkError ule) {
System.err.println("Could not load intrpthrd003 library"); System.err.println("Could not load " + AGENT_LIB + " library");
System.err.println("java.library.path:" System.err.println("java.library.path:"
+ System.getProperty("java.library.path")); + System.getProperty("java.library.path"));
throw ule; throw ule;
} }
} }
native static int check(int ind, Thread thr); native static int check(long ind, Thread thr);
native static int getResult(); native static int getResult();
native static boolean isThreadNotAliveError(); native static boolean isThreadNotAliveError();
@ -51,20 +53,34 @@ public class intrpthrd003 {
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/); System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
} }
public static int run(String argv[], PrintStream ref) { public static int run(String args[], PrintStream ref) {
intrpthrd003a runn[] = new intrpthrd003a[THREADS_NUMBER]; int timeMax = 0;
if (args.length == 0) {
System.out.println("Case 1: JVM/TI InterruptThread()"); timeMax = DEF_TIME_MAX;
for (int i = 0; i < THREADS_NUMBER; i++ ) { } else {
runn[i] = new intrpthrd003a();
int late_count = 1;
synchronized (runn[i].syncObject) {
runn[i].start();
try { try {
runn[i].syncObject.wait(); timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
for (; late_count <= N_LATE_CALLS; late_count++) { System.out.println("About to execute for " + timeMax + " seconds.");
if (check(i, runn[i]) == 2) break;
long count = 0;
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
intrpthrd003a thr = new intrpthrd003a();
synchronized (thr.syncObject) {
thr.start();
try {
thr.syncObject.wait();
while (true) {
if (check(count, thr) == 2) break;
if (isThreadNotAliveError()) { if (isThreadNotAliveError()) {
// Done with InterruptThread() calls since // Done with InterruptThread() calls since
@ -77,75 +93,27 @@ public class intrpthrd003 {
} }
} }
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to JVM/TI InterruptThread()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause an InterruptThread() " +
"call after thread exit.");
try { try {
runn[i].join(); thr.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new Error("Unexpected: " + e); throw new Error("Unexpected: " + e);
} }
if (check(i, runn[i]) == 2) break; if (check(count, thr) == 2) break;
if (!isThreadNotAliveError()) {
throw new Error("Expected JVMTI_ERROR_THREAD_NOT_ALIVE " +
"after thread #" + i + " has been join()'ed");
}
} }
int res = getResult(); System.out.println("Executed " + count + " loops in " + timeMax +
if (res != 0) { " seconds.");
return res;
return getResult();
} }
System.out.println("Case 2: java.lang.Thread.interrupt()"); public static void usage() {
for (int i = 0; i < THREADS_NUMBER; i++ ) { System.err.println("Usage: " + AGENT_LIB + " [time_max]");
runn[i] = new intrpthrd003a(); System.err.println("where:");
int late_count = 1; System.err.println(" time_max max looping time in seconds");
synchronized (runn[i].syncObject) { System.err.println(" (default is " + DEF_TIME_MAX +
runn[i].start(); " seconds)");
try { System.exit(1);
runn[i].syncObject.wait();
for (; late_count <= N_LATE_CALLS; late_count++) {
runn[i].interrupt();
if (!runn[i].isAlive()) {
// Done with Thread.interrupt() calls since
// thread is not alive.
break;
}
}
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
System.out.println("INFO: thread #" + i + ": made " + late_count +
" late calls to java.lang.Thread.interrupt()");
System.out.println("INFO: thread #" + i + ": N_LATE_CALLS==" +
N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a Thread.interrupt() " +
"call after thread exit.");
try {
runn[i].join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
runn[i].interrupt();
if (runn[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
}
return res;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/* /*
* @test * @test
* *
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/InterruptThread/intrpthrd003. * @summary converted from VM Testbase nsk/jvmti/InterruptThread/intrpthrd003.
* VM Testbase keywords: [quick, jpda, jvmti, noras] * VM Testbase keywords: [quick, jpda, jvmti, noras]
* VM Testbase readme: * VM Testbase readme:
@ -41,10 +42,10 @@
* COMMENTS * COMMENTS
* Derived from nsk/jvmti/InterruptThread/intrpthrd002. * Derived from nsk/jvmti/InterruptThread/intrpthrd002.
* *
* @requires vm.jvmti
* @library /vmTestbase * @library /vmTestbase
* /test/lib * /test/lib
* @run main/othervm/native * @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib:intrpthrd003 * -agentlib:intrpthrd003
* nsk.jvmti.InterruptThread.intrpthrd003 * nsk.jvmti.InterruptThread.intrpthrd003
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "jvmti.h" #include "jvmti.h"
#include "jni_tools.h"
#include "agent_common.h" #include "agent_common.h"
#include "JVMTITools.h" #include "JVMTITools.h"
@ -90,7 +91,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_nsk_jvmti_InterruptThread_intrpthrd003_check (JNIEnv *env, jobject oobj, Java_nsk_jvmti_InterruptThread_intrpthrd003_check (JNIEnv *env, jobject oobj,
jint ind, jthread thr) { jlong ind, jthread thr) {
intrpthrd_err = jvmti->InterruptThread(thr); intrpthrd_err = jvmti->InterruptThread(thr);
if (intrpthrd_err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY && if (intrpthrd_err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY &&
@ -103,7 +104,7 @@ Java_nsk_jvmti_InterruptThread_intrpthrd003_check (JNIEnv *env, jobject oobj,
break; break;
default: default:
printf("(thr#%d) error expected: JVMTI_ERROR_NONE or JVMTI_ERROR_THREAD_NOT_ALIVE,", ind); printf("(thr#%" LL "d) error expected: JVMTI_ERROR_NONE or JVMTI_ERROR_THREAD_NOT_ALIVE,", ind);
printf(" got: %s (%d)\n", TranslateError(intrpthrd_err), intrpthrd_err); printf(" got: %s (%d)\n", TranslateError(intrpthrd_err), intrpthrd_err);
result = STATUS_FAILED; result = STATUS_FAILED;
break; break;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -42,12 +42,13 @@ import java.io.*;
* The test was changed due to the bug 4448675. * The test was changed due to the bug 4448675.
*/ */
public class popframe011 { public class popframe011 {
private final static String AGENT_LIB = "popframe011";
private final static int DEF_TIME_MAX = 30; // default max # secs to test
static final int PASSED = 0; static final int PASSED = 0;
static final int FAILED = 2; static final int FAILED = 2;
static final int JCK_STATUS_BASE = 95; static final int JCK_STATUS_BASE = 95;
static final int N_LATE_CALLS = 100;
static boolean DEBUG_MODE = false; static boolean DEBUG_MODE = false;
static volatile boolean popFdone = false; static volatile boolean popFdone = false;
static volatile int totRes = PASSED; static volatile int totRes = PASSED;
@ -58,9 +59,9 @@ public class popframe011 {
static { static {
try { try {
System.loadLibrary("popframe011"); System.loadLibrary(AGENT_LIB);
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
System.err.println("Could not load popframe011 library"); System.err.println("Could not load " + AGENT_LIB + " library");
System.err.println("java.library.path:" + System.err.println("java.library.path:" +
System.getProperty("java.library.path")); System.getProperty("java.library.path"));
throw e; throw e;
@ -81,15 +82,44 @@ public class popframe011 {
} }
private int runIt(String argv[], PrintStream out) { private int runIt(String argv[], PrintStream out) {
int timeMax = 0;
if (argv.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
int argIndex = 0;
int argvLeft = argv.length;
if (argv[0].equals("-v")) {
DEBUG_MODE = true;
argIndex = 1;
argvLeft--;
}
if (argvLeft == 0) {
timeMax = DEF_TIME_MAX;
} else if (argvLeft == 1) {
try {
timeMax = Integer.parseUnsignedInt(argv[argIndex]);
} catch (NumberFormatException nfe) {
System.err.println("'" + argv[argIndex] +
"': invalid timeMax value.");
usage();
}
} else {
usage();
}
}
System.out.println("About to execute for " + timeMax + " seconds.");
// Original popframe002 test block starts here: // Original popframe002 test block starts here:
// //
int retValue = 0; int retValue = 0;
this.out = out; this.out = out;
for (int i = 0; i < argv.length; i++) {
if (argv[i].equals("-v")) // verbose mode long count = 0;
DEBUG_MODE = true; long start_time = System.currentTimeMillis();
} while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
popFdone = false;
popFrameClsThr = new popFrameCls(); popFrameClsThr = new popFrameCls();
synchronized (barrier) { // force a child thread to pause synchronized (barrier) { // force a child thread to pause
@ -156,8 +186,7 @@ public class popframe011 {
// //
// Original popframe002 test block ends here. // Original popframe002 test block ends here.
int late_count = 1; while (true) {
for (; late_count <= N_LATE_CALLS; late_count++) {
/* check that if the thread, whose top frame is to be popped, /* check that if the thread, whose top frame is to be popped,
has not been suspended and is exiting, the PopFrame() will has not been suspended and is exiting, the PopFrame() will
return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED or return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED or
@ -182,16 +211,33 @@ public class popframe011 {
} }
} }
out.println("INFO: made " + late_count + try {
" late calls to JVM/TI PopFrame()"); popFrameClsThr.join();
out.println("INFO: N_LATE_CALLS==" + N_LATE_CALLS + " value is " + } catch (InterruptedException e) {
((late_count >= N_LATE_CALLS) ? "NOT " : "") + throw new Error("Unexpected: " + e);
"large enough to cause a PopFrame() call after thread " + }
"exit.");
if (totRes != PASSED) {
break;
}
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
return totRes; return totRes;
} }
public static void usage() {
System.err.println("Usage: " + AGENT_LIB + " [-v][time_max]");
System.err.println("where:");
System.err.println(" -v verbose mode");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
class popFrameCls extends Thread { class popFrameCls extends Thread {
public void run() { public void run() {
boolean compl = true; boolean compl = true;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/* /*
* @test * @test
* *
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/PopFrame/popframe011. * @summary converted from VM Testbase nsk/jvmti/PopFrame/popframe011.
* VM Testbase keywords: [jpda, jvmti, noras] * VM Testbase keywords: [jpda, jvmti, noras]
* VM Testbase readme: * VM Testbase readme:
@ -36,10 +37,10 @@
* COMMENTS * COMMENTS
* Derived from nsk/jvmti/PopFrame/popframe002. * Derived from nsk/jvmti/PopFrame/popframe002.
* *
* @requires vm.jvmti
* @library /vmTestbase * @library /vmTestbase
* /test/lib * /test/lib
* @run main/othervm/native * @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib:popframe011 * -agentlib:popframe011
* nsk.jvmti.PopFrame.popframe011 * nsk.jvmti.PopFrame.popframe011
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,12 +29,14 @@ import nsk.share.*;
import nsk.share.jvmti.*; import nsk.share.jvmti.*;
public class suspendthrd003 extends DebugeeClass { public class suspendthrd003 extends DebugeeClass {
private final static String AGENT_LIB = "suspendthrd003";
private final static int DEF_TIME_MAX = 30; // default max # secs to test
final static int N_THREADS = 10; public static Wicket mainEntrance;
// load native library if required // load native library if required
static { static {
System.loadLibrary("suspendthrd003"); System.loadLibrary(AGENT_LIB);
} }
// run test from command line // run test from command line
@ -67,8 +69,26 @@ public class suspendthrd003 extends DebugeeClass {
log = new Log(out, argHandler); log = new Log(out, argHandler);
timeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds timeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
for (int i = 0; i < N_THREADS; i++) { String[] args = argHandler.getArguments();
System.out.println("Starting TestedThread #" + i + "."); int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
int res = -1;
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
// Original suspendthrd001 test block starts here: // Original suspendthrd001 test block starts here:
// //
@ -76,15 +96,14 @@ public class suspendthrd003 extends DebugeeClass {
// Note: Cannot use TestedThread-N for thread name since // Note: Cannot use TestedThread-N for thread name since
// the agent has to know the thread's name. // the agent has to know the thread's name.
thread = new suspendthrd003Thread("TestedThread"); thread = new suspendthrd003Thread("TestedThread");
mainEntrance = new Wicket();
// run tested thread // run tested thread
log.display("Starting tested thread"); log.display("Starting tested thread");
try { try {
thread.start(); thread.start();
// SP1-w - wait for TestedThread-N to be ready // SP1-w - wait for TestedThread-N to be ready
if (!thread.checkReady()) { mainEntrance.waitFor();
throw new Failure("Unable to prepare tested thread: " + thread);
}
// testing sync // testing sync
log.display("Sync: thread started"); log.display("Sync: thread started");
@ -122,15 +141,26 @@ public class suspendthrd003 extends DebugeeClass {
resetAgentData(); // reset for another iteration resetAgentData(); // reset for another iteration
} }
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
return status; return status;
} }
public static void usage() {
System.err.println("Usage: " + AGENT_LIB + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
} }
/* =================================================================== */ /* =================================================================== */
// basic class for tested threads // basic class for tested threads
class suspendthrd003Thread extends Thread { class suspendthrd003Thread extends Thread {
private volatile boolean threadReady = false;
private volatile boolean shouldFinish = false; private volatile boolean shouldFinish = false;
// make thread with specific name // make thread with specific name
@ -142,7 +172,7 @@ class suspendthrd003Thread extends Thread {
public void run() { public void run() {
// run in a loop // run in a loop
// SP1-n - tell main we are ready // SP1-n - tell main we are ready
threadReady = true; suspendthrd003.mainEntrance.unlock();
int i = 0; int i = 0;
int n = 1000; int n = 1000;
while (!shouldFinish) { while (!shouldFinish) {
@ -157,18 +187,6 @@ class suspendthrd003Thread extends Thread {
} }
} }
// check if thread is ready
public boolean checkReady() {
try {
while (!threadReady) {
sleep(1000);
}
} catch (InterruptedException e) {
throw new Failure("Interruption while preparing tested thread: \n\t" + e);
}
return threadReady;
}
// let thread to finish // let thread to finish
public void letFinish() { public void letFinish() {
shouldFinish = true; shouldFinish = true;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/* /*
* @test * @test
* *
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/SuspendThread/suspendthrd003. * @summary converted from VM Testbase nsk/jvmti/SuspendThread/suspendthrd003.
* VM Testbase keywords: [jpda, jvmti, noras] * VM Testbase keywords: [jpda, jvmti, noras]
* VM Testbase readme: * VM Testbase readme:
@ -170,10 +171,10 @@
* exit(data.monitor) * exit(data.monitor)
* } // end resetAgentData() * } // end resetAgentData()
* *
* @requires vm.jvmti
* @library /vmTestbase * @library /vmTestbase
* /test/lib * /test/lib
* @run main/othervm/native * @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib:suspendthrd003=-waittime=5 * -agentlib:suspendthrd003=-waittime=5
* nsk.jvmti.SuspendThread.suspendthrd003 * nsk.jvmti.SuspendThread.suspendthrd003
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,6 @@ static jlong timeout = 0;
/* constant names */ /* constant names */
#define THREAD_NAME "TestedThread" #define THREAD_NAME "TestedThread"
#define N_LATE_CALLS 10000
/* ============================================================================= */ /* ============================================================================= */
@ -54,7 +53,6 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
/* perform testing */ /* perform testing */
{ {
jthread testedThread = NULL; jthread testedThread = NULL;
int late_count;
NSK_DISPLAY1("Find thread: %s\n", THREAD_NAME); NSK_DISPLAY1("Find thread: %s\n", THREAD_NAME);
if (!NSK_VERIFY((testedThread = if (!NSK_VERIFY((testedThread =
@ -97,16 +95,15 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
} }
/* Original agentProc test block ends here. */ /* Original agentProc test block ends here. */
/* while (true) {
* Using printf() instead of NSK_DISPLAY1() in this loop
* in order to slow down the rate of SuspendThread() calls.
*/
for (late_count = 0; late_count < N_LATE_CALLS; late_count++) {
jvmtiError l_err; jvmtiError l_err;
printf("INFO: Late suspend thread: %p\n", (void*)testedThread); NSK_DISPLAY1("INFO: Late suspend thread: %p\n", (void*)testedThread);
l_err = jvmti->SuspendThread(testedThread); l_err = jvmti->SuspendThread(testedThread);
if (l_err != JVMTI_ERROR_NONE) { if (l_err != JVMTI_ERROR_NONE) {
printf("INFO: Late suspend thread err: %d\n", l_err); if (l_err != JVMTI_ERROR_THREAD_NOT_ALIVE) {
NSK_DISPLAY1("INFO: Late suspend thread err: %d\n", l_err);
nsk_jvmti_setFailStatus();
}
// testedThread has exited so we're done with late calls // testedThread has exited so we're done with late calls
break; break;
} }
@ -116,15 +113,10 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
NSK_DISPLAY1("INFO: Late resume thread: %p\n", (void*)testedThread); NSK_DISPLAY1("INFO: Late resume thread: %p\n", (void*)testedThread);
if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(testedThread))) { if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(testedThread))) {
nsk_jvmti_setFailStatus(); nsk_jvmti_setFailStatus();
break;
} }
} }
printf("INFO: made %d late calls to JVM/TI SuspendThread()\n",
late_count);
printf("INFO: N_LATE_CALLS == %d value is %slarge enough to cause a "
"SuspendThread() call after thread exit.\n", N_LATE_CALLS,
(late_count == N_LATE_CALLS) ? "NOT " : "");
/* Second part of original agentProc test block starts here: */ /* Second part of original agentProc test block starts here: */
NSK_DISPLAY0("Wait for thread to finish\n"); NSK_DISPLAY0("Wait for thread to finish\n");
// SP4.1-n - notify agent is waiting and wait // SP4.1-n - notify agent is waiting and wait

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,16 +28,40 @@ import java.io.*;
import nsk.share.*; import nsk.share.*;
public class issuspended002 { public class issuspended002 {
private static Wicket mainEntrance = new Wicket(); private final static int DEF_TIME_MAX = 30; // default max # secs to test
private final static String PROG_NAME = "issuspended002";
private static Wicket mainEntrance;
private static boolean testFailed = false; private static boolean testFailed = false;
private static Object waiter = new Object();
public static void main(String[] argv) { public static void main(String[] argv) {
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out)); System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
} }
public static int run(String[] argv, PrintStream out) { public static int run(String[] argv, PrintStream out) {
int timeMax = 0;
if (argv.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(argv[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + argv[0] + "': invalid timeMax value.");
usage();
}
}
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
MyThread thread = new MyThread(out); MyThread thread = new MyThread(out);
mainEntrance = new Wicket();
thread.start(); thread.start();
// Wait for MyThread to start // Wait for MyThread to start
@ -51,6 +75,7 @@ public class issuspended002 {
out.println("ThreadInfo.isSuspended() returned true, before " out.println("ThreadInfo.isSuspended() returned true, before "
+ "Thread.suspend() was invoked."); + "Thread.suspend() was invoked.");
testFailed = true; testFailed = true;
break;
} }
thread.suspend(); thread.suspend();
@ -61,6 +86,7 @@ public class issuspended002 {
out.println("ThreadInfo.isSuspended() returned false, after " out.println("ThreadInfo.isSuspended() returned false, after "
+ "Thread.suspend() was invoked."); + "Thread.suspend() was invoked.");
testFailed = true; testFailed = true;
break;
} }
thread.resume(); thread.resume();
@ -71,18 +97,20 @@ public class issuspended002 {
out.println("ThreadInfo.isSuspended() returned true, after " out.println("ThreadInfo.isSuspended() returned true, after "
+ "Thread.resume() was invoked."); + "Thread.resume() was invoked.");
testFailed = true; testFailed = true;
break;
} }
synchronized (waiter) {
thread.die = true; thread.die = true;
waiter.notifyAll();
}
int count = 0;
while (true) { while (true) {
info = mbean.getThreadInfo(id, Integer.MAX_VALUE); info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
if (info == null) { if (info == null) {
// the thread has exited // the thread has exited
break; break;
} }
count++;
isSuspended = info.isSuspended(); isSuspended = info.isSuspended();
if (isSuspended) { if (isSuspended) {
out.println("Failure 4."); out.println("Failure 4.");
@ -92,17 +120,27 @@ public class issuspended002 {
break; break;
} }
} }
}
out.println("INFO: made " + count + " late getThreadInfo() calls."); System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
if (testFailed) if (testFailed)
out.println("TEST FAILED"); out.println("TEST FAILED");
return (testFailed) ? Consts.TEST_FAILED : Consts.TEST_PASSED; return (testFailed) ? Consts.TEST_FAILED : Consts.TEST_PASSED;
} }
public static void usage() {
System.err.println("Usage: " + PROG_NAME + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
private static class MyThread extends Thread { private static class MyThread extends Thread {
final static long WAIT_TIME = 500; // Milliseconds final static long WAIT_TIME = 10; // Milliseconds
Object object = new Object();
volatile boolean die = false; volatile boolean die = false;
PrintStream out; PrintStream out;
@ -116,13 +154,14 @@ public class issuspended002 {
mainEntrance.unlock(); mainEntrance.unlock();
while (!die) { while (!die) {
synchronized(object) { synchronized(waiter) {
try { try {
object.wait(WAIT_TIME); waiter.wait(WAIT_TIME);
} catch (InterruptedException e) { } catch (InterruptedException e) {
out.println("Unexpected exception."); out.println("Unexpected exception.");
e.printStackTrace(out); e.printStackTrace(out);
testFailed = true; testFailed = true;
break;
} }
} // synchronized } // synchronized
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/* /*
* @test * @test
* *
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/monitoring/ThreadInfo/isSuspended/issuspended002. * @summary converted from VM Testbase nsk/monitoring/ThreadInfo/isSuspended/issuspended002.
* VM Testbase keywords: [quick, monitoring] * VM Testbase keywords: [quick, monitoring]
* VM Testbase readme: * VM Testbase readme:
@ -36,6 +37,6 @@
* *
* @library /vmTestbase * @library /vmTestbase
* /test/lib * /test/lib
* @run main/othervm -Xlog:thread+smr=debug nsk.monitoring.ThreadInfo.isSuspended.issuspended002 * @run main/othervm nsk.monitoring.ThreadInfo.isSuspended.issuspended002
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,8 +29,12 @@ import nsk.share.*;
import nsk.monitoring.share.*; import nsk.monitoring.share.*;
public class find006 { public class find006 {
private static Wicket mainEntrance = new Wicket(); private final static int DEF_TIME_MAX = 30; // default max # secs to test
private final static String PROG_NAME = "find006";
private static Wicket mainEntrance;
private static boolean testFailed = false; private static boolean testFailed = false;
private static Object waiter = new Object();
public static void main(String[] argv) { public static void main(String[] argv) {
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out)); System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
@ -38,6 +42,20 @@ public class find006 {
public static int run(String[] argv, PrintStream out) { public static int run(String[] argv, PrintStream out) {
ArgumentHandler argHandler = new ArgumentHandler(argv); ArgumentHandler argHandler = new ArgumentHandler(argv);
String[] args = argHandler.getArguments();
int timeMax = 0;
if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else {
try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
Log log = new Log(out, argHandler); Log log = new Log(out, argHandler);
ThreadMonitor monitor = Monitor.getThreadMonitor(log, argHandler); ThreadMonitor monitor = Monitor.getThreadMonitor(log, argHandler);
long id = Thread.currentThread().getId(); long id = Thread.currentThread().getId();
@ -60,20 +78,29 @@ public class find006 {
} }
} }
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
MyThread thread = new MyThread(out); MyThread thread = new MyThread(out);
mainEntrance = new Wicket();
thread.start(); thread.start();
// Wait for MyThread to start // Wait for MyThread to start
mainEntrance.waitFor(); mainEntrance.waitFor();
id = thread.getId(); id = thread.getId();
synchronized (waiter) {
thread.die = true; thread.die = true;
waiter.notifyAll();
}
int count = 0;
while (true) { while (true) {
ids = monitor.findMonitorDeadlockedThreads(); ids = monitor.findMonitorDeadlockedThreads();
count++;
ThreadInfo info = mbean.getThreadInfo(id, Integer.MAX_VALUE); ThreadInfo info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
if (info == null) { if (info == null) {
// the thread has exited // the thread has exited
@ -81,14 +108,30 @@ public class find006 {
} }
} }
out.println("INFO: made " + count + " late findMonitorDeadlockedThreads() calls."); try {
thread.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
return (testFailed) ? Consts.TEST_FAILED : Consts.TEST_PASSED; return (testFailed) ? Consts.TEST_FAILED : Consts.TEST_PASSED;
} }
public static void usage() {
System.err.println("Usage: " + PROG_NAME + " [time_max]");
System.err.println("where:");
System.err.println(" time_max max looping time in seconds");
System.err.println(" (default is " + DEF_TIME_MAX +
" seconds)");
System.exit(1);
}
private static class MyThread extends Thread { private static class MyThread extends Thread {
final static long WAIT_TIME = 500; // Milliseconds final static long WAIT_TIME = 10; // Milliseconds
Object object = new Object();
volatile boolean die = false; volatile boolean die = false;
PrintStream out; PrintStream out;
@ -102,9 +145,9 @@ public class find006 {
mainEntrance.unlock(); mainEntrance.unlock();
while (!die) { while (!die) {
synchronized(object) { synchronized(waiter) {
try { try {
object.wait(WAIT_TIME); waiter.wait(WAIT_TIME);
} catch (InterruptedException e) { } catch (InterruptedException e) {
out.println("Unexpected exception."); out.println("Unexpected exception.");
e.printStackTrace(out); e.printStackTrace(out);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/* /*
* @test * @test
* *
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/monitoring/ThreadMXBean/findMonitorDeadlockedThreads/find006. * @summary converted from VM Testbase nsk/monitoring/ThreadMXBean/findMonitorDeadlockedThreads/find006.
* VM Testbase keywords: [quick, monitoring] * VM Testbase keywords: [quick, monitoring]
* VM Testbase readme: * VM Testbase readme:
@ -37,7 +38,6 @@
* @library /vmTestbase * @library /vmTestbase
* /test/lib * /test/lib
* @run main/othervm * @run main/othervm
* -Xlog:thread+smr=debug
* nsk.monitoring.ThreadMXBean.findMonitorDeadlockedThreads.find006 * nsk.monitoring.ThreadMXBean.findMonitorDeadlockedThreads.find006
*/ */