< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/getallstktr001.cpp

Print this page
rev 51730 : 8210700: Clean up JNI_ENV_ARG and factorize the macros for vmTestbase/jvmti/unit tests
Summary:
Reviewed-by:

*** 25,67 **** #include <string.h> #include "jvmti.h" #include "jni_tools.h" #include "agent_common.h" - #ifdef __cplusplus extern "C" { - #endif - - #ifndef JNI_ENV_ARG - - #ifdef __cplusplus - #define JNI_ENV_ARG(x, y) y - #define JNI_ENV_ARG1(x) - #define JNI_ENV_PTR(x) x - #else - #define JNI_ENV_ARG(x,y) x, y - #define JNI_ENV_ARG1(x) x - #define JNI_ENV_PTR(x) (*x) - #endif - - #endif - - #define JVMTI_ENV_ARG JNI_ENV_ARG - #define JVMTI_ENV_ARG1 JNI_ENV_ARG1 - #define JVMTI_ENV_PTR JNI_ENV_PTR #define STATUS_FAILED 2 #define PASSED 0 #define JVMTI_ERROR_CHECK(str,res) \ ! if ( res != JVMTI_ERROR_NONE) { \ printf("%s %d\n" ,str, res); \ return res; \ } #define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) \ ! if ( res != err) { \ printf("%s unexpected error %d\n", str, res); \ return res; \ } #define JVMTI_ERROR_CHECK_VOID(str,res) \ --- 25,47 ---- #include <string.h> #include "jvmti.h" #include "jni_tools.h" #include "agent_common.h" extern "C" { #define STATUS_FAILED 2 #define PASSED 0 #define JVMTI_ERROR_CHECK(str,res) \ ! if (res != JVMTI_ERROR_NONE) { \ printf("%s %d\n" ,str, res); \ return res; \ } #define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) \ ! if (res != err) { \ printf("%s unexpected error %d\n", str, res); \ return res; \ } #define JVMTI_ERROR_CHECK_VOID(str,res) \
*** 103,124 **** } #endif jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { jint res; ! res = JNI_ENV_PTR(jvm)-> ! GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1); if (res < 0) { printf("Wrong result of a valid call to GetEnv!\n"); return JNI_ERR; } /* Add capabilities */ ! res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); ! res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps)); JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); return JNI_OK; } --- 83,103 ---- } #endif jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) { jint res; ! res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1); if (res < 0) { printf("Wrong result of a valid call to GetEnv!\n"); return JNI_ERR; } /* Add capabilities */ ! res = jvmti->GetPotentialCapabilities(&jvmti_caps); JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); ! res = jvmti->AddCapabilities(&jvmti_caps); JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res); return JNI_OK; }
*** 137,148 **** { jvmtiError ret; char sz[128]; sprintf(sz, "Raw-monitor"); ! ret = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti, sz), ! &jraw_monitor); if (ret != JVMTI_ERROR_NONE) { printf("Error: Raw monitor create %d \n", ret); iGlobalStatus = STATUS_FAILED; } --- 116,126 ---- { jvmtiError ret; char sz[128]; sprintf(sz, "Raw-monitor"); ! ret = jvmti->CreateRawMonitor(sz, &jraw_monitor); if (ret != JVMTI_ERROR_NONE) { printf("Error: Raw monitor create %d \n", ret); iGlobalStatus = STATUS_FAILED; }
*** 152,162 **** Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorEnter( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = JVMTI_ENV_PTR(jvmti)->RawMonitorEnter(JVMTI_ENV_ARG(jvmti, jraw_monitor)); if (ret != JVMTI_ERROR_NONE) { printf("Error: Raw monitor enter %d \n", ret); iGlobalStatus = STATUS_FAILED; } --- 130,140 ---- Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorEnter( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = jvmti->RawMonitorEnter(jraw_monitor); if (ret != JVMTI_ERROR_NONE) { printf("Error: Raw monitor enter %d \n", ret); iGlobalStatus = STATUS_FAILED; }
*** 166,176 **** Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorExit( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = JVMTI_ENV_PTR(jvmti)->RawMonitorExit(JVMTI_ENV_ARG(jvmti, jraw_monitor)); if (ret != JVMTI_ERROR_NONE) { printf("Error: RawMonitorExit %d \n", ret); iGlobalStatus = STATUS_FAILED; } --- 144,154 ---- Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_RawMonitorExit( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = jvmti->RawMonitorExit(jraw_monitor); if (ret != JVMTI_ERROR_NONE) { printf("Error: RawMonitorExit %d \n", ret); iGlobalStatus = STATUS_FAILED; }
*** 271,319 **** JNIEnv * env, jclass cls) { jvmtiError ret; int ti; ! ret = JVMTI_ENV_PTR(jvmti)->GetAllStackTraces(JVMTI_ENV_ARG(jvmti, MAX_FRAMES_CNT), ! &stack_buf1, ! &threads_count); if (ret != JVMTI_ERROR_NONE) { printf("Error: GetAllStackTraces %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jthread) * threads_count), ! (unsigned char**)&thread_list); if (ret != JVMTI_ERROR_NONE) { printf("Error: Allocate failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } for (ti = 0; ti < threads_count; ti++) { thread_list[ti] = ! (jthread)JNI_ENV_PTR(env)->NewGlobalRef( ! JNI_ENV_ARG(env, stack_buf1[ti].thread)); } } JNIEXPORT void JNICALL Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadsInfo( JNIEnv * env, jclass cls) { jvmtiError ret; int ti; ! ret = JVMTI_ENV_PTR(jvmti)->Allocate(JVMTI_ENV_ARG(jvmti, sizeof(jvmtiThreadInfo) * threads_count), (unsigned char**)&thread_info); if (ret != JVMTI_ERROR_NONE) { printf("Error: Allocate failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } for (ti = 0; ti < threads_count; ti++) { ! ret = JVMTI_ENV_PTR(jvmti)->GetThreadInfo(JVMTI_ENV_ARG(jvmti, thread_list[ti]), ! &thread_info[ti]); if (ret != JVMTI_ERROR_NONE) { printf("Error: GetThreadInfo %d \n", ret); iGlobalStatus = STATUS_FAILED; } printf("GetThreadInfo %d: thread: %s\n", ti, thread_info[ti].name); --- 249,293 ---- JNIEnv * env, jclass cls) { jvmtiError ret; int ti; ! ret = jvmti->GetAllStackTraces(MAX_FRAMES_CNT, &stack_buf1, &threads_count); if (ret != JVMTI_ERROR_NONE) { printf("Error: GetAllStackTraces %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = jvmti->Allocate(sizeof(jthread) * threads_count, ! (unsigned char**) &thread_list); if (ret != JVMTI_ERROR_NONE) { printf("Error: Allocate failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } for (ti = 0; ti < threads_count; ti++) { thread_list[ti] = ! (jthread)env->NewGlobalRef(stack_buf1[ti].thread); } } JNIEXPORT void JNICALL Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadsInfo( JNIEnv * env, jclass cls) { jvmtiError ret; int ti; ! ret = jvmti->Allocate(sizeof(jvmtiThreadInfo) * threads_count, (unsigned char**)&thread_info); if (ret != JVMTI_ERROR_NONE) { printf("Error: Allocate failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } for (ti = 0; ti < threads_count; ti++) { ! ret = jvmti->GetThreadInfo(thread_list[ti], &thread_info[ti]); if (ret != JVMTI_ERROR_NONE) { printf("Error: GetThreadInfo %d \n", ret); iGlobalStatus = STATUS_FAILED; } printf("GetThreadInfo %d: thread: %s\n", ti, thread_info[ti].name);
*** 325,339 **** Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadListStackTraces( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = JVMTI_ENV_PTR(jvmti)->GetThreadListStackTraces( ! JVMTI_ENV_ARG(jvmti, threads_count), ! thread_list, ! MAX_FRAMES_CNT, ! &stack_buf2); if (ret != JVMTI_ERROR_NONE) { printf("Error: GetThreadListStackTraces %d \n", ret); iGlobalStatus = STATUS_FAILED; } --- 299,310 ---- Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_GetThreadListStackTraces( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = jvmti->GetThreadListStackTraces( ! threads_count, thread_list, MAX_FRAMES_CNT, &stack_buf2); if (ret != JVMTI_ERROR_NONE) { printf("Error: GetThreadListStackTraces %d \n", ret); iGlobalStatus = STATUS_FAILED; }
*** 342,352 **** JNIEXPORT void JNICALL Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_ForceGC( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = JVMTI_ENV_PTR(jvmti)->ForceGarbageCollection(JVMTI_ENV_ARG1(jvmti)); if (ret != JVMTI_ERROR_NONE) { printf("Error: ForceGarbageCollection %d \n", ret); iGlobalStatus = STATUS_FAILED; } --- 313,323 ---- JNIEXPORT void JNICALL Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_ForceGC( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = jvmti->ForceGarbageCollection(); if (ret != JVMTI_ERROR_NONE) { printf("Error: ForceGarbageCollection %d \n", ret); iGlobalStatus = STATUS_FAILED; }
*** 363,394 **** Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_DeallocateBuffers( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)stack_buf1)); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate stack_buf1 failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)stack_buf2)); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate stack_buf2 failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)thread_info)); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate thread_info failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = JVMTI_ENV_PTR(jvmti)->Deallocate(JVMTI_ENV_ARG(jvmti, (unsigned char *)thread_list)); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate thread_list failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } } - #ifdef __cplusplus } - #endif --- 334,363 ---- Java_nsk_jvmti_unit_GetAllStackTraces_getallstktr001_DeallocateBuffers( JNIEnv * env, jclass cls) { jvmtiError ret; ! ret = jvmti->Deallocate((unsigned char *) stack_buf1); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate stack_buf1 failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = jvmti->Deallocate((unsigned char *) stack_buf2); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate stack_buf2 failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = jvmti->Deallocate((unsigned char *) thread_info); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate thread_info failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } ! ret = jvmti->Deallocate((unsigned char *) thread_list); if (ret != JVMTI_ERROR_NONE) { printf("Error: Deallocate thread_list failed with %d \n", ret); iGlobalStatus = STATUS_FAILED; } } }
< prev index next >