< prev index next >
test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/agent_tools.cpp
Print this page
rev 52185 : [mq]: refactor
*** 75,85 ****
/* ============================================================================= */
static jvmtiError init_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) {
data->thread_state = NEW;
data->last_debuggee_status = NSK_STATUS_PASSED;
! return NSK_CPP_STUB3(CreateRawMonitor, jvmti_env, "agent_data_monitor", &data->monitor);
}
/** Reset agent data to prepare for another run. */
void nsk_jvmti_resetAgentData() {
rawMonitorEnter(jvmti_env, agent_data.monitor);
--- 75,85 ----
/* ============================================================================= */
static jvmtiError init_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) {
data->thread_state = NEW;
data->last_debuggee_status = NSK_STATUS_PASSED;
! return jvmti_env->CreateRawMonitor("agent_data_monitor", &data->monitor);
}
/** Reset agent data to prepare for another run. */
void nsk_jvmti_resetAgentData() {
rawMonitorEnter(jvmti_env, agent_data.monitor);
*** 91,108 ****
agent_data.last_debuggee_status = NSK_STATUS_PASSED;
rawMonitorExit(jvmti_env, agent_data.monitor);
}
static jvmtiError free_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) {
! return NSK_CPP_STUB2(DestroyRawMonitor, jvmti_env, data->monitor);
}
/** Create JVMTI environment. */
jvmtiEnv* nsk_jvmti_createJVMTIEnv(JavaVM* javaVM, void* reserved) {
jvm = javaVM;
! if (!NSK_VERIFY(
! NSK_CPP_STUB3(GetEnv, javaVM, (void **)&jvmti_env, JVMTI_VERSION_1_1) == JNI_OK)) {
nsk_jvmti_setFailStatus();
return NULL;
}
if (!NSK_JVMTI_VERIFY(init_agent_data(jvmti_env, &agent_data))) {
--- 91,107 ----
agent_data.last_debuggee_status = NSK_STATUS_PASSED;
rawMonitorExit(jvmti_env, agent_data.monitor);
}
static jvmtiError free_agent_data(jvmtiEnv *jvmti_env, agent_data_t *data) {
! return jvmti_env->DestroyRawMonitor(data->monitor);
}
/** Create JVMTI environment. */
jvmtiEnv* nsk_jvmti_createJVMTIEnv(JavaVM* javaVM, void* reserved) {
jvm = javaVM;
! if (!NSK_VERIFY(javaVM->GetEnv((void **)&jvmti_env, JVMTI_VERSION_1_1) == JNI_OK)) {
nsk_jvmti_setFailStatus();
return NULL;
}
if (!NSK_JVMTI_VERIFY(init_agent_data(jvmti_env, &agent_data))) {
*** 114,125 ****
}
/** Dispose JVMTI environment */
static int nsk_jvmti_disposeJVMTIEnv(jvmtiEnv* jvmti_env) {
if (jvmti_env != NULL) {
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB1(DisposeEnvironment, jvmti_env))) {
nsk_jvmti_setFailStatus();
return NSK_FALSE;
}
if (!NSK_JVMTI_VERIFY(free_agent_data(jvmti_env, &agent_data))) {
--- 113,123 ----
}
/** Dispose JVMTI environment */
static int nsk_jvmti_disposeJVMTIEnv(jvmtiEnv* jvmti_env) {
if (jvmti_env != NULL) {
! if (!NSK_JVMTI_VERIFY(jvmti_env->DisposeEnvironment())) {
nsk_jvmti_setFailStatus();
return NSK_FALSE;
}
if (!NSK_JVMTI_VERIFY(free_agent_data(jvmti_env, &agent_data))) {
*** 163,173 ****
}
/* finalize agent thread */
{
/* gelete global ref for agent thread */
! NSK_CPP_STUB2(DeleteGlobalRef, agentJNI, agentThread);
agentThread = NULL;
}
}
/** Start wrapper for user agent thread. */
--- 161,171 ----
}
/* finalize agent thread */
{
/* gelete global ref for agent thread */
! agentJNI->DeleteGlobalRef(agentThread);
agentThread = NULL;
}
}
/** Start wrapper for user agent thread. */
*** 182,220 ****
jclass threadClass = NULL;
jmethodID threadCtor = NULL;
jobject threadObject = NULL;
jobject threadGlobalRef = NULL;
! if (!NSK_JNI_VERIFY(jni_env, (threadClass =
! NSK_CPP_STUB2(FindClass, jni_env, THREAD_CLASS_NAME)) != NULL)) {
return NULL;
}
if (!NSK_JNI_VERIFY(jni_env, (threadCtor =
! NSK_CPP_STUB4(GetMethodID, jni_env, threadClass, THREAD_CTOR_NAME, THREAD_CTOR_SIGNATURE)) != NULL))
return NULL;
! if (!NSK_JNI_VERIFY(jni_env, (threadName =
! NSK_CPP_STUB2(NewStringUTF, jni_env, THREAD_NAME)) != NULL))
return NULL;
if (!NSK_JNI_VERIFY(jni_env, (threadObject =
! NSK_CPP_STUB4(NewObject, jni_env, threadClass, threadCtor, threadName)) != NULL))
return NULL;
if (!NSK_JNI_VERIFY(jni_env, (threadGlobalRef =
! NSK_CPP_STUB2(NewGlobalRef, jni_env, threadObject)) != NULL)) {
! NSK_CPP_STUB2(DeleteLocalRef, jni_env, threadObject);
return NULL;
}
agentThread = (jthread)threadGlobalRef;
if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB5(RunAgentThread, jvmti_env, agentThread,
! &agentThreadWrapper, agentThreadArg, THREAD_PRIORITY))) {
! NSK_CPP_STUB2(DeleteGlobalRef, jni_env, threadGlobalRef);
! NSK_CPP_STUB2(DeleteLocalRef, jni_env, threadObject);
return NULL;
}
return agentThread;
}
--- 180,215 ----
jclass threadClass = NULL;
jmethodID threadCtor = NULL;
jobject threadObject = NULL;
jobject threadGlobalRef = NULL;
! if (!NSK_JNI_VERIFY(jni_env, (threadClass = jni_env->FindClass(THREAD_CLASS_NAME)) != NULL)) {
return NULL;
}
if (!NSK_JNI_VERIFY(jni_env, (threadCtor =
! jni_env->GetMethodID(threadClass, THREAD_CTOR_NAME, THREAD_CTOR_SIGNATURE)) != NULL))
return NULL;
! if (!NSK_JNI_VERIFY(jni_env, (threadName = jni_env->NewStringUTF(THREAD_NAME)) != NULL))
return NULL;
if (!NSK_JNI_VERIFY(jni_env, (threadObject =
! jni_env->NewObject(threadClass, threadCtor, threadName)) != NULL))
return NULL;
if (!NSK_JNI_VERIFY(jni_env, (threadGlobalRef =
! jni_env->NewGlobalRef(threadObject)) != NULL)) {
! jni_env->DeleteLocalRef(threadObject);
return NULL;
}
agentThread = (jthread)threadGlobalRef;
if (!NSK_JVMTI_VERIFY(
! jvmti_env->RunAgentThread(agentThread, &agentThreadWrapper, agentThreadArg, THREAD_PRIORITY))) {
! jni_env->DeleteGlobalRef(threadGlobalRef);
! jni_env->DeleteLocalRef(threadObject);
return NULL;
}
return agentThread;
}
*** 393,442 ****
if (!NSK_VERIFY(signature != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB3(GetLoadedClasses, jvmti_env, &count, &classes))) {
nsk_jvmti_setFailStatus();
return NULL;
}
for (i = 0; i < count; i++) {
char* sig = NULL;
char* generic = NULL;
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB4(GetClassSignature, jvmti_env, classes[i], &sig, &generic))) {
nsk_jvmti_setFailStatus();
break;
}
if (sig != NULL && strcmp(signature, sig) == 0) {
foundClass = classes[i];
}
! if (!(NSK_JVMTI_VERIFY(
! NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig))
! && NSK_JVMTI_VERIFY(
! NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)generic)))) {
nsk_jvmti_setFailStatus();
break;
}
if (foundClass != NULL)
break;
}
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)classes))) {
nsk_jvmti_setFailStatus();
return NULL;
}
if (!NSK_JNI_VERIFY(jni_env, (foundClass = (jclass)
! NSK_CPP_STUB2(NewGlobalRef, jni_env, foundClass)) != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
return foundClass;
--- 388,432 ----
if (!NSK_VERIFY(signature != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
! if (!NSK_JVMTI_VERIFY(jvmti_env->GetLoadedClasses(&count, &classes))) {
nsk_jvmti_setFailStatus();
return NULL;
}
for (i = 0; i < count; i++) {
char* sig = NULL;
char* generic = NULL;
! if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(classes[i], &sig, &generic))) {
nsk_jvmti_setFailStatus();
break;
}
if (sig != NULL && strcmp(signature, sig) == 0) {
foundClass = classes[i];
}
! if (!(NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)sig))
! && NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)generic)))) {
nsk_jvmti_setFailStatus();
break;
}
if (foundClass != NULL)
break;
}
! if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)classes))) {
nsk_jvmti_setFailStatus();
return NULL;
}
if (!NSK_JNI_VERIFY(jni_env, (foundClass = (jclass)
! jni_env->NewGlobalRef(foundClass)) != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
return foundClass;
*** 452,490 ****
if (!NSK_VERIFY(name != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB3(GetAllThreads, jvmti_env, &count, &threads))) {
nsk_jvmti_setFailStatus();
return NULL;
}
for (i = 0; i < count; i++) {
jvmtiThreadInfo info;
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB3(GetThreadInfo, jvmti_env, threads[i], &info))) {
nsk_jvmti_setFailStatus();
break;
}
if (info.name != NULL && strcmp(name, info.name) == 0) {
foundThread = threads[i];
break;
}
}
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)threads))) {
nsk_jvmti_setFailStatus();
return NULL;
}
if (!NSK_JNI_VERIFY(jni_env, (foundThread = (jthread)
! NSK_CPP_STUB2(NewGlobalRef, jni_env, foundThread)) != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
return foundThread;
--- 442,477 ----
if (!NSK_VERIFY(name != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
! if (!NSK_JVMTI_VERIFY(jvmti_env->GetAllThreads(&count, &threads))) {
nsk_jvmti_setFailStatus();
return NULL;
}
for (i = 0; i < count; i++) {
jvmtiThreadInfo info;
! if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(threads[i], &info))) {
nsk_jvmti_setFailStatus();
break;
}
if (info.name != NULL && strcmp(name, info.name) == 0) {
foundThread = threads[i];
break;
}
}
! if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)threads))) {
nsk_jvmti_setFailStatus();
return NULL;
}
if (!NSK_JNI_VERIFY(jni_env, (foundThread = (jthread)
! jni_env->NewGlobalRef(foundThread)) != NULL)) {
nsk_jvmti_setFailStatus();
return NULL;
}
return foundThread;
*** 497,508 ****
int nsk_jvmti_addLocationCapabilities() {
jvmtiCapabilities caps;
memset(&caps, 0, sizeof(caps));
caps.can_get_line_numbers = 1;
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps)))
return NSK_FALSE;
return NSK_TRUE;
}
--- 484,494 ----
int nsk_jvmti_addLocationCapabilities() {
jvmtiCapabilities caps;
memset(&caps, 0, sizeof(caps));
caps.can_get_line_numbers = 1;
! if (!NSK_JVMTI_VERIFY(jvmti_env->AddCapabilities(&caps)))
return NSK_FALSE;
return NSK_TRUE;
}
*** 513,524 ****
if (!nsk_jvmti_addLocationCapabilities())
return NSK_FALSE;
memset(&caps, 0, sizeof(caps));
caps.can_generate_breakpoint_events = 1;
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps)))
return NSK_FALSE;
return NSK_TRUE;
}
--- 499,509 ----
if (!nsk_jvmti_addLocationCapabilities())
return NSK_FALSE;
memset(&caps, 0, sizeof(caps));
caps.can_generate_breakpoint_events = 1;
! if (!NSK_JVMTI_VERIFY(jvmti_env->AddCapabilities(&caps)))
return NSK_FALSE;
return NSK_TRUE;
}
*** 527,547 ****
jint count = 0;
jvmtiLineNumberEntry* table = NULL;
jlocation location = NSK_JVMTI_INVALID_JLOCATION;
int i;
! if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetLineNumberTable, jvmti_env, method, &count, &table)))
return NSK_JVMTI_INVALID_JLOCATION;
for (i = 0; i < count; i++) {
if (table[i].line_number == line) {
location = table[i].start_location;
break;
}
}
! if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)table)))
return NSK_JVMTI_INVALID_JLOCATION;
return location;
}
--- 512,532 ----
jint count = 0;
jvmtiLineNumberEntry* table = NULL;
jlocation location = NSK_JVMTI_INVALID_JLOCATION;
int i;
! if (!NSK_JVMTI_VERIFY(jvmti_env->GetLineNumberTable(method, &count, &table)))
return NSK_JVMTI_INVALID_JLOCATION;
for (i = 0; i < count; i++) {
if (table[i].line_number == line) {
location = table[i].start_location;
break;
}
}
! if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)table)))
return NSK_JVMTI_INVALID_JLOCATION;
return location;
}
*** 551,561 ****
if (!NSK_VERIFY((location =
nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION))
return NSK_JVMTI_INVALID_JLOCATION;
! if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, jvmti_env, method, location)))
return NSK_JVMTI_INVALID_JLOCATION;
return location;
}
--- 536,546 ----
if (!NSK_VERIFY((location =
nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION))
return NSK_JVMTI_INVALID_JLOCATION;
! if (!NSK_JVMTI_VERIFY(jvmti_env->SetBreakpoint(method, location)))
return NSK_JVMTI_INVALID_JLOCATION;
return location;
}
*** 565,575 ****
if (!NSK_VERIFY((location =
nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION))
return NSK_JVMTI_INVALID_JLOCATION;
! if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ClearBreakpoint, jvmti_env, method, location)))
return NSK_JVMTI_INVALID_JLOCATION;
return location;
}
--- 550,560 ----
if (!NSK_VERIFY((location =
nsk_jvmti_getLineLocation(cls, method, line)) != NSK_JVMTI_INVALID_JLOCATION))
return NSK_JVMTI_INVALID_JLOCATION;
! if (!NSK_JVMTI_VERIFY(jvmti_env->ClearBreakpoint(method, location)))
return NSK_JVMTI_INVALID_JLOCATION;
return location;
}
*** 578,590 ****
/** Enable or disable given events. */
int nsk_jvmti_enableEvents(jvmtiEventMode enable, int size, jvmtiEvent list[], jthread thread) {
int i;
for (i = 0; i < size; i++) {
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, enable,
! list[i], thread))) {
nsk_jvmti_setFailStatus();
return NSK_FALSE;
}
}
return NSK_TRUE;
--- 563,573 ----
/** Enable or disable given events. */
int nsk_jvmti_enableEvents(jvmtiEventMode enable, int size, jvmtiEvent list[], jthread thread) {
int i;
for (i = 0; i < size; i++) {
! if (!NSK_JVMTI_VERIFY(jvmti_env->SetEventNotificationMode(enable, list[i], thread))) {
nsk_jvmti_setFailStatus();
return NSK_FALSE;
}
}
return NSK_TRUE;
*** 622,664 ****
jclass cls;
char *class_sig = NULL;
char *name = NULL;
char *sig = NULL;
! if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
nsk_jvmti_setFailStatus();
return;
}
if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE)
return;
! if (NSK_JVMTI_VERIFY(
! NSK_CPP_STUB5(GetMethodName, jvmti_env, mid, &name, &sig, NULL))) {
if (strcmp(name, BIND_METHOD_NAME) == 0 &&
strcmp(sig, BIND_METHOD_SIGNATURE) == 0) {
! if (NSK_JVMTI_VERIFY(
! NSK_CPP_STUB3(GetMethodDeclaringClass, jvmti_env, mid, &cls))
! && NSK_JVMTI_VERIFY(
! NSK_CPP_STUB4(GetClassSignature, jvmti_env, cls, &class_sig, NULL))
&& strcmp(class_sig, BIND_CLASS_NAME) == 0
&& address != (void*)Java_nsk_share_jvmti_DebugeeClass_checkStatus) {
checkStatus_func = (checkStatus_type)address;
NSK_TRACE(*new_address_ptr = (void*)MA_checkStatus);
}
}
}
if (name != NULL)
! NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name);
if (sig != NULL)
! NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)sig);
if (class_sig != NULL)
! NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)class_sig);
}
/**
* Initialize multiple agent:
* establish processing of nativeMethodBind events
--- 605,644 ----
jclass cls;
char *class_sig = NULL;
char *name = NULL;
char *sig = NULL;
! if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
nsk_jvmti_setFailStatus();
return;
}
if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE)
return;
! if (NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(mid, &name, &sig, NULL))) {
if (strcmp(name, BIND_METHOD_NAME) == 0 &&
strcmp(sig, BIND_METHOD_SIGNATURE) == 0) {
! if (NSK_JVMTI_VERIFY(jvmti_env->GetMethodDeclaringClass(mid, &cls))
! && NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(cls, &class_sig, NULL))
&& strcmp(class_sig, BIND_CLASS_NAME) == 0
&& address != (void*)Java_nsk_share_jvmti_DebugeeClass_checkStatus) {
checkStatus_func = (checkStatus_type)address;
NSK_TRACE(*new_address_ptr = (void*)MA_checkStatus);
}
}
}
if (name != NULL)
! jvmti_env->Deallocate((unsigned char*)name);
if (sig != NULL)
! jvmti_env->Deallocate((unsigned char*)sig);
if (class_sig != NULL)
! jvmti_env->Deallocate((unsigned char*)class_sig);
}
/**
* Initialize multiple agent:
* establish processing of nativeMethodBind events
*** 679,701 ****
{
jvmtiCapabilities caps;
memset(&caps, 0, sizeof(caps));
caps.can_generate_native_method_bind_events = 1;
! if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti_env, &caps)))
return NSK_FALSE;
}
callbacks->NativeMethodBind = nativeMethodBind;
! if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB3(SetEventCallbacks, jvmti_env, callbacks,
! sizeof(jvmtiEventCallbacks))))
return NSK_FALSE;
if (!NSK_JVMTI_VERIFY(
! NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE,
! JVMTI_EVENT_NATIVE_METHOD_BIND, NULL)))
return NSK_FALSE;
return NSK_TRUE;
}
--- 659,678 ----
{
jvmtiCapabilities caps;
memset(&caps, 0, sizeof(caps));
caps.can_generate_native_method_bind_events = 1;
! if (!NSK_JVMTI_VERIFY(jvmti_env->AddCapabilities(&caps)))
return NSK_FALSE;
}
callbacks->NativeMethodBind = nativeMethodBind;
! if (!NSK_JVMTI_VERIFY(jvmti_env->SetEventCallbacks(callbacks, sizeof(jvmtiEventCallbacks))))
return NSK_FALSE;
if (!NSK_JVMTI_VERIFY(
! jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_NATIVE_METHOD_BIND, NULL)))
return NSK_FALSE;
return NSK_TRUE;
}
*** 729,739 ****
void nsk_jvmti_showPossessedCapabilities(jvmtiEnv *jvmti_env) {
jvmtiCapabilities caps;
! if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities, jvmti_env, &caps))) {
return;
}
NSK_DISPLAY0("\n");
NSK_DISPLAY0("Possessed capabilities:\n");
--- 706,716 ----
void nsk_jvmti_showPossessedCapabilities(jvmtiEnv *jvmti_env) {
jvmtiCapabilities caps;
! if (!NSK_JVMTI_VERIFY(jvmti_env->GetCapabilities(&caps))) {
return;
}
NSK_DISPLAY0("\n");
NSK_DISPLAY0("Possessed capabilities:\n");
< prev index next >