8294483: Remove vmTestbase/nsk/jvmti/GetThreadState tests.

Reviewed-by: kvn, dholmes
This commit is contained in:
Leonid Mesnik 2022-09-27 22:47:01 +00:00
parent 6ad151d096
commit f8d9fa8873
21 changed files with 0 additions and 2417 deletions

View File

@ -1036,11 +1036,6 @@ vmTestbase_nsk_jvmti_quick = \
vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/TestDescription.java \
vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/TestDescription.java \
vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/TestDescription.java \
vmTestbase/nsk/jvmti/GetThreadState/thrstat001/TestDescription.java \
vmTestbase/nsk/jvmti/GetThreadState/thrstat002/TestDescription.java \
vmTestbase/nsk/jvmti/GetThreadState/thrstat003/TestDescription.java \
vmTestbase/nsk/jvmti/GetThreadState/thrstat004/TestDescription.java \
vmTestbase/nsk/jvmti/GetThreadState/thrstat005/TestDescription.java \
vmTestbase/nsk/jvmti/GetTime/gettime001/TestDescription.java \
vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/TestDescription.java \
vmTestbase/nsk/jvmti/GetTopThreadGroups/topthrgrp001/TestDescription.java \

View File

@ -1,118 +0,0 @@
/*
* Copyright (c) 2004, 2018, 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.
*/
package nsk.jvmti.GetThreadState;
import java.io.PrintStream;
public class thrstat001 {
public static final int STATUS_RUNNING = 0;
public static final int STATUS_MONITOR = 1;
public static final int STATUS_WAIT = 2;
native static void checkStatus(int statInd);
native static int getRes();
public static void main(String[] args) {
args = nsk.share.jvmti.JVMTITest.commonInit(args);
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[], PrintStream ref) {
thrstat001 t = new thrstat001();
t.meth();
return getRes();
}
// barriers for testing thread status values
public static Lock startingMonitor = new Lock();
public static Object blockingMonitor = new Object();
public static Lock endingMonitor = new Lock();
void meth() {
thrstat001a thr = new thrstat001a("thr1");
synchronized (blockingMonitor) {
synchronized (startingMonitor) {
startingMonitor.val = 0;
thr.start();
while (startingMonitor.val == 0) {
try {
startingMonitor.wait();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
}
Thread.yield();
checkStatus(STATUS_MONITOR);
}
synchronized (endingMonitor) {
checkStatus(STATUS_WAIT);
endingMonitor.val++;
endingMonitor.notify();
}
try {
thr.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
static class Lock {
public int val = 0;
}
}
class thrstat001a extends Thread {
public thrstat001a(String name) {
super(name);
}
public void run() {
synchronized (thrstat001.endingMonitor) {
thrstat001.checkStatus(thrstat001.STATUS_RUNNING);
synchronized (thrstat001.startingMonitor) {
thrstat001.startingMonitor.val++;
thrstat001.startingMonitor.notifyAll();
}
synchronized (thrstat001.blockingMonitor) {
}
thrstat001.endingMonitor.val = 0;
while (thrstat001.endingMonitor.val == 0) {
try {
thrstat001.endingMonitor.wait();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
}
}
}

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2018, 2020, 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
*
* @summary converted from VM Testbase nsk/jvmti/GetThreadState/thrstat001.
* VM Testbase keywords: [quick, jpda, jvmti, onload_only_logic, noras]
* VM Testbase readme:
* DESCRIPTION
* The test exercises JVMTI function GetThreadState. Java program
* launchs thread and 3 times calls a native method checkStatus. This
* method calls GetThreadState and checks if the returned value is
* correct.
* The test exercises JVMTI function GetThreadState. Java program
* launches a thread and 3 times calls a native method checkStatus.
* This method calls GetThreadState and checks if the returned value is:
* - JVMTI_THREAD_STATE_RUNNABLE
* if thread is runnable
* - JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
* if thread is waiting to enter sync. block
* - JVMTI_THREAD_STATE_IN_OBJECT_WAIT
* if thread is waiting by object.wait()
* The test also enables JVMPI_EVENT_METHOD_ENTRY and JVMPI_EVENT_METHOD_EXIT
* events and checks if GetThreadState returns JVMPI_THREAD_RUNNABLE for
* their threads.
* Failing criteria for the test are:
* - value returned by GetThreadState does not match expected value;
* - failures of used JVMTI functions.
* COMMENTS
* Converted the test to use GetThreadState instead of GetThreadStatus.
* The test was updated to be more precise in its thread state transitions.
* Fixed according to 4387521 bug.
* To fix bug 4463667,
* 1) two code fragments with "Thread.sleep(500);" are replaced
* with following ones:
* Object obj = new Object();
* *
* *
* synchronized (obj) {
* obj.wait(500);
* }
* 2) extra waiting time
* synchronized (obj) {
* obj.wait(500);
* }
* is added to get waiting time certainly after "contendCount"
* is set to 1.
* Fixed according to 4669812 bug.
* Ported from JVMDI.
* Fixed according to 4925857 bug:
* - rearranged synchronization of tested thread
* - enhanced descripton
*
* @library /vmTestbase
* /test/lib
* @run main/othervm/native -agentlib:thrstat001 nsk.jvmti.GetThreadState.thrstat001
*/

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2018, 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.
*/
#include "native_thread.cpp"
#include "nsk_tools.cpp"
#include "jni_tools.cpp"
#include "jvmti_tools.cpp"
#include "agent_tools.cpp"
#include "jvmti_FollowRefObjects.cpp"
#include "Injector.cpp"
#include "JVMTITools.cpp"
#include "agent_common.cpp"
#include "thrstat001.cpp"

View File

@ -1,256 +0,0 @@
/*
* Copyright (c) 2004, 2019, 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.
*/
#include <stdio.h>
#include <string.h>
#include "jvmti.h"
#include "agent_common.h"
#include "JVMTITools.h"
extern "C" {
#define PASSED 0
#define STATUS_FAILED 2
#define WAIT_START 100
#define WAIT_TIME (2*60*1000)
static jvmtiEnv *jvmti = NULL;
static jvmtiCapabilities caps;
static jvmtiEventCallbacks callbacks;
static jrawMonitorID access_lock;
static jrawMonitorID wait_lock;
static jint result = PASSED;
static jthread thr_ptr = NULL;
static jint state[] = {
JVMTI_THREAD_STATE_RUNNABLE,
JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
JVMTI_THREAD_STATE_IN_OBJECT_WAIT
};
static void
lock(const char* func_name, jrawMonitorID lock) {
jvmtiError err = jvmti->RawMonitorEnter(lock);
if (err != JVMTI_ERROR_NONE) {
printf("%s: unexpected error in RawMonitorEnter: %s (%d)\n",
func_name, TranslateError(err), err);
result = STATUS_FAILED;
}
}
static void
unlock(const char* func_name, jrawMonitorID lock) {
jvmtiError err = jvmti->RawMonitorExit(lock);
if (err != JVMTI_ERROR_NONE) {
printf("%s: unexpected error in RawMonitorExit: %s (%d)\n",
func_name, TranslateError(err), err);
result = STATUS_FAILED;
}
}
static void
wait(const char* func_name, jrawMonitorID lock, jint millis) {
jvmtiError err = jvmti->RawMonitorWait(lock, (jlong)millis);
if (err != JVMTI_ERROR_NONE) {
printf("%s: unexpected error in RawMonitorWait: %s (%d)\n",
func_name, TranslateError(err), err);
result = STATUS_FAILED;
}
}
static void
set_notification_mode(const char* event_name,
jvmtiEventMode mode,
jvmtiEvent event_type,
jthread event_thread) {
const char* action = (mode == JVMTI_ENABLE) ? "enable" : "disable";
jvmtiError err = jvmti->SetEventNotificationMode(mode, event_type, event_thread);
if (err != JVMTI_ERROR_NONE) {
printf("Failed to %s %s event: %s (%d)\n",
action, event_name, TranslateError(err), err);
result = STATUS_FAILED;
}
}
void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) {
set_notification_mode("JVMTI_EVENT_THREAD_START", JVMTI_ENABLE,
JVMTI_EVENT_THREAD_START, NULL);
}
void JNICALL
ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) {
jvmtiError err;
jvmtiThreadInfo thrInfo;
lock("ThreadStart", access_lock);
err = jvmti_env->GetThreadInfo(thread, &thrInfo);
if (err != JVMTI_ERROR_NONE) {
printf("(GetThreadInfo#TS) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
if (thrInfo.name != NULL && strcmp(thrInfo.name, "thr1") == 0) {
thr_ptr = env->NewGlobalRef(thread);
printf(">>> ThreadStart: \"%s\", 0x%p\n", thrInfo.name, thr_ptr);
set_notification_mode("JVMTI_EVENT_THREAD_START", JVMTI_DISABLE,
JVMTI_EVENT_THREAD_START, NULL);
}
unlock("ThreadStart", access_lock);
}
#ifdef STATIC_BUILD
JNIEXPORT jint JNICALL Agent_OnLoad_thrstat001(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNICALL Agent_OnAttach_thrstat001(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNI_OnLoad_thrstat001(JavaVM *jvm, char *options, void *reserved) {
return JNI_VERSION_1_8;
}
#endif
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
jint res;
jvmtiError err;
printf("Agent_Initialize started\n");
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
if (res != JNI_OK || jvmti == NULL) {
printf("Wrong result of a valid call to GetEnv!\n");
return JNI_ERR;
}
err = jvmti->GetPotentialCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->AddCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {
printf("(AddCapabilities) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->GetCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {
printf("(GetCapabilities) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->CreateRawMonitor("_access_lock", &access_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(CreateRawMonitor)#access_lock unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(CreateRawMonitor#wait_lock) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
callbacks.VMInit = &VMInit;
callbacks.ThreadStart = &ThreadStart;
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
if (err != JVMTI_ERROR_NONE) {
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
set_notification_mode("JVMTI_EVENT_VM_INIT", JVMTI_ENABLE,
JVMTI_EVENT_VM_INIT, NULL);
printf("Agent_Initialize finished\n\n");
return JNI_OK;
}
JNIEXPORT void JNICALL
Java_nsk_jvmti_GetThreadState_thrstat001_checkStatus(JNIEnv *env,
jclass cls, jint statInd) {
jvmtiError err;
jint thrState;
jint millis;
printf("native method checkStatus started\n");
if (jvmti == NULL) {
printf("JVMTI client was not properly loaded!\n");
result = STATUS_FAILED;
return;
}
if (thr_ptr == NULL) {
printf("Missing thread \"thr1\" start event\n");
result = STATUS_FAILED;
return;
}
/* wait until thread gets an expected state */
for (millis = WAIT_START; millis < WAIT_TIME; millis <<= 1) {
err = jvmti->GetThreadState(thr_ptr, &thrState);
if (err != JVMTI_ERROR_NONE) {
printf("(GetThreadState#%d) unexpected error: %s (%d)\n",
statInd, TranslateError(err), err);
result = STATUS_FAILED;
}
if ((thrState & state[statInd]) != 0) {
break;
}
lock("checkStatus", wait_lock);
wait("checkStatus", wait_lock, millis);
unlock("checkStatus", wait_lock);
}
printf(">>> thread \"thr1\" (0x%p) state: %s (%d)\n",
thr_ptr, TranslateState(thrState), thrState);
if ((thrState & state[statInd]) == 0) {
printf("Wrong thread \"thr1\" (0x%p) state:\n", thr_ptr);
printf(" expected: %s (%d)\n",
TranslateState(state[statInd]), state[statInd]);
printf(" actual: %s (%d)\n",
TranslateState(thrState), thrState);
result = STATUS_FAILED;
}
printf("native method checkStatus finished\n\n");
}
JNIEXPORT jint JNICALL
Java_nsk_jvmti_GetThreadState_thrstat001_getRes(JNIEnv *env, jclass cls) {
printf("native method getRes: result: %d\n\n", result);
return result;
}
}

View File

@ -1,194 +0,0 @@
/*
* 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
* 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.
*/
package nsk.jvmti.GetThreadState;
import nsk.share.Wicket;
import java.io.PrintStream;
public class thrstat002 {
public static final int STATUS_RUNNING = 0;
public static final int STATUS_MONITOR = 1;
public static final int STATUS_WAIT = 2;
native static void init(int waitTime);
native static void checkStatus(int statInd, boolean susp);
native static int getRes();
public static void main(String[] args) {
args = nsk.share.jvmti.JVMTITest.commonInit(args);
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String args[], PrintStream out) {
int waitTime = 2;
if (args.length > 0) {
try {
int i = Integer.parseInt(args[0]);
waitTime = i;
} catch (NumberFormatException ex) {
out.println("# Wrong argument \"" + args[0]
+ "\", the default value is used");
}
}
out.println("# Waiting time = " + waitTime + " mins");
init(waitTime);
new thrstat002().meth();
return getRes();
}
public static Wicket startingBarrier;
public static Wicket runningBarrier;
public static Object blockingMonitor = new Object();
public static Lock endingMonitor = new Lock();
static volatile boolean targetAboutToLock = false;
void meth() {
thrstat002a thr = new thrstat002a("thr1");
startingBarrier = new Wicket();
runningBarrier = new Wicket();
synchronized (blockingMonitor) {
thr.start();
System.out.println("thrstat002.meth after thr.start()");
startingBarrier.waitFor();
System.out.println("thrstat002.meth after thr.startingBarrier.waitFor()");
waitForThreadBlocked(thr);
checkStatus(STATUS_MONITOR, false);
System.out.println("thrstat002.meth after checkStatus(STATUS_MONITOR,false)");
thr.suspend();
System.out.println("thrstat002.meth after thr.suspend()");
checkStatus(STATUS_MONITOR, true);
System.out.println("thrstat002.meth after checkStatus(STATUS_MONITOR,true)");
thr.resume();
System.out.println("thrstat002.meth after thr.resume()");
checkStatus(STATUS_MONITOR, false);
System.out.println("thrstat002.meth after checkStatus(STATUS_MONITOR,false)");
}
runningBarrier.waitFor();
checkStatus(STATUS_RUNNING, false);
thr.suspend();
checkStatus(STATUS_RUNNING, true);
thr.resume();
checkStatus(STATUS_RUNNING, false);
thr.letItGo();
synchronized (endingMonitor) {
checkStatus(STATUS_WAIT, false);
thr.suspend();
checkStatus(STATUS_WAIT, true);
thr.resume();
checkStatus(STATUS_WAIT, false);
endingMonitor.val++;
endingMonitor.notifyAll();
}
try {
thr.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
private static void waitForThreadBlocked(Thread t) {
// Ensure that the thread is blocked on the right monitor
while (!targetAboutToLock || t.getState() != Thread.State.BLOCKED) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
System.out.println("thrstat002.waitForThreadBlocked was interrupted: " + ex.getMessage());
}
}
}
static class Lock {
public int val = 0;
}
}
class thrstat002a extends Thread {
private volatile boolean flag = true;
public thrstat002a(String name) {
super(name);
}
public void run() {
synchronized (thrstat002.endingMonitor) {
System.out.println("thrstat002a.run before startingBarrier.unlock");
thrstat002.startingBarrier.unlock();
System.out.println("thrstat002a.run after startingBarrier.unlock");
System.out.println("thrstat002a.run before blockingMonitor lock");
thrstat002.targetAboutToLock = true;
synchronized (thrstat002.blockingMonitor) {
System.out.println("thrstat002a.run blockingMonitor locked");
}
System.out.println("thrstat002a.run after blockingMonitor lock");
System.out.println("thrstat002a.run before runningBarrier unlock");
thrstat002.runningBarrier.unlock();
// Don't do println's from this point until we have exited the loop,
// else we can suspend in the println in an unexpected state.
int i = 0;
int n = 1000;
while (flag) {
if (n <= 0) {
n = 1000;
}
if (i > n) {
i = 0;
n--;
}
i++;
}
thrstat002.endingMonitor.val = 0;
while (thrstat002.endingMonitor.val == 0) {
try {
thrstat002.endingMonitor.wait();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
System.out.println("thrstat002a.run before endingMonitor unlock");
}
}
public void letItGo() {
flag = false;
}
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2018, 2020, 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
*
* @summary converted from VM Testbase nsk/jvmti/GetThreadState/thrstat002.
* VM Testbase keywords: [quick, jpda, jvmti, onload_only_logic, noras, quarantine]
* VM Testbase comments: 6260469
* VM Testbase readme:
* DESCRIPTION
* The test exercises JVMDI function GetThreadState. Java program launches
* a thread and for various thread states calls Thread.suspend()/resume()
* methods or JVMDI functions SuspendThread/ResumeThread. Then native method
* checkStatus is invoked. This method calls GetThreadState and checks if
* the returned values are correct and JVMTI_THREAD_STATE_SUSPENDED bit
* is set (or clear after resume).
* The thread statuses are:
* - JVMTI_THREAD_STATE_RUNNABLE
* if thread is runnable
* - JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
* if thread is waiting to enter sync. block
* - JVMTI_THREAD_STATE_IN_OBJECT_WAIT
* if thread is waiting by object.wait()
* Failing criteria for the test are:
* - values returned by GetThreadState are not the same as expected;
* - failure of used JVMTI functions.
* COMMENTS
* Converted the test to use GetThreadState instead of GetThreadStatus.
* Fixed according to 4387521 and 4427103 bugs.
* Fixed according to 4463667 bug.
* Fixed according to 4669812 bug.
* Ported from JVMDI.
* Fixed according to 4925857 bug:
* - rearranged synchronization of tested thread
* - enhanced descripton
*
* @library /vmTestbase
* /test/lib
* @run main/othervm/native -agentlib:thrstat002 nsk.jvmti.GetThreadState.thrstat002 5
*/

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2018, 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.
*/
#include "native_thread.cpp"
#include "nsk_tools.cpp"
#include "jni_tools.cpp"
#include "jvmti_tools.cpp"
#include "agent_tools.cpp"
#include "jvmti_FollowRefObjects.cpp"
#include "Injector.cpp"
#include "JVMTITools.cpp"
#include "agent_common.cpp"
#include "thrstat002.cpp"

View File

@ -1,470 +0,0 @@
/*
* 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
* 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.
*/
#include <stdio.h>
#include <string.h>
#include "jvmti.h"
#include "agent_common.h"
#include "JVMTITools.h"
extern "C" {
#define PASSED 0
#define STATUS_FAILED 2
#define WAIT_START 100
static jvmtiEnv *jvmti = NULL;
static jvmtiCapabilities caps;
static jvmtiEventCallbacks callbacks;
static jrawMonitorID access_lock, wait_lock;
static jint result = PASSED;
static jboolean printdump = JNI_FALSE;
static jthread thr_ptr = NULL;
static jint wait_time = 0;
static jint state[] = {
JVMTI_THREAD_STATE_RUNNABLE,
JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
JVMTI_THREAD_STATE_IN_OBJECT_WAIT
};
#if 1 // support for debug tracing
#define LOG(...) \
{ \
printf(__VA_ARGS__); \
fflush(stdout); \
}
#define MAX_FRAME_COUNT_PRINT_STACK_TRACE 200
static void
check_jvmti_status(JNIEnv* jni, jvmtiError err, const char* msg) {
if (err != JVMTI_ERROR_NONE) {
LOG("check_jvmti_status: JVMTI function returned error: %s (%d)\n", TranslateError(err), err);
jni->FatalError(msg);
}
}
static void
deallocate(jvmtiEnv *jvmti, JNIEnv* jni, void* ptr) {
jvmtiError err;
err = jvmti->Deallocate((unsigned char*)ptr);
check_jvmti_status(jni, err, "deallocate: error in JVMTI Deallocate call");
}
static char*
get_method_class_name(jvmtiEnv *jvmti, JNIEnv* jni, jmethodID method) {
jclass klass = NULL;
char* cname = NULL;
char* result = NULL;
jvmtiError err;
err = jvmti->GetMethodDeclaringClass(method, &klass);
check_jvmti_status(jni, err, "get_method_class_name: error in JVMTI GetMethodDeclaringClass");
err = jvmti->GetClassSignature(klass, &cname, NULL);
check_jvmti_status(jni, err, "get_method_class_name: error in JVMTI GetClassSignature");
size_t len = strlen(cname) - 2; // get rid of leading 'L' and trailing ';'
err = jvmti->Allocate((jlong)(len + 1), (unsigned char**)&result);
check_jvmti_status(jni, err, "get_method_class_name: error in JVMTI Allocate");
strncpy(result, cname + 1, len); // skip leading 'L'
result[len] = '\0';
deallocate(jvmti, jni, (void*)cname);
return result;
}
static void
print_method(jvmtiEnv *jvmti, JNIEnv* jni, jmethodID method, jint depth) {
char* cname = NULL;
char* mname = NULL;
char* msign = NULL;
jvmtiError err;
cname = get_method_class_name(jvmti, jni, method);
err = jvmti->GetMethodName(method, &mname, &msign, NULL);
check_jvmti_status(jni, err, "print_method: error in JVMTI GetMethodName");
LOG("%2d: %s: %s%s\n", depth, cname, mname, msign);
fflush(0);
deallocate(jvmti, jni, (void*)cname);
deallocate(jvmti, jni, (void*)mname);
deallocate(jvmti, jni, (void*)msign);
}
static char*
get_thread_name(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread) {
jvmtiThreadInfo thr_info;
jvmtiError err;
memset(&thr_info, 0, sizeof(thr_info));
err = jvmti->GetThreadInfo(thread, &thr_info);
check_jvmti_status(jni, err, "get_thread_name: error in JVMTI GetThreadInfo call");
return thr_info.name == NULL ? (char*)"<Unnamed thread>" : thr_info.name;
}
static void
print_stack_trace(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread) {
jvmtiFrameInfo frames[MAX_FRAME_COUNT_PRINT_STACK_TRACE];
char* tname = get_thread_name(jvmti, jni, thread);
jint count = 0;
jvmtiError err;
err = jvmti->GetStackTrace(thread, 0, MAX_FRAME_COUNT_PRINT_STACK_TRACE, frames, &count);
check_jvmti_status(jni, err, "print_stack_trace: error in JVMTI GetStackTrace");
LOG("JVMTI Stack Trace for thread %s: frame count: %d\n", tname, count);
for (int depth = 0; depth < count; depth++) {
print_method(jvmti, jni, frames[depth].method, depth);
}
deallocate(jvmti, jni, (void*)tname);
LOG("\n");
}
#endif // support for debug tracing
void printStateFlags(jint flags) {
if (flags & JVMTI_THREAD_STATE_SUSPENDED)
printf(" JVMTI_THREAD_STATE_SUSPENDED");
if (flags & JVMTI_THREAD_STATE_INTERRUPTED)
printf(" JVMTI_THREAD_STATE_INTERRUPTED");
if (flags & JVMTI_THREAD_STATE_IN_NATIVE)
printf(" JVMTI_THREAD_STATE_IN_NATIVE");
printf(" (0x%0x)\n", flags);
}
void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) {
jvmtiError err;
err = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE,
JVMTI_EVENT_THREAD_START, NULL);
if (err != JVMTI_ERROR_NONE) {
printf("Failed to enable THREAD_START event: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
}
void JNICALL
ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) {
jvmtiThreadInfo thrInfo;
jvmtiError err;
err = jvmti_env->RawMonitorEnter(access_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorEnter) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
err = jvmti_env->GetThreadInfo(thread, &thrInfo);
if (err != JVMTI_ERROR_NONE) {
printf("(GetThreadInfo) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
if (thrInfo.name != NULL && strcmp(thrInfo.name, "thr1") == 0) {
thr_ptr = env->NewGlobalRef(thread);
if (printdump == JNI_TRUE) {
printf(">>> ThreadStart: \"%s\", 0x%p\n", thrInfo.name, thr_ptr);
}
}
err = jvmti_env->RawMonitorExit(access_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorExit) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
}
#ifdef STATIC_BUILD
JNIEXPORT jint JNICALL Agent_OnLoad_thrstat002(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNICALL Agent_OnAttach_thrstat002(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNI_OnLoad_thrstat002(JavaVM *jvm, char *options, void *reserved) {
return JNI_VERSION_1_8;
}
#endif
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
jint res;
jvmtiError err;
if (options != NULL && strcmp(options, "printdump") == 0) {
printdump = JNI_TRUE;
}
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
if (res != JNI_OK || jvmti == NULL) {
printf("Wrong result of a valid call to GetEnv !\n");
return JNI_ERR;
}
err = jvmti->GetPotentialCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->AddCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {
printf("(AddCapabilities) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->GetCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {
printf("(GetCapabilities) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
if (!caps.can_suspend) {
printf("Warning: suspend/resume is not implemented\n");
}
err = jvmti->CreateRawMonitor("_access_lock", &access_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(CreateRawMonitor) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(CreateRawMonitor) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
callbacks.VMInit = &VMInit;
callbacks.ThreadStart = &ThreadStart;
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
if (err != JVMTI_ERROR_NONE) {
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
JVMTI_EVENT_VM_INIT, NULL);
if (err != JVMTI_ERROR_NONE) {
printf("Failed to enable VM_INIT event: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
return JNI_OK;
}
JNIEXPORT void JNICALL
Java_nsk_jvmti_GetThreadState_thrstat002_init(JNIEnv *env, jclass cls,
jint waitTime) {
wait_time = waitTime * 60000;
}
void wait_for(jint millis) {
jvmtiError err;
err = jvmti->RawMonitorEnter(wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorEnter#check) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
err = jvmti->RawMonitorWait(wait_lock, (jlong)millis);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorWait#check) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
err = jvmti->RawMonitorExit(wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorExit#check) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
}
JNIEXPORT void JNICALL
Java_nsk_jvmti_GetThreadState_thrstat002_checkStatus(JNIEnv *env, jclass cls,
jint statInd, jboolean suspended) {
jint thrState;
jint suspState = -1;
jint right_stat = (suspended ? JVMTI_THREAD_STATE_SUSPENDED : 0);
jvmtiError right_ans = (suspended ? JVMTI_ERROR_THREAD_SUSPENDED : JVMTI_ERROR_NONE);
const char *suspStr = (suspended ? ", suspended" : "");
jvmtiError err;
jint millis;
jboolean timeout_is_reached;
unsigned int waited_millis;
if (jvmti == NULL) {
printf("JVMTI client was not properly loaded!\n");
result = STATUS_FAILED;
return;
}
if (thr_ptr == NULL) {
printf("Missing thread \"thr1\" start event\n");
result = STATUS_FAILED;
return;
}
if (!caps.can_suspend) {
return;
}
printf("START checkStatus for \"thr1\" (0x%p%s), check state: %s\n",
thr_ptr, suspStr, TranslateState(state[statInd]));
timeout_is_reached = JNI_TRUE;
for (millis = WAIT_START, waited_millis=0; millis < wait_time; millis <<= 1) {
err = jvmti->GetThreadState(thr_ptr, &thrState);
if (err != JVMTI_ERROR_NONE) {
printf("(GetThreadState#%d) unexpected error: %s (%d)\n",
statInd, TranslateError(err), err);
result = STATUS_FAILED;
timeout_is_reached = JNI_FALSE;
break;
}
suspState = thrState & JVMTI_THREAD_STATE_SUSPENDED;
if (suspended || (thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0 ||
(state[statInd] == JVMTI_THREAD_STATE_RUNNABLE)) {
timeout_is_reached = JNI_FALSE;
break;
}
waited_millis += millis;
wait_for(millis);
}
if (printdump == JNI_TRUE) {
printf(">>> thread \"thr1\" (0x%p) state: %s (%d)\n",
thr_ptr, TranslateState(thrState), thrState);
printf(">>>\tflags:");
printStateFlags(suspState);
}
if (timeout_is_reached == JNI_TRUE) {
printf("Error: timeout (%d secs) has been reached\n", waited_millis/1000);
}
if ((thrState & state[statInd]) == 0) {
printf("Wrong thread \"thr1\" (0x%p%s) state:\n", thr_ptr, suspStr);
printf(" expected: %s (%d)\n",
TranslateState(state[statInd]), state[statInd]);
printf(" actual: %s (%d)\n",
TranslateState(thrState), thrState);
result = STATUS_FAILED;
}
if (suspState != right_stat) {
printf("Wrong thread \"thr1\" (0x%p%s) state flags:\n",
thr_ptr, suspStr);
printf(" expected:");
printStateFlags(right_stat);
printf(" actual:");
printStateFlags(suspState);
result = STATUS_FAILED;
}
err = jvmti->SuspendThread(thr_ptr);
if (err != right_ans) {
printf("Wrong result of SuspendThread() for \"thr1\" (0x%p%s):\n",
thr_ptr, suspStr);
printf(" expected: %s (%d), actual: %s (%d)\n",
TranslateError(right_ans), right_ans, TranslateError(err), err);
result = STATUS_FAILED;
}
if (!suspended) {
// wait till thread is not suspended
timeout_is_reached = JNI_TRUE;
for (millis = WAIT_START, waited_millis=0; millis < wait_time; millis <<= 1) {
waited_millis += millis;
wait_for(millis);
err = jvmti->GetThreadState(thr_ptr, &thrState);
if (err != JVMTI_ERROR_NONE) {
printf("(GetThreadState#%d,after) unexpected error: %s (%d)\n",
statInd, TranslateError(err), err);
timeout_is_reached = JNI_FALSE;
result = STATUS_FAILED;
break;
}
suspState = thrState & JVMTI_THREAD_STATE_SUSPENDED;
if (suspState) {
timeout_is_reached = JNI_FALSE;
break;
}
}
if (timeout_is_reached == JNI_TRUE) {
printf("Error: timeout (%d secs) has been reached\n", waited_millis/1000);
}
if ((thrState & state[statInd]) == 0) {
printf("Wrong thread \"thr1\" (0x%p) state after SuspendThread:\n",
thr_ptr);
printf(" expected: %s (%d)\n",
TranslateState(state[statInd]), state[statInd]);
printf(" actual: %s (%d)\n",
TranslateState(thrState), thrState);
#ifdef DBG
print_stack_trace(jvmti, env, thr_ptr);
#endif
result = STATUS_FAILED;
}
if (suspState != JVMTI_THREAD_STATE_SUSPENDED) {
printf("Wrong thread \"thr1\" (0x%p) state flags", thr_ptr);
printf(" after SuspendThread:\n");
printf(" expected:");
printStateFlags(JVMTI_THREAD_STATE_SUSPENDED);
printf(" actual:");
printStateFlags(suspState);
result = STATUS_FAILED;
}
err = jvmti->ResumeThread(thr_ptr);
if (err != JVMTI_ERROR_NONE) {
printf("(ResumeThread#%d) unexpected error: %s (%d)\n",
statInd, TranslateError(err), err);
result = STATUS_FAILED;
}
}
fflush(0);
}
JNIEXPORT jint JNICALL
Java_nsk_jvmti_GetThreadState_thrstat002_getRes(JNIEnv *env, jclass cls) {
return result;
}
}

View File

@ -1,102 +0,0 @@
/*
* Copyright (c) 2004, 2018, 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.
*/
package nsk.jvmti.GetThreadState;
import java.io.PrintStream;
public class thrstat003 {
final static int JCK_STATUS_BASE = 95;
static final int NOT_STARTED = 0;
static final int SLEEPING = 1;
static final int ZOMBIE = 2;
native static void init(int waitTime);
native static int check(Thread thread, int status);
public static void main(String args[]) {
args = nsk.share.jvmti.JVMTITest.commonInit(args);
// produce JCK-like exit status.
System.exit(run(args, System.out) + JCK_STATUS_BASE);
}
static int contendCount = 0;
public static Object lock = new Object();
public static int waitTime = 2;
public static int run(String args[], PrintStream out) {
if (args.length > 0) {
try {
int i = Integer.parseInt(args[0]);
waitTime = i;
} catch (NumberFormatException ex) {
out.println("# Wrong argument \"" + args[0]
+ "\", the default value is used");
}
}
out.println("# Waiting time = " + waitTime + " mins");
init(waitTime);
TestThread t = new TestThread();
check(t, NOT_STARTED);
synchronized (lock) {
t.start();
try {
lock.wait();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
}
check(t, SLEEPING);
t.interrupt();
try {
t.join();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}
return check(t, ZOMBIE);
}
static class TestThread extends Thread {
public void run() {
synchronized (lock) {
lock.notify();
}
try {
sleep(waitTime*60000);
} catch (InterruptedException e) {
// OK, it's expected
}
}
}
}

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2018, 2020, 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
*
* @summary converted from VM Testbase nsk/jvmti/GetThreadState/thrstat003.
* VM Testbase keywords: [quick, jpda, jvmti, noras]
* VM Testbase readme:
* DESCRIPTION
* The test exercises JVMTI function GetThreadState.
* The test checks if the function returns:
* - NEW if thread has not run yet
* - STATE_SLEEPING if Thread.sleep() has been called
* - STATE_TERMINATED if thread has exited
* COMMENTS
* Converted the test to use GetThreadState instead of GetThreadStatus.
* Ported from JVMDI.
*
* @library /vmTestbase
* /test/lib
* @run main/othervm/native -agentlib:thrstat003 nsk.jvmti.GetThreadState.thrstat003 5
*/

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2018, 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.
*/
#include "native_thread.cpp"
#include "nsk_tools.cpp"
#include "jni_tools.cpp"
#include "jvmti_tools.cpp"
#include "agent_tools.cpp"
#include "jvmti_FollowRefObjects.cpp"
#include "Injector.cpp"
#include "JVMTITools.cpp"
#include "agent_common.cpp"
#include "thrstat003.cpp"

View File

@ -1,159 +0,0 @@
/*
* Copyright (c) 2004, 2018, 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.
*/
#include <stdio.h>
#include <string.h>
#include "jvmti.h"
#include "agent_common.h"
#include "JVMTITools.h"
extern "C" {
#define PASSED 0
#define STATUS_FAILED 2
#define WAIT_START 100
static jvmtiEnv *jvmti = NULL;
static jint result = PASSED;
static jboolean printdump = JNI_FALSE;
static jint wait_time = 0;
static jint state[] = {
0, /* JVMTI_THREAD_STATUS_NOT_STARTED, */
JVMTI_THREAD_STATE_SLEEPING,
JVMTI_THREAD_STATE_TERMINATED /* JVMTI_THREAD_STATUS_ZOMBIE */
};
JNIEXPORT void JNICALL
Java_nsk_jvmti_GetThreadState_thrstat003_init(JNIEnv *env, jclass cls,
jint waitTime) {
wait_time = waitTime * 60000;
}
#ifdef STATIC_BUILD
JNIEXPORT jint JNICALL Agent_OnLoad_thrstat003(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNICALL Agent_OnAttach_thrstat003(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNI_OnLoad_thrstat003(JavaVM *jvm, char *options, void *reserved) {
return JNI_VERSION_1_8;
}
#endif
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
jint res;
if (options != NULL && strcmp(options, "printdump") == 0) {
printdump = JNI_TRUE;
}
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
if (res != JNI_OK || jvmti == NULL) {
printf("Wrong result of a valid call to GetEnv!\n");
return JNI_ERR;
}
return JNI_OK;
}
JNIEXPORT jint JNICALL
Java_nsk_jvmti_GetThreadState_thrstat003_check(JNIEnv *env, jclass cls,
jthread thr, jint statInd) {
jvmtiError err;
jrawMonitorID wait_lock;
jint thrState;
jint i;
if (jvmti == NULL) {
printf("JVMTI client was not properly loaded!\n");
return STATUS_FAILED;
}
err = jvmti->CreateRawMonitor("_wait_lock", &wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(CreateRawMonitor#%d) unexpected error: %s (%d)\n",
statInd, TranslateError(err), err);
result = STATUS_FAILED;
}
for (i = WAIT_START; i < wait_time; i <<= 1) {
err = jvmti->GetThreadState(thr, &thrState);
if (err != JVMTI_ERROR_NONE) {
printf("(GetThreadState#%d) unexpected error: %s (%d)\n",
statInd, TranslateError(err), err);
result = STATUS_FAILED;
}
if (printdump == JNI_TRUE) {
printf(">>> thread state: %s (%d)\n",
TranslateState(thrState), thrState);
}
if ((thrState & JVMTI_THREAD_STATE_RUNNABLE) == 0) {
break;
}
err = jvmti->RawMonitorEnter(wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorEnter) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
err = jvmti->RawMonitorWait(wait_lock, (jlong)i);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorWait) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
err = jvmti->RawMonitorExit(wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorExit) unexpected error: %s (%d)\n",
TranslateError(err), err);
result = STATUS_FAILED;
}
}
err = jvmti->DestroyRawMonitor(wait_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(DestroyRawMonitor#%d) unexpected error: %s (%d)\n",
statInd, TranslateError(err), err);
result = STATUS_FAILED;
}
/* We expect that thread is NOT_STARTED if statInd == 0 */
if (statInd == 0 && thrState != state[statInd]) {
result = STATUS_FAILED;
} else if (statInd != 0 && (thrState & state[statInd]) == 0) {
result = STATUS_FAILED;
}
if (result == STATUS_FAILED) {
printf("Wrong state: %s (%d)\n", TranslateState(thrState), thrState);
printf(" expected: %s (%d)\n",
TranslateState(state[statInd]), state[statInd]);
}
return result;
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (c) 2004, 2018, 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.
*/
package nsk.jvmti.GetThreadState;
import java.io.PrintStream;
public class thrstat004 {
final static int JCK_STATUS_BASE = 95;
native static int check(Thread thr);
public static void main(String args[]) {
args = nsk.share.jvmti.JVMTITest.commonInit(args);
// produce JCK-like exit status.
System.exit(run(args, System.out) + JCK_STATUS_BASE);
}
public static int run(String args[], PrintStream out) {
return check(Thread.currentThread());
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (c) 2018, 2020, 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
*
* @summary converted from VM Testbase nsk/jvmti/GetThreadState/thrstat004.
* VM Testbase keywords: [quick, jpda, jvmti, noras]
* VM Testbase readme:
* DESCRIPTION
* The test exercises JVMTI function
* GetThreadState(thread, threadStatusPtr)
* The test checks if the function returns:
* - JVMTI_ERROR_NULL_POINTER if threadStatusPtr is null
* - JVMTI_ERROR_NULL_POINTER if suspendStatusPtr is null
* - JVMTI_ERROR_INVALID_THREAD if thread is not a thread object
* COMMENTS
* Converted the test to use GetThreadState instead of GetThreadStatus.
* Ported from JVMDI.
*
* @library /vmTestbase
* /test/lib
* @run main/othervm/native -agentlib:thrstat004 nsk.jvmti.GetThreadState.thrstat004
*/

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2018, 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.
*/
#include "native_thread.cpp"
#include "nsk_tools.cpp"
#include "jni_tools.cpp"
#include "jvmti_tools.cpp"
#include "agent_tools.cpp"
#include "jvmti_FollowRefObjects.cpp"
#include "Injector.cpp"
#include "JVMTITools.cpp"
#include "agent_common.cpp"
#include "thrstat004.cpp"

View File

@ -1,100 +0,0 @@
/*
* Copyright (c) 2004, 2018, 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.
*/
#include <stdio.h>
#include <string.h>
#include "jvmti.h"
#include "agent_common.h"
#include "JVMTITools.h"
extern "C" {
#define PASSED 0
#define STATUS_FAILED 2
static jvmtiEnv *jvmti = NULL;
static jint result = PASSED;
static jboolean printdump = JNI_FALSE;
#ifdef STATIC_BUILD
JNIEXPORT jint JNICALL Agent_OnLoad_thrstat004(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNICALL Agent_OnAttach_thrstat004(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNI_OnLoad_thrstat004(JavaVM *jvm, char *options, void *reserved) {
return JNI_VERSION_1_8;
}
#endif
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
jint res;
if (options != NULL && strcmp(options, "printdump") == 0) {
printdump = JNI_TRUE;
}
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
if (res != JNI_OK || jvmti == NULL) {
printf("Wrong result of a valid call to GetEnv!\n");
return JNI_ERR;
}
return JNI_OK;
}
JNIEXPORT jint JNICALL
Java_nsk_jvmti_GetThreadState_thrstat004_check(JNIEnv *env, jclass cls, jthread thr) {
jvmtiError err;
jint thrState;
if (jvmti == NULL) {
printf("JVMTI client was not properly loaded!\n");
return STATUS_FAILED;
}
if (printdump == JNI_TRUE) {
printf(">>> (threadStatePtr) null pointer check ...\n");
}
err = jvmti->GetThreadState(thr, NULL);
if (err != JVMTI_ERROR_NULL_POINTER) {
printf("(threadStatePtr) error expected: JVMTI_ERROR_NULL_POINTER,\n");
printf(" got: %s (%d)\n", TranslateError(err), err);
result = STATUS_FAILED;
}
if (printdump == JNI_TRUE) {
printf(">>> invalid thread check ...\n");
}
err = jvmti->GetThreadState(cls, &thrState);
if (err != JVMTI_ERROR_INVALID_THREAD) {
printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n");
printf(" got: %s (%d)\n", TranslateError(err), err);
result = STATUS_FAILED;
}
return result;
}
}

View File

@ -1,338 +0,0 @@
/*
* Copyright (c) 2007, 2018, 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.
*/
package nsk.jvmti.GetThreadState;
import java.io.PrintStream;
import java.util.concurrent.*;
import java.util.concurrent.locks.*;
public class thrstat005 {
final static int JCK_STATUS_BASE = 95;
public static final int TS_NEW = 0;
public static final int TS_TERMINATED = 1;
public static final int TS_RUN_RUNNING = 2;
public static final int TS_RUN_BLOCKED = 3;
public static final int TS_RUN_WAIT_TIMED = 4;
public static final int TS_RUN_WAIT_INDEF = 5;
public static final int TS_RUN_WAIT_PARKED_TIMED = 6;
public static final int TS_RUN_WAIT_PARKED_INDEF = 7;
public static final int TS_RUN_WAIT_SLEEP = 8; /* assumes _TIMED */
public static final int WAIT_TIME = 250;
public PrintStream _out;
public Thread _thrMain;
public TestThread _thrDummy;
public int _passCnt, _failCnt;
/**
* Set waiting time for checkThreadState
*/
native static void setWaitTime(int sec);
/**
* Check that thread state (TS_xxx) is what we expect
* (for TS_xxx -> JVMTI_THREAD_STATE_xxx mapping see table in thrstat005.c)
*/
native static boolean checkThreadState(Thread t, int stateIdx);
public static void main(String args[]) {
args = nsk.share.jvmti.JVMTITest.commonInit(args);
System.exit(run(args, System.out) + JCK_STATUS_BASE);
}
public static int run(String args[], PrintStream out) {
return new thrstat005(out).run();
}
thrstat005(PrintStream out) {
_out = out;
_thrMain = Thread.currentThread();
setWaitTime(WAIT_TIME * 23 / 11);
}
public int run() {
_failCnt = 0;
_passCnt = 0;
testAndPrint("New", TS_NEW);
testAndPrint("Running", TS_RUN_RUNNING);
testAndPrint("Blocked on monitor", TS_RUN_BLOCKED);
testAndPrint("Waiting with timeout", TS_RUN_WAIT_TIMED);
testAndPrint("Waiting forever", TS_RUN_WAIT_INDEF);
testAndPrint("Parking forever", TS_RUN_WAIT_PARKED_TIMED);
testAndPrint("Parking with timeout", TS_RUN_WAIT_PARKED_INDEF);
testAndPrint("Sleeping", TS_RUN_WAIT_SLEEP);
testAndPrint("Terminating", TS_TERMINATED);
log(">>> PASS/FAIL: " + _passCnt + "/" + _failCnt);
return _failCnt > 0 ? 2 : 0;
}
public void testAndPrint(String name, int state) {
boolean fPassed;
try {
log(">>> Testing state: " + name);
fPassed = test(state);
} catch ( BrokenBarrierException e ) {
log("Main: broken barrier exception");
fPassed = false;
} catch ( InterruptedException e ) {
log("Main: interrupted exception");
fPassed = false;
}
log(">>> " + (fPassed ? "PASSED" : "FAILED") + " testing state: " + name);
if ( fPassed )
_passCnt++;
else
_failCnt++;
}
public boolean test(int state) throws BrokenBarrierException, InterruptedException {
boolean fRes;
switch ( state ) {
case TS_NEW:
log("Main: Creating new thread");
_thrDummy = new TestThread();
fRes = checkThreadState(_thrDummy, state);
_thrDummy.start();
return fRes;
case TS_RUN_RUNNING:
log("Main: Running thread");
_thrDummy._fRun = true;
fRes = sendStateAndCheckIt(state);
_thrDummy._fRun = false;
return fRes;
case TS_RUN_BLOCKED:
log("Main: Blocking thread");
synchronized ( _thrDummy._mon ) {
return sendStateAndCheckIt(state);
}
case TS_RUN_WAIT_TIMED:
case TS_RUN_WAIT_INDEF:
log("Main: Thread will wait");
_thrDummy._fRun = true;
fRes = sendStateAndCheckIt(state);
_thrDummy._fRun = false;
do {
log("Main: Notifying the thread");
synchronized ( _thrDummy._mon ) {
_thrDummy._mon.notify();
}
if ( ! _thrDummy._fInTest ) {
break;
}
Thread.sleep(WAIT_TIME / 4);
} while ( true );
return fRes;
case TS_RUN_WAIT_PARKED_TIMED:
case TS_RUN_WAIT_PARKED_INDEF:
log("Main: Thread will park");
_thrDummy._fRun = true;
fRes = sendStateAndCheckIt(state);
_thrDummy._fRun = false;
do {
log("Main: Unparking the thread");
LockSupport.unpark(_thrDummy);
if ( ! _thrDummy._fInTest ) {
break;
}
Thread.sleep(WAIT_TIME);
} while ( true );
return fRes;
case TS_RUN_WAIT_SLEEP:
log("Main: Thread will sleep");
_thrDummy._fRun = true;
fRes = sendStateAndCheckIt(state);
_thrDummy._fRun = false;
return fRes;
case TS_TERMINATED:
log("Main: Terminating thread");
_thrDummy.sendTestState(state);
log("Main: Waiting for join");
_thrDummy.join();
return checkThreadState(_thrDummy, state);
}
return false;
}
public boolean sendStateAndCheckIt(int state) throws BrokenBarrierException, InterruptedException {
_thrDummy.sendTestState(state);
while ( ! _thrDummy._fInTest ) {
log("Main: Waiting for the thread to start the test");
Thread.sleep(WAIT_TIME * 29 / 7); // Wait time should not be a multiple of WAIT_TIME
}
return checkThreadState(_thrDummy, state);
}
synchronized void log(String s) {
_out.println(s);
_out.flush();
}
class TestThread extends Thread {
SynchronousQueue<Integer> _taskQueue = new SynchronousQueue<Integer>();
public volatile boolean _fRun = true;
public volatile boolean _fInTest = false;
public Object _mon = new Object();
public void sendTestState(int state) throws BrokenBarrierException, InterruptedException {
_taskQueue.put(state);
}
public int recvTestState() {
int state = TS_NEW;
try {
state = _taskQueue.take();
} catch ( InterruptedException e ) {
log("Thread: interrupted exception " + e);
}
return state;
}
public void run() {
log("Thread: started");
while ( true ) {
int state = recvTestState();
switch ( state ) {
case TS_NEW:
log("Thread: ERROR IN TEST: TS_NEW");
break;
case TS_RUN_RUNNING:
int i = 0;
log("Thread: Running...");
_fInTest = true;
while ( _fRun ) i++;
log("Thread: Running: done");
_fInTest = false;
break;
case TS_RUN_BLOCKED:
log("Thread: Blocking...");
_fInTest = true;
synchronized ( _mon ) {}
log("Thread: Blocking: done");
_fInTest = false;
break;
case TS_RUN_WAIT_TIMED:
log("Thread: Waiting with timeout...");
while ( _fRun ) {
synchronized ( _mon ) {
_fInTest = true;
try {
_mon.wait(WAIT_TIME);
} catch ( InterruptedException e ) {
log("Thread: Interrupted exception");
}
}
}
log("Thread: Waiting: done");
_fInTest = false;
break;
case TS_RUN_WAIT_INDEF:
log("Thread: Waiting indefinitely...");
_fInTest = true;
synchronized ( _mon ) {
try {
_mon.wait();
} catch ( InterruptedException e ) {
log("Thread: Interrupted exception");
}
log("Thread: Waiting: done");
_fInTest = false;
}
break;
case TS_RUN_WAIT_SLEEP:
log("Thread: Sleeping...");
while ( _fRun ) {
try {
_fInTest = true;
Thread.sleep(WAIT_TIME);
} catch ( InterruptedException e ) {
log("Thread: Interrupted exception");
}
}
log("Thread: Sleeping: done");
_fInTest = false;
break;
case TS_RUN_WAIT_PARKED_TIMED:
log("Thread: Parking indefinitely...");
_fInTest = true;
while ( _fRun ) {
LockSupport.park();
}
log("Thread: Parking: done");
_fInTest = false;
break;
case TS_RUN_WAIT_PARKED_INDEF:
log("Thread: Parking with timeout...");
_fInTest = true;
while ( _fRun ) {
LockSupport.parkUntil(System.currentTimeMillis() + WAIT_TIME);
}
log("Thread: Parking: done");
_fInTest = false;
break;
case TS_TERMINATED:
log("Thread: terminating");
return;
}
}
}
}
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2018, 2020, 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
*
* @summary converted from VM Testbase nsk/jvmti/GetThreadState/thrstat005.
* VM Testbase keywords: [quick, jpda, jvmti, noras]
* VM Testbase readme:
* DESCRIPTION
* The test verifies that the new hierarchical flags returned by GetThreadState()
* are properly set in various thread states as requested in bug #5041847.
* Flags being tested are:
* JVMTI_THREAD_STATE_ALIVE
* JVMTI_THREAD_STATE_TERMINATED
* JVMTI_THREAD_STATE_RUNNABLE
* JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
* JVMTI_THREAD_STATE_WAITING
* JVMTI_THREAD_STATE_WAITING_INDEFINITELY
* JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT
* JVMTI_THREAD_STATE_SLEEPING
* JVMTI_THREAD_STATE_IN_OBJECT_WAIT
* JVMTI_THREAD_STATE_PARKED
* The state is checked in the following test cases:
* - A new thread is created
* - Thread is running (doing some computations)
* - Thread is blocked on a monitor (synchronized (...) { ... })
* - Thread is waiting in wait(timeout)
* - Thread is waiting in wait() w/o a timeout
* - Thread is parked using LockSupport.park()
* - Thread is parked using LockSupport.parkUntil()
* - Thread is in Thread.sleep()
* - Thread has terminated
* For more information see bugs #5041847, #4980307 and J2SE 5.0+ JVMTI spec.
* COMMENTS
*
* @library /vmTestbase
* /test/lib
* @run main/othervm/native -agentlib:thrstat005 nsk.jvmti.GetThreadState.thrstat005
*/

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2018, 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.
*/
#include "native_thread.cpp"
#include "nsk_tools.cpp"
#include "jni_tools.cpp"
#include "jvmti_tools.cpp"
#include "agent_tools.cpp"
#include "jvmti_FollowRefObjects.cpp"
#include "Injector.cpp"
#include "JVMTITools.cpp"
#include "agent_common.cpp"
#include "thrstat005.cpp"

View File

@ -1,170 +0,0 @@
/*
* Copyright (c) 2007, 2018, 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.
*/
/*
*/
#include <stdio.h>
#include <string.h>
#include "jvmti.h"
#include "agent_common.h"
#ifndef STANDALONE
#include "JVMTITools.h"
#endif
extern "C" {
#define THREAD_STATE_MASK ~(JVMTI_THREAD_STATE_SUSPENDED \
| JVMTI_THREAD_STATE_INTERRUPTED \
| JVMTI_THREAD_STATE_IN_NATIVE \
| JVMTI_THREAD_STATE_VENDOR_1 \
| JVMTI_THREAD_STATE_VENDOR_2 \
| JVMTI_THREAD_STATE_VENDOR_3)
static int g_ThreadState[] = {
0, /* TS_NEW */
JVMTI_THREAD_STATE_TERMINATED, /* TS_TERMINATED */
JVMTI_THREAD_STATE_ALIVE
| JVMTI_THREAD_STATE_RUNNABLE, /* TS_RUN_RUNNING */
JVMTI_THREAD_STATE_ALIVE
| JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, /* TS_RUN_BLOCKED */
JVMTI_THREAD_STATE_ALIVE
| JVMTI_THREAD_STATE_IN_OBJECT_WAIT
| JVMTI_THREAD_STATE_WAITING
| JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_TIMED */
JVMTI_THREAD_STATE_ALIVE
| JVMTI_THREAD_STATE_IN_OBJECT_WAIT
| JVMTI_THREAD_STATE_WAITING
| JVMTI_THREAD_STATE_WAITING_INDEFINITELY, /* TS_RUN_WAIT_INDEF */
JVMTI_THREAD_STATE_ALIVE
| JVMTI_THREAD_STATE_PARKED
| JVMTI_THREAD_STATE_WAITING
| JVMTI_THREAD_STATE_WAITING_INDEFINITELY, /* TS_RUN_WAIT_PARKED_INDEF */
JVMTI_THREAD_STATE_ALIVE
| JVMTI_THREAD_STATE_PARKED
| JVMTI_THREAD_STATE_WAITING
| JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_PARKED_TIMED */
JVMTI_THREAD_STATE_ALIVE
| JVMTI_THREAD_STATE_SLEEPING
| JVMTI_THREAD_STATE_WAITING
| JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, /* TS_RUN_WAIT_SLEEPING */
};
static jvmtiEnv * g_ppJvmtiEnv = NULL;
static int g_waitTime = 1000;
jrawMonitorID g_waitMon; /* Monitor is used just for sleeping */
void reportError(const char * szErr, jvmtiError res) {
#ifndef STANDALONE
printf("%s (%d: %s)\n", szErr, res, TranslateError(res));
#else
printf("%s (%d)\n", szErr, res);
#endif
fflush(stdout);
}
#ifdef STATIC_BUILD
JNIEXPORT jint JNICALL Agent_OnLoad_thrstat005(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNICALL Agent_OnAttach_thrstat005(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNI_OnLoad_thrstat005(JavaVM *jvm, char *options, void *reserved) {
return JNI_VERSION_1_8;
}
#endif
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
jvmtiError error;
jint res;
res = jvm->GetEnv((void **) &g_ppJvmtiEnv, JVMTI_VERSION_1_1);
if (res != JNI_OK || !g_ppJvmtiEnv) {
printf("Agent_OnLoad: Error: GetEnv returned error or NULL\n");
return JNI_ERR;
}
error = g_ppJvmtiEnv->CreateRawMonitor("beast", &g_waitMon);
if (error != JVMTI_ERROR_NONE) {
reportError("Agent_OnLoad: error creating raw monitor", error);
return JNI_ERR;
}
return JNI_OK;
}
JNIEXPORT void JNICALL
Java_nsk_jvmti_GetThreadState_thrstat005_setWaitTime(JNIEnv * pEnv, jclass klass, jint waitTime) {
g_waitTime = waitTime;
}
JNIEXPORT jboolean JNICALL
Java_nsk_jvmti_GetThreadState_thrstat005_checkThreadState(JNIEnv * pEnv, jclass klass, jthread thread, jint stateIdx) {
jint thrState;
jint maskedThrState;
int waitTime = 10;
/* Repeat querying status until waitTime < g_waitTime */
do {
jvmtiError res = g_ppJvmtiEnv->GetThreadState(thread, &thrState);
if (res != JVMTI_ERROR_NONE) {
reportError("GetThreadState: unexpected error", res);
return JNI_FALSE;
}
maskedThrState = thrState & THREAD_STATE_MASK;
printf("GetThreadState = %x. Masked: %x. Must be: %x\n", thrState, maskedThrState, g_ThreadState[stateIdx]);
fflush(stdout);
if (maskedThrState == g_ThreadState[stateIdx])
return JNI_TRUE;
printf("checkThreadState: wait %d ms\n", waitTime);
fflush(stdout);
res = g_ppJvmtiEnv->RawMonitorEnter(g_waitMon);
if (res != JVMTI_ERROR_NONE) {
reportError("GetThreadState: unexpected error from RawMontiorEnter", res);
return JNI_FALSE;
}
res = g_ppJvmtiEnv->RawMonitorWait(g_waitMon, waitTime);
if (res != JVMTI_ERROR_NONE) {
reportError("GetThreadState: unexpected error from RawMontiorWait", res);
return JNI_FALSE;
}
res = g_ppJvmtiEnv->RawMonitorExit(g_waitMon);
if (res != JVMTI_ERROR_NONE) {
reportError("GetThreadState: unexpected error from RawMonitorExit", res);
return JNI_FALSE;
}
waitTime <<= 1;
} while (waitTime < g_waitTime);
return JNI_FALSE;
}
}