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/JI06/ji06t001/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

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.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,16 @@
/**
* @test
* @bug 8167108
* @bug 8167108 8266130
* @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;
public class InterruptAtExit extends Thread {
final static int N_THREADS = 32;
final static int N_LATE_CALLS = 1000;
private final static int DEF_TIME_MAX = 30; // default max # secs to test
private final static String PROG_NAME = "InterruptAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -42,32 +42,46 @@ public class InterruptAtExit extends Thread {
// Tell main thread we have started.
startSyncObj.countDown();
try {
// Wait for main thread to interrupt us so we
// can race to exit.
// Wait for main thread to tell us to race to the exit.
exitSyncObj.await();
} 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) {
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++ ) {
threads[i] = new InterruptAtExit();
int late_count = 1;
threads[i].start();
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
InterruptAtExit thread = new InterruptAtExit();
thread.start();
try {
// 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
// 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()) {
if (!thread.isAlive()) {
// Done with Thread.interrupt() calls since
// thread is not alive.
break;
@ -77,30 +91,30 @@ public class InterruptAtExit extends Thread {
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 {
threads[i].join();
thread.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
threads[i].interrupt();
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
thread.interrupt();
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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);
}
}
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,16 @@
/**
* @test
* @bug 8167108
* @bug 8167108 8266130
* @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;
public class IsInterruptedAtExit extends Thread {
final static int N_THREADS = 32;
final static int N_LATE_CALLS = 2000;
private final static int DEF_TIME_MAX = 30; // default max # secs to test
private final static String PROG_NAME = "IsInterruptedAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -42,33 +42,46 @@ public class IsInterruptedAtExit extends Thread {
// Tell main thread we have started.
startSyncObj.countDown();
try {
// Wait for main thread to interrupt us so we
// can race to exit.
// Wait for main thread to tell us to race to the exit.
exitSyncObj.await();
} catch (InterruptedException e) {
// ignore because we expect one
throw new RuntimeException("Unexpected: " + e);
}
}
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++ ) {
threads[i] = new IsInterruptedAtExit();
int late_count = 1;
threads[i].start();
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
IsInterruptedAtExit thread = new IsInterruptedAtExit();
thread.start();
try {
// 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
// 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()) {
if (!thread.isAlive()) {
// Done with Thread.isInterrupted() calls since
// thread is not alive.
break;
@ -78,30 +91,30 @@ public class IsInterruptedAtExit extends Thread {
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 {
threads[i].join();
thread.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
threads[i].isInterrupted();
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
thread.isInterrupted();
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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);
}
}
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,16 @@
/**
* @test
* @bug 8167108
* @bug 8167108 8266130
* @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;
public class SetNameAtExit extends Thread {
final static int N_THREADS = 32;
final static int N_LATE_CALLS = 1000;
private final static int DEF_TIME_MAX = 30; // default max # secs to test
private final static String PROG_NAME = "SetNameAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -42,33 +42,46 @@ public class SetNameAtExit extends Thread {
// Tell main thread we have started.
startSyncObj.countDown();
try {
// Wait for main thread to interrupt us so we
// can race to exit.
// Wait for main thread to tell us to race to the exit.
exitSyncObj.await();
} catch (InterruptedException e) {
// ignore because we expect one
throw new RuntimeException("Unexpected: " + e);
}
}
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++ ) {
threads[i] = new SetNameAtExit();
int late_count = 1;
threads[i].start();
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
SetNameAtExit thread = new SetNameAtExit();
thread.start();
try {
// 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
// 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()) {
if (!thread.isAlive()) {
// Done with Thread.setName() calls since
// thread is not alive.
break;
@ -78,30 +91,30 @@ public class SetNameAtExit extends Thread {
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 {
threads[i].join();
thread.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
threads[i].setName("T" + i + "-done");
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
thread.setName("T" + count + "-done");
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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);
}
}
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,19 +23,19 @@
/**
* @test
* @bug 8167108
* @bug 8167108 8266130
* @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;
public class SetPriorityAtExit extends Thread {
final static int N_THREADS = 32;
final static int N_LATE_CALLS = 2000;
private final static int DEF_TIME_MAX = 30; // default max # secs to test
private final static String PROG_NAME = "SetPriorityAtExit";
final static int MIN = java.lang.Thread.MIN_PRIORITY;
final static int NORM = java.lang.Thread.NORM_PRIORITY;
private final static int MIN = java.lang.Thread.MIN_PRIORITY;
private final static int NORM = java.lang.Thread.NORM_PRIORITY;
public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -45,39 +45,51 @@ public class SetPriorityAtExit extends Thread {
// Tell main thread we have started.
startSyncObj.countDown();
try {
// Wait for main thread to interrupt us so we
// can race to exit.
// Wait for main thread to tell us to race to the exit.
exitSyncObj.await();
} catch (InterruptedException e) {
// ignore because we expect one
throw new RuntimeException("Unexpected: " + e);
}
}
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;
for (int i = 0; i < N_THREADS; i++ ) {
threads[i] = new SetPriorityAtExit();
int late_count = 1;
threads[i].start();
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
SetPriorityAtExit thread = new SetPriorityAtExit();
thread.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 setPriority()
// calls will come in during thread exit.
threads[i].interrupt();
for (; late_count <= N_LATE_CALLS; late_count++) {
threads[i].setPriority(prio);
thread.startSyncObj.await();
// Tell the worker thread to race to the exit and the
// Thread.setPriority() calls will come in during
// thread exit.
thread.exitSyncObj.countDown();
while (true) {
thread.setPriority(prio);
if (prio == MIN) {
prio = NORM;
} else {
prio = MIN;
}
if (!threads[i].isAlive()) {
if (!thread.isAlive()) {
// Done with Thread.setPriority() calls since
// thread is not alive.
break;
@ -86,31 +98,32 @@ public class SetPriorityAtExit extends Thread {
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
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.");
thread.setPriority(prio);
try {
threads[i].join();
thread.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
threads[i].setPriority(prio);
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
thread.setPriority(prio);
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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);
}
}
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,17 +23,17 @@
/**
* @test
* @bug 8167108
* @bug 8167108 8266130
* @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.TimeUnit;
public class StopAtExit extends Thread {
final static int N_THREADS = 32;
final static int N_LATE_CALLS = 1000;
private final static int DEF_TIME_MAX = 30; // default max # secs to test
private final static String PROG_NAME = "StopAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1);
public CountDownLatch startSyncObj = new CountDownLatch(1);
@ -44,11 +44,10 @@ public class StopAtExit extends Thread {
// Tell main thread we have started.
startSyncObj.countDown();
try {
// Wait for main thread to interrupt us so we
// can race to exit.
// Wait for main thread to tell us to race to the exit.
exitSyncObj.await();
} catch (InterruptedException e) {
// ignore because we expect one
throw new RuntimeException("Unexpected: " + e);
}
} catch (ThreadDeath td) {
// 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) {
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++ ) {
threads[i] = new StopAtExit();
int late_count = 1;
threads[i].start();
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
StopAtExit thread = new StopAtExit();
thread.start();
try {
// 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
// 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()) {
if (!thread.isAlive()) {
// Done with Thread.stop() calls since
// thread is not alive.
break;
@ -90,30 +102,30 @@ public class StopAtExit extends 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 {
threads[i].join();
thread.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
threads[i].stop();
if (threads[i].isAlive()) {
throw new Error("Expected !Thread.isAlive() after thread #" +
i + " has been join()'ed");
}
thread.stop();
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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);
}
}
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.
*
* 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;
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 WAIT_TIME = 100;
final static int N_LATE_CHECKS = 1000;
final static int N_THREADS = 10;
static {
try {
System.loadLibrary("objmonusage006");
System.loadLibrary(AGENT_LIB);
} 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.getProperty("java.library.path"));
throw ule;
@ -59,9 +58,25 @@ public class objmonusage006 {
}
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;
for (int i = 0; i < N_THREADS; i++) {
System.out.println("Starting LockingThread #" + i + ".");
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
// Original objmonusage005 test block starts here:
//
@ -86,23 +101,43 @@ public class objmonusage006 {
// lockCheck needs to be locked for JVM/TI
// GetObjectMonitorUsage() to cover the right
// code paths.
System.out.println("LockingThread #" + i + " starting "
+ N_LATE_CHECKS + " late checks.");
for (int j = 0; j < N_LATE_CHECKS; j++) {
while (true) {
check(lockCheck);
res = getRes();
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;
}
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 {
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/*
* @test
*
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/GetObjectMonitorUsage/objmonusage006.
* VM Testbase keywords: [jpda, jvmti, noras]
* VM Testbase readme:
@ -36,10 +37,10 @@
* COMMENTS
* Derived from nsk/jvmti/GetObjectMonitorUsage/objmonusage005.
*
* @requires vm.jvmti
* @library /vmTestbase
* /test/lib
* @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib: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.
*
* 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;
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 N_LATE_CALLS = 1000;
static {
try {
System.loadLibrary("intrpthrd003");
System.loadLibrary(AGENT_LIB);
} 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.getProperty("java.library.path"));
throw ule;
}
}
native static int check(int ind, Thread thr);
native static int check(long ind, Thread thr);
native static int getResult();
native static boolean isThreadNotAliveError();
@ -51,20 +53,34 @@ public class intrpthrd003 {
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[], PrintStream ref) {
intrpthrd003a runn[] = new intrpthrd003a[THREADS_NUMBER];
public static int run(String args[], PrintStream ref) {
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("Case 1: JVM/TI InterruptThread()");
for (int i = 0; i < THREADS_NUMBER; i++ ) {
runn[i] = new intrpthrd003a();
int late_count = 1;
synchronized (runn[i].syncObject) {
runn[i].start();
System.out.println("About to execute for " + timeMax + " seconds.");
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 {
runn[i].syncObject.wait();
thr.syncObject.wait();
for (; late_count <= N_LATE_CALLS; late_count++) {
if (check(i, runn[i]) == 2) break;
while (true) {
if (check(count, thr) == 2) break;
if (isThreadNotAliveError()) {
// 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 {
runn[i].join();
thr.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
if (check(i, runn[i]) == 2) break;
if (!isThreadNotAliveError()) {
throw new Error("Expected JVMTI_ERROR_THREAD_NOT_ALIVE " +
"after thread #" + i + " has been join()'ed");
}
if (check(count, thr) == 2) break;
}
int res = getResult();
if (res != 0) {
return res;
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
System.out.println("Case 2: java.lang.Thread.interrupt()");
for (int i = 0; i < THREADS_NUMBER; i++ ) {
runn[i] = new intrpthrd003a();
int late_count = 1;
synchronized (runn[i].syncObject) {
runn[i].start();
try {
runn[i].syncObject.wait();
return getResult();
}
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;
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);
}
}

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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/*
* @test
*
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/InterruptThread/intrpthrd003.
* VM Testbase keywords: [quick, jpda, jvmti, noras]
* VM Testbase readme:
@ -41,10 +42,10 @@
* COMMENTS
* Derived from nsk/jvmti/InterruptThread/intrpthrd002.
*
* @requires vm.jvmti
* @library /vmTestbase
* /test/lib
* @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib: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.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
#include "jvmti.h"
#include "jni_tools.h"
#include "agent_common.h"
#include "JVMTITools.h"
@ -90,7 +91,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
JNIEXPORT jint JNICALL
Java_nsk_jvmti_InterruptThread_intrpthrd003_check (JNIEnv *env, jobject oobj,
jint ind, jthread thr) {
jlong ind, jthread thr) {
intrpthrd_err = jvmti->InterruptThread(thr);
if (intrpthrd_err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY &&
@ -103,7 +104,7 @@ Java_nsk_jvmti_InterruptThread_intrpthrd003_check (JNIEnv *env, jobject oobj,
break;
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);
result = STATUS_FAILED;
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.
*
* 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.
*/
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 FAILED = 2;
static final int JCK_STATUS_BASE = 95;
static final int N_LATE_CALLS = 100;
static boolean DEBUG_MODE = false;
static volatile boolean popFdone = false;
static volatile int totRes = PASSED;
@ -58,9 +59,9 @@ public class popframe011 {
static {
try {
System.loadLibrary("popframe011");
System.loadLibrary(AGENT_LIB);
} 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.getProperty("java.library.path"));
throw e;
@ -81,117 +82,162 @@ public class popframe011 {
}
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:
//
int retValue = 0;
this.out = out;
for (int i = 0; i < argv.length; i++) {
if (argv[i].equals("-v")) // verbose mode
DEBUG_MODE = true;
}
popFrameClsThr = new popFrameCls();
synchronized (barrier) { // force a child thread to pause
synchronized(readi) {
popFrameClsThr.start(); // start the child thread
long count = 0;
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
popFdone = false;
popFrameClsThr = new popFrameCls();
synchronized (barrier) { // force a child thread to pause
synchronized(readi) {
popFrameClsThr.start(); // start the child thread
// wait until the thread will enter into a necessary method
try {
readi.wait(); // wait for the child readiness
} catch (Exception e) {
out.println("TEST FAILURE: waiting for " +
popFrameClsThr.toString() + ": caught " + e);
return FAILED;
try {
readi.wait(); // wait for the child readiness
} catch (Exception e) {
out.println("TEST FAILURE: waiting for " +
popFrameClsThr.toString() + ": caught " + e);
return FAILED;
}
}
}
/* check that if PopFrame() would be invoked with NULL pointer to
the thread, it will return the error JVMTI_ERROR_NULL_POINTER */
if (DEBUG_MODE)
totRes = retValue = doPopFrame(1, popFrameClsThr);
else
totRes = retValue = doPopFrame(0, popFrameClsThr);
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #1 PASSED:\n" +
"\tPopFrame(), being invoked with NULL pointer " +
"to the thread,\n" +
"\treturned the appropriate error JVMTI_ERROR_NULL_POINTER");
if (DEBUG_MODE)
totRes = retValue = doPopFrame(1, popFrameClsThr);
else
totRes = retValue = doPopFrame(0, popFrameClsThr);
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #1 PASSED:\n" +
"\tPopFrame(), being invoked with NULL pointer " +
"to the thread,\n" +
"\treturned the appropriate error JVMTI_ERROR_NULL_POINTER");
/* check that if the thread, whose top frame is to be popped,
is invalid, the PopFrame() will return the error
JVMTI_ERROR_INVALID_THREAD */
if (DEBUG_MODE)
retValue = doPopFrame(3, popFrameClsThr);
else
retValue = doPopFrame(2, popFrameClsThr);
if (retValue == FAILED) {
popFdone = true;
totRes = FAILED;
} else
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #3 PASSED:\n" +
"\tPopFrame(), being invoked with " +
"the invalid thread,\n" +
"\treturned the appropriate error " +
"JVMTI_ERROR_INVALID_THREAD");
if (DEBUG_MODE)
retValue = doPopFrame(3, popFrameClsThr);
else
retValue = doPopFrame(2, popFrameClsThr);
if (retValue == FAILED) {
popFdone = true;
totRes = FAILED;
} else
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #3 PASSED:\n" +
"\tPopFrame(), being invoked with " +
"the invalid thread,\n" +
"\treturned the appropriate error " +
"JVMTI_ERROR_INVALID_THREAD");
/* check that if the thread, whose top frame is to be popped,
has not been suspended, the PopFrame() will return the error
JVMTI_ERROR_THREAD_NOT_SUSPENDED */
if (DEBUG_MODE)
retValue = doPopFrame(5, popFrameClsThr);
else
retValue = doPopFrame(4, popFrameClsThr);
if (retValue == FAILED) {
popFdone = true;
totRes = FAILED;
} else
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #5 PASSED:\n" +
"\tPopFrame(), being invoked with " +
"the non suspended thread,\n" +
"\treturned the appropriate error " +
"JVMTI_ERROR_THREAD_NOT_SUSPENDED");
}
//
// Original popframe002 test block ends here.
if (DEBUG_MODE)
retValue = doPopFrame(5, popFrameClsThr);
else
retValue = doPopFrame(4, popFrameClsThr);
if (retValue == FAILED) {
popFdone = true;
totRes = FAILED;
} else
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #5 PASSED:\n" +
"\tPopFrame(), being invoked with " +
"the non suspended thread,\n" +
"\treturned the appropriate error " +
"JVMTI_ERROR_THREAD_NOT_SUSPENDED");
}
//
// Original popframe002 test block ends here.
int late_count = 1;
for (; late_count <= N_LATE_CALLS; late_count++) {
while (true) {
/* check that if the thread, whose top frame is to be popped,
has not been suspended and is exiting, the PopFrame() will
return the error JVMTI_ERROR_THREAD_NOT_SUSPENDED or
JVMTI_ERROR_THREAD_NOT_ALIVE */
if (DEBUG_MODE)
retValue = doPopFrame(7, popFrameClsThr);
else
retValue = doPopFrame(6, popFrameClsThr);
if (retValue == FAILED) {
popFdone = true;
totRes = FAILED;
} else
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #7 PASSED:\n" +
"\tPopFrame(), being invoked with " +
"the non suspended and is exiting thread,\n" +
"\treturned the appropriate error " +
"JVMTI_ERROR_THREAD_NOT_SUSPENDED");
if (isThreadNotAliveError()) {
// Done with PopFrame() calls since thread is not alive.
if (DEBUG_MODE)
retValue = doPopFrame(7, popFrameClsThr);
else
retValue = doPopFrame(6, popFrameClsThr);
if (retValue == FAILED) {
popFdone = true;
totRes = FAILED;
} else
if (DEBUG_MODE && retValue == PASSED)
out.println("Check #7 PASSED:\n" +
"\tPopFrame(), being invoked with " +
"the non suspended and is exiting thread,\n" +
"\treturned the appropriate error " +
"JVMTI_ERROR_THREAD_NOT_SUSPENDED");
if (isThreadNotAliveError()) {
// Done with PopFrame() calls since thread is not alive.
break;
}
}
try {
popFrameClsThr.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
if (totRes != PASSED) {
break;
}
}
out.println("INFO: made " + late_count +
" late calls to JVM/TI PopFrame()");
out.println("INFO: N_LATE_CALLS==" + N_LATE_CALLS + " value is " +
((late_count >= N_LATE_CALLS) ? "NOT " : "") +
"large enough to cause a PopFrame() call after thread " +
"exit.");
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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 {
public void run() {
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/*
* @test
*
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/PopFrame/popframe011.
* VM Testbase keywords: [jpda, jvmti, noras]
* VM Testbase readme:
@ -36,10 +37,10 @@
* COMMENTS
* Derived from nsk/jvmti/PopFrame/popframe002.
*
* @requires vm.jvmti
* @library /vmTestbase
* /test/lib
* @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib: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.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,12 +29,14 @@ import nsk.share.*;
import nsk.share.jvmti.*;
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
static {
System.loadLibrary("suspendthrd003");
System.loadLibrary(AGENT_LIB);
}
// run test from command line
@ -67,8 +69,26 @@ public class suspendthrd003 extends DebugeeClass {
log = new Log(out, argHandler);
timeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
for (int i = 0; i < N_THREADS; i++) {
System.out.println("Starting TestedThread #" + i + ".");
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();
}
}
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:
//
@ -76,15 +96,14 @@ public class suspendthrd003 extends DebugeeClass {
// Note: Cannot use TestedThread-N for thread name since
// the agent has to know the thread's name.
thread = new suspendthrd003Thread("TestedThread");
mainEntrance = new Wicket();
// run tested thread
log.display("Starting tested thread");
try {
thread.start();
// SP1-w - wait for TestedThread-N to be ready
if (!thread.checkReady()) {
throw new Failure("Unable to prepare tested thread: " + thread);
}
mainEntrance.waitFor();
// testing sync
log.display("Sync: thread started");
@ -122,15 +141,26 @@ public class suspendthrd003 extends DebugeeClass {
resetAgentData(); // reset for another iteration
}
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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
class suspendthrd003Thread extends Thread {
private volatile boolean threadReady = false;
private volatile boolean shouldFinish = false;
// make thread with specific name
@ -142,7 +172,7 @@ class suspendthrd003Thread extends Thread {
public void run() {
// run in a loop
// SP1-n - tell main we are ready
threadReady = true;
suspendthrd003.mainEntrance.unlock();
int i = 0;
int n = 1000;
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
public void letFinish() {
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/*
* @test
*
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/jvmti/SuspendThread/suspendthrd003.
* VM Testbase keywords: [jpda, jvmti, noras]
* VM Testbase readme:
@ -170,10 +171,10 @@
* exit(data.monitor)
* } // end resetAgentData()
*
* @requires vm.jvmti
* @library /vmTestbase
* /test/lib
* @run main/othervm/native
* -Xlog:thread+smr=debug
* -agentlib:suspendthrd003=-waittime=5
* 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,6 @@ static jlong timeout = 0;
/* constant names */
#define THREAD_NAME "TestedThread"
#define N_LATE_CALLS 10000
/* ============================================================================= */
@ -54,7 +53,6 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
/* perform testing */
{
jthread testedThread = NULL;
int late_count;
NSK_DISPLAY1("Find thread: %s\n", THREAD_NAME);
if (!NSK_VERIFY((testedThread =
@ -97,16 +95,15 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
}
/* Original agentProc test block ends here. */
/*
* 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++) {
while (true) {
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);
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
break;
}
@ -116,15 +113,10 @@ agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
NSK_DISPLAY1("INFO: Late resume thread: %p\n", (void*)testedThread);
if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(testedThread))) {
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: */
NSK_DISPLAY0("Wait for thread to finish\n");
// 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,81 +28,119 @@ import java.io.*;
import nsk.share.*;
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 Object waiter = new Object();
public static void main(String[] argv) {
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
}
public static int run(String[] argv, PrintStream out) {
ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
MyThread thread = new MyThread(out);
thread.start();
// Wait for MyThread to start
mainEntrance.waitFor();
long id = thread.getId();
ThreadInfo info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
boolean isSuspended = info.isSuspended();
if (isSuspended) {
out.println("Failure 1.");
out.println("ThreadInfo.isSuspended() returned true, before "
+ "Thread.suspend() was invoked.");
testFailed = true;
}
thread.suspend();
info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
isSuspended = info.isSuspended();
if (!isSuspended) {
out.println("Failure 2.");
out.println("ThreadInfo.isSuspended() returned false, after "
+ "Thread.suspend() was invoked.");
testFailed = true;
}
thread.resume();
info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
isSuspended = info.isSuspended();
if (isSuspended) {
out.println("Failure 3.");
out.println("ThreadInfo.isSuspended() returned true, after "
+ "Thread.resume() was invoked.");
testFailed = true;
}
thread.die = true;
int count = 0;
while (true) {
info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
if (info == null) {
// the thread has exited
break;
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();
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
isSuspended = info.isSuspended();
MyThread thread = new MyThread(out);
mainEntrance = new Wicket();
thread.start();
// Wait for MyThread to start
mainEntrance.waitFor();
long id = thread.getId();
ThreadInfo info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
boolean isSuspended = info.isSuspended();
if (isSuspended) {
out.println("Failure 4.");
out.println("ThreadInfo.isSuspended() returned true, after "
+ "thread.die was set to true.");
out.println("Failure 1.");
out.println("ThreadInfo.isSuspended() returned true, before "
+ "Thread.suspend() was invoked.");
testFailed = true;
break;
}
thread.suspend();
info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
isSuspended = info.isSuspended();
if (!isSuspended) {
out.println("Failure 2.");
out.println("ThreadInfo.isSuspended() returned false, after "
+ "Thread.suspend() was invoked.");
testFailed = true;
break;
}
thread.resume();
info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
isSuspended = info.isSuspended();
if (isSuspended) {
out.println("Failure 3.");
out.println("ThreadInfo.isSuspended() returned true, after "
+ "Thread.resume() was invoked.");
testFailed = true;
break;
}
synchronized (waiter) {
thread.die = true;
waiter.notifyAll();
}
while (true) {
info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
if (info == null) {
// the thread has exited
break;
}
isSuspended = info.isSuspended();
if (isSuspended) {
out.println("Failure 4.");
out.println("ThreadInfo.isSuspended() returned true, after "
+ "thread.die was set to true.");
testFailed = true;
break;
}
}
}
out.println("INFO: made " + count + " late getThreadInfo() calls.");
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
if (testFailed)
out.println("TEST FAILED");
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 {
final static long WAIT_TIME = 500; // Milliseconds
Object object = new Object();
final static long WAIT_TIME = 10; // Milliseconds
volatile boolean die = false;
PrintStream out;
@ -116,13 +154,14 @@ public class issuspended002 {
mainEntrance.unlock();
while (!die) {
synchronized(object) {
synchronized(waiter) {
try {
object.wait(WAIT_TIME);
waiter.wait(WAIT_TIME);
} catch (InterruptedException e) {
out.println("Unexpected exception.");
e.printStackTrace(out);
testFailed = true;
break;
}
} // 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/*
* @test
*
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/monitoring/ThreadInfo/isSuspended/issuspended002.
* VM Testbase keywords: [quick, monitoring]
* VM Testbase readme:
@ -36,6 +37,6 @@
*
* @library /vmTestbase
* /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.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,8 +29,12 @@ import nsk.share.*;
import nsk.monitoring.share.*;
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 Object waiter = new Object();
public static void main(String[] argv) {
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) {
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);
ThreadMonitor monitor = Monitor.getThreadMonitor(log, argHandler);
long id = Thread.currentThread().getId();
@ -60,35 +78,60 @@ public class find006 {
}
}
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0;
ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
MyThread thread = new MyThread(out);
thread.start();
// Wait for MyThread to start
mainEntrance.waitFor();
id = thread.getId();
thread.die = true;
int count = 0;
while (true) {
ids = monitor.findMonitorDeadlockedThreads();
long start_time = System.currentTimeMillis();
while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
ThreadInfo info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
if (info == null) {
// the thread has exited
break;
MyThread thread = new MyThread(out);
mainEntrance = new Wicket();
thread.start();
// Wait for MyThread to start
mainEntrance.waitFor();
id = thread.getId();
synchronized (waiter) {
thread.die = true;
waiter.notifyAll();
}
while (true) {
ids = monitor.findMonitorDeadlockedThreads();
ThreadInfo info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
if (info == null) {
// the thread has exited
break;
}
}
try {
thread.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
out.println("INFO: made " + count + " late findMonitorDeadlockedThreads() calls.");
System.out.println("Executed " + count + " loops in " + timeMax +
" seconds.");
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 {
final static long WAIT_TIME = 500; // Milliseconds
Object object = new Object();
final static long WAIT_TIME = 10; // Milliseconds
volatile boolean die = false;
PrintStream out;
@ -102,9 +145,9 @@ public class find006 {
mainEntrance.unlock();
while (!die) {
synchronized(object) {
synchronized(waiter) {
try {
object.wait(WAIT_TIME);
waiter.wait(WAIT_TIME);
} catch (InterruptedException e) {
out.println("Unexpected exception.");
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
/*
* @test
*
* @bug 8167108 8266130
* @summary converted from VM Testbase nsk/monitoring/ThreadMXBean/findMonitorDeadlockedThreads/find006.
* VM Testbase keywords: [quick, monitoring]
* VM Testbase readme:
@ -37,7 +38,6 @@
* @library /vmTestbase
* /test/lib
* @run main/othervm
* -Xlog:thread+smr=debug
* nsk.monitoring.ThreadMXBean.findMonitorDeadlockedThreads.find006
*/