mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-14 18:03:44 +00:00
8294486: Remove vmTestbase/nsk/jvmti/ tests ported to serviceability/jvmti.
Reviewed-by: sspitsyn
This commit is contained in:
parent
fec61746d1
commit
3bd3caf897
@ -866,7 +866,6 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/Agent_OnLoad/agentonload003/TestDriver.java \
|
||||
vmTestbase/nsk/jvmti/Agent_OnUnload/agentonunload001/TestDriver.java \
|
||||
vmTestbase/nsk/jvmti/Breakpoint/breakpoint001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk003/TestDescription.java \
|
||||
@ -876,8 +875,6 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk007/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk008/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk009/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClassLoad/classload001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClassPrepare/classprep001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/TestDescription.java \
|
||||
@ -895,18 +892,8 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/DestroyRawMonitor/drrawmon004/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/Exception/exception001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ExceptionCatch/excatch001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FieldAccess/fieldacc001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FieldAccess/fieldacc002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FieldAccess/fieldacc003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FieldAccess/fieldacc004/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FieldModification/fieldmod001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FieldModification/fieldmod002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ForceGarbageCollection/forcegc002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FramePop/framepop001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/FramePop/framepop002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GenerateEvents/genevents001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetAllThreads/allthr001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetAllThreads/allthr002/TestDescription.java \
|
||||
@ -939,9 +926,6 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/GetClassStatus/getclstat005/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetCurrentThreadCpuTimerInfo/curthrtimerinfo001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetEnvironmentLocalStorage/getenvstor001/TestDescription.java \
|
||||
@ -957,11 +941,6 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/GetFieldName/getfldnm003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetFieldName/getfldnm004/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetFieldName/getfldnm005/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetFrameCount/framecnt001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetFrameCount/framecnt002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetFrameCount/framecnt003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetFrameLocation/frameloc002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetFrameLocation/frameloc003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf005/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf006/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetImplementedInterfaces/getintrf007/TestDescription.java \
|
||||
@ -1017,15 +996,6 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/GetSystemProperties/getsysprops002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetSystemProperty/getsysprop002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr004/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr005/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr006/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr007/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr008/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetStackTrace/getstacktr009/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetTag/gettag001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime002/TestDescription.java \
|
||||
@ -1033,8 +1003,6 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/GetThreadGroupChildren/getthrdgrpchld001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetThreadGroupInfo/thrgrpinfo002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetThreadInfo/thrinfo002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetThreadLocalStorage/getthrdstor001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetTime/gettime001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/GetTimerInfo/timerinfo001/TestDescription.java \
|
||||
@ -1087,17 +1055,6 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/IterateThroughHeap/filter-class-tagged/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/IterateThroughHeap/filter-class-untagged/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/IterateThroughHeap/abort/Abort.java \
|
||||
vmTestbase/nsk/jvmti/MethodEntry/mentry001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/MethodEntry/mentry002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/MethodExit/mexit002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/MonitorContendedEnter/mcontenter001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/MonitorContendedEntered/mcontentered001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/MonitorWait/monitorwait001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/MonitorWaited/monitorwaited001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/NativeMethodBind/nativemethbind004/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/NotifyFramePop/nframepop001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/TestDescription.java \
|
||||
@ -1212,20 +1169,12 @@ vmTestbase_nsk_jvmti_quick = \
|
||||
vmTestbase/nsk/jvmti/SetThreadLocalStorage/setthrdstor003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/SetVerboseFlag/setvrbflag002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/SingleStep/singlestep001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/SingleStep/singlestep003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/SuspendThread/suspendthrd001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/SuspendThreadList/suspendthrdlst001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/StopThread/stopthrd006/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/StopThread/stopthrd007/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ThreadEnd/threadend001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ThreadEnd/threadend002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ThreadStart/threadstart001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ThreadStart/threadstart002/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/ThreadStart/threadstart003/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/VMDeath/vmdeath001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/VMInit/vminit001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/VMObjectAlloc/vmobjalloc001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/scenarios/allocation/AP02/ap02t001/TestDescription.java \
|
||||
vmTestbase/nsk/jvmti/scenarios/allocation/AP03/ap03t001/TestDescription.java \
|
||||
|
||||
@ -49,8 +49,8 @@ public class classprep01 {
|
||||
System.loadLibrary("classprep01");
|
||||
}
|
||||
|
||||
native static void getReady();
|
||||
native static int check();
|
||||
native static void getReady(Thread thread);
|
||||
native static int check(Thread thread);
|
||||
|
||||
static volatile int result;
|
||||
public static void main(String args[]) {
|
||||
@ -59,9 +59,9 @@ public class classprep01 {
|
||||
}
|
||||
public static void testVirtualThread() {
|
||||
Thread thread = Thread.startVirtualThread(() -> {
|
||||
getReady();
|
||||
getReady(Thread.currentThread());
|
||||
new TestClassVirtual().run();
|
||||
result = check();
|
||||
result = check(Thread.currentThread());
|
||||
});
|
||||
try {
|
||||
thread.join();
|
||||
@ -74,9 +74,22 @@ public class classprep01 {
|
||||
}
|
||||
}
|
||||
public static void testPlatformThread() {
|
||||
getReady();
|
||||
Thread otherThread = new Thread(() -> {
|
||||
new TestClass2().run();
|
||||
});
|
||||
|
||||
getReady(Thread.currentThread());
|
||||
|
||||
// should generate the events
|
||||
new TestClass().run();
|
||||
result = check();
|
||||
|
||||
// loading classes on other thread should not generate the events
|
||||
otherThread.start();
|
||||
try {
|
||||
otherThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
result = check(Thread.currentThread());
|
||||
if (result != 0) {
|
||||
throw new RuntimeException("check failed with result " + result);
|
||||
}
|
||||
@ -88,7 +101,7 @@ public class classprep01 {
|
||||
void run();
|
||||
}
|
||||
|
||||
static class TestClass implements TestInterface {
|
||||
static class TestClass implements TestInterface {
|
||||
static int i = 0;
|
||||
int count = 0;
|
||||
static {
|
||||
@ -116,5 +129,12 @@ public class classprep01 {
|
||||
}
|
||||
}
|
||||
|
||||
interface TestInterface2 {
|
||||
void run();
|
||||
}
|
||||
|
||||
static class TestClass2 implements TestInterface2 {
|
||||
public void run() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +63,13 @@ static class_info virtual_classes[] = {
|
||||
{ (char *)"Lclassprep01$TestClassVirtual;", EXP_STATUS, 3, 2, 1 }
|
||||
};
|
||||
|
||||
// These classes are loaded on a different thread.
|
||||
// We should not get ClassPrepare events for them.
|
||||
static const class_info unexpectedClasses[] = {
|
||||
{ (char *)"Lclassprep01$TestInterface2;", 0, 0, 0, 0 },
|
||||
{ (char *)"Lclassprep01$TestClass2;", 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
void printStatus(jint status) {
|
||||
int flags = 0;
|
||||
if ((status & JVMTI_CLASS_STATUS_VERIFIED) != 0) {
|
||||
@ -87,6 +94,17 @@ void printStatus(jint status) {
|
||||
LOG(" (0x%x)\n", status);
|
||||
}
|
||||
|
||||
const size_t NOT_FOUND = (size_t)(-1);
|
||||
|
||||
size_t findClass(const char *classSig, const class_info *arr, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (strcmp(classSig, arr[i].sig) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
void JNICALL ClassPrepare(jvmtiEnv *jvmti, JNIEnv *jni, jthread thr, jclass cls) {
|
||||
jvmtiError err;
|
||||
class_info inf;
|
||||
@ -183,9 +201,21 @@ void JNICALL ClassPrepare(jvmtiEnv *jvmti, JNIEnv *jni, jthread thr, jclass cls)
|
||||
}
|
||||
LOG("\n");
|
||||
|
||||
if (eventsCount >= eventsExpected) {
|
||||
LOG("(#%" PRIuPTR ") too many events: %" PRIuPTR ", expected: %" PRIuPTR "\n",
|
||||
eventsCount, eventsCount + 1, eventsExpected);
|
||||
size_t expectedClassIdx = findClass(inf.sig, classes, 2);
|
||||
// Test classes loading may cause system classes loading - skip them.
|
||||
if (expectedClassIdx == NOT_FOUND) {
|
||||
size_t unexpectedClassIdx = findClass(inf.sig, unexpectedClasses,
|
||||
sizeof(unexpectedClasses)/sizeof(class_info));
|
||||
if (unexpectedClassIdx != NOT_FOUND) {
|
||||
printf("# wrong class: \"%s\"\n", inf.sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventsCount != expectedClassIdx) {
|
||||
printf("(#%" PRIuPTR ") unexpected order: %" PRIuPTR ", expected: %" PRIuPTR "\n",
|
||||
eventsCount, expectedClassIdx, eventsCount);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
@ -266,24 +296,17 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_classprep01_getReady(JNIEnv *jni, jclass cls) {
|
||||
Java_classprep01_getReady(JNIEnv *jni, jclass cls, jthread thread) {
|
||||
jvmtiError err;
|
||||
jthread prep_thread;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
LOG("JVMTI client was not properly loaded!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti->GetCurrentThread(&prep_thread);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
LOG("Failed to get current thread: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
eventsCount = 0;
|
||||
if (jni->IsVirtualThread(prep_thread)) {
|
||||
if (jni->IsVirtualThread(thread)) {
|
||||
classes = virtual_classes;
|
||||
eventsExpected = sizeof(virtual_classes)/sizeof(class_info);
|
||||
} else {
|
||||
@ -291,9 +314,9 @@ Java_classprep01_getReady(JNIEnv *jni, jclass cls) {
|
||||
eventsExpected = sizeof(kernel_classes)/sizeof(class_info);
|
||||
}
|
||||
LOG("Requesting enabling JVMTI_EVENT_CLASS_PREPARE in thread.\n");
|
||||
print_thread_info(jvmti, jni, prep_thread);
|
||||
print_thread_info(jvmti, jni, thread);
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, prep_thread);
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, thread);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
LOG("Failed to enable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
@ -301,25 +324,18 @@ Java_classprep01_getReady(JNIEnv *jni, jclass cls) {
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_classprep01_check(JNIEnv *jni, jclass cls) {
|
||||
Java_classprep01_check(JNIEnv *jni, jclass cls, jthread thread) {
|
||||
jvmtiError err;
|
||||
jthread prep_thread;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
LOG("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti->GetCurrentThread(&prep_thread);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
LOG("Failed to get current thread: %s (%d)\n", TranslateError(err), err);
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
LOG("Requesting disabling JVMTI_EVENT_CLASS_PREPARE in thread.\n");
|
||||
print_thread_info(jvmti, jni, prep_thread);
|
||||
print_thread_info(jvmti, jni, thread);
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_CLASS_PREPARE, prep_thread);
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_CLASS_PREPARE, thread);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
LOG("Failed to disable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.Breakpoint;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import nsk.share.*;
|
||||
import nsk.share.jvmti.*;
|
||||
|
||||
/**
|
||||
* This test exercises the JVMTI event <code>Breakpoint</code>.
|
||||
* <br>It verifies that thread info, method info and location of
|
||||
* received Breakpoint events will be the same with two breakpoints
|
||||
* previously set on the methods <code>bpMethod()</code> and
|
||||
* <code>bpMethod2()</code> via the function SetBreakpoint().
|
||||
*/
|
||||
public class breakpoint001 {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("breakpoint001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load \"breakpoint001\" library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native int check();
|
||||
|
||||
public static void main(String[] argv) {
|
||||
argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
|
||||
|
||||
// produce JCK-like exit status
|
||||
System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
|
||||
}
|
||||
|
||||
public static int run(String argv[], PrintStream out) {
|
||||
return new breakpoint001().runThis(argv, out);
|
||||
}
|
||||
|
||||
private int runThis(String argv[], PrintStream out) {
|
||||
ArgumentHandler argHandler = new ArgumentHandler(argv);
|
||||
Log log = new Log(out, argHandler);
|
||||
Thread.currentThread().setName("breakpoint001Thr");
|
||||
|
||||
log.display("\nReaching a breakpoint method ...\n");
|
||||
bpMethod();
|
||||
log.display("The breakpoint method leaved ...");
|
||||
|
||||
return check();
|
||||
}
|
||||
|
||||
/**
|
||||
* dummy method used only to reach breakpoint set in the agent
|
||||
*/
|
||||
private void bpMethod() {
|
||||
int dummyVar = bpMethod2();
|
||||
}
|
||||
|
||||
/**
|
||||
* dummy method used only to reach breakpoint set in the agent
|
||||
*/
|
||||
private int bpMethod2() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1,51 +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/Breakpoint/breakpoint001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, onload_only_caps, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* This test exercises the JVMTI event Breakpoint.
|
||||
* It verifies that thread info, method info and location of received
|
||||
* Breakpoint events will be the same with two breakpoints previously
|
||||
* set on the methods 'bpMethod()' and 'bpMethod2()' via the function
|
||||
* SetBreakpoint().
|
||||
* COMMENTS
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
*
|
||||
* @comment make sure breakpoint001 is compiled with full debug info
|
||||
* @build nsk.jvmti.Breakpoint.breakpoint001
|
||||
* @clean nsk.jvmti.Breakpoint.breakpoint001
|
||||
* @compile -g:lines,source,vars ../breakpoint001.java
|
||||
*
|
||||
* @run main/othervm/native
|
||||
* -agentlib:breakpoint001=-waittime=5
|
||||
* nsk.jvmti.Breakpoint.breakpoint001
|
||||
*/
|
||||
|
||||
@ -1,304 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* 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 "nsk_tools.h"
|
||||
#include "JVMTITools.h"
|
||||
#include "jvmti_tools.h"
|
||||
#include "jni_tools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define STATUS_FAILED 2
|
||||
#define PASSED 0
|
||||
|
||||
#define METH_NUM 2
|
||||
static const char *METHODS[][2] = {
|
||||
{ "bpMethod", "()V" },
|
||||
{ "bpMethod2", "()I" }
|
||||
};
|
||||
|
||||
static const char *CLASS_SIG =
|
||||
"Lnsk/jvmti/Breakpoint/breakpoint001;";
|
||||
|
||||
static const char *THREAD_NAME = "breakpoint001Thr";
|
||||
|
||||
static volatile int bpEvents[METH_NUM];
|
||||
static volatile jint result = PASSED;
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
|
||||
static volatile int callbacksEnabled = NSK_TRUE;
|
||||
static jrawMonitorID agent_lock;
|
||||
|
||||
static void initCounters() {
|
||||
int i;
|
||||
|
||||
for (i=0; i<METH_NUM; i++)
|
||||
bpEvents[i] = 0;
|
||||
}
|
||||
|
||||
static void setBP(jvmtiEnv *jvmti_env, JNIEnv *env, jclass klass) {
|
||||
jmethodID mid;
|
||||
int i;
|
||||
|
||||
for (i=0; i<METH_NUM; i++) {
|
||||
if (!NSK_JNI_VERIFY(env, (mid = env->GetMethodID(klass, METHODS[i][0], METHODS[i][1])) != NULL))
|
||||
env->FatalError("failed to get ID for the java method\n");
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->SetBreakpoint(mid, 0)))
|
||||
env->FatalError("failed to set breakpoint\n");
|
||||
}
|
||||
}
|
||||
|
||||
/** callback functions **/
|
||||
void JNICALL
|
||||
ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, jclass klass) {
|
||||
char *sig, *generic;
|
||||
|
||||
jvmti->RawMonitorEnter(agent_lock);
|
||||
|
||||
if (callbacksEnabled) {
|
||||
// GetClassSignature may be called only during the start or the live phase
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(klass, &sig, &generic)))
|
||||
env->FatalError("failed to obtain a class signature\n");
|
||||
|
||||
if (sig != NULL && (strcmp(sig, CLASS_SIG) == 0)) {
|
||||
NSK_DISPLAY1(
|
||||
"ClassLoad event received for the class \"%s\"\n"
|
||||
"\tsetting breakpoints ...\n",
|
||||
sig);
|
||||
setBP(jvmti_env, env, klass);
|
||||
}
|
||||
}
|
||||
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
}
|
||||
|
||||
void JNICALL
|
||||
Breakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
|
||||
jmethodID method, jlocation location) {
|
||||
jclass klass;
|
||||
char *clsSig, *generic, *methNam, *methSig;
|
||||
jvmtiThreadInfo thr_info;
|
||||
int checkStatus = PASSED;
|
||||
int i;
|
||||
|
||||
NSK_DISPLAY0(">>>> Breakpoint event received\n");
|
||||
|
||||
/* checking thread info */
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &thr_info))) {
|
||||
result = STATUS_FAILED;
|
||||
NSK_COMPLAIN0("TEST FAILED: unable to get thread info during Breakpoint callback\n\n");
|
||||
return;
|
||||
}
|
||||
if (thr_info.name == NULL ||
|
||||
strcmp(thr_info.name,THREAD_NAME) != 0 ||
|
||||
thr_info.is_daemon == JNI_TRUE) {
|
||||
result = checkStatus = STATUS_FAILED;
|
||||
NSK_COMPLAIN2(
|
||||
"TEST FAILED: Breakpoint event with unexpected thread info:\n"
|
||||
"\tname: \"%s\"\ttype: %s thread\n\n",
|
||||
(thr_info.name == NULL) ? "NULL" : thr_info.name,
|
||||
(thr_info.is_daemon == JNI_TRUE) ? "deamon" : "user");
|
||||
}
|
||||
else
|
||||
NSK_DISPLAY2("CHECK PASSED: thread name: \"%s\"\ttype: %s thread\n",
|
||||
thr_info.name, (thr_info.is_daemon == JNI_TRUE) ? "deamon" : "user");
|
||||
|
||||
/* checking location */
|
||||
if (location != 0) {
|
||||
result = checkStatus = STATUS_FAILED;
|
||||
NSK_COMPLAIN1("TEST FAILED: Breakpoint event with unexpected location %ld:\n\n",
|
||||
(long) location);
|
||||
}
|
||||
else
|
||||
NSK_DISPLAY1("CHECK PASSED: location: %ld as expected\n",
|
||||
(long) location);
|
||||
|
||||
/* checking method info */
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodDeclaringClass(method, &klass))) {
|
||||
result = checkStatus = STATUS_FAILED;
|
||||
NSK_COMPLAIN0("TEST FAILED: unable to get method declaring class during Breakpoint callback\n\n");
|
||||
return;
|
||||
}
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(klass, &clsSig, &generic))) {
|
||||
result = checkStatus = STATUS_FAILED;
|
||||
NSK_COMPLAIN0("TEST FAILED: unable to obtain a class signature during Breakpoint callback\n\n");
|
||||
return;
|
||||
}
|
||||
if (clsSig == NULL ||
|
||||
strcmp(clsSig,CLASS_SIG) != 0) {
|
||||
result = checkStatus = STATUS_FAILED;
|
||||
NSK_COMPLAIN1(
|
||||
"TEST FAILED: Breakpoint event with unexpected class signature:\n"
|
||||
"\t\"%s\"\n\n",
|
||||
(clsSig == NULL) ? "NULL" : clsSig);
|
||||
}
|
||||
else
|
||||
NSK_DISPLAY1("CHECK PASSED: class signature: \"%s\"\n",
|
||||
clsSig);
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &methNam, &methSig, NULL))) {
|
||||
result = checkStatus = STATUS_FAILED;
|
||||
NSK_COMPLAIN0("TEST FAILED: unable to get method name during Breakpoint callback\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0; i<METH_NUM; i++)
|
||||
if (strcmp(methNam, METHODS[i][0]) == 0 &&
|
||||
strcmp(methSig, METHODS[i][1]) == 0) {
|
||||
NSK_DISPLAY2("CHECK PASSED: method name: \"%s\"\tsignature: \"%s\"\n",
|
||||
methNam, methSig);
|
||||
if (checkStatus == PASSED)
|
||||
bpEvents[i]++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*) methNam))) {
|
||||
result = STATUS_FAILED;
|
||||
NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method name\n\n");
|
||||
}
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*) methSig))) {
|
||||
result = STATUS_FAILED;
|
||||
NSK_COMPLAIN0("TEST FAILED: unable to deallocate memory pointed to method signature\n\n");
|
||||
}
|
||||
|
||||
NSK_DISPLAY0("<<<<\n\n");
|
||||
}
|
||||
|
||||
|
||||
void JNICALL
|
||||
VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env) {
|
||||
jvmti->RawMonitorEnter(agent_lock);
|
||||
|
||||
callbacksEnabled = NSK_TRUE;
|
||||
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
}
|
||||
|
||||
|
||||
void JNICALL
|
||||
VMDeath(jvmtiEnv *jvmti_env, JNIEnv* jni_env) {
|
||||
jvmti->RawMonitorEnter(agent_lock);
|
||||
|
||||
callbacksEnabled = NSK_FALSE;
|
||||
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
}
|
||||
/************************/
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_Breakpoint_breakpoint001_check(
|
||||
JNIEnv *env, jobject obj) {
|
||||
int i;
|
||||
|
||||
for (i=0; i<METH_NUM; i++) {
|
||||
if (bpEvents[i] != 1) {
|
||||
result = STATUS_FAILED;
|
||||
NSK_COMPLAIN3(
|
||||
"TEST FAILED: wrong number of Breakpoint events\n"
|
||||
"\tfor the method \"%s %s\":\n"
|
||||
"\t\tgot: %d\texpected: 1\n",
|
||||
METHODS[i][0], METHODS[i][1], bpEvents[i]);
|
||||
}
|
||||
else
|
||||
NSK_DISPLAY3("CHECK PASSED: %d Breakpoint event(s) for the method \"%s %s\" as expected\n",
|
||||
bpEvents[i], METHODS[i][0], METHODS[i][1]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_breakpoint001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_breakpoint001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_breakpoint001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiCapabilities caps;
|
||||
|
||||
/* init framework and parse options */
|
||||
if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
|
||||
return JNI_ERR;
|
||||
|
||||
/* create JVMTI environment */
|
||||
if (!NSK_VERIFY((jvmti =
|
||||
nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
|
||||
return JNI_ERR;
|
||||
|
||||
initCounters();
|
||||
|
||||
/* add capability to generate compiled method events */
|
||||
memset(&caps, 0, sizeof(jvmtiCapabilities));
|
||||
caps.can_generate_breakpoint_events = 1;
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
|
||||
return JNI_ERR;
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))
|
||||
return JNI_ERR;
|
||||
|
||||
if (!caps.can_generate_single_step_events)
|
||||
NSK_DISPLAY0("Warning: generation of single step events is not implemented\n");
|
||||
|
||||
/* set event callback */
|
||||
NSK_DISPLAY0("setting event callbacks ...\n");
|
||||
(void) memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.ClassLoad = &ClassLoad;
|
||||
callbacks.Breakpoint = &Breakpoint;
|
||||
callbacks.VMStart = &VMStart;
|
||||
callbacks.VMDeath = &VMDeath;
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
|
||||
return JNI_ERR;
|
||||
|
||||
NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL)))
|
||||
return JNI_ERR;
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
|
||||
return JNI_ERR;
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL)))
|
||||
return JNI_ERR;
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL)))
|
||||
return JNI_ERR;
|
||||
NSK_DISPLAY0("enabling the events done\n\n");
|
||||
|
||||
if (jvmti->CreateRawMonitor("agent_lock", &agent_lock) != JVMTI_ERROR_NONE) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "breakpoint001.cpp"
|
||||
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.ClassLoad;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import nsk.share.*;
|
||||
|
||||
/**
|
||||
* The test exercises the JVMTI event Class Load.<br>
|
||||
* It verifies that the event will be sent for the auxiliary class
|
||||
* <code>TestedClass</code> and array of type <code>TestedClass</code>
|
||||
* and vise versa for primitive classes and arrays of primitive types
|
||||
* in accordance with the ClassLoad spec:<br>
|
||||
* <code>Arrays of non-primitive types have class load events. Arrays of
|
||||
* primitive types do not have class load events. Primitive classes (for
|
||||
* example, java.lang.Integer.TYPE) do not have class load events.</code>
|
||||
*/
|
||||
public class classload001 {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("classload001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load \"classload001\" library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native int check();
|
||||
|
||||
public static void main(String args[]) {
|
||||
args = nsk.share.jvmti.JVMTITest.commonInit(args);
|
||||
|
||||
// produce JCK-like exit status.
|
||||
System.exit(run(args, System.out) + Consts.JCK_STATUS_BASE);
|
||||
}
|
||||
|
||||
public static int run(String args[], PrintStream out) {
|
||||
return new classload001().runIt(args, out);
|
||||
}
|
||||
|
||||
private int runIt(String args[], PrintStream out) {
|
||||
return check();
|
||||
}
|
||||
|
||||
// classes & arrays used to verify an assertion in the agent
|
||||
Class boolCls = Boolean.TYPE;
|
||||
Class byteCls = Byte.TYPE;
|
||||
Class charCls = Character.TYPE;
|
||||
Class doubleCls = Double.TYPE;
|
||||
Class floatCls = Float.TYPE;
|
||||
Class intCls = Integer.TYPE;
|
||||
Class longCls = Long.TYPE;
|
||||
Class shortCls = Short.TYPE;
|
||||
|
||||
Class boolClArr[] = {Boolean.TYPE, Boolean.TYPE};
|
||||
Class byteClArr[] = {Byte.TYPE, Byte.TYPE};
|
||||
Class charClArr[] = {Character.TYPE};
|
||||
Class doubleClArr[] = {Double.TYPE};
|
||||
Class floatClArr[] = {Float.TYPE, Float.TYPE};
|
||||
Class intClArr[] = {Integer.TYPE};
|
||||
Class longClArr[] = {Long.TYPE};
|
||||
Class shortClArr[] = {Short.TYPE, Short.TYPE};
|
||||
|
||||
boolean boolArr[] = {false, true};
|
||||
byte byteArr[] = {Byte.MAX_VALUE};
|
||||
char charArr[] = {'a'};
|
||||
double doubleArr[] = {Double.MIN_VALUE};
|
||||
float floatArr[] = {Float.MAX_VALUE};
|
||||
int intArr[] = {Integer.MIN_VALUE};
|
||||
long longArr[] = {Long.MAX_VALUE};
|
||||
short shortArr[] = {Short.MIN_VALUE};
|
||||
|
||||
TestedClass testedCls[] = {new TestedClass()};
|
||||
|
||||
class TestedClass {}
|
||||
}
|
||||
@ -1,47 +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/ClassLoad/classload001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, onload_only_logic, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises the JVMTI event Class Load.
|
||||
* It verifies that the event will be sent for the auxiliary class
|
||||
* 'TestedClass' and not sent for array of type 'TestedClass' and for
|
||||
* primitive classes and arrays of primitive types in accordance with
|
||||
* the ClassLoad spec:
|
||||
* "Array class creation does not generate a class load event. The
|
||||
* creation of a primitive class (for example, java.lang.Integer.TYPE)
|
||||
* does not generate a class load event."
|
||||
* COMMENTS
|
||||
* Fixed the 5031200 bug.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:classload001=-waittime=5 nsk.jvmti.ClassLoad.classload001
|
||||
*/
|
||||
|
||||
@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <jvmti.h>
|
||||
#include "agent_common.h"
|
||||
|
||||
#include "nsk_tools.h"
|
||||
#include "JVMTITools.h"
|
||||
#include "jvmti_tools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
/* classes which must have the class load event */
|
||||
static const char *expSigs[] = {
|
||||
"Lnsk/jvmti/ClassLoad/classload001;",
|
||||
"Lnsk/jvmti/ClassLoad/classload001$TestedClass;"
|
||||
};
|
||||
#define EXP_SIG_NUM (sizeof(expSigs)/sizeof(char*))
|
||||
|
||||
/* classes which must not have the class load event */
|
||||
static const char *unexpSigs[] = {
|
||||
"Z", /* boolean */
|
||||
"B", /* byte */
|
||||
"C", /* char */
|
||||
"D", /* double */
|
||||
"F", /* float */
|
||||
"I", /* integer */
|
||||
"J", /* long */
|
||||
"S", /* short */
|
||||
|
||||
"[Z", /* boolean array */
|
||||
"[B", /* byte array */
|
||||
"[C", /* char array */
|
||||
"[D", /* double array */
|
||||
"[F", /* float array */
|
||||
"[I", /* integer array */
|
||||
"[J", /* long array */
|
||||
"[S", /* short array */
|
||||
"[Lnsk/jvmti/ClassLoad/classload001$TestedClass;"
|
||||
};
|
||||
#define UNEXP_SIG_NUM (sizeof(unexpSigs)/sizeof(char*))
|
||||
|
||||
static volatile int clsEvents[EXP_SIG_NUM];
|
||||
static volatile int primClsEvents[UNEXP_SIG_NUM];
|
||||
|
||||
static jint result = PASSED;
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jrawMonitorID countLock;
|
||||
|
||||
static void initCounters() {
|
||||
size_t i;
|
||||
|
||||
for (i=0; i<EXP_SIG_NUM; i++)
|
||||
clsEvents[i] = 0;
|
||||
|
||||
for (i=0; i<UNEXP_SIG_NUM; i++)
|
||||
primClsEvents[i] = 0;
|
||||
}
|
||||
|
||||
static int findSig(char *sig, int expected) {
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i<((expected == 1) ? EXP_SIG_NUM : UNEXP_SIG_NUM); i++)
|
||||
if (sig != NULL &&
|
||||
strcmp(((expected == 1) ? expSigs[i] : unexpSigs[i]), sig) == 0)
|
||||
return i; /* the signature found, return index */
|
||||
|
||||
return -1; /* the signature not found */
|
||||
}
|
||||
|
||||
static void lock(jvmtiEnv *jvmti_env, JNIEnv *jni_env) {
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->RawMonitorEnter(countLock)))
|
||||
jni_env->FatalError("failed to enter a raw monitor\n");
|
||||
}
|
||||
|
||||
static void unlock(jvmtiEnv *jvmti_env, JNIEnv *jni_env) {
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->RawMonitorExit(countLock)))
|
||||
jni_env->FatalError("failed to exit a raw monitor\n");
|
||||
}
|
||||
|
||||
/** callback functions **/
|
||||
void JNICALL
|
||||
ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, jclass klass) {
|
||||
int i = 0;
|
||||
char *sig, *generic;
|
||||
|
||||
lock(jvmti_env, env);
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(klass, &sig, &generic))) {
|
||||
result = STATUS_FAILED;
|
||||
NSK_COMPLAIN0("TEST FAILURE: unable to obtain a class signature\n");
|
||||
unlock(jvmti_env, env);
|
||||
return;
|
||||
}
|
||||
|
||||
i = findSig(sig, 1);
|
||||
if (i != -1) {
|
||||
clsEvents[i]++;
|
||||
NSK_DISPLAY1("CHECK PASSED: ClassLoad event received for the class \"%s\" as expected\n",
|
||||
sig);
|
||||
}
|
||||
else {
|
||||
i = findSig(sig, 0);
|
||||
if (i != -1) {
|
||||
result = STATUS_FAILED;
|
||||
primClsEvents[i]++;
|
||||
NSK_COMPLAIN1(
|
||||
"TEST FAILED: JVMTI_EVENT_CLASS_LOAD event received for\n"
|
||||
"\t a primitive class/array of primitive types with the signature \"%s\"\n",
|
||||
sig);
|
||||
}
|
||||
}
|
||||
|
||||
unlock(jvmti_env, env);
|
||||
}
|
||||
/************************/
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_ClassLoad_classload001_check(
|
||||
JNIEnv *env, jobject obj) {
|
||||
size_t i;
|
||||
|
||||
for (i=0; i<EXP_SIG_NUM; i++)
|
||||
if (clsEvents[i] != 1) {
|
||||
result = STATUS_FAILED;
|
||||
NSK_COMPLAIN2("TEST FAILED: wrong number of JVMTI_EVENT_CLASS_LOAD events for \"%s\":\n\tgot: %d\texpected: 1\n",
|
||||
expSigs[i], clsEvents[i]);
|
||||
}
|
||||
|
||||
for (i=0; i<UNEXP_SIG_NUM; i++)
|
||||
if (primClsEvents[i] != 0)
|
||||
NSK_COMPLAIN0("TEST FAILED: there are JVMTI_EVENT_CLASS_LOAD events for the primitive classes\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_classload001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_classload001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_classload001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
/* init framework and parse options */
|
||||
if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
|
||||
return JNI_ERR;
|
||||
|
||||
/* create JVMTI environment */
|
||||
if (!NSK_VERIFY((jvmti =
|
||||
nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
|
||||
return JNI_ERR;
|
||||
|
||||
initCounters();
|
||||
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_counter_lock", &countLock)))
|
||||
return JNI_ERR;
|
||||
|
||||
NSK_DISPLAY0("setting event callbacks ...\n");
|
||||
(void) memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.ClassLoad = &ClassLoad;
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
|
||||
return JNI_ERR;
|
||||
|
||||
NSK_DISPLAY0("setting event callbacks done\nenabling ClassLoad event ...\n");
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL)))
|
||||
return JNI_ERR;
|
||||
NSK_DISPLAY0("the event enabled\n");
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "classload001.cpp"
|
||||
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* 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.ClassPrepare;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class classprep001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("classprep001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load classprep001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady(Thread thread);
|
||||
native static int check(Thread thread);
|
||||
|
||||
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) {
|
||||
Thread otherThread = new Thread(() -> {
|
||||
new TestClass2().run();
|
||||
});
|
||||
|
||||
getReady(Thread.currentThread());
|
||||
|
||||
// should generate the events
|
||||
new TestClass().run();
|
||||
|
||||
// loading classes on other thread should not generate the events
|
||||
otherThread.start();
|
||||
try {
|
||||
otherThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
return check(Thread.currentThread());
|
||||
}
|
||||
|
||||
interface TestInterface {
|
||||
int constant = Integer.parseInt("10");
|
||||
void run();
|
||||
}
|
||||
|
||||
static class TestClass implements TestInterface {
|
||||
static int i = 0;
|
||||
int count = 0;
|
||||
static {
|
||||
i++;
|
||||
}
|
||||
public void run() {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
interface TestInterface2 {
|
||||
void run();
|
||||
}
|
||||
|
||||
static class TestClass2 implements TestInterface2 {
|
||||
public void run() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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/ClassPrepare/classprep001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI event callback function ClassPrepare.
|
||||
* The test checks if class prepare event is generated when
|
||||
* class preparation is complete, and, at this point, class
|
||||
* fields, methods, and implemented interfaces are available,
|
||||
* and no code from the class has been executed.
|
||||
* COMMENTS
|
||||
* Fixed according to the bug 4651181.
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:classprep001 nsk.jvmti.ClassPrepare.classprep001
|
||||
*/
|
||||
|
||||
@ -1,336 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* 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 <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
#define EXP_STATUS (JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED)
|
||||
|
||||
typedef struct {
|
||||
char *sig;
|
||||
jint status;
|
||||
jint mcount;
|
||||
jint fcount;
|
||||
jint icount;
|
||||
} writable_class_info;
|
||||
|
||||
typedef struct {
|
||||
const char *sig;
|
||||
jint status;
|
||||
jint mcount;
|
||||
jint fcount;
|
||||
jint icount;
|
||||
} class_info;
|
||||
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static size_t eventsCount = 0;
|
||||
static size_t eventsExpected = 0;
|
||||
static class_info classes[] = {
|
||||
{ "Lnsk/jvmti/ClassPrepare/classprep001$TestInterface;", EXP_STATUS, 2, 1, 0 },
|
||||
{ "Lnsk/jvmti/ClassPrepare/classprep001$TestClass;", EXP_STATUS, 3, 2, 1 }
|
||||
};
|
||||
// These classes are loaded on a different thread.
|
||||
// We should not get ClassPrepare events for them.
|
||||
static const class_info unexpectedClasses[] = {
|
||||
{ "Lnsk/jvmti/ClassPrepare/classprep001$TestInterface2;", 0, 0, 0, 0 },
|
||||
{ "Lnsk/jvmti/ClassPrepare/classprep001$TestClass2;", 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
void printStatus(jint status) {
|
||||
int flags = 0;
|
||||
if ((status & JVMTI_CLASS_STATUS_VERIFIED) != 0) {
|
||||
printf("JVMTI_CLASS_STATUS_VERIFIED");
|
||||
flags++;
|
||||
}
|
||||
if ((status & JVMTI_CLASS_STATUS_PREPARED) != 0) {
|
||||
if (flags > 0) printf(" | ");
|
||||
printf("JVMTI_CLASS_STATUS_PREPARED");
|
||||
flags++;
|
||||
}
|
||||
if ((status & JVMTI_CLASS_STATUS_INITIALIZED) != 0) {
|
||||
if (flags > 0) printf(" | ");
|
||||
printf("JVMTI_CLASS_STATUS_INITIALIZED");
|
||||
flags++;
|
||||
}
|
||||
if ((status & JVMTI_CLASS_STATUS_ERROR) != 0) {
|
||||
if (flags > 0) printf(" | ");
|
||||
printf("JVMTI_CLASS_STATUS_ERROR");
|
||||
flags++;
|
||||
}
|
||||
printf(" (0x%x)\n", status);
|
||||
}
|
||||
|
||||
const size_t NOT_FOUND = (size_t)(-1);
|
||||
|
||||
size_t findClass(const char *classSig, const class_info *arr, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (strcmp(classSig, arr[i].sig) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jclass cls) {
|
||||
jvmtiError err;
|
||||
writable_class_info inf;
|
||||
jmethodID *methods;
|
||||
jfieldID *fields;
|
||||
jclass *interfaces;
|
||||
char *name, *sig, *generic;
|
||||
int i;
|
||||
|
||||
err = jvmti_env->GetClassSignature(cls, &inf.sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
eventsCount, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassStatus(cls, &inf.status);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassStatus#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
eventsCount, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
err = jvmti_env->GetClassMethods(cls, &inf.mcount, &methods);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassMethods#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
eventsCount, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassFields(cls, &inf.fcount, &fields);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassMethods#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
eventsCount, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetImplementedInterfaces(cls,
|
||||
&inf.icount, &interfaces);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetImplementedInterfaces#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
eventsCount, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> [class prepare event #%" PRIuPTR "]", eventsCount);
|
||||
printf(" \"%s\"\n", inf.sig);
|
||||
printf(">>> status: ");
|
||||
printStatus(inf.status);
|
||||
printf(">>> %d methods:", inf.mcount);
|
||||
for (i = 0; i < inf.mcount; i++) {
|
||||
if (i > 0) printf(",");
|
||||
if (methods[i] == NULL) {
|
||||
printf(" null");
|
||||
} else {
|
||||
err = jvmti_env->GetMethodName(methods[i],
|
||||
&name, &sig, &generic);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
printf(" \"%s%s\"", name, sig);
|
||||
} else {
|
||||
printf(" ???");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf(">>> %d fields:", inf.fcount);
|
||||
for (i = 0; i < inf.fcount; i++) {
|
||||
if (i > 0) printf(",");
|
||||
if (fields[i] == NULL) {
|
||||
printf(" null");
|
||||
} else {
|
||||
err = jvmti_env->GetFieldName(cls, fields[i],
|
||||
&name, &sig, &generic);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
printf(" \"%s, %s\"", name, sig);
|
||||
} else {
|
||||
printf(" ???");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf(">>> %d interfaces:", inf.icount);
|
||||
for (i = 0; i < inf.icount; i++) {
|
||||
if (i > 0) printf(",");
|
||||
if (interfaces[i] == NULL) {
|
||||
printf(" null");
|
||||
} else {
|
||||
err = jvmti_env->GetClassSignature(
|
||||
interfaces[i], &sig, &generic);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
printf(" \"%s\"", sig);
|
||||
} else {
|
||||
printf(" ???");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
size_t expectedClassIdx = findClass(inf.sig, classes, sizeof(classes)/sizeof(class_info));
|
||||
// Test classes loading may cause system classes loading - skip them.
|
||||
if (expectedClassIdx == NOT_FOUND) {
|
||||
size_t unexpectedClassIdx = findClass(inf.sig, unexpectedClasses,
|
||||
sizeof(unexpectedClasses)/sizeof(class_info));
|
||||
if (unexpectedClassIdx != NOT_FOUND) {
|
||||
printf("# wrong class: \"%s\"\n", inf.sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventsCount != expectedClassIdx) {
|
||||
printf("(#%" PRIuPTR ") unexpected order: %" PRIuPTR ", expected: %" PRIuPTR "\n",
|
||||
eventsCount, expectedClassIdx, eventsCount);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (inf.status != classes[eventsCount].status) {
|
||||
printf("(#%" PRIuPTR ") wrong status: ", eventsCount);
|
||||
printStatus(inf.status);
|
||||
printf(" expected: ");
|
||||
printStatus(classes[eventsCount].status);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (inf.mcount != classes[eventsCount].mcount) {
|
||||
printf("(#%" PRIuPTR ") wrong number of methods: 0x%x",
|
||||
eventsCount, inf.mcount);
|
||||
printf(", expected: 0x%x\n", classes[eventsCount].mcount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (inf.fcount != classes[eventsCount].fcount) {
|
||||
printf("(#%" PRIuPTR ") wrong number of fields: 0x%x",
|
||||
eventsCount, inf.fcount);
|
||||
printf(", expected: 0x%x\n", classes[eventsCount].fcount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (inf.icount != classes[eventsCount].icount) {
|
||||
printf("(#%" PRIuPTR ") wrong number of interfaces: 0x%x",
|
||||
eventsCount, inf.icount);
|
||||
printf(", expected: 0x%x\n", classes[eventsCount].icount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
eventsCount++;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_classprep001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_classprep001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_classprep001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
callbacks.ClassPrepare = &ClassPrepare;
|
||||
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_ClassPrepare_classprep001_getReady(JNIEnv *env, jclass cls, jthread thread) {
|
||||
jvmtiError err;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_CLASS_PREPARE, thread);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected = sizeof(classes)/sizeof(class_info);
|
||||
} else {
|
||||
printf("Failed to enable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_ClassPrepare_classprep001_check(JNIEnv *env, jclass cls, jthread thread) {
|
||||
jvmtiError err;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE,
|
||||
JVMTI_EVENT_CLASS_PREPARE, thread);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to disable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of class prepare events: %" PRIuPTR ", expected: %" PRIuPTR "\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "classprep001.cpp"
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.Exception;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class exception001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("exception001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load exception001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static int check();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -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/Exception/exception001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function Exception.
|
||||
* The test checks if the parameters of the function contain
|
||||
* the expected values for the following exceptions thrown by Java methods:
|
||||
* - custom class exception001c extending Throwable
|
||||
* - ArithmeticException caused by division with zero devisor
|
||||
* - IndexOutOfBoundsException caused by using out of range array index
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @compile exception001a.jasm
|
||||
* @run main/othervm/native -agentlib:exception001 nsk.jvmti.Exception.exception001
|
||||
*/
|
||||
|
||||
@ -1,315 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *t_cls;
|
||||
char *t_name;
|
||||
char *t_sig;
|
||||
jlocation t_loc;
|
||||
char *c_cls;
|
||||
char *c_name;
|
||||
char *c_sig;
|
||||
jlocation c_loc;
|
||||
} writable_exceptionInfo;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *t_cls;
|
||||
const char *t_name;
|
||||
const char *t_sig;
|
||||
jlocation t_loc;
|
||||
const char *c_cls;
|
||||
const char *c_name;
|
||||
const char *c_sig;
|
||||
jlocation c_loc;
|
||||
} exceptionInfo;
|
||||
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jvmtiCapabilities caps;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static exceptionInfo exs[] = {
|
||||
{ "Lnsk/jvmti/Exception/exception001c;",
|
||||
"Lnsk/jvmti/Exception/exception001b;", "meth1", "()V", 7,
|
||||
"Lnsk/jvmti/Exception/exception001a;", "run", "()V", 14 },
|
||||
{ "Ljava/lang/ArithmeticException;",
|
||||
"Lnsk/jvmti/Exception/exception001b;", "meth2", "(I)I", 3,
|
||||
"Lnsk/jvmti/Exception/exception001a;", "run", "()V", 24 },
|
||||
{ "Ljava/lang/ArrayIndexOutOfBoundsException;",
|
||||
"Lnsk/jvmti/Exception/exception001b;", "meth3", "(I)I", 10,
|
||||
"Lnsk/jvmti/Exception/exception001a;", "run", "()V", 34 }
|
||||
};
|
||||
static int eventsCount = 0;
|
||||
static int eventsExpected = 0;
|
||||
|
||||
void JNICALL
|
||||
Exception(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr,
|
||||
jmethodID method, jlocation location, jobject exception,
|
||||
jmethodID catch_method, jlocation catch_location) {
|
||||
jvmtiError err;
|
||||
writable_exceptionInfo ex;
|
||||
jclass cls;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving Exception info ...\n");
|
||||
}
|
||||
cls = env->GetObjectClass(exception);
|
||||
err = jvmti_env->GetClassSignature(cls, &ex.name, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass#t) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls, &ex.t_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature#t) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method,
|
||||
&ex.t_name, &ex.t_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName#t) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
ex.t_loc = location;
|
||||
err = jvmti_env->GetMethodDeclaringClass(catch_method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass#c) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls, &ex.c_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature#c) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(catch_method,
|
||||
&ex.c_name, &ex.c_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName#c) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
ex.c_loc = catch_location;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> %s\n", ex.name);
|
||||
printf(">>> thrown at %s.%s%s:0x%x%08x\n",
|
||||
ex.t_cls, ex.t_name, ex.t_sig,
|
||||
(jint)(ex.t_loc >> 32), (jint)ex.t_loc);
|
||||
printf(">>> catch at %s.%s%s:0x%x%08x\n",
|
||||
ex.c_cls, ex.c_name, ex.c_sig,
|
||||
(jint)(ex.c_loc >> 32), (jint)ex.c_loc);
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(exs)/sizeof(exceptionInfo); i++) {
|
||||
if (ex.name != NULL && strcmp(ex.name, exs[i].name) == 0
|
||||
&& ex.t_cls != NULL && strcmp(ex.t_cls, exs[i].t_cls) == 0
|
||||
&& ex.t_name != NULL && strcmp(ex.t_name, exs[i].t_name) == 0
|
||||
&& ex.t_sig != NULL && strcmp(ex.t_sig, exs[i].t_sig) == 0
|
||||
&& ex.c_cls != NULL && strcmp(ex.c_cls, exs[i].c_cls) == 0
|
||||
&& ex.c_name != NULL && strcmp(ex.c_name, exs[i].c_name) == 0
|
||||
&& ex.c_sig != NULL && strcmp(ex.c_sig, exs[i].c_sig) == 0
|
||||
&& ex.t_loc == exs[i].t_loc && ex.c_loc == exs[i].c_loc) {
|
||||
eventsCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == sizeof(exs)/sizeof(exceptionInfo)) {
|
||||
printf("Unexpected exception event:\n");
|
||||
printf(" %s\n", ex.name);
|
||||
printf(" thrown at %s.%s%s:0x%x%08x\n",
|
||||
ex.t_cls, ex.t_name, ex.t_sig,
|
||||
(jint)(ex.t_loc >> 32), (jint)ex.t_loc);
|
||||
printf(" catch at %s.%s%s:0x%x%08x\n",
|
||||
ex.c_cls, ex.c_name, ex.c_sig,
|
||||
(jint)(ex.c_loc >> 32), (jint)ex.c_loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_exception001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_exception001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_exception001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_exception_events) {
|
||||
callbacks.Exception = &Exception;
|
||||
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: Exception event is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_Exception_exception001_check(JNIEnv *env, jclass cls) {
|
||||
jvmtiError err;
|
||||
jthread thread;
|
||||
jclass clz;
|
||||
jmethodID mid;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (!caps.can_generate_exception_events) {
|
||||
return result;
|
||||
}
|
||||
|
||||
clz = env->FindClass("nsk/jvmti/Exception/exception001c");
|
||||
if (clz == NULL) {
|
||||
printf("Cannot find exception001c class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
clz = env->FindClass("nsk/jvmti/Exception/exception001b");
|
||||
if (clz == NULL) {
|
||||
printf("Cannot find exception001b class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
clz = env->FindClass("nsk/jvmti/Exception/exception001a");
|
||||
if (clz == NULL) {
|
||||
printf("Cannot find exception001a class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
mid = env->GetStaticMethodID(clz, "run", "()V");
|
||||
if (mid == NULL) {
|
||||
printf("Cannot find method run!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti->GetCurrentThread(&thread);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to get current thread: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_EXCEPTION, thread);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected = sizeof(exs)/sizeof(exceptionInfo);
|
||||
} else {
|
||||
printf("Failed to enable JVMTI_EVENT_EXCEPTION: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
env->CallStaticVoidMethod(clz, mid);
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE,
|
||||
JVMTI_EVENT_EXCEPTION, thread);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to disable JVMTI_EVENT_EXCEPTION: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of exception events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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/Exception;
|
||||
|
||||
/* Reassembled from the following Java pattern:
|
||||
*
|
||||
* public class exception001a {
|
||||
* public static void run() {
|
||||
* exception001b t = new exception001b();
|
||||
* try {
|
||||
* t.meth1();
|
||||
* } catch (Throwable e) {}
|
||||
* try {
|
||||
* t.meth2(0);
|
||||
* } catch (Throwable e) {}
|
||||
* try {
|
||||
* t.meth3(2);
|
||||
* } catch (Throwable e) {}
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class exception001b {
|
||||
* public static void meth1() throws Throwable {
|
||||
* throw new exception001c();
|
||||
* }
|
||||
*
|
||||
* public int meth2(int i) throws ArithmeticException {
|
||||
* return (10 / i);
|
||||
* }
|
||||
*
|
||||
* public int meth3(int i) throws IndexOutOfBoundsException {
|
||||
* int arr[] = {1};
|
||||
* return arr[i];
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class exception001c extends Throwable {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
super public class exception001a {
|
||||
|
||||
public Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
public static Method run:"()V" stack 2 locals 2 {
|
||||
new class exception001b;
|
||||
dup;
|
||||
invokespecial Method exception001b."<init>":"()V";
|
||||
astore_0;
|
||||
try t0;
|
||||
invokestatic Method exception001b.meth1:"()V";
|
||||
endtry t0;
|
||||
goto L15;
|
||||
catch t0 java/lang/Throwable; // bci=14
|
||||
astore_1;
|
||||
try t1;
|
||||
L15: aload_0;
|
||||
iconst_0;
|
||||
invokevirtual Method exception001b.meth2:"(I)I";
|
||||
pop;
|
||||
endtry t1;
|
||||
goto L25;
|
||||
catch t1 java/lang/Throwable; // bci=24
|
||||
astore_1;
|
||||
try t2;
|
||||
L25: aload_0;
|
||||
iconst_2;
|
||||
invokevirtual Method exception001b.meth3:"(I)I";
|
||||
pop;
|
||||
endtry t2;
|
||||
goto L35;
|
||||
catch t2 java/lang/Throwable; // bci=34
|
||||
astore_1;
|
||||
L35: return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
super class exception001b {
|
||||
|
||||
Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
public static Method meth1:"()V"
|
||||
throws java/lang/Throwable
|
||||
stack 2 locals 0 {
|
||||
new class exception001c;
|
||||
dup;
|
||||
invokespecial Method exception001c."<init>":"()V";
|
||||
athrow; // bci=7
|
||||
}
|
||||
|
||||
public Method meth2:"(I)I"
|
||||
throws java/lang/ArithmeticException
|
||||
stack 2 locals 2 {
|
||||
bipush 10;
|
||||
iload_1;
|
||||
idiv; // bci=3
|
||||
ireturn;
|
||||
}
|
||||
|
||||
public Method meth3:"(I)I"
|
||||
throws java/lang/IndexOutOfBoundsException
|
||||
stack 4 locals 3 {
|
||||
iconst_1;
|
||||
newarray int;
|
||||
dup;
|
||||
iconst_0;
|
||||
iconst_1;
|
||||
iastore;
|
||||
astore_2;
|
||||
aload_2;
|
||||
iload_1;
|
||||
iaload; // bci=10
|
||||
ireturn;
|
||||
}
|
||||
}
|
||||
|
||||
super class exception001c extends java/lang/Throwable {
|
||||
|
||||
Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Throwable."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "exception001.cpp"
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.ExceptionCatch;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class excatch001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("excatch001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load excatch001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static int check();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -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/ExceptionCatch/excatch001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function ExceptionCatch.
|
||||
* The test checks if the parameters of the function contain the
|
||||
* expected values for the following exceptions thrown by Java methods:
|
||||
* - custom class exception001c extending Throwable
|
||||
* - ArithmeticException caused by division with zero devisor
|
||||
* - IndexOutOfBoundsException caused by using out of range array index
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @compile excatch001a.jasm
|
||||
* @run main/othervm/native -agentlib:excatch001 nsk.jvmti.ExceptionCatch.excatch001
|
||||
*/
|
||||
|
||||
@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *c_cls;
|
||||
char *c_name;
|
||||
char *c_sig;
|
||||
jlocation c_loc;
|
||||
} writable_exceptionInfo;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *c_cls;
|
||||
const char *c_name;
|
||||
const char *c_sig;
|
||||
jlocation c_loc;
|
||||
} exceptionInfo;
|
||||
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jvmtiCapabilities caps;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static exceptionInfo exs[] = {
|
||||
{ "Lnsk/jvmti/ExceptionCatch/excatch001c;",
|
||||
"Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 14 },
|
||||
{ "Ljava/lang/ArithmeticException;",
|
||||
"Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 24 },
|
||||
{ "Ljava/lang/ArrayIndexOutOfBoundsException;",
|
||||
"Lnsk/jvmti/ExceptionCatch/excatch001a;", "run", "()V", 34 }
|
||||
};
|
||||
static int eventsCount = 0;
|
||||
static int eventsExpected = 0;
|
||||
|
||||
void JNICALL
|
||||
ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr,
|
||||
jmethodID method, jlocation location, jobject exception) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
writable_exceptionInfo ex;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving ExceptionCatch info ...\n");
|
||||
}
|
||||
cls = env->GetObjectClass(exception);
|
||||
err = jvmti_env->GetClassSignature(cls, &ex.name, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature#e) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls, &ex.c_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature#c) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method,
|
||||
&ex.c_name, &ex.c_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
ex.c_loc = location;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> %s\n", ex.name);
|
||||
printf(">>> catch at %s.%s%s:0x%x%08x\n",
|
||||
ex.c_cls, ex.c_name, ex.c_sig,
|
||||
(jint)(ex.c_loc >> 32), (jint)ex.c_loc);
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(exs)/sizeof(exceptionInfo); i++) {
|
||||
if (ex.name != NULL && strcmp(ex.name, exs[i].name) == 0
|
||||
&& ex.c_cls != NULL && strcmp(ex.c_cls, exs[i].c_cls) == 0
|
||||
&& ex.c_name != NULL && strcmp(ex.c_name, exs[i].c_name) == 0
|
||||
&& ex.c_sig != NULL && strcmp(ex.c_sig, exs[i].c_sig) == 0
|
||||
&& ex.c_loc == exs[i].c_loc) {
|
||||
eventsCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == sizeof(exs)/sizeof(exceptionInfo)) {
|
||||
printf("Unexpected exception catch event:\n");
|
||||
printf(" %s\n", ex.name);
|
||||
printf(" catch at %s.%s%s:0x%x%08x\n",
|
||||
ex.c_cls, ex.c_name, ex.c_sig,
|
||||
(jint)(ex.c_loc >> 32), (jint)ex.c_loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_excatch001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_excatch001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_excatch001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_exception_events) {
|
||||
callbacks.ExceptionCatch = &ExceptionCatch;
|
||||
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: Exception event is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_ExceptionCatch_excatch001_check(JNIEnv *env, jclass cls) {
|
||||
jvmtiError err;
|
||||
jclass clz;
|
||||
jmethodID mid;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (!caps.can_generate_exception_events) {
|
||||
return result;
|
||||
}
|
||||
|
||||
clz = env->FindClass("nsk/jvmti/ExceptionCatch/excatch001c");
|
||||
if (clz == NULL) {
|
||||
printf("Cannot find excatch001c class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
clz = env->FindClass("nsk/jvmti/ExceptionCatch/excatch001b");
|
||||
if (clz == NULL) {
|
||||
printf("Cannot find excatch001b class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
clz = env->FindClass("nsk/jvmti/ExceptionCatch/excatch001a");
|
||||
if (clz == NULL) {
|
||||
printf("Cannot find excatch001a class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
mid = env->GetStaticMethodID(clz, "run", "()V");
|
||||
if (mid == NULL) {
|
||||
printf("Cannot find method run!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_EXCEPTION_CATCH, NULL);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected = sizeof(exs)/sizeof(exceptionInfo);
|
||||
} else {
|
||||
printf("Failed to enable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
env->CallStaticVoidMethod(clz, mid);
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE,
|
||||
JVMTI_EVENT_EXCEPTION_CATCH, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to disable JVMTI_EVENT_EXCEPTION_CATCH: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of exception catch events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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/ExceptionCatch;
|
||||
|
||||
/* Reassembled from the following Java pattern:
|
||||
*
|
||||
* public class excatch001a {
|
||||
* public static void run() {
|
||||
* excatch001b t = new excatch001b();
|
||||
* try {
|
||||
* t.meth1();
|
||||
* } catch (Throwable e) {}
|
||||
* try {
|
||||
* t.meth2(0);
|
||||
* } catch (Throwable e) {}
|
||||
* try {
|
||||
* t.meth3(2);
|
||||
* } catch (Throwable e) {}
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class excatch001b {
|
||||
* public static void meth1() throws Throwable {
|
||||
* throw new excatch001c();
|
||||
* }
|
||||
*
|
||||
* public int meth2(int i) throws ArithmeticException {
|
||||
* return (10 / i);
|
||||
* }
|
||||
*
|
||||
* public int meth3(int i) throws IndexOutOfBoundsException {
|
||||
* int arr[] = {1};
|
||||
* return arr[i];
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class excatch001c extends Throwable {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
super public class excatch001a {
|
||||
|
||||
public Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
public static Method run:"()V" stack 2 locals 2 {
|
||||
new class excatch001b;
|
||||
dup;
|
||||
invokespecial Method excatch001b."<init>":"()V";
|
||||
astore_0;
|
||||
try t0;
|
||||
invokestatic Method excatch001b.meth1:"()V";
|
||||
endtry t0;
|
||||
goto L15;
|
||||
catch t0 java/lang/Throwable; // bci=14
|
||||
astore_1;
|
||||
try t1;
|
||||
L15: aload_0;
|
||||
iconst_0;
|
||||
invokevirtual Method excatch001b.meth2:"(I)I";
|
||||
pop;
|
||||
endtry t1;
|
||||
goto L25;
|
||||
catch t1 java/lang/Throwable; // bci=24
|
||||
astore_1;
|
||||
try t2;
|
||||
L25: aload_0;
|
||||
iconst_2;
|
||||
invokevirtual Method excatch001b.meth3:"(I)I";
|
||||
pop;
|
||||
endtry t2;
|
||||
goto L35;
|
||||
catch t2 java/lang/Throwable; // bci=34
|
||||
astore_1;
|
||||
L35: return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
super class excatch001b {
|
||||
|
||||
Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
public static Method meth1:"()V"
|
||||
throws java/lang/Throwable
|
||||
stack 2 locals 0 {
|
||||
new class excatch001c;
|
||||
dup;
|
||||
invokespecial Method excatch001c."<init>":"()V";
|
||||
athrow; // bci=7
|
||||
}
|
||||
|
||||
public Method meth2:"(I)I"
|
||||
throws java/lang/ArithmeticException
|
||||
stack 2 locals 2 {
|
||||
bipush 10;
|
||||
iload_1;
|
||||
idiv; // bci=3
|
||||
ireturn;
|
||||
}
|
||||
|
||||
public Method meth3:"(I)I"
|
||||
throws java/lang/IndexOutOfBoundsException
|
||||
stack 4 locals 3 {
|
||||
iconst_1;
|
||||
newarray int;
|
||||
dup;
|
||||
iconst_0;
|
||||
iconst_1;
|
||||
iastore;
|
||||
astore_2;
|
||||
aload_2;
|
||||
iload_1;
|
||||
iaload; // bci=10
|
||||
ireturn;
|
||||
}
|
||||
}
|
||||
|
||||
super class excatch001c extends java/lang/Throwable {
|
||||
|
||||
Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Throwable."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "excatch001.cpp"
|
||||
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FieldAccess;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class fieldacc001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("fieldacc001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load fieldacc001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady();
|
||||
native static int check();
|
||||
|
||||
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) {
|
||||
getReady();
|
||||
fieldacc001a t = new fieldacc001a();
|
||||
t.run();
|
||||
return check();
|
||||
}
|
||||
}
|
||||
@ -1,44 +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/FieldAccess/fieldacc001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function FieldAccess.
|
||||
* The test checks if the parameters of the function contain the
|
||||
* expected values.
|
||||
* COMMENTS
|
||||
* Fixed according to 4669812 bug.
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @compile fieldacc001a.jasm
|
||||
* @run main/othervm/native -agentlib:fieldacc001 nsk.jvmti.FieldAccess.fieldacc001
|
||||
*/
|
||||
|
||||
@ -1,360 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
char *m_cls;
|
||||
char *m_name;
|
||||
char *m_sig;
|
||||
jlocation loc;
|
||||
char *f_cls;
|
||||
char *f_name;
|
||||
char *f_sig;
|
||||
jboolean is_static;
|
||||
} writable_watch_info;
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
const char *m_cls;
|
||||
const char *m_name;
|
||||
const char *m_sig;
|
||||
jlocation loc;
|
||||
const char *f_cls;
|
||||
const char *f_name;
|
||||
const char *f_sig;
|
||||
jboolean is_static;
|
||||
} watch_info;
|
||||
|
||||
static jvmtiEnv *jvmti;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static int eventsExpected = 0;
|
||||
static int eventsCount = 0;
|
||||
static watch_info watches[] = {
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 2,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticBoolean", "Z", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 6,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceBoolean", "Z", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 15,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticByte", "B", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 19,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceByte", "B", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 28,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticShort", "S", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 32,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceShort", "S", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 41,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticInt", "I", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 45,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceInt", "I", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 54,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticLong", "J", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 58,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceLong", "J", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 68,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticFloat", "F", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 72,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceFloat", "F", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 82,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticDouble", "D", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 86,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceDouble", "D", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 96,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticChar", "C", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 100,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceChar", "C", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 109,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 113,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 122,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "staticArrInt", "[I", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc001a;", "run", "()I", 128,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc001a;", "instanceArrInt", "[I", JNI_FALSE }
|
||||
};
|
||||
|
||||
|
||||
void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method,
|
||||
jlocation location, jclass field_klass, jobject obj, jfieldID field) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
writable_watch_info watch;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
eventsCount++;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving access watch info ...\n");
|
||||
}
|
||||
watch.fid = field;
|
||||
watch.loc = location;
|
||||
watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE;
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls,
|
||||
&watch.m_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method,
|
||||
&watch.m_name, &watch.m_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(field_klass,
|
||||
&watch.f_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFieldName(field_klass, field,
|
||||
&watch.f_name, &watch.f_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFieldName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", watch.m_cls);
|
||||
printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig);
|
||||
printf(">>> location: 0x%x%08x\n",
|
||||
(jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(">>> field cls: \"%s\"\n", watch.f_cls);
|
||||
printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig);
|
||||
printf(">>> object: 0x%p\n", obj);
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watch.fid == watches[i].fid) {
|
||||
if (watch.m_cls == NULL ||
|
||||
strcmp(watch.m_cls, watches[i].m_cls) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n",
|
||||
i, watch.m_cls, watches[i].m_cls);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_name == NULL ||
|
||||
strcmp(watch.m_name, watches[i].m_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"",
|
||||
i, watch.m_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_sig == NULL ||
|
||||
strcmp(watch.m_sig, watches[i].m_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"",
|
||||
i, watch.m_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.loc != watches[i].loc) {
|
||||
printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x",
|
||||
i, (jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(", expected: 0x%x%08x\n",
|
||||
(jint)(watches[i].loc >> 32), (jint)watches[i].loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_name == NULL ||
|
||||
strcmp(watch.f_name, watches[i].f_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"",
|
||||
i, watch.f_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_sig == NULL ||
|
||||
strcmp(watch.f_sig, watches[i].f_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"",
|
||||
i, watch.f_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.is_static != watches[i].is_static) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field type: %s", i,
|
||||
(watch.is_static == JNI_TRUE) ? "static" : "instance");
|
||||
printf(", expected: %s\n",
|
||||
(watches[i].is_static == JNI_TRUE) ? "static" : "instance");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("Unexpected field access catched: 0x%p\n", watch.fid);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_fieldacc001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_field_access_events) {
|
||||
callbacks.FieldAccess = &FieldAccess;
|
||||
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_FIELD_ACCESS, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: FieldAccess watch is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_FieldAccess_fieldacc001_getReady(JNIEnv *env, jclass klass) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
size_t i;
|
||||
|
||||
if (!caps.can_generate_field_access_events) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> setting field access watches ...\n");
|
||||
}
|
||||
cls = env->FindClass("nsk/jvmti/FieldAccess/fieldacc001a");
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find fieldacc001a class!\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watches[i].is_static == JNI_TRUE) {
|
||||
watches[i].fid = env->GetStaticFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
} else {
|
||||
watches[i].fid = env->GetFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
}
|
||||
if (watches[i].fid == NULL) {
|
||||
printf("Cannot find field \"%s\"!\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti->SetFieldAccessWatch(cls, watches[i].fid);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_FieldAccess_fieldacc001_check(JNIEnv *env, jclass cls) {
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of field access events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,193 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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/FieldAccess;
|
||||
|
||||
super public class fieldacc001a {
|
||||
|
||||
static Field staticBoolean:Z;
|
||||
static Field staticByte:B;
|
||||
static Field staticShort:S;
|
||||
static Field staticInt:I;
|
||||
static Field staticLong:J;
|
||||
static Field staticFloat:F;
|
||||
static Field staticDouble:D;
|
||||
static Field staticChar:C;
|
||||
static Field staticObject:"Ljava/lang/Object;";
|
||||
static Field staticArrInt:"[I";
|
||||
Field instanceBoolean:Z;
|
||||
Field instanceByte:B;
|
||||
Field instanceShort:S;
|
||||
Field instanceInt:I;
|
||||
Field instanceLong:J;
|
||||
Field instanceFloat:F;
|
||||
Field instanceDouble:D;
|
||||
Field instanceChar:C;
|
||||
Field instanceObject:"Ljava/lang/Object;";
|
||||
Field instanceArrInt:"[I";
|
||||
|
||||
public Method "<init>":"()V" stack 5 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
aload_0;
|
||||
iconst_0;
|
||||
putfield Field instanceBoolean:"Z";
|
||||
aload_0;
|
||||
bipush 10;
|
||||
putfield Field instanceByte:"B";
|
||||
aload_0;
|
||||
bipush 20;
|
||||
putfield Field instanceShort:"S";
|
||||
aload_0;
|
||||
bipush 30;
|
||||
putfield Field instanceInt:"I";
|
||||
aload_0;
|
||||
ldc2_w long 40l;
|
||||
putfield Field instanceLong:"J";
|
||||
aload_0;
|
||||
ldc float 0.05f;
|
||||
putfield Field instanceFloat:"F";
|
||||
aload_0;
|
||||
ldc2_w double 0.06d;
|
||||
putfield Field instanceDouble:"D";
|
||||
aload_0;
|
||||
bipush 122;
|
||||
putfield Field instanceChar:"C";
|
||||
aload_0;
|
||||
new class java/lang/Object;
|
||||
dup;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
putfield Field instanceObject:"Ljava/lang/Object;";
|
||||
aload_0;
|
||||
iconst_2;
|
||||
newarray int;
|
||||
dup;
|
||||
iconst_0;
|
||||
bipush 70;
|
||||
iastore;
|
||||
dup;
|
||||
iconst_1;
|
||||
bipush 80;
|
||||
iastore;
|
||||
putfield Field instanceArrInt:"[I";
|
||||
return;
|
||||
}
|
||||
|
||||
public Method run:"()I" stack 4 locals 2 {
|
||||
iconst_0;
|
||||
istore_1;
|
||||
getstatic Field staticBoolean:"Z"; // bci=2
|
||||
aload_0;
|
||||
getfield Field instanceBoolean:"Z"; // bci=6
|
||||
if_icmpne L15;
|
||||
iinc 1, 1;
|
||||
L15: getstatic Field staticByte:"B"; // bci=15
|
||||
aload_0;
|
||||
getfield Field instanceByte:"B"; // bci=19
|
||||
if_icmpne L28;
|
||||
iinc 1, 1;
|
||||
L28: getstatic Field staticShort:"S"; // bci=28
|
||||
aload_0;
|
||||
getfield Field instanceShort:"S"; // bci=32
|
||||
if_icmpne L41;
|
||||
iinc 1, 1;
|
||||
L41: getstatic Field staticInt:"I"; // bci=41
|
||||
aload_0;
|
||||
getfield Field instanceInt:"I"; // bci=45
|
||||
if_icmpne L54;
|
||||
iinc 1, 1;
|
||||
L54: getstatic Field staticLong:"J"; // bci=54
|
||||
aload_0;
|
||||
getfield Field instanceLong:"J"; // bci=58
|
||||
lcmp;
|
||||
ifne L68;
|
||||
iinc 1, 1;
|
||||
L68: getstatic Field staticFloat:"F"; // bci=68
|
||||
aload_0;
|
||||
getfield Field instanceFloat:"F"; // bci=72
|
||||
fcmpl;
|
||||
ifne L82;
|
||||
iinc 1, 1;
|
||||
L82: getstatic Field staticDouble:"D"; // bci=82
|
||||
aload_0;
|
||||
getfield Field instanceDouble:"D"; // bci=86
|
||||
dcmpl;
|
||||
ifne L96;
|
||||
iinc 1, 1;
|
||||
L96: getstatic Field staticChar:"C"; // bci=96
|
||||
aload_0;
|
||||
getfield Field instanceChar:"C"; // bci=100
|
||||
if_icmpne L109;
|
||||
iinc 1, 1;
|
||||
L109: getstatic Field staticObject:"Ljava/lang/Object;"; // bci=109
|
||||
aload_0;
|
||||
getfield Field instanceObject:"Ljava/lang/Object;"; // bci=113
|
||||
if_acmpne L122;
|
||||
iinc 1, 1;
|
||||
L122: getstatic Field staticArrInt:"[I"; // bci=122
|
||||
iconst_0;
|
||||
iaload;
|
||||
aload_0;
|
||||
getfield Field instanceArrInt:"[I"; // bci=128
|
||||
iconst_1;
|
||||
iaload;
|
||||
if_icmpne L139;
|
||||
iinc 1, 1;
|
||||
L139: iload_1;
|
||||
ireturn;
|
||||
}
|
||||
|
||||
static Method "<clinit>":"()V" stack 4 locals 0 {
|
||||
iconst_1;
|
||||
putstatic Field staticBoolean:"Z";
|
||||
iconst_1;
|
||||
putstatic Field staticByte:"B";
|
||||
iconst_2;
|
||||
putstatic Field staticShort:"S";
|
||||
iconst_3;
|
||||
putstatic Field staticInt:"I";
|
||||
ldc2_w long 4l;
|
||||
putstatic Field staticLong:"J";
|
||||
ldc float 0.5f;
|
||||
putstatic Field staticFloat:"F";
|
||||
ldc2_w double 0.6d;
|
||||
putstatic Field staticDouble:"D";
|
||||
bipush 97;
|
||||
putstatic Field staticChar:"C";
|
||||
aconst_null;
|
||||
putstatic Field staticObject:"Ljava/lang/Object;";
|
||||
iconst_2;
|
||||
newarray int;
|
||||
dup;
|
||||
iconst_0;
|
||||
bipush 7;
|
||||
iastore;
|
||||
dup;
|
||||
iconst_1;
|
||||
bipush 8;
|
||||
iastore;
|
||||
putstatic Field staticArrInt:"[I";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "fieldacc001.cpp"
|
||||
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FieldAccess;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class fieldacc002 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("fieldacc002");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load fieldacc002 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady();
|
||||
native static int check(Object obj);
|
||||
|
||||
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) {
|
||||
fieldacc002a t = new fieldacc002a();
|
||||
getReady();
|
||||
return check(t);
|
||||
}
|
||||
}
|
||||
|
||||
class fieldacc002a {
|
||||
static boolean staticBoolean = true;
|
||||
static byte staticByte = 1;
|
||||
static short staticShort = 2;
|
||||
static int staticInt = 3;
|
||||
static long staticLong = 4;
|
||||
static float staticFloat = 0.5F;
|
||||
static double staticDouble = 0.6;
|
||||
static char staticChar = '\u0007';
|
||||
static Object staticObject = new Object();
|
||||
static int staticArrInt[] = {8};
|
||||
|
||||
boolean instanceBoolean = false;
|
||||
byte instanceByte = 10;
|
||||
short instanceShort = 20;
|
||||
int instanceInt = 30;
|
||||
long instanceLong = 40;
|
||||
float instanceFloat = 0.05F;
|
||||
double instanceDouble = 0.06;
|
||||
char instanceChar = '\u0070';
|
||||
Object instanceObject = new Object();
|
||||
int instanceArrInt[] = {80};
|
||||
}
|
||||
@ -1,43 +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/FieldAccess/fieldacc002.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function FieldAccess.
|
||||
* The test checks if the parameters of the function contain the
|
||||
* expected values for fields accessed from JNI code.
|
||||
* COMMENTS
|
||||
* Fixed according to 4669812 bug.
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:fieldacc002 nsk.jvmti.FieldAccess.fieldacc002
|
||||
*/
|
||||
|
||||
@ -1,401 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
char *m_cls;
|
||||
char *m_name;
|
||||
char *m_sig;
|
||||
jlocation loc;
|
||||
char *f_cls;
|
||||
char *f_name;
|
||||
char *f_sig;
|
||||
jboolean is_static;
|
||||
} writable_watch_info;
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
const char *m_cls;
|
||||
const char *m_name;
|
||||
const char *m_sig;
|
||||
jlocation loc;
|
||||
const char *f_cls;
|
||||
const char *f_name;
|
||||
const char *f_sig;
|
||||
jboolean is_static;
|
||||
} watch_info;
|
||||
|
||||
static jvmtiEnv *jvmti;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static int eventsExpected = 0;
|
||||
static int eventsCount = 0;
|
||||
static watch_info watches[] = {
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticBoolean", "Z", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticByte", "B", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticShort", "S", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticInt", "I", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticLong", "J", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticFloat", "F", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticDouble", "D", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticChar", "C", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "staticArrInt", "[I", JNI_TRUE },
|
||||
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceBoolean", "Z", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceByte", "B", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceShort", "S", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceInt", "I", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceLong", "J", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceFloat", "F", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceDouble", "D", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceChar", "C", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc002a;", "instanceArrInt", "[I", JNI_FALSE }
|
||||
};
|
||||
|
||||
void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method,
|
||||
jlocation location, jclass field_klass, jobject obj, jfieldID field) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
writable_watch_info watch;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
eventsCount++;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving access watch info ...\n");
|
||||
}
|
||||
watch.fid = field;
|
||||
watch.loc = location;
|
||||
watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE;
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls,
|
||||
&watch.m_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method,
|
||||
&watch.m_name, &watch.m_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(field_klass,
|
||||
&watch.f_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFieldName(field_klass, field,
|
||||
&watch.f_name, &watch.f_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFieldName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", watch.m_cls);
|
||||
printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig);
|
||||
printf(">>> location: 0x%x%08x\n",
|
||||
(jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(">>> field cls: \"%s\"\n", watch.f_cls);
|
||||
printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig);
|
||||
printf(">>> object: 0x%p\n", obj);
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watch.fid == watches[i].fid) {
|
||||
if (watch.m_cls == NULL ||
|
||||
strcmp(watch.m_cls, watches[i].m_cls) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n",
|
||||
i, watch.m_cls, watches[i].m_cls);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_name == NULL ||
|
||||
strcmp(watch.m_name, watches[i].m_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"",
|
||||
i, watch.m_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_sig == NULL ||
|
||||
strcmp(watch.m_sig, watches[i].m_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"",
|
||||
i, watch.m_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.loc != watches[i].loc) {
|
||||
printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x",
|
||||
i, (jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(", expected: 0x%x%08x\n",
|
||||
(jint)(watches[i].loc >> 32), (jint)watches[i].loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_name == NULL ||
|
||||
strcmp(watch.f_name, watches[i].f_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"",
|
||||
i, watch.f_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_sig == NULL ||
|
||||
strcmp(watch.f_sig, watches[i].f_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"",
|
||||
i, watch.f_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.is_static != watches[i].is_static) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field type: %s", i,
|
||||
(watch.is_static == JNI_TRUE) ? "static" : "instance");
|
||||
printf(", expected: %s\n",
|
||||
(watches[i].is_static == JNI_TRUE) ? "static" : "instance");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("Unexpected field access catched: 0x%p\n", watch.fid);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_fieldacc002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_field_access_events) {
|
||||
callbacks.FieldAccess = &FieldAccess;
|
||||
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_FIELD_ACCESS, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: FieldAccess watch is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_nsk_jvmti_FieldAccess_fieldacc002_getReady(JNIEnv *env, jclass clz) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
size_t i;
|
||||
|
||||
if (!caps.can_generate_field_access_events) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> setting field access watches ...\n");
|
||||
}
|
||||
|
||||
cls = env->FindClass("nsk/jvmti/FieldAccess/fieldacc002a");
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find fieldacc002a class!\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watches[i].is_static == JNI_TRUE) {
|
||||
watches[i].fid = env->GetStaticFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
} else {
|
||||
watches[i].fid = env->GetFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
}
|
||||
if (watches[i].fid == NULL) {
|
||||
printf("Cannot find field \"%s\"!\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti->SetFieldAccessWatch(cls, watches[i].fid);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_FieldAccess_fieldacc002_check(JNIEnv *env, jclass clz, jobject obj) {
|
||||
jclass cls;
|
||||
|
||||
if (!caps.can_generate_field_access_events) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> accessing fields ...\n");
|
||||
}
|
||||
|
||||
cls = env->FindClass("nsk/jvmti/FieldAccess/fieldacc002a");
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find fieldacc002a class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
env->GetStaticBooleanField(cls, watches[0].fid);
|
||||
env->GetStaticByteField(cls, watches[1].fid);
|
||||
env->GetStaticShortField(cls, watches[2].fid);
|
||||
env->GetStaticIntField(cls, watches[3].fid);
|
||||
env->GetStaticLongField(cls, watches[4].fid);
|
||||
env->GetStaticFloatField(cls, watches[5].fid);
|
||||
env->GetStaticDoubleField(cls, watches[6].fid);
|
||||
env->GetStaticCharField(cls, watches[7].fid);
|
||||
env->GetStaticObjectField(cls, watches[8].fid);
|
||||
env->GetStaticObjectField(cls, watches[9].fid);
|
||||
|
||||
env->GetBooleanField(obj, watches[10].fid);
|
||||
env->GetByteField(obj, watches[11].fid);
|
||||
env->GetShortField(obj, watches[12].fid);
|
||||
env->GetIntField(obj, watches[13].fid);
|
||||
env->GetLongField(obj, watches[14].fid);
|
||||
env->GetFloatField(obj, watches[15].fid);
|
||||
env->GetDoubleField(obj, watches[16].fid);
|
||||
env->GetCharField(obj, watches[17].fid);
|
||||
env->GetObjectField(obj, watches[18].fid);
|
||||
env->GetObjectField(obj, watches[19].fid);
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of field access events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "fieldacc002.cpp"
|
||||
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FieldAccess;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class fieldacc003 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("fieldacc003");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load fieldacc003 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady();
|
||||
native static int check();
|
||||
|
||||
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) {
|
||||
getReady();
|
||||
fieldacc003a t = new fieldacc003a();
|
||||
t.run();
|
||||
return check();
|
||||
}
|
||||
}
|
||||
|
||||
class fieldacc003e {
|
||||
boolean extendsBoolean = false;
|
||||
byte extendsByte = 10;
|
||||
short extendsShort = 20;
|
||||
int extendsInt = 30;
|
||||
long extendsLong = 40;
|
||||
float extendsFloat = 0.05F;
|
||||
double extendsDouble = 0.06;
|
||||
char extendsChar = 'D';
|
||||
Object extendsObject = new Object();
|
||||
int extendsArrInt[] = {70, 80};
|
||||
}
|
||||
|
||||
class fieldacc003a extends fieldacc003e {
|
||||
public int run() {
|
||||
int i = 0;
|
||||
if (extendsBoolean == true) i++;
|
||||
if (extendsByte == 1) i++;
|
||||
if (extendsShort == 2) i++;
|
||||
if (extendsInt == 3) i++;
|
||||
if (extendsLong == 4) i++;
|
||||
if (extendsFloat == 0.5F) i++;
|
||||
if (extendsDouble == 0.6) i++;
|
||||
if (extendsChar == 'C') i++;
|
||||
if (extendsObject == this) i++;
|
||||
if (extendsArrInt[1] == 7) i++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -1,44 +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/FieldAccess/fieldacc003.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function FieldAccess.
|
||||
* The test sets access watches on fields which are defined in
|
||||
* superclass, then triggers access watch events on these fields
|
||||
* and checks if clazz, method, location, field_clazz, field and
|
||||
* object parameters the function contain the expected values.
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:fieldacc003 nsk.jvmti.FieldAccess.fieldacc003
|
||||
*/
|
||||
|
||||
@ -1,339 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
char *m_cls;
|
||||
char *m_name;
|
||||
char *m_sig;
|
||||
jlocation loc;
|
||||
char *f_cls;
|
||||
char *f_name;
|
||||
char *f_sig;
|
||||
jboolean is_static;
|
||||
} writable_watch_info;
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
const char *m_cls;
|
||||
const char *m_name;
|
||||
const char *m_sig;
|
||||
jlocation loc;
|
||||
const char *f_cls;
|
||||
const char *f_name;
|
||||
const char *f_sig;
|
||||
jboolean is_static;
|
||||
} watch_info;
|
||||
|
||||
static jvmtiEnv *jvmti;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static int eventsExpected = 0;
|
||||
static int eventsCount = 0;
|
||||
static watch_info watches[] = {
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 3,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsBoolean", "Z", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 14,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsByte", "B", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 25,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsShort", "S", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 36,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsInt", "I", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 47,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsLong", "J", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 61,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsFloat", "F", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 74,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsDouble", "D", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 88,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsChar", "C", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 100,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsObject", "Ljava/lang/Object;", JNI_FALSE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc003a;", "run", "()I", 111,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc003a;", "extendsArrInt", "[I", JNI_FALSE }
|
||||
};
|
||||
|
||||
void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method,
|
||||
jlocation location, jclass field_klass, jobject obj, jfieldID field) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
writable_watch_info watch;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
eventsCount++;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving access watch info ...\n");
|
||||
}
|
||||
watch.fid = field;
|
||||
watch.loc = location;
|
||||
watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE;
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls,
|
||||
&watch.m_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method,
|
||||
&watch.m_name, &watch.m_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(field_klass,
|
||||
&watch.f_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFieldName(field_klass, field,
|
||||
&watch.f_name, &watch.f_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFieldName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", watch.m_cls);
|
||||
printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig);
|
||||
printf(">>> location: 0x%x%08x\n",
|
||||
(jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(">>> field cls: \"%s\"\n", watch.f_cls);
|
||||
printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig);
|
||||
printf(">>> object: 0x%p\n", obj);
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watch.fid == watches[i].fid) {
|
||||
if (watch.m_cls == NULL ||
|
||||
strcmp(watch.m_cls, watches[i].m_cls) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n",
|
||||
i, watch.m_cls, watches[i].m_cls);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_name == NULL ||
|
||||
strcmp(watch.m_name, watches[i].m_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"",
|
||||
i, watch.m_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_sig == NULL ||
|
||||
strcmp(watch.m_sig, watches[i].m_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"",
|
||||
i, watch.m_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.loc != watches[i].loc) {
|
||||
printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x",
|
||||
i, (jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(", expected: 0x%x%08x\n",
|
||||
(jint)(watches[i].loc >> 32), (jint)watches[i].loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_name == NULL ||
|
||||
strcmp(watch.f_name, watches[i].f_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"",
|
||||
i, watch.f_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_sig == NULL ||
|
||||
strcmp(watch.f_sig, watches[i].f_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"",
|
||||
i, watch.f_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.is_static != watches[i].is_static) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field type: %s", i,
|
||||
(watch.is_static == JNI_TRUE) ? "static" : "instance");
|
||||
printf(", expected: %s\n",
|
||||
(watches[i].is_static == JNI_TRUE) ? "static" : "instance");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("Unexpected field access catched: 0x%p\n", watch.fid);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_fieldacc003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_field_access_events) {
|
||||
callbacks.FieldAccess = &FieldAccess;
|
||||
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_FIELD_ACCESS, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: FieldAccess watch is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_FieldAccess_fieldacc003_getReady(JNIEnv *env, jclass klass) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
size_t i;
|
||||
|
||||
if (!caps.can_generate_field_access_events) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> setting field access watches ...\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
cls = env->FindClass(watches[i].f_cls);
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find %s class!\n", watches[i].f_cls);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (watches[i].is_static == JNI_TRUE) {
|
||||
watches[i].fid = env->GetStaticFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
} else {
|
||||
watches[i].fid = env->GetFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
}
|
||||
if (watches[i].fid == NULL) {
|
||||
printf("Cannot get field ID for \"%s:%s\"\n",
|
||||
watches[i].f_name, watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti->SetFieldAccessWatch(cls, watches[i].fid);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_FieldAccess_fieldacc003_check(JNIEnv *env, jclass cls) {
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of field access events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "fieldacc003.cpp"
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FieldAccess;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class fieldacc004 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("fieldacc004");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load fieldacc004 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady();
|
||||
native static int check();
|
||||
|
||||
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) {
|
||||
getReady();
|
||||
fieldacc004a t = new fieldacc004a();
|
||||
t.run();
|
||||
return check();
|
||||
}
|
||||
}
|
||||
|
||||
interface fieldacc004i {
|
||||
static Object interfaceObject = new Object();
|
||||
static int interfaceArrInt[] = {1, 2};
|
||||
}
|
||||
|
||||
class fieldacc004a implements fieldacc004i {
|
||||
public int run() {
|
||||
int i = 0;
|
||||
if (interfaceObject == this) i++;
|
||||
if (interfaceArrInt[0] == 3) i++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -1,44 +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/FieldAccess/fieldacc004.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function FieldAccess.
|
||||
* The test sets access watches on fields which are defined in
|
||||
* superinterface, then triggers access watch events on these fields
|
||||
* and checks if clazz, method, location, field_clazz, field and
|
||||
* object parameters of the function contain the expected values.
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:fieldacc004 nsk.jvmti.FieldAccess.fieldacc004
|
||||
*/
|
||||
|
||||
@ -1,325 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
char *m_cls;
|
||||
char *m_name;
|
||||
char *m_sig;
|
||||
jlocation loc;
|
||||
char *f_cls;
|
||||
char *f_name;
|
||||
char *f_sig;
|
||||
jboolean is_static;
|
||||
} writable_watch_info;
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
const char *m_cls;
|
||||
const char *m_name;
|
||||
const char *m_sig;
|
||||
jlocation loc;
|
||||
const char *f_cls;
|
||||
const char *f_name;
|
||||
const char *f_sig;
|
||||
jboolean is_static;
|
||||
} watch_info;
|
||||
|
||||
static jvmtiEnv *jvmti;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static int eventsExpected = 0;
|
||||
static int eventsCount = 0;
|
||||
static watch_info watches[] = {
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc004a;", "run", "()I", 2,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc004a;", "interfaceObject",
|
||||
"Ljava/lang/Object;", JNI_TRUE },
|
||||
{ NULL, "Lnsk/jvmti/FieldAccess/fieldacc004a;", "run", "()I", 12,
|
||||
"Lnsk/jvmti/FieldAccess/fieldacc004a;", "interfaceArrInt",
|
||||
"[I", JNI_TRUE }
|
||||
};
|
||||
|
||||
void JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method,
|
||||
jlocation location, jclass field_klass, jobject obj, jfieldID field) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
writable_watch_info watch;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
eventsCount++;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving access watch info ...\n");
|
||||
}
|
||||
watch.fid = field;
|
||||
watch.loc = location;
|
||||
watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE;
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls,
|
||||
&watch.m_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method,
|
||||
&watch.m_name, &watch.m_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(field_klass,
|
||||
&watch.f_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFieldName(field_klass, field,
|
||||
&watch.f_name, &watch.f_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFieldName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", watch.m_cls);
|
||||
printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig);
|
||||
printf(">>> location: 0x%x%08x\n",
|
||||
(jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(">>> field cls: \"%s\"\n", watch.f_cls);
|
||||
printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig);
|
||||
printf(">>> object: 0x%p\n", obj);
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watch.fid == watches[i].fid) {
|
||||
if (watch.m_cls == NULL ||
|
||||
strcmp(watch.m_cls, watches[i].m_cls) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n",
|
||||
i, watch.m_cls, watches[i].m_cls);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_name == NULL ||
|
||||
strcmp(watch.m_name, watches[i].m_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"",
|
||||
i, watch.m_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_sig == NULL ||
|
||||
strcmp(watch.m_sig, watches[i].m_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"",
|
||||
i, watch.m_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.loc != watches[i].loc) {
|
||||
printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x",
|
||||
i, (jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(", expected: 0x%x%08x\n",
|
||||
(jint)(watches[i].loc >> 32), (jint)watches[i].loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_name == NULL ||
|
||||
strcmp(watch.f_name, watches[i].f_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"",
|
||||
i, watch.f_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_sig == NULL ||
|
||||
strcmp(watch.f_sig, watches[i].f_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"",
|
||||
i, watch.f_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.is_static != watches[i].is_static) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field type: %s", i,
|
||||
(watch.is_static == JNI_TRUE) ? "static" : "instance");
|
||||
printf(", expected: %s\n",
|
||||
(watches[i].is_static == JNI_TRUE) ? "static" : "instance");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("Unexpected field access catched: 0x%p\n", watch.fid);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_fieldacc004(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_fieldacc004(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_fieldacc004(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_field_access_events) {
|
||||
callbacks.FieldAccess = &FieldAccess;
|
||||
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_FIELD_ACCESS, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FIELD_ACCESS: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: FieldAccess watch is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_FieldAccess_fieldacc004_getReady(JNIEnv *env, jclass klass) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
size_t i;
|
||||
|
||||
if (!caps.can_generate_field_access_events) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> setting field access watches ...\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
cls = env->FindClass(watches[i].f_cls);
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find %s class!\n", watches[i].f_cls);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (watches[i].is_static == JNI_TRUE) {
|
||||
watches[i].fid = env->GetStaticFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
} else {
|
||||
watches[i].fid = env->GetFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
}
|
||||
if (watches[i].fid == NULL) {
|
||||
printf("Cannot get field ID for \"%s:%s\"\n",
|
||||
watches[i].f_name, watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti->SetFieldAccessWatch(cls, watches[i].fid);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(SetFieldAccessWatch#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_FieldAccess_fieldacc004_check(JNIEnv *env, jclass cls) {
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of field access events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "fieldacc004.cpp"
|
||||
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FieldModification;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class fieldmod001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("fieldmod001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load fieldmod001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady(Object o1, Object o2, int a1[], int a2[]);
|
||||
native static int check();
|
||||
|
||||
static Object obj1 = new Object();
|
||||
static Object obj2 = new Object();
|
||||
static int arr1[] = new int[1];
|
||||
static int arr2[] = new int[2];
|
||||
|
||||
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) {
|
||||
getReady(obj1, obj2, arr1, arr2);
|
||||
fieldmod001a t = new fieldmod001a();
|
||||
t.run();
|
||||
return check();
|
||||
}
|
||||
}
|
||||
@ -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/FieldModification/fieldmod001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras, quarantine]
|
||||
* VM Testbase comments: 8016181
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function FieldModification.
|
||||
* The test checks if the parameters of the function contain the
|
||||
* expected values.
|
||||
* COMMENTS
|
||||
* Fixed according to 4669812 bug.
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @compile fieldmod001a.jasm
|
||||
* @run main/othervm/native -agentlib:fieldmod001 nsk.jvmti.FieldModification.fieldmod001
|
||||
*/
|
||||
|
||||
@ -1,460 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
char *m_cls;
|
||||
char *m_name;
|
||||
char *m_sig;
|
||||
jlocation loc;
|
||||
char *f_cls;
|
||||
char *f_name;
|
||||
char *f_sig;
|
||||
jboolean is_static;
|
||||
jvalue val;
|
||||
} writable_watch_info;
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
const char *m_cls;
|
||||
const char *m_name;
|
||||
const char *m_sig;
|
||||
jlocation loc;
|
||||
const char *f_cls;
|
||||
const char *f_name;
|
||||
const char *f_sig;
|
||||
const jboolean is_static;
|
||||
jvalue val;
|
||||
} watch_info;
|
||||
|
||||
static jvmtiEnv *jvmti;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static int eventsExpected = 0;
|
||||
static int eventsCount = 0;
|
||||
static watch_info watches[] = {
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 1,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticBoolean", "Z", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 5,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticByte", "B", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 9,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticShort", "S", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 13,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticInt", "I", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 19,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticLong", "J", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 24,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticFloat", "F", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 30,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticDouble", "D", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 35,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticChar", "C", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 41,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 47,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "staticArrInt", "[I", JNI_TRUE, {} },
|
||||
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 52,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceBoolean", "Z", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 58,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceByte", "B", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 64,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceShort", "S", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 70,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceInt", "I", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 77,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceLong", "J", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 83,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceFloat", "F", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 90,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceDouble", "D", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 96,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceChar", "C", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 103,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod001a;", "run", "()V", 110,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod001a;", "instanceArrInt", "[I", JNI_FALSE, {} }
|
||||
};
|
||||
|
||||
void printValue(jvalue val, char *sig) {
|
||||
switch (*sig) {
|
||||
case 'J':
|
||||
printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j);
|
||||
break;
|
||||
case 'F':
|
||||
printf("%.3f", (double)val.f);
|
||||
break;
|
||||
case 'D':
|
||||
printf("%f", (double)val.d);
|
||||
break;
|
||||
case 'L':
|
||||
case '[':
|
||||
printf("0x%p", val.l);
|
||||
break;
|
||||
case 'Z':
|
||||
printf("0x%x", val.z);
|
||||
break;
|
||||
case 'B':
|
||||
printf("%d", val.b);
|
||||
break;
|
||||
case 'S':
|
||||
printf("%d", val.s);
|
||||
break;
|
||||
case 'C':
|
||||
printf("0x%x", val.c);
|
||||
break;
|
||||
case 'I':
|
||||
printf("%d", val.i);
|
||||
break;
|
||||
default:
|
||||
printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int isEqual(JNIEnv *env, char *sig, jvalue v1, jvalue v2) {
|
||||
switch (*sig) {
|
||||
case 'J':
|
||||
return (v1.j == v2.j);
|
||||
case 'F':
|
||||
return (v1.f == v2.f);
|
||||
case 'D':
|
||||
return (v1.d == v2.d);
|
||||
case 'L':
|
||||
case '[':
|
||||
return env->IsSameObject(v1.l, v2.l);
|
||||
case 'Z':
|
||||
return (v1.z == v2.z);
|
||||
case 'B':
|
||||
return (v1.b == v2.b);
|
||||
case 'S':
|
||||
return (v1.s == v2.s);
|
||||
case 'C':
|
||||
return (v1.c == v2.c);
|
||||
case 'I':
|
||||
return (v1.i == v2.i);
|
||||
default:
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method, jlocation location,
|
||||
jclass field_klass, jobject obj,
|
||||
jfieldID field, char sig, jvalue new_value) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
writable_watch_info watch;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
eventsCount++;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving modification watch info ...\n");
|
||||
}
|
||||
watch.fid = field;
|
||||
watch.loc = location;
|
||||
watch.val = new_value;
|
||||
watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE;
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls,
|
||||
&watch.m_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method,
|
||||
&watch.m_name, &watch.m_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(field_klass,
|
||||
&watch.f_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFieldName(field_klass, field,
|
||||
&watch.f_name, &watch.f_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFieldName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", watch.m_cls);
|
||||
printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig);
|
||||
printf(">>> location: 0x%x%08x\n",
|
||||
(jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(">>> field cls: \"%s\"\n", watch.f_cls);
|
||||
printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig);
|
||||
printf(">>> object: 0x%p\n", obj);
|
||||
printf(">>> new value: ");
|
||||
printValue(watch.val, watch.f_sig);
|
||||
printf("\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watch.fid == watches[i].fid) {
|
||||
if (watch.m_cls == NULL ||
|
||||
strcmp(watch.m_cls, watches[i].m_cls) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n",
|
||||
i, watch.m_cls, watches[i].m_cls);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_name == NULL ||
|
||||
strcmp(watch.m_name, watches[i].m_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"",
|
||||
i, watch.m_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_sig == NULL ||
|
||||
strcmp(watch.m_sig, watches[i].m_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"",
|
||||
i, watch.m_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.loc != watches[i].loc) {
|
||||
printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x",
|
||||
i, (jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(", expected: 0x%x%08x\n",
|
||||
(jint)(watches[i].loc >> 32), (jint)watches[i].loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_name == NULL ||
|
||||
strcmp(watch.f_name, watches[i].f_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"",
|
||||
i, watch.f_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_sig == NULL ||
|
||||
strcmp(watch.f_sig, watches[i].f_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"",
|
||||
i, watch.f_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.is_static != watches[i].is_static) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field type: %s", i,
|
||||
(watch.is_static == JNI_TRUE) ? "static" : "instance");
|
||||
printf(", expected: %s\n",
|
||||
(watches[i].is_static == JNI_TRUE) ? "static" : "instance");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (!isEqual((JNIEnv *)env, watch.f_sig, watch.val, watches[i].val)) {
|
||||
printf("(watch#%" PRIuPTR ") wrong new value: ", i);
|
||||
printValue(watch.val, watch.f_sig);
|
||||
printf(", expected: ");
|
||||
printValue(watches[i].val, watch.f_sig);
|
||||
printf("\n");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("Unexpected field modification catched: 0x%p\n", watch.fid);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_fieldmod001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_fieldmod001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_fieldmod001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_field_modification_events) {
|
||||
callbacks.FieldModification = &FieldModification;
|
||||
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_FIELD_MODIFICATION, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: FieldModification watch is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_FieldModification_fieldmod001_getReady(JNIEnv *env, jclass klass,
|
||||
jobject obj1, jobject obj2, jobject arr1, jobject arr2) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
size_t i;
|
||||
|
||||
if (!caps.can_generate_field_modification_events) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> setting field modification watches ...\n");
|
||||
}
|
||||
cls = env->FindClass("nsk/jvmti/FieldModification/fieldmod001a");
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find fieldmod001a class!\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watches[i].is_static == JNI_TRUE) {
|
||||
watches[i].fid = env->GetStaticFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
} else {
|
||||
watches[i].fid = env->GetFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
}
|
||||
if (watches[i].fid == NULL) {
|
||||
printf("Cannot get field ID for \"%s:%s\"\n",
|
||||
watches[i].f_name, watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti->SetFieldModificationWatch(cls, watches[i].fid);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
watches[0].val.z = JNI_TRUE;
|
||||
watches[1].val.b = 1;
|
||||
watches[2].val.s = 2;
|
||||
watches[3].val.i = 3;
|
||||
watches[4].val.j = 4;
|
||||
watches[5].val.f = 0.5F;
|
||||
watches[6].val.d = 0.6;
|
||||
watches[7].val.c = 0x61;
|
||||
watches[8].val.l = env->NewGlobalRef(obj1);
|
||||
watches[9].val.l = env->NewGlobalRef(arr1);
|
||||
|
||||
watches[10].val.z = JNI_FALSE;
|
||||
watches[11].val.b = 10;
|
||||
watches[12].val.s = 20;
|
||||
watches[13].val.i = 30;
|
||||
watches[14].val.j = 40;
|
||||
watches[15].val.f = 0.05F;
|
||||
watches[16].val.d = 0.06;
|
||||
watches[17].val.c = 0x7a;
|
||||
watches[18].val.l = env->NewGlobalRef(obj2);
|
||||
watches[19].val.l = env->NewGlobalRef(arr2);
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_FieldModification_fieldmod001_check(JNIEnv *env, jclass cls) {
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of field modification events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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/FieldModification;
|
||||
|
||||
super public class fieldmod001a {
|
||||
|
||||
static Field staticBoolean:Z;
|
||||
static Field staticByte:B;
|
||||
static Field staticShort:S;
|
||||
static Field staticInt:I;
|
||||
static Field staticLong:J;
|
||||
static Field staticFloat:F;
|
||||
static Field staticDouble:D;
|
||||
static Field staticChar:C;
|
||||
static Field staticObject:"Ljava/lang/Object;";
|
||||
static Field staticArrInt:"[I";
|
||||
Field instanceBoolean:Z;
|
||||
Field instanceByte:B;
|
||||
Field instanceShort:S;
|
||||
Field instanceInt:I;
|
||||
Field instanceLong:J;
|
||||
Field instanceFloat:F;
|
||||
Field instanceDouble:D;
|
||||
Field instanceChar:C;
|
||||
Field instanceObject:"Ljava/lang/Object;";
|
||||
Field instanceArrInt:"[I";
|
||||
|
||||
public Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
public Method run:"()V" stack 5 locals 1 {
|
||||
iconst_1;
|
||||
putstatic Field staticBoolean:"Z"; // bci=1
|
||||
iconst_1;
|
||||
putstatic Field staticByte:"B"; // bci=5
|
||||
iconst_2;
|
||||
putstatic Field staticShort:"S"; // bci=9
|
||||
iconst_3;
|
||||
putstatic Field staticInt:"I"; // bci=13
|
||||
ldc2_w long 4l;
|
||||
putstatic Field staticLong:"J"; // bci=19
|
||||
ldc float 0.5f;
|
||||
putstatic Field staticFloat:"F"; // bci=24
|
||||
ldc2_w double 0.6d;
|
||||
putstatic Field staticDouble:"D"; // bci=30
|
||||
bipush 97;
|
||||
putstatic Field staticChar:"C"; // bci=35
|
||||
getstatic Field fieldmod001.obj1:"Ljava/lang/Object;";
|
||||
putstatic Field staticObject:"Ljava/lang/Object;"; // bci=41
|
||||
getstatic Field fieldmod001.arr1:"[I";
|
||||
putstatic Field staticArrInt:"[I"; // bci=47
|
||||
aload_0;
|
||||
iconst_0;
|
||||
putfield Field instanceBoolean:"Z"; // bci=52
|
||||
aload_0;
|
||||
bipush 10;
|
||||
putfield Field instanceByte:"B"; // bci=58
|
||||
aload_0;
|
||||
bipush 20;
|
||||
putfield Field instanceShort:"S"; // bci=64
|
||||
aload_0;
|
||||
bipush 30;
|
||||
putfield Field instanceInt:"I"; // bci=70
|
||||
aload_0;
|
||||
ldc2_w long 40l;
|
||||
putfield Field instanceLong:"J"; // bci=77
|
||||
aload_0;
|
||||
ldc float 0.05f;
|
||||
putfield Field instanceFloat:"F"; // bci=83
|
||||
aload_0;
|
||||
ldc2_w double 0.06d;
|
||||
putfield Field instanceDouble:"D"; // bci=90
|
||||
aload_0;
|
||||
bipush 122;
|
||||
putfield Field instanceChar:"C"; // bci=96
|
||||
aload_0;
|
||||
getstatic Field fieldmod001.obj2:"Ljava/lang/Object;";
|
||||
putfield Field instanceObject:"Ljava/lang/Object;"; // bci=103
|
||||
aload_0;
|
||||
getstatic Field fieldmod001.arr2:"[I";
|
||||
putfield Field instanceArrInt:"[I"; // bci=110
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -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 "fieldmod001.cpp"
|
||||
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FieldModification;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class fieldmod002 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("fieldmod002");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load fieldmod002 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady();
|
||||
native static int check(Object obj);
|
||||
|
||||
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) {
|
||||
fieldmod002a t = new fieldmod002a();
|
||||
getReady();
|
||||
return check(t);
|
||||
}
|
||||
}
|
||||
|
||||
class fieldmod002a {
|
||||
static boolean staticBoolean;
|
||||
static byte staticByte;
|
||||
static short staticShort;
|
||||
static int staticInt;
|
||||
static long staticLong;
|
||||
static float staticFloat;
|
||||
static double staticDouble;
|
||||
static char staticChar;
|
||||
static Object staticObject;
|
||||
static int staticArrInt[];
|
||||
boolean instanceBoolean;
|
||||
byte instanceByte;
|
||||
short instanceShort;
|
||||
int instanceInt;
|
||||
long instanceLong;
|
||||
float instanceFloat;
|
||||
double instanceDouble;
|
||||
char instanceChar;
|
||||
Object instanceObject;
|
||||
int instanceArrInt[];
|
||||
}
|
||||
@ -1,43 +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/FieldModification/fieldmod002.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI event callback function FieldModification.
|
||||
* The test checks if the parameters of the function contain the
|
||||
* expected values for fields modified from JNI code.
|
||||
* COMMENTS
|
||||
* Fixed according to 4669812 bug.
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:fieldmod002 nsk.jvmti.FieldModification.fieldmod002
|
||||
*/
|
||||
|
||||
@ -1,510 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
char *m_cls;
|
||||
char *m_name;
|
||||
char *m_sig;
|
||||
jlocation loc;
|
||||
char *f_cls;
|
||||
char *f_name;
|
||||
char *f_sig;
|
||||
jboolean is_static;
|
||||
jvalue val;
|
||||
} writable_watch_info;
|
||||
|
||||
typedef struct {
|
||||
jfieldID fid;
|
||||
const char *m_cls;
|
||||
const char *m_name;
|
||||
const char *m_sig;
|
||||
jlocation loc;
|
||||
const char *f_cls;
|
||||
const char *f_name;
|
||||
const char *f_sig;
|
||||
jboolean is_static;
|
||||
jvalue val;
|
||||
} watch_info;
|
||||
|
||||
static jvmtiEnv *jvmti;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static int eventsExpected = 0;
|
||||
static int eventsCount = 0;
|
||||
static watch_info watches[] = {
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticBoolean", "Z", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticByte", "B", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticShort", "S", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticInt", "I", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticLong", "J", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticFloat", "F", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticDouble", "D", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticChar", "C", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticObject", "Ljava/lang/Object;", JNI_TRUE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "staticArrInt", "[I", JNI_TRUE, {} },
|
||||
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceBoolean", "Z", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceByte", "B", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceShort", "S", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceInt", "I", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceLong", "J", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceFloat", "F", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceDouble", "D", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceChar", "C", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceObject", "Ljava/lang/Object;", JNI_FALSE, {} },
|
||||
{ NULL, "Lnsk/jvmti/FieldModification/fieldmod002;", "check", "(Ljava/lang/Object;)I", 0,
|
||||
"Lnsk/jvmti/FieldModification/fieldmod002a;", "instanceArrInt", "[I", JNI_FALSE, {} }
|
||||
};
|
||||
|
||||
void printValue(jvalue val, char *sig) {
|
||||
switch (*sig) {
|
||||
case 'J':
|
||||
printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j);
|
||||
break;
|
||||
case 'F':
|
||||
printf("%.3f", (double)val.f);
|
||||
break;
|
||||
case 'D':
|
||||
printf("%f", (double)val.d);
|
||||
break;
|
||||
case 'L':
|
||||
case '[':
|
||||
printf("0x%p", val.l);
|
||||
break;
|
||||
case 'Z':
|
||||
printf("0x%x", val.z);
|
||||
break;
|
||||
case 'B':
|
||||
printf("%d", val.b);
|
||||
break;
|
||||
case 'S':
|
||||
printf("%d", val.s);
|
||||
break;
|
||||
case 'C':
|
||||
printf("0x%x", val.c);
|
||||
break;
|
||||
case 'I':
|
||||
printf("%d", val.i);
|
||||
break;
|
||||
default:
|
||||
printf("0x%x%08x", (jint)(val.j >> 32), (jint)val.j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int isEqual(JNIEnv *env, char *sig, jvalue v1, jvalue v2) {
|
||||
switch (*sig) {
|
||||
case 'J':
|
||||
return (v1.j == v2.j);
|
||||
case 'F':
|
||||
return (v1.f == v2.f);
|
||||
case 'D':
|
||||
return (v1.d == v2.d);
|
||||
case 'L':
|
||||
case '[':
|
||||
return env->IsSameObject(v1.l, v2.l);
|
||||
case 'Z':
|
||||
return (v1.z == v2.z);
|
||||
case 'B':
|
||||
return (v1.b == v2.b);
|
||||
case 'S':
|
||||
return (v1.s == v2.s);
|
||||
case 'C':
|
||||
return (v1.c == v2.c);
|
||||
case 'I':
|
||||
return (v1.i == v2.i);
|
||||
default:
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
void JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method, jlocation location,
|
||||
jclass field_klass, jobject obj,
|
||||
jfieldID field, char sig, jvalue new_value) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
writable_watch_info watch;
|
||||
char *generic;
|
||||
size_t i;
|
||||
|
||||
eventsCount++;
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving modification watch info ...\n");
|
||||
}
|
||||
watch.fid = field;
|
||||
watch.loc = location;
|
||||
watch.is_static = (obj == NULL) ? JNI_TRUE : JNI_FALSE;
|
||||
watch.val = new_value;
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls,
|
||||
&watch.m_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method, &watch.m_name, &watch.m_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(field_klass,
|
||||
&watch.f_cls, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFieldName(field_klass, field,
|
||||
&watch.f_name, &watch.f_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFieldName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", watch.m_cls);
|
||||
printf(">>> method: \"%s%s\"\n", watch.m_name, watch.m_sig);
|
||||
printf(">>> location: 0x%x%08x\n",
|
||||
(jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(">>> field cls: \"%s\"\n", watch.f_cls);
|
||||
printf(">>> field: \"%s:%s\"\n", watch.f_name, watch.f_sig);
|
||||
printf(">>> object: 0x%p\n", obj);
|
||||
printf(">>> new value: ");
|
||||
printValue(watch.val, watch.f_sig);
|
||||
printf("\n");
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watch.fid == watches[i].fid) {
|
||||
if (watch.m_cls == NULL ||
|
||||
strcmp(watch.m_cls, watches[i].m_cls) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong class: \"%s\", expected: \"%s\"\n",
|
||||
i, watch.m_cls, watches[i].m_cls);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_name == NULL ||
|
||||
strcmp(watch.m_name, watches[i].m_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method name: \"%s\"",
|
||||
i, watch.m_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.m_sig == NULL ||
|
||||
strcmp(watch.m_sig, watches[i].m_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong method sig: \"%s\"",
|
||||
i, watch.m_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].m_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.loc != watches[i].loc) {
|
||||
printf("(watch#%" PRIuPTR ") wrong location: 0x%x%08x",
|
||||
i, (jint)(watch.loc >> 32), (jint)watch.loc);
|
||||
printf(", expected: 0x%x%08x\n",
|
||||
(jint)(watches[i].loc >> 32), (jint)watches[i].loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_name == NULL ||
|
||||
strcmp(watch.f_name, watches[i].f_name) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field name: \"%s\"",
|
||||
i, watch.f_name);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.f_sig == NULL ||
|
||||
strcmp(watch.f_sig, watches[i].f_sig) != 0) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field sig: \"%s\"",
|
||||
i, watch.f_sig);
|
||||
printf(", expected: \"%s\"\n", watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (watch.is_static != watches[i].is_static) {
|
||||
printf("(watch#%" PRIuPTR ") wrong field type: %s", i,
|
||||
(watch.is_static == JNI_TRUE) ? "static" : "instance");
|
||||
printf(", expected: %s\n",
|
||||
(watches[i].is_static == JNI_TRUE) ? "static" : "instance");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (!isEqual((JNIEnv *)env, watch.f_sig, watch.val, watches[i].val)) {
|
||||
printf("(watch#%" PRIuPTR ") wrong new value: ", i);
|
||||
printValue(watch.val, watch.f_sig);
|
||||
printf(", expected: ");
|
||||
printValue(watches[i].val, watch.f_sig);
|
||||
printf("\n");
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("Unexpected field modification catched: 0x%p\n", watch.fid);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_fieldmod002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_fieldmod002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_fieldmod002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_field_modification_events) {
|
||||
callbacks.FieldModification = &FieldModification;
|
||||
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_FIELD_MODIFICATION, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FIELD_MODIFICATION: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: FieldModification watch is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_FieldModification_fieldmod002_getReady(JNIEnv *env, jclass clz) {
|
||||
jvmtiError err;
|
||||
jclass cls;
|
||||
jmethodID ctor;
|
||||
jintArray arr1, arr2;
|
||||
jobject obj1, obj2;
|
||||
size_t i;
|
||||
|
||||
if (!caps.can_generate_field_modification_events) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> setting field modification watches ...\n");
|
||||
}
|
||||
cls = env->FindClass("nsk/jvmti/FieldModification/fieldmod002a");
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find fieldmod001a class!\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < sizeof(watches)/sizeof(watch_info); i++) {
|
||||
if (watches[i].is_static == JNI_TRUE) {
|
||||
watches[i].fid = env->GetStaticFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
} else {
|
||||
watches[i].fid = env->GetFieldID(
|
||||
cls, watches[i].f_name, watches[i].f_sig);
|
||||
}
|
||||
if (watches[i].fid == NULL) {
|
||||
printf("Cannot get field ID for \"%s:%s\"\n",
|
||||
watches[i].f_name, watches[i].f_sig);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti->SetFieldModificationWatch(cls, watches[i].fid);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(SetFieldModificationWatch#%" PRIuPTR ") unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ctor = env->GetMethodID(cls, "<init>", "()V");
|
||||
obj1 = env->NewGlobalRef(env->NewObject(cls, ctor));
|
||||
obj2 = env->NewGlobalRef(env->NewObject(cls, ctor));
|
||||
arr1 = (jintArray) env->NewGlobalRef(env->NewIntArray((jsize) 1));
|
||||
arr2 = (jintArray) env->NewGlobalRef(env->NewIntArray((jsize) 1));
|
||||
|
||||
watches[0].val.z = JNI_TRUE;
|
||||
watches[1].val.b = 1;
|
||||
watches[2].val.s = 2;
|
||||
watches[3].val.i = 3;
|
||||
watches[4].val.j = 4;
|
||||
watches[5].val.f = 0.5F;
|
||||
watches[6].val.d = 0.6;
|
||||
watches[7].val.c = 0x7;
|
||||
watches[8].val.l = obj1;
|
||||
watches[9].val.l = arr1;
|
||||
|
||||
watches[10].val.z = JNI_FALSE;
|
||||
watches[11].val.b = 10;
|
||||
watches[12].val.s = 20;
|
||||
watches[13].val.i = 30;
|
||||
watches[14].val.j = 40;
|
||||
watches[15].val.f = 0.05F;
|
||||
watches[16].val.d = 0.06;
|
||||
watches[17].val.c = 0x70;
|
||||
watches[18].val.l = obj2;
|
||||
watches[19].val.l = arr2;
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_FieldModification_fieldmod002_check(JNIEnv *env,
|
||||
jclass clz, jobject obj) {
|
||||
jclass cls;
|
||||
|
||||
if (!caps.can_generate_field_modification_events) {
|
||||
return PASSED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> modifying fields ...\n");
|
||||
}
|
||||
|
||||
cls = env->FindClass("nsk/jvmti/FieldModification/fieldmod002a");
|
||||
if (cls == NULL) {
|
||||
printf("Cannot find fieldmod001a class!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
env->SetStaticBooleanField(cls, watches[0].fid, watches[0].val.z);
|
||||
env->SetStaticByteField(cls, watches[1].fid, watches[1].val.b);
|
||||
env->SetStaticShortField(cls, watches[2].fid, watches[2].val.s);
|
||||
env->SetStaticIntField(cls, watches[3].fid, watches[3].val.i);
|
||||
env->SetStaticLongField(cls, watches[4].fid, watches[4].val.j);
|
||||
env->SetStaticFloatField(cls, watches[5].fid, watches[5].val.f);
|
||||
env->SetStaticDoubleField(cls, watches[6].fid, watches[6].val.d);
|
||||
env->SetStaticCharField(cls, watches[7].fid, watches[7].val.c);
|
||||
env->SetStaticObjectField(cls, watches[8].fid, watches[8].val.l);
|
||||
env->SetStaticObjectField(cls, watches[9].fid, watches[9].val.l);
|
||||
|
||||
env->SetBooleanField(obj, watches[10].fid, watches[10].val.z);
|
||||
env->SetByteField(obj, watches[11].fid, watches[11].val.b);
|
||||
env->SetShortField(obj, watches[12].fid, watches[12].val.s);
|
||||
env->SetIntField(obj, watches[13].fid, watches[13].val.i);
|
||||
env->SetLongField(obj, watches[14].fid, watches[14].val.j);
|
||||
env->SetFloatField(obj, watches[15].fid, watches[15].val.f);
|
||||
env->SetDoubleField(obj, watches[16].fid, watches[16].val.d);
|
||||
env->SetCharField(obj, watches[17].fid, watches[17].val.c);
|
||||
env->SetObjectField(obj, watches[18].fid, watches[18].val.l);
|
||||
env->SetObjectField(obj, watches[19].fid, watches[19].val.l);
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of field modification events: %d, expected: %d\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "fieldmod002.cpp"
|
||||
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FramePop;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class framepop001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("framepop001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load framepop001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static int check();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public static void chain() {
|
||||
}
|
||||
}
|
||||
@ -1,47 +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/FramePop/framepop001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI event callback function FramePop.
|
||||
* The test checks the following:
|
||||
* - if clazz, method and frame parameters contain expected values
|
||||
* for event generated upon exit from single method in single frame
|
||||
* specified in call to NotifyFramePop.
|
||||
* - if GetFrameLocation indentifies the executable location
|
||||
* in the returning method, immediately prior to the return.
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @compile framepop001a.jasm
|
||||
* @run main/othervm/native -agentlib:framepop001 nsk.jvmti.FramePop.framepop001
|
||||
*/
|
||||
|
||||
@ -1,289 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
const char *cls_sig;
|
||||
const char *name;
|
||||
const char *sig;
|
||||
jlocation loc;
|
||||
} pop_info;
|
||||
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jvmtiCapabilities caps;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static size_t eventsExpected = 0;
|
||||
static size_t eventsCount = 0;
|
||||
static pop_info pops[] = {
|
||||
{ "Lnsk/jvmti/FramePop/framepop001;", "chain", "()V", 0 },
|
||||
{ "Lnsk/jvmti/FramePop/framepop001a;", "dummy", "()V", 3 },
|
||||
};
|
||||
|
||||
void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method, jlocation location) {
|
||||
jvmtiError err;
|
||||
|
||||
err = jvmti_env->NotifyFramePop(thr, 0);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(NotifyFramePop#0) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti_env->NotifyFramePop(thr, 1);
|
||||
if (err == JVMTI_ERROR_NONE) {
|
||||
eventsExpected++;
|
||||
} else {
|
||||
printf("(NotifyFramePop#1) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method, jboolean wasPopedByException) {
|
||||
jvmtiError err;
|
||||
char *cls_sig, *name, *sig, *generic;
|
||||
jclass cls;
|
||||
jmethodID mid;
|
||||
jlocation loc;
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving frame pop info ...\n");
|
||||
}
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetClassSignature(cls, &cls_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetMethodName(method, &name, &sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFrameLocation) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", cls_sig);
|
||||
printf(">>> method: \"%s%s\"\n", name, sig);
|
||||
printf(">>> location: 0x%x%08x\n",
|
||||
(jint)(loc >> 32), (jint)loc);
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
if (eventsCount < sizeof(pops)/sizeof(pop_info)) {
|
||||
if (cls_sig == NULL ||
|
||||
strcmp(cls_sig, pops[eventsCount].cls_sig) != 0) {
|
||||
printf("(pop#%" PRIuPTR ") wrong class: \"%s\"",
|
||||
eventsCount, cls_sig);
|
||||
printf(", expected: \"%s\"\n", pops[eventsCount].cls_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (name == NULL ||
|
||||
strcmp(name, pops[eventsCount].name) != 0) {
|
||||
printf("(pop#%" PRIuPTR ") wrong method name: \"%s\"",
|
||||
eventsCount, name);
|
||||
printf(", expected: \"%s\"\n", pops[eventsCount].name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (sig == NULL ||
|
||||
strcmp(sig, pops[eventsCount].sig) != 0) {
|
||||
printf("(pop#%" PRIuPTR ") wrong method sig: \"%s\"",
|
||||
eventsCount, sig);
|
||||
printf(", expected: \"%s\"\n", pops[eventsCount].sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (loc != pops[eventsCount].loc) {
|
||||
printf("(pop#%" PRIuPTR ") wrong location: 0x%x%08x",
|
||||
eventsCount, (jint)(loc >> 32), (jint)loc);
|
||||
printf(", expected: 0x%x\n", (jint)pops[eventsCount].loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
} else {
|
||||
printf("Unexpected frame pop catched:");
|
||||
printf(" class: \"%s\"\n", cls_sig);
|
||||
printf(" method: \"%s%s\"\n", name, sig);
|
||||
printf(" location: 0x%x%08x\n", (jint)(loc >> 32), (jint)loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
eventsCount++;
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_framepop001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_framepop001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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_generate_frame_pop_events &&
|
||||
caps.can_generate_breakpoint_events) {
|
||||
callbacks.Breakpoint = &Breakpoint;
|
||||
callbacks.FramePop = &FramePop;
|
||||
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: FramePop or Breakpoint event is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_FramePop_framepop001_check(JNIEnv *env, jclass cls) {
|
||||
jvmtiError err;
|
||||
jclass clz;
|
||||
jmethodID mid;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (!caps.can_generate_frame_pop_events ||
|
||||
!caps.can_generate_breakpoint_events) {
|
||||
return result;
|
||||
}
|
||||
|
||||
mid = env->GetStaticMethodID(cls, "chain", "()V");
|
||||
if (mid == 0) {
|
||||
printf("Cannot find Method ID for method chain\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
err = jvmti->SetBreakpoint(mid, 0);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to SetBreakpoint: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_FRAME_POP, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FRAME_POP event: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_BREAKPOINT, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable BREAKPOINT event: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
clz = env->FindClass("nsk/jvmti/FramePop/framepop001a");
|
||||
if (clz == NULL) {
|
||||
printf("Cannot find framepop001a class!\n");
|
||||
result = STATUS_FAILED;
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
mid = env->GetStaticMethodID(clz, "dummy", "()V");
|
||||
if (mid == 0) {
|
||||
printf("Cannot find Method ID for method dummy\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
env->CallStaticVoidMethod(clz, mid);
|
||||
|
||||
if (eventsCount != eventsExpected) {
|
||||
printf("Wrong number of frame pop events: %" PRIuPTR ", expected: %" PRIuPTR "\n",
|
||||
eventsCount, eventsExpected);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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/FramePop;
|
||||
|
||||
super public class framepop001a {
|
||||
|
||||
public Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
public static Method dummy:"()V" stack 0 locals 0 {
|
||||
invokestatic Method framepop001.chain:"()V";
|
||||
return; // bci=3
|
||||
}
|
||||
}
|
||||
@ -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 "framepop001.cpp"
|
||||
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.FramePop;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class framepop002 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
final static int THREADS_LIMIT = 20;
|
||||
final static int NESTING_DEPTH = 100;
|
||||
final static String TEST_THREAD_NAME_BASE = "Test Thread #";
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("framepop002");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load framepop002 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady();
|
||||
native static int check();
|
||||
|
||||
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) {
|
||||
TestThread[] t = new TestThread[THREADS_LIMIT];
|
||||
getReady();
|
||||
for (int i = 0; i < THREADS_LIMIT; i++) {
|
||||
t[i] = new TestThread(TEST_THREAD_NAME_BASE + i);
|
||||
t[i].start();
|
||||
}
|
||||
for (int i = 0; i < THREADS_LIMIT; i++) {
|
||||
try {
|
||||
t[i].join();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected: " + e);
|
||||
}
|
||||
}
|
||||
return check();
|
||||
}
|
||||
|
||||
static class TestThread extends Thread {
|
||||
int nestingCount = 0;
|
||||
|
||||
// Constructor
|
||||
TestThread(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (nestingCount < NESTING_DEPTH) {
|
||||
nestingCount++;
|
||||
run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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/FramePop/framepop002.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI event callback function FramePop.
|
||||
* The test do some nesting/recursive calls watching frame pop
|
||||
* events to be uniquely identified by thread/class/method/frame_depth.
|
||||
* COMMENTS
|
||||
* The test was created as a result of investigating the following bugs
|
||||
* intended to write a regression test:
|
||||
* 4335224 Bug 4245697 not completely fixed jevent.u.frame.frame incorrect
|
||||
* 4504077 java: dbx should not hold on to a frameid after thread suspension
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:framepop002 nsk.jvmti.FramePop.framepop002
|
||||
*/
|
||||
|
||||
@ -1,477 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "JVMTITools.h"
|
||||
#include "jvmti_tools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
#define MAX_THREADS 32
|
||||
|
||||
typedef struct item *item_t;
|
||||
struct item {
|
||||
item_t next;
|
||||
jmethodID method;
|
||||
int depth;
|
||||
} item;
|
||||
|
||||
typedef struct thr {
|
||||
jthread thread;
|
||||
item_t tos;
|
||||
} thr;
|
||||
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jvmtiCapabilities caps;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jrawMonitorID event_lock;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static jboolean watch_events = JNI_FALSE;
|
||||
|
||||
static int pop_count = 0;
|
||||
static int push_count = 0;
|
||||
static int thr_count = 0;
|
||||
static int max_depth = 0;
|
||||
static thr threads[MAX_THREADS];
|
||||
|
||||
static volatile int callbacksEnabled = NSK_FALSE;
|
||||
static jrawMonitorID agent_lock;
|
||||
|
||||
static
|
||||
int isTestThread(jvmtiEnv *jvmti_env, jthread thr) {
|
||||
jvmtiError err;
|
||||
jvmtiThreadInfo inf;
|
||||
const char* TEST_THREAD_NAME_BASE = "Test Thread";
|
||||
|
||||
err = jvmti_env->GetThreadInfo(thr, &inf);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetThreadInfo) unexpected error: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return 0;
|
||||
}
|
||||
return strncmp(inf.name, TEST_THREAD_NAME_BASE, strlen(TEST_THREAD_NAME_BASE)) == 0;
|
||||
}
|
||||
|
||||
static
|
||||
void printInfo(jvmtiEnv *jvmti_env, jthread thr, jmethodID method, int depth) {
|
||||
jvmtiError err;
|
||||
jvmtiThreadInfo inf;
|
||||
char *clsig, *name, *sig, *generic;
|
||||
jclass cls;
|
||||
|
||||
err = jvmti_env->GetThreadInfo(thr, &inf);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetThreadInfo) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti_env->GetMethodDeclaringClass(method, &cls);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti_env->GetClassSignature(cls, &clsig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti_env->GetMethodName(method, &name, &sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" %s: %s.%s%s, depth = %d\n", inf.name, clsig, name, sig, depth);
|
||||
|
||||
jvmti_env->Deallocate((unsigned char *)sig);
|
||||
jvmti_env->Deallocate((unsigned char *)name);
|
||||
jvmti_env->Deallocate((unsigned char *)clsig);
|
||||
jvmti_env->Deallocate((unsigned char *)inf.name);
|
||||
}
|
||||
|
||||
static
|
||||
void pop(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr, jmethodID method, int depth) {
|
||||
item_t old;
|
||||
int i, count = 0;
|
||||
|
||||
for (i = 0; i < thr_count; i++) {
|
||||
if (env->IsSameObject(threads[i].thread, thr)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == thr_count) {
|
||||
watch_events = JNI_FALSE;
|
||||
printf("Unknown thread:\n");
|
||||
printInfo(jvmti_env, thr, method, depth);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (threads[i].tos == NULL) {
|
||||
watch_events = JNI_FALSE;
|
||||
printf("Stack underflow:\n");
|
||||
printInfo(jvmti_env, thr, method, depth);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
pop_count++;
|
||||
old = threads[i].tos;
|
||||
threads[i].tos = threads[i].tos->next;
|
||||
if (old->method == method && old->depth == depth) {
|
||||
free(old);
|
||||
return;
|
||||
}
|
||||
free(old);
|
||||
} while (threads[i].tos != NULL);
|
||||
|
||||
watch_events = JNI_FALSE;
|
||||
printf("Frame pop does not match any entry:\n");
|
||||
printInfo(jvmti_env, thr, method, depth);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
static
|
||||
void push(JNIEnv *env, jthread thr, jmethodID method, int depth) {
|
||||
item_t new_item;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < thr_count; i++) {
|
||||
if (env->IsSameObject(threads[i].thread, thr)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == thr_count) {
|
||||
thr_count++;
|
||||
if (thr_count == MAX_THREADS) {
|
||||
watch_events = JNI_FALSE;
|
||||
printf("Out of threads\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
threads[i].thread = env->NewGlobalRef(thr);
|
||||
threads[i].tos = NULL;
|
||||
}
|
||||
|
||||
new_item = (item_t)malloc(sizeof(item));
|
||||
if (new_item == NULL) {
|
||||
watch_events = JNI_FALSE;
|
||||
printf("Out of memory\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
new_item->next = threads[i].tos;
|
||||
new_item->method = method;
|
||||
new_item->depth = depth;
|
||||
threads[i].tos = new_item;
|
||||
push_count++;
|
||||
max_depth = (max_depth < depth) ? depth : max_depth;
|
||||
}
|
||||
|
||||
void JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method) {
|
||||
jvmtiError err;
|
||||
jboolean isNative;
|
||||
jint frameCount;
|
||||
|
||||
if (watch_events == JNI_FALSE) return;
|
||||
|
||||
jvmti->RawMonitorEnter(agent_lock);
|
||||
|
||||
if (!callbacksEnabled) {
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti_env->GetFrameCount(thr, &frameCount);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFrameCount#entry) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti_env->IsMethodNative(method, &isNative);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(IsMethodNative) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (isTestThread(jvmti_env, thr)) {
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> %sMethod entry\n>>>",
|
||||
(isNative == JNI_TRUE) ? "Native " : "");
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
}
|
||||
if (isNative == JNI_FALSE) {
|
||||
err = jvmti_env->RawMonitorEnter(event_lock);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(RawMonitorEnter) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
push((JNIEnv *)env, thr, method, frameCount);
|
||||
err = jvmti_env->RawMonitorExit(event_lock);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(RawMonitorExit) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
err = jvmti_env->NotifyFramePop(thr, 0);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(NotifyFramePop) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
}
|
||||
|
||||
void JNICALL VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env) {
|
||||
jvmti->RawMonitorEnter(agent_lock);
|
||||
|
||||
callbacksEnabled = NSK_TRUE;
|
||||
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
}
|
||||
|
||||
|
||||
void JNICALL VMDeath(jvmtiEnv *jvmti_env, JNIEnv* jni_env) {
|
||||
jvmti->RawMonitorEnter(agent_lock);
|
||||
|
||||
callbacksEnabled = NSK_FALSE;
|
||||
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
}
|
||||
|
||||
void JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID method, jboolean wasPopedByException) {
|
||||
jvmtiError err;
|
||||
jint frameCount;
|
||||
|
||||
jvmti->RawMonitorEnter(agent_lock);
|
||||
|
||||
if (!callbacksEnabled) {
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
return;
|
||||
}
|
||||
err = jvmti_env->GetFrameCount(thr, &frameCount);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFrameCount#entry) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTestThread(jvmti_env, thr)) {
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> Frame Pop\n>>>");
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
}
|
||||
err = jvmti_env->RawMonitorEnter(event_lock);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(RawMonitorEnter) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
pop(jvmti_env, (JNIEnv *)env, thr, method, frameCount);
|
||||
err = jvmti_env->RawMonitorExit(event_lock);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(RawMonitorExit) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
printInfo(jvmti_env, thr, method, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
jvmti->RawMonitorExit(agent_lock);
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_framepop002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_framepop002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_framepop002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
err = jvmti->CreateRawMonitor("_event_lock", &event_lock);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(CreateRawMonitor) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
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_generate_frame_pop_events &&
|
||||
caps.can_generate_method_entry_events) {
|
||||
callbacks.MethodEntry = &MethodEntry;
|
||||
callbacks.FramePop = &FramePop;
|
||||
callbacks.VMStart = &VMStart;
|
||||
callbacks.VMDeath = &VMDeath;
|
||||
|
||||
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL)))
|
||||
return JNI_ERR;
|
||||
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
|
||||
return JNI_ERR;
|
||||
|
||||
if (jvmti->CreateRawMonitor("agent_lock", &agent_lock) != JVMTI_ERROR_NONE) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("Warning: FramePop or MethodEntry event is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_nsk_jvmti_FramePop_framepop002_getReady(JNIEnv *env, jclass cls) {
|
||||
jvmtiError err;
|
||||
|
||||
if (!caps.can_generate_frame_pop_events ||
|
||||
!caps.can_generate_method_entry_events) {
|
||||
return ;
|
||||
}
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_METHOD_ENTRY, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_FRAME_POP, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to enable JVMTI_EVENT_FRAME_POP event: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
watch_events = JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_nsk_jvmti_FramePop_framepop002_check(JNIEnv *env, jclass cls) {
|
||||
jvmtiError err;
|
||||
|
||||
watch_events = JNI_FALSE;
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE,
|
||||
JVMTI_EVENT_FRAME_POP, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to disable JVMTI_EVENT_FRAME_POP event: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE,
|
||||
JVMTI_EVENT_METHOD_ENTRY, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("Failed to disable JVMTI_EVENT_METHOD_ENTRY event: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf("%d threads, %d method entrys, %d frame pops, max depth = %d\n",
|
||||
thr_count, push_count, pop_count, max_depth);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "framepop002.cpp"
|
||||
@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetCurrentContendedMonitor;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class contmon001 {
|
||||
|
||||
native static void checkMon(int point, Thread thr, Object mon);
|
||||
native static int getRes();
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("contmon001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load contmon001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
public static volatile boolean startingBarrier = true;
|
||||
public static volatile boolean waitingBarrier = true;
|
||||
static Object lockFld = new Object();
|
||||
|
||||
static boolean DEBUG_MODE = false;
|
||||
static PrintStream out;
|
||||
|
||||
public static void main(String[] args) {
|
||||
args = nsk.share.jvmti.JVMTITest.commonInit(args);
|
||||
|
||||
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
|
||||
}
|
||||
|
||||
public static void doSleep() {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
throw new Error("Unexpected " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int run(String argv[], PrintStream ref) {
|
||||
out = ref;
|
||||
for (int i = 0; i < argv.length; i++) {
|
||||
if (argv[i].equals("-v")) // verbose mode
|
||||
DEBUG_MODE = true;
|
||||
}
|
||||
|
||||
Object lock = new Object();
|
||||
Thread currThr = Thread.currentThread();
|
||||
|
||||
if (DEBUG_MODE)
|
||||
out.println("\nCheck #1: verifying a contended monitor of current thread \""
|
||||
+ currThr.getName() + "\" ...");
|
||||
synchronized (lock) {
|
||||
checkMon(1, currThr, null);
|
||||
}
|
||||
if (DEBUG_MODE)
|
||||
out.println("Check #1 done");
|
||||
|
||||
contmon001a thr = new contmon001a();
|
||||
|
||||
thr.start();
|
||||
if (DEBUG_MODE)
|
||||
out.println("\nWaiting for auxiliary thread ...");
|
||||
while (startingBarrier) {
|
||||
doSleep();
|
||||
}
|
||||
if (DEBUG_MODE)
|
||||
out.println("Auxiliary thread is ready");
|
||||
|
||||
if (DEBUG_MODE)
|
||||
out.println("\nCheck #3: verifying a contended monitor of auxiliary thread ...");
|
||||
checkMon(3, thr, null);
|
||||
if (DEBUG_MODE)
|
||||
out.println("Check #3 done");
|
||||
|
||||
thr.letItGo();
|
||||
|
||||
while (waitingBarrier) {
|
||||
doSleep();
|
||||
}
|
||||
synchronized (lockFld) {
|
||||
if (DEBUG_MODE)
|
||||
out.println("\nMain thread entered lockFld's monitor"
|
||||
+ "\n\tand calling lockFld.notifyAll() to awake auxiliary thread");
|
||||
lockFld.notifyAll();
|
||||
if (DEBUG_MODE)
|
||||
out.println("\nCheck #4: verifying a contended monitor of auxiliary thread ...");
|
||||
checkMon(4, thr, lockFld);
|
||||
if (DEBUG_MODE)
|
||||
out.println("Check #4 done");
|
||||
}
|
||||
|
||||
if (DEBUG_MODE)
|
||||
out.println("\nMain thread released lockFld's monitor"
|
||||
+ "\n\tand waiting for auxiliary thread death ...");
|
||||
|
||||
try {
|
||||
thr.join();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected " + e);
|
||||
}
|
||||
if (DEBUG_MODE)
|
||||
out.println("\nCheck #5: verifying a contended monitor of dead auxiliary thread ...");
|
||||
checkMon(5, thr, null);
|
||||
if (DEBUG_MODE)
|
||||
out.println("Check #5 done");
|
||||
|
||||
return getRes();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class contmon001a extends Thread {
|
||||
private volatile boolean flag = true;
|
||||
|
||||
public void run() {
|
||||
if (contmon001.DEBUG_MODE)
|
||||
contmon001.out.println("check #2: verifying a contended monitor of current auxiliary thread ...");
|
||||
contmon001.checkMon(2, currentThread(), null);
|
||||
if (contmon001.DEBUG_MODE)
|
||||
contmon001.out.println("check #2 done");
|
||||
|
||||
if (contmon001.DEBUG_MODE)
|
||||
contmon001.out.println("notifying main thread");
|
||||
contmon001.startingBarrier = false;
|
||||
|
||||
if (contmon001.DEBUG_MODE)
|
||||
contmon001.out.println("thread is going to loop while <flag> is true ...");
|
||||
int i = 0;
|
||||
int n = 1000;
|
||||
while (flag) {
|
||||
if (n <= 0) {
|
||||
n = 1000;
|
||||
}
|
||||
if (i > n) {
|
||||
i = 0;
|
||||
n--;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (contmon001.DEBUG_MODE)
|
||||
contmon001.out.println("looping is done: <flag> is false");
|
||||
|
||||
synchronized (contmon001.lockFld) {
|
||||
contmon001.waitingBarrier = false;
|
||||
if (contmon001.DEBUG_MODE)
|
||||
contmon001.out.println("\nthread entered lockFld's monitor"
|
||||
+ "\n\tand releasing it through the lockFld.wait() call");
|
||||
try {
|
||||
contmon001.lockFld.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected " + e);
|
||||
}
|
||||
}
|
||||
|
||||
if (contmon001.DEBUG_MODE)
|
||||
contmon001.out.println("thread exiting");
|
||||
}
|
||||
|
||||
public void letItGo() {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
@ -1,66 +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/GetCurrentContendedMonitor/contmon001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI function GetCurrentContendedMonitor.
|
||||
* The test cases include:
|
||||
* - current contended monitor: present or not;
|
||||
* - thread: current, non-current;
|
||||
* - thread waiting to enter a monitor or after wait();
|
||||
* Failing criteria for the test are:
|
||||
* - object returned by GetCurrentContendedMonitor is not the same
|
||||
* as expected;
|
||||
* - failures of used JVMTI functions.
|
||||
* COMMENTS
|
||||
* By today, the test is referred from two bugs, 4327280 and 4463667
|
||||
* To fix bug 4463667, one code fragment with "Thread.sleep(500);"
|
||||
* is replaced with following one:
|
||||
* Object obj = new Object();
|
||||
* *
|
||||
* *
|
||||
* synchronized (obj) {
|
||||
* obj.wait(500);
|
||||
* }
|
||||
* Note. Until 4327280 gets fixing, the correction cannot be tested.
|
||||
* Fixed according to 4509016 bug.
|
||||
* Fixed according to 4669812 bug.
|
||||
* The test was fixed due to the following bug:
|
||||
* 4762695 nsk/jvmti/GetCurrentContendedMonitor/contmon001 has an
|
||||
* incorrect test
|
||||
* Ported from JVMDI.
|
||||
* Fixed according to 4925857 bug:
|
||||
* - rearranged synchronization of tested thread
|
||||
* - enhanced descripton
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:contmon001 nsk.jvmti.GetCurrentContendedMonitor.contmon001
|
||||
*/
|
||||
|
||||
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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 jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_contmon001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_contmon001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_contmon001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
jint res;
|
||||
|
||||
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->GetCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
if (!caps.can_get_current_contended_monitor) {
|
||||
/* GetCurrentContendedMonitor is not currently available, but
|
||||
* is it potentially available?
|
||||
*/
|
||||
err = jvmti->GetPotentialCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
if (caps.can_get_current_contended_monitor) {
|
||||
/* Yes, GetCurrentContendedMonitor is potentially available.
|
||||
* Let's turn it on!
|
||||
*/
|
||||
memset(&caps, 0, sizeof(jvmtiCapabilities));
|
||||
caps.can_get_current_contended_monitor = 1;
|
||||
err = jvmti->AddCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(AddCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: GetCurrentContendedMonitor is not implemented\n");
|
||||
}
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon001_checkMon(JNIEnv *env, jclass cls,
|
||||
jint point, jthread thr, jobject lock) {
|
||||
jvmtiError err;
|
||||
jobject mon = NULL;
|
||||
|
||||
err = jvmti->GetCurrentContendedMonitor(thr, &mon);
|
||||
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY &&
|
||||
!caps.can_get_current_contended_monitor) {
|
||||
/* It's OK */
|
||||
} else if (err == JVMTI_ERROR_THREAD_NOT_ALIVE && point == 5) {
|
||||
return; /* Ok, it must be a dead thread */
|
||||
} else if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetCurrentContendedMonitor#%d) unexpected error: %s (%d)\n",
|
||||
point, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
} else if (env->IsSameObject(lock, mon) == JNI_FALSE) {
|
||||
printf("(IsSameObject#%d) unexpected monitor object: 0x%p\n",
|
||||
point, mon);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon001_getRes(JNIEnv *env, jclass cls) {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "contmon001.cpp"
|
||||
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetCurrentContendedMonitor;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class contmon002 {
|
||||
|
||||
native static void checkMon(int point, Thread thr);
|
||||
native static int getRes();
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("contmon002");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load contmon002 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean startingBarrier = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
args = nsk.share.jvmti.JVMTITest.commonInit(args);
|
||||
|
||||
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
|
||||
}
|
||||
|
||||
public static void doSleep() {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
throw new Error("Unexpected " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int run(String argv[], PrintStream ref) {
|
||||
checkMon(1, Thread.currentThread());
|
||||
|
||||
contmon002a thr = new contmon002a();
|
||||
thr.start();
|
||||
while (startingBarrier) {
|
||||
doSleep();
|
||||
}
|
||||
checkMon(2, thr);
|
||||
thr.letItGo();
|
||||
try {
|
||||
thr.join();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected " + e);
|
||||
}
|
||||
|
||||
return getRes();
|
||||
}
|
||||
}
|
||||
|
||||
class contmon002a extends Thread {
|
||||
private volatile boolean flag = true;
|
||||
|
||||
private synchronized void meth() {
|
||||
contmon002.startingBarrier = false;
|
||||
int i = 0;
|
||||
int n = 1000;
|
||||
while (flag) {
|
||||
if (n <= 0) {
|
||||
n = 1000;
|
||||
}
|
||||
if (i > n) {
|
||||
i = 0;
|
||||
n--;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
meth();
|
||||
}
|
||||
|
||||
public void letItGo() {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
@ -1,48 +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/GetCurrentContendedMonitor/contmon002.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test checks if JVMTI function GetCurrentContendedMonitor returns
|
||||
* NULL when there is no current contended monitor.
|
||||
* Failing criteria for the test are:
|
||||
* - value returned by GetCurrentContendedMonitor is not NULL;
|
||||
* - failures of used JVMTI functions.
|
||||
* COMMENTS
|
||||
* Fixed according to the bug 4509016.
|
||||
* Ported from JVMDI.
|
||||
* Fixed according to 4925857 bug:
|
||||
* - rearranged synchronization of tested thread
|
||||
* - enhanced descripton
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:contmon002 nsk.jvmti.GetCurrentContendedMonitor.contmon002
|
||||
*/
|
||||
|
||||
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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;
|
||||
static jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_contmon002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_contmon002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_contmon002(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;
|
||||
|
||||
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->GetCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
if (!caps.can_get_current_contended_monitor) {
|
||||
/*
|
||||
* GetCurrentContendedMonitor is not currently available, but
|
||||
* is it potentially available?
|
||||
*/
|
||||
err = jvmti->GetPotentialCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
if (caps.can_get_current_contended_monitor) {
|
||||
/*
|
||||
* Yes, GetCurrentContendedMonitor is potentially available.
|
||||
* Let's turn it on!
|
||||
*/
|
||||
memset(&caps, 0, sizeof(jvmtiCapabilities));
|
||||
caps.can_get_current_contended_monitor = 1;
|
||||
err = jvmti->AddCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(AddCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: GetCurrentContendedMonitor is not implemented\n");
|
||||
}
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_GetCurrentContendedMonitor_contmon002_checkMon(JNIEnv *env, jclass cls, jint point, jthread thr) {
|
||||
jvmtiError err;
|
||||
jobject mon = NULL;
|
||||
|
||||
err = jvmti->GetCurrentContendedMonitor(thr, &mon);
|
||||
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY &&
|
||||
!caps.can_get_current_contended_monitor) {
|
||||
/* It is OK */
|
||||
} else if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetCurrentContendedMonitor#%d) unexpected error: %s (%d)\n",
|
||||
point, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
} else if (mon != NULL) {
|
||||
printf("(#%d) unexpected monitor object: 0x%p\n", point, mon);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_nsk_jvmti_GetCurrentContendedMonitor_contmon002_getRes(JNIEnv *env, jclass cls) {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "contmon002.cpp"
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetCurrentContendedMonitor;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class contmon003 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("contmon003");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load contmon003 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -1,44 +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/GetCurrentContendedMonitor/contmon003.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI function
|
||||
* GetCurrentContendedMonitor(thread, monitorPtr).
|
||||
* The test checks if the function returns:
|
||||
* - JVMTI_ERROR_INVALID_THREAD if thread is not a thread object
|
||||
* - JVMTI_ERROR_NULL_POINTER if monitorPtr is null
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:contmon003 nsk.jvmti.GetCurrentContendedMonitor.contmon003
|
||||
*/
|
||||
|
||||
@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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 jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_contmon003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_contmon003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_contmon003(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->GetCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
if (!caps.can_get_current_contended_monitor) {
|
||||
/*
|
||||
* GetCurrentContendedMonitor is not currently available, but
|
||||
* is it potentially available?
|
||||
*/
|
||||
err = jvmti->GetPotentialCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
if (caps.can_get_current_contended_monitor) {
|
||||
/*
|
||||
* Yes, GetCurrentContendedMonitor is potentially available.
|
||||
* Let's turn it on!
|
||||
*/
|
||||
memset(&caps, 0, sizeof(jvmtiCapabilities));
|
||||
caps.can_get_current_contended_monitor = 1;
|
||||
err = jvmti->AddCapabilities(&caps);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(AddCapabilities) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: GetCurrentContendedMonitor is not implemented\n");
|
||||
}
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_GetCurrentContendedMonitor_contmon003_check(JNIEnv *env,
|
||||
jclass cls, jthread thr) {
|
||||
jvmtiError err;
|
||||
jobject monitor;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> invalid thread check ...\n");
|
||||
}
|
||||
err = jvmti->GetCurrentContendedMonitor(cls, &monitor);
|
||||
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY &&
|
||||
!caps.can_get_current_contended_monitor) {
|
||||
/* It is OK */
|
||||
} else 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;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> null pointer check ...\n");
|
||||
}
|
||||
err = jvmti->GetCurrentContendedMonitor(thr, NULL);
|
||||
if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY &&
|
||||
!caps.can_get_current_contended_monitor) {
|
||||
/* It is OK */
|
||||
} else if (err != JVMTI_ERROR_NULL_POINTER) {
|
||||
printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n");
|
||||
printf(" got: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "contmon003.cpp"
|
||||
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetFrameCount;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class framecnt001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
native static void checkFrames(Thread thr, int thr_num, int ans);
|
||||
native static int getRes();
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("framecnt001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load framecnt001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
static Object flag1 = new Object();
|
||||
static Object flag2 = new Object();
|
||||
static Object check_flag = new Object();
|
||||
|
||||
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 argv[], PrintStream ref) {
|
||||
Thread currThread = Thread.currentThread();
|
||||
framecnt001a thr1 = new framecnt001a("thr1", 0, flag1);
|
||||
framecnt001a thr2 = new framecnt001a("thr2", 500, flag2);
|
||||
synchronized(check_flag) {
|
||||
synchronized(flag1) {
|
||||
synchronized(flag2) {
|
||||
thr1.start();
|
||||
thr2.start();
|
||||
checkFrames(currThread, 0, 3);
|
||||
try {
|
||||
flag1.wait();
|
||||
flag2.wait();
|
||||
} catch(InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
checkFrames(thr1, 1, 1);
|
||||
checkFrames(thr2, 2, 501);
|
||||
}
|
||||
return getRes();
|
||||
}
|
||||
}
|
||||
|
||||
class framecnt001a extends Thread {
|
||||
int steps;
|
||||
Object flag;
|
||||
|
||||
framecnt001a(String name, int steps, Object flag) {
|
||||
super(name);
|
||||
this.steps = steps;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (steps > 0) {
|
||||
steps--;
|
||||
run();
|
||||
}
|
||||
synchronized(flag) {
|
||||
flag.notify(); // let main thread know that all frames are in place
|
||||
}
|
||||
synchronized(framecnt001.check_flag) { // wait for the check done
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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/GetFrameCount/framecnt001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI function GetFrameCount.
|
||||
* The function is called by a native method for the current thread
|
||||
* and for two more threads. The test suspends these two threads
|
||||
* before GetFrameCount invocation.
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @build nsk.jvmti.GetFrameCount.framecnt001
|
||||
* @run main/othervm/native ExecDriver --java
|
||||
* -agentlib:framecnt001
|
||||
* nsk.jvmti.GetFrameCount.framecnt001
|
||||
*/
|
||||
|
||||
@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#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 jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_framecnt001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_framecnt001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_framecnt001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
jint res;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_nsk_jvmti_GetFrameCount_framecnt001_checkFrames(JNIEnv *env, jclass cls,
|
||||
jthread thr, jint thr_num, jint fnum) {
|
||||
jvmtiError err;
|
||||
jint frameCount;
|
||||
|
||||
if (!caps.can_suspend) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (thr_num != 0) {
|
||||
err = jvmti->SuspendThread(thr);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SuspendThread#%d) unexpected error: %s (%d)\n",
|
||||
thr_num, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
err = jvmti->GetFrameCount(thr, &frameCount);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFrameCount#%d) unexpected error: %s (%d)\n",
|
||||
thr_num, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
} else if (frameCount != fnum) {
|
||||
printf("Thread #%d: number of frames expected: %d, got: %d\n",
|
||||
thr_num, fnum, frameCount);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (thr_num != 0) {
|
||||
err = jvmti->ResumeThread(thr);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(ResumeThread#%d) unexpected error: %s (%d)\n",
|
||||
thr_num, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFrameCount_framecnt001_getRes(JNIEnv *env, jclass cls) {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "framecnt001.cpp"
|
||||
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetFrameCount;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class framecnt002 {
|
||||
|
||||
native static void checkFrames(Thread thr, int thr_num);
|
||||
native static int getRes();
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("framecnt002");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load framecnt002 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static int flag = 0;
|
||||
|
||||
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 argv[], PrintStream ref) {
|
||||
Thread currThread = Thread.currentThread();
|
||||
framecnt002a thr1 = new framecnt002a();
|
||||
checkFrames(thr1, 1);
|
||||
checkFrames(currThread, 0);
|
||||
return getRes();
|
||||
}
|
||||
}
|
||||
|
||||
class framecnt002a extends Thread {
|
||||
public void run() {
|
||||
}
|
||||
}
|
||||
@ -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/GetFrameCount/framecnt002.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test checks that JVMTI function GetFrameCount returns proper
|
||||
* error codes when is called:
|
||||
* - with NULL passed as the second actual parameter,
|
||||
* - for a thread which is not is not alive.
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
* Updating test to meet JVMTI spec 0.2.30:
|
||||
* - check not alive thread
|
||||
* - check JVMTI_ERROR_THREAD_NOT_ALIVE instead of JVMTI_ERROR_THREAD_NOT_SUSPENDED
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:framecnt002 nsk.jvmti.GetFrameCount.framecnt002
|
||||
*/
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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;
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_framecnt002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_framecnt002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_framecnt002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jint res;
|
||||
|
||||
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 void JNICALL Java_nsk_jvmti_GetFrameCount_framecnt002_checkFrames(JNIEnv *env, jclass cls,
|
||||
jthread thr, jint thr_num) {
|
||||
jvmtiError err;
|
||||
jint frameCount;
|
||||
|
||||
if (thr_num == 0) {
|
||||
err = jvmti->GetFrameCount(thr, NULL);
|
||||
if (err != JVMTI_ERROR_NULL_POINTER) {
|
||||
printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
} else {
|
||||
err = jvmti->GetFrameCount(thr, &frameCount);
|
||||
if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) {
|
||||
printf("Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE, got: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_nsk_jvmti_GetFrameCount_framecnt002_getRes(JNIEnv *env, jclass cls) {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "framecnt002.cpp"
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetFrameCount;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class framecnt003 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("framecnt003");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load framecnt003 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static int check();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -1,42 +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/GetFrameCount/framecnt003.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI function GetFrameCount(thread, countPtr).
|
||||
* The test checks if the function returns JVMTI_ERROR_INVALID_THREAD
|
||||
* if thread is not a thread object.
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:framecnt003 nsk.jvmti.GetFrameCount.framecnt003
|
||||
*/
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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;
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_framecnt003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_framecnt003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_framecnt003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jint res;
|
||||
|
||||
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_GetFrameCount_framecnt003_check(JNIEnv *env, jclass cls) {
|
||||
jvmtiError err;
|
||||
jint countPtr;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti->GetFrameCount(cls, &countPtr);
|
||||
if (err != JVMTI_ERROR_INVALID_THREAD) {
|
||||
printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n");
|
||||
printf(" actual: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "framecnt003.cpp"
|
||||
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetFrameLocation;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class frameloc001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("frameloc001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load frameloc001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static void getReady(Class cls);
|
||||
native static boolean checkFrame01(Thread thr, Class cls, boolean mustPass);
|
||||
native static int getRes();
|
||||
|
||||
static int fld = 0;
|
||||
static Object lock1 = new Object();
|
||||
static Object lock2 = new Object();
|
||||
|
||||
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 argv[], PrintStream ref) {
|
||||
frameloc001a thr = new frameloc001a();
|
||||
|
||||
getReady(frameloc001a.class);
|
||||
thr.meth01(2000);
|
||||
|
||||
synchronized (lock2) {
|
||||
synchronized (lock1) {
|
||||
thr.start();
|
||||
try {
|
||||
lock1.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected " + e);
|
||||
}
|
||||
}
|
||||
waitForChildThread(thr);
|
||||
checkFrame01(thr, frameloc001a.class, true);
|
||||
}
|
||||
|
||||
return getRes();
|
||||
}
|
||||
|
||||
private static void waitForChildThread(frameloc001a thr) {
|
||||
// Wait for child thread to reach expected position. Wait up to 5 seconds.
|
||||
final int MAX_WAIT_MS = 5000;
|
||||
int sumWaitMs = 0;
|
||||
while (!checkFrame01(thr, frameloc001a.class, false) && sumWaitMs <= MAX_WAIT_MS) {
|
||||
try {
|
||||
System.out.println("Waited: " + sumWaitMs);
|
||||
final int sleepMs = 20;
|
||||
sumWaitMs += sleepMs;
|
||||
Thread.sleep(sleepMs);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
throw new Error("Unexpected " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,51 +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/GetFrameLocation/frameloc001.
|
||||
* VM Testbase keywords: [jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercise JVMTI function GetFrameLocation.
|
||||
* The test debug agent calls the function from the hook
|
||||
* function and native method for the test cases:
|
||||
* - current and other threads;
|
||||
* - currently executing instructions:
|
||||
* 1) astore_2 after catching exception (in frameloc001a.meth01)
|
||||
* 2) monitorenter (in frameloc001a.run)
|
||||
* COMMENTS
|
||||
* Fixed according to the rfe 4388972.
|
||||
* Tested bytecode was relocated to frameloc001a.jasm
|
||||
* adjusting the expected locations.
|
||||
* Fixed according to 4669812 bug.
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @compile frameloc001a.jasm
|
||||
* @run main/othervm/native -agentlib:frameloc001 nsk.jvmti.GetFrameLocation.frameloc001
|
||||
*/
|
||||
|
||||
@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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 jvmtiCapabilities caps;
|
||||
static jvmtiEventCallbacks callbacks;
|
||||
static jint result = PASSED;
|
||||
static jmethodID mid1;
|
||||
|
||||
// If mustPass is false we just check if we have reached the correct instruction location.
|
||||
// This is used to wait for the child thread to reach the expected position.
|
||||
jboolean checkFrame(jvmtiEnv *jvmti_env, JNIEnv *env,
|
||||
jthread thr, jmethodID exp_mid, jlocation exp_loc, jlocation exp_loc_alternative, jboolean mustPass) {
|
||||
jvmtiError err;
|
||||
jmethodID mid = NULL;
|
||||
jlocation loc = -1;
|
||||
char *meth, *sig, *generic;
|
||||
jboolean isOk = JNI_FALSE;
|
||||
|
||||
err = jvmti_env->GetMethodName(exp_mid, &meth, &sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti_env->GetFrameLocation(thr, 0, &mid, &loc);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFrameLocation#%s) unexpected error: %s (%d)\n",
|
||||
meth, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
} else {
|
||||
if (exp_mid != mid) {
|
||||
printf("Method \"%s\" current frame's method ID", meth);
|
||||
printf(" expected: 0x%p, got: 0x%p\n", exp_mid, mid);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
isOk = exp_loc == loc || exp_loc_alternative == loc;
|
||||
if (!isOk && mustPass) {
|
||||
printf("Method \"%s\" current frame's location", meth);
|
||||
printf(" expected: 0x%x or 0x%x, got: 0x%x%08x\n",
|
||||
(jint)exp_loc, (jint)exp_loc_alternative, (jint)(loc >> 32), (jint)loc);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
return isOk && result == PASSED;
|
||||
}
|
||||
|
||||
void JNICALL
|
||||
ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr,
|
||||
jmethodID method, jlocation location, jobject exception) {
|
||||
if (method == mid1) {
|
||||
checkFrame(jvmti_env, (JNIEnv *)env, thr, method, location, location, JNI_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_frameloc001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_frameloc001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_frameloc001(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;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
if (caps.can_generate_exception_events) {
|
||||
callbacks.ExceptionCatch = &ExceptionCatch;
|
||||
err = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SetEventCallbacks) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: ExceptionCatch event is not implemented\n");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_GetFrameLocation_frameloc001_getReady(JNIEnv *env, jclass cls,
|
||||
jclass klass) {
|
||||
jvmtiError err;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!caps.can_generate_exception_events) {
|
||||
return;
|
||||
}
|
||||
|
||||
mid1 = env->GetMethodID(klass, "meth01", "(I)V");
|
||||
if (mid1 == NULL) {
|
||||
printf("Cannot get jmethodID for method \"meth01\"\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
|
||||
JVMTI_EVENT_EXCEPTION_CATCH, NULL);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SetEventNotificationMode) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_nsk_jvmti_GetFrameLocation_frameloc001_checkFrame01(JNIEnv *env,
|
||||
jclass cls, jthread thr, jclass klass, jboolean mustPass) {
|
||||
jvmtiError err;
|
||||
jmethodID mid;
|
||||
jboolean isOk = JNI_FALSE;
|
||||
|
||||
if (jvmti == NULL || !caps.can_suspend) {
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
mid = env->GetMethodID(klass, "run", "()V");
|
||||
if (mid == NULL) {
|
||||
printf("Cannot get jmethodID for method \"run\"\n");
|
||||
result = STATUS_FAILED;
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
err = jvmti->SuspendThread(thr);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SuspendThread) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
// This tests the location of a throw/catch statement.
|
||||
// The returned location may be either the throw or the catch statement.
|
||||
// It seems like the throw statement is returned in compiled code (-Xcomp),
|
||||
// but the catch statement is returned in interpreted code.
|
||||
// Both locations are valid.
|
||||
// See bug JDK-4527281.
|
||||
isOk = checkFrame(jvmti, env, thr, mid, 31, 32, mustPass);
|
||||
|
||||
err = jvmti->ResumeThread(thr);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(ResumeThread) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
return isOk && result == PASSED;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_GetFrameLocation_frameloc001_getRes(JNIEnv *env, jclass cls) {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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/GetFrameLocation;
|
||||
|
||||
/* Reassembled from the following Java pattern:
|
||||
*
|
||||
* class frameloc001a extends Thread {
|
||||
* public void meth01(int i) {
|
||||
* try {
|
||||
* if (i > 0) {
|
||||
* throw new Throwable();
|
||||
* }
|
||||
* } catch (Throwable e) {}
|
||||
* }
|
||||
* public void run() {
|
||||
* int local = 2003;
|
||||
* synchronized (frameloc001.lock1) {
|
||||
* frameloc001.lock1.notify();
|
||||
* }
|
||||
* synchronized (frameloc001.lock2) {
|
||||
* frameloc001.fld = local;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
super class frameloc001a extends java/lang/Thread {
|
||||
|
||||
Method "<init>":"()V" stack 1 locals 1 {
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Thread."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
public Method meth01:"(I)V" stack 2 locals 3 {
|
||||
try t0;
|
||||
iload_1;
|
||||
ifle L12;
|
||||
new class java/lang/Throwable;
|
||||
dup;
|
||||
invokespecial Method java/lang/Throwable."<init>":"()V";
|
||||
athrow;
|
||||
endtry t0;
|
||||
L12: goto L16;
|
||||
catch t0 java/lang/Throwable;
|
||||
astore_2; // bci=15, expected to be here
|
||||
L16: return;
|
||||
}
|
||||
|
||||
public Method run:"()V" stack 1 locals 5 {
|
||||
sipush 2003;
|
||||
istore_1;
|
||||
getstatic Field frameloc001.lock1:"Ljava/lang/Object;";
|
||||
astore_2;
|
||||
aload_2;
|
||||
monitorenter;
|
||||
try t0;
|
||||
getstatic Field frameloc001.lock1:"Ljava/lang/Object;";
|
||||
invokevirtual Method java/lang/Object.notify:"()V";
|
||||
aload_2;
|
||||
monitorexit;
|
||||
endtry t0;
|
||||
goto L26;
|
||||
catch t0 #0;
|
||||
catch t1 #0;
|
||||
try t1;
|
||||
astore_3;
|
||||
aload_2;
|
||||
monitorexit;
|
||||
endtry t1;
|
||||
aload_3;
|
||||
athrow;
|
||||
L26: getstatic Field frameloc001.lock2:"Ljava/lang/Object;";
|
||||
astore_3;
|
||||
aload_3;
|
||||
monitorenter; // bci=31, expected to be here
|
||||
try t2;
|
||||
iload_1;
|
||||
putstatic Field frameloc001.fld:"I";
|
||||
aload_3;
|
||||
monitorexit;
|
||||
endtry t2;
|
||||
goto L48;
|
||||
catch t2 #0;
|
||||
catch t3 #0;
|
||||
try t3;
|
||||
astore 4;
|
||||
aload_3;
|
||||
monitorexit;
|
||||
endtry t3;
|
||||
aload 4;
|
||||
athrow;
|
||||
L48: return;
|
||||
}
|
||||
}
|
||||
@ -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 "frameloc001.cpp"
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetFrameLocation;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class frameloc002 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("frameloc002");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load frameloc002 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -1,44 +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/GetFrameLocation/frameloc002.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI function GetFrameLocation.
|
||||
* The test checks if the function returns expected values
|
||||
* for a native (JNI) frame.
|
||||
* COMMENTS
|
||||
* Fixed according to 4802866 bug.
|
||||
* Ported from JVMDI.
|
||||
* Fixed the 5004632 bug.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:frameloc002 nsk.jvmti.GetFrameLocation.frameloc002
|
||||
*/
|
||||
|
||||
@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "jvmti.h"
|
||||
#include "agent_common.h"
|
||||
#include "jni_tools.h"
|
||||
#include "JVMTITools.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#define PASSED 0
|
||||
#define STATUS_FAILED 2
|
||||
|
||||
typedef struct {
|
||||
const char *cls_sig;
|
||||
const char *name;
|
||||
const char *sig;
|
||||
jlocation loc;
|
||||
} frame_info;
|
||||
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static frame_info fi =
|
||||
{ "Lnsk/jvmti/GetFrameLocation/frameloc002;", "check",
|
||||
"(Ljava/lang/Thread;)I", -1 };
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_frameloc002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_frameloc002(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_frameloc002(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_GetFrameLocation_frameloc002_check(JNIEnv *env, jclass cls, jthread thr) {
|
||||
jvmtiError err;
|
||||
jclass klass;
|
||||
jmethodID mid;
|
||||
jlocation loc;
|
||||
char *cls_sig, *name, *sig, *generic;
|
||||
char buffer[32];
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> acquiring frame location ...\n");
|
||||
}
|
||||
err = jvmti->GetFrameLocation(thr, 0, &mid, &loc);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetFrameLocation) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> retrieving class/method info ...\n");
|
||||
}
|
||||
err = jvmti->GetMethodDeclaringClass(mid, &klass);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return result;
|
||||
}
|
||||
err = jvmti->GetClassSignature(klass, &cls_sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return result;
|
||||
}
|
||||
err = jvmti->GetMethodName(mid, &name, &sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", cls_sig);
|
||||
printf(">>> method: \"%s%s\"\n", name, sig);
|
||||
printf(">>> location: %s\n",
|
||||
jlong_to_string(loc, buffer));
|
||||
}
|
||||
|
||||
if (cls_sig == NULL ||
|
||||
strcmp(cls_sig, fi.cls_sig) != 0) {
|
||||
printf("(GetFrameLocation) wrong class: \"%s\"", cls_sig);
|
||||
printf(", expected: \"%s\"\n", fi.cls_sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (name == NULL ||
|
||||
strcmp(name, fi.name) != 0) {
|
||||
printf("(GetFrameLocation) wrong method name: \"%s\"", name);
|
||||
printf(", expected: \"%s\"\n", fi.name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (sig == NULL ||
|
||||
strcmp(sig, fi.sig) != 0) {
|
||||
printf("(GetFrameLocation) wrong method signature: \"%s\"", sig);
|
||||
printf(", expected: \"%s\"\n", fi.sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (loc != fi.loc) {
|
||||
printf("(GetFrameLocation) wrong location: %s",
|
||||
jlong_to_string(loc, buffer));
|
||||
printf(", expected: %s\n",
|
||||
jlong_to_string(fi.loc, buffer));
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "frameloc002.cpp"
|
||||
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetFrameLocation;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class frameloc003 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("frameloc003");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load frameloc003 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static int check(Thread thread);
|
||||
|
||||
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 Object lockStart = new Object();
|
||||
public static Object lockFinish = new Object();
|
||||
|
||||
public static int run(String args[], PrintStream out) {
|
||||
TestThread t = new TestThread();
|
||||
|
||||
synchronized (lockStart) {
|
||||
t.start();
|
||||
try {
|
||||
lockStart.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected: " + e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int res = check(t);
|
||||
|
||||
synchronized (lockFinish) {
|
||||
lockFinish.notify();
|
||||
}
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected: " + e);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static class TestThread extends Thread {
|
||||
public void run() {
|
||||
synchronized (lockFinish) {
|
||||
synchronized (lockStart) {
|
||||
lockStart.notify();
|
||||
}
|
||||
try {
|
||||
lockFinish.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("Unexpected: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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/GetFrameLocation/frameloc003.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI function
|
||||
* GetFrameLocation(thread, depth, methodPtr, locationPtr).
|
||||
* The test checks if the function returns:
|
||||
* - JVMTI_ERROR_INVALID_THREAD if thread is not a thread object
|
||||
* - JVMTI_ERROR_ILLEGAL_ARGUMENT if depth less than zero
|
||||
* - JVMTI_ERROR_NULL_POINTER if any of pointers is null
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm/native -agentlib:frameloc003 nsk.jvmti.GetFrameLocation.frameloc003
|
||||
*/
|
||||
|
||||
@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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 jvmtiCapabilities caps;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_frameloc003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_frameloc003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_frameloc003(JavaVM *jvm, char *options, void *reserved) {
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
#endif
|
||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||
jvmtiError err;
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_nsk_jvmti_GetFrameLocation_frameloc003_check(JNIEnv *env, jclass cls, jthread thr) {
|
||||
jvmtiError err;
|
||||
jmethodID mid;
|
||||
jlocation loc;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
return STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> invalid thread check ...\n");
|
||||
}
|
||||
err = jvmti->GetFrameLocation(cls, 0, &mid, &loc);
|
||||
if (err != JVMTI_ERROR_INVALID_THREAD) {
|
||||
printf("Error expected: JVMTI_ERROR_INVALID_THREAD,\n");
|
||||
printf(" actual: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (!caps.can_suspend) {
|
||||
return result;
|
||||
}
|
||||
|
||||
err = jvmti->SuspendThread(thr);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(SuspendThread) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> invalid depth check ...\n");
|
||||
}
|
||||
err = jvmti->GetFrameLocation(thr, -1, &mid, &loc);
|
||||
if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) {
|
||||
printf("Error expected: JVMTI_ERROR_ILLEGAL_ARGUMENT,\n");
|
||||
printf(" actual: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> (methodPtr) null pointer check ...\n");
|
||||
}
|
||||
err = jvmti->GetFrameLocation(thr, 0, NULL, &loc);
|
||||
if (err != JVMTI_ERROR_NULL_POINTER) {
|
||||
printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n");
|
||||
printf(" actual: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> (locationPtr) null pointer check ...\n");
|
||||
}
|
||||
err = jvmti->GetFrameLocation(thr, 0, &mid, NULL);
|
||||
if (err != JVMTI_ERROR_NULL_POINTER) {
|
||||
printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n");
|
||||
printf(" actual: %s (%d)\n", TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
err = jvmti->ResumeThread(thr);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(ResumeThread) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> ... done\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 "frameloc003.cpp"
|
||||
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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.GetStackTrace;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class getstacktr001 {
|
||||
|
||||
final static int JCK_STATUS_BASE = 95;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("getstacktr001");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.err.println("Could not load getstacktr001 library");
|
||||
System.err.println("java.library.path:"
|
||||
+ System.getProperty("java.library.path"));
|
||||
throw ule;
|
||||
}
|
||||
}
|
||||
|
||||
native static int chain();
|
||||
native static void check(Thread thread);
|
||||
|
||||
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 chain();
|
||||
}
|
||||
|
||||
public static void dummy() {
|
||||
check(Thread.currentThread());
|
||||
}
|
||||
}
|
||||
@ -1,47 +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/GetStackTrace/getstacktr001.
|
||||
* VM Testbase keywords: [quick, jpda, jvmti, noras]
|
||||
* VM Testbase readme:
|
||||
* DESCRIPTION
|
||||
* The test exercises JVMTI function GetStackTrace for the current thread.
|
||||
* The test checks the following:
|
||||
* - if function returns the expected frame of a Java method
|
||||
* - if function returns the expected frame of a JNI method
|
||||
* - if function returns the expected number of frames.
|
||||
* COMMENTS
|
||||
* Ported from JVMDI.
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @build nsk.jvmti.GetStackTrace.getstacktr001
|
||||
* @run main/othervm/native ExecDriver --java
|
||||
* -agentlib:getstacktr001
|
||||
* nsk.jvmti.GetStackTrace.getstacktr001
|
||||
*/
|
||||
|
||||
@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 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
|
||||
|
||||
typedef struct {
|
||||
const char *cls;
|
||||
const char *name;
|
||||
const char *sig;
|
||||
} frame_info;
|
||||
|
||||
static jvmtiEnv *jvmti = NULL;
|
||||
static jint result = PASSED;
|
||||
static jboolean printdump = JNI_FALSE;
|
||||
static frame_info frames[] = {
|
||||
{ "Lnsk/jvmti/GetStackTrace/getstacktr001;", "check",
|
||||
"(Ljava/lang/Thread;)V" },
|
||||
{ "Lnsk/jvmti/GetStackTrace/getstacktr001;", "dummy", "()V" },
|
||||
{ "Lnsk/jvmti/GetStackTrace/getstacktr001;", "chain", "()I" },
|
||||
{ "Lnsk/jvmti/GetStackTrace/getstacktr001;", "run",
|
||||
"([Ljava/lang/String;Ljava/io/PrintStream;)I" },
|
||||
{ "Lnsk/jvmti/GetStackTrace/getstacktr001;", "main",
|
||||
"([Ljava/lang/String;)V" }
|
||||
};
|
||||
|
||||
#define NUMBER_OF_STACK_FRAMES ((int) (sizeof(frames)/sizeof(frame_info)))
|
||||
|
||||
#ifdef STATIC_BUILD
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad_getstacktr001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach_getstacktr001(JavaVM *jvm, char *options, void *reserved) {
|
||||
return Agent_Initialize(jvm, options, reserved);
|
||||
}
|
||||
JNIEXPORT jint JNI_OnLoad_getstacktr001(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_GetStackTrace_getstacktr001_chain(JNIEnv *env, jclass cls) {
|
||||
jmethodID mid;
|
||||
|
||||
mid = env->GetStaticMethodID(cls, "dummy", "()V");
|
||||
env->CallStaticVoidMethod(cls, mid);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_nsk_jvmti_GetStackTrace_getstacktr001_check(JNIEnv *env, jclass cls, jthread thread) {
|
||||
jvmtiError err;
|
||||
jvmtiFrameInfo f[NUMBER_OF_STACK_FRAMES + 1];
|
||||
jclass callerClass;
|
||||
char *sigClass, *name, *sig, *generic;
|
||||
jint i, count;
|
||||
|
||||
if (jvmti == NULL) {
|
||||
printf("JVMTI client was not properly loaded!\n");
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
err = jvmti->GetStackTrace(thread, 0,
|
||||
NUMBER_OF_STACK_FRAMES + 1, f, &count);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetStackTrace) unexpected error: %s (%d)\n",
|
||||
TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
if (count != NUMBER_OF_STACK_FRAMES) {
|
||||
printf("Wrong number of frames: %d, expected: %d\n",
|
||||
count, NUMBER_OF_STACK_FRAMES);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
for (i = 0; i < count; i++) {
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> checking frame#%d ...\n", i);
|
||||
}
|
||||
err = jvmti->GetMethodDeclaringClass(
|
||||
f[i].method, &callerClass);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodDeclaringClass#%d) unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
continue;
|
||||
}
|
||||
err = jvmti->GetClassSignature(callerClass,
|
||||
&sigClass, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetClassSignature#%d) unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
continue;
|
||||
}
|
||||
err = jvmti->GetMethodName(f[i].method, &name, &sig, &generic);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
printf("(GetMethodName#%d) unexpected error: %s (%d)\n",
|
||||
i, TranslateError(err), err);
|
||||
result = STATUS_FAILED;
|
||||
continue;
|
||||
}
|
||||
if (printdump == JNI_TRUE) {
|
||||
printf(">>> class: \"%s\"\n", sigClass);
|
||||
printf(">>> method: \"%s%s\"\n", name, sig);
|
||||
printf(">>> %d ... done\n", i);
|
||||
}
|
||||
if (i < NUMBER_OF_STACK_FRAMES) {
|
||||
if (sigClass == NULL || strcmp(sigClass, frames[i].cls) != 0) {
|
||||
printf("(frame#%d) wrong class sig: \"%s\", expected: \"%s\"\n",
|
||||
i, sigClass, frames[i].cls);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (name == NULL || strcmp(name, frames[i].name) != 0) {
|
||||
printf("(frame#%d) wrong method name: \"%s\", expected: \"%s\"\n",
|
||||
i, name, frames[i].name);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
if (sig == NULL || strcmp(sig, frames[i].sig) != 0) {
|
||||
printf("(frame#%d) wrong method sig: \"%s\", expected: \"%s\"\n",
|
||||
i, sig, frames[i].sig);
|
||||
result = STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user