< prev index next >
test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/ForceGarbageCollection/gc/gc.cpp
Print this page
rev 51722 : 8210700: Clean up JNI_ENV_ARG and factorize the macros for vmTestbase/jvmti/unit tests
Summary:
Reviewed-by:
*** 24,54 ****
#include <stdio.h>
#include <string.h>
#include "jvmti.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 JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;}
#define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; }
#define THREADS_LIMIT 8
--- 24,35 ----
*** 128,171 ****
if (strstr(options, "printdump")) {
printdump = 1;
}
}
! res = JNI_ENV_PTR(jvm)->
! GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1);
if (res < 0) {
debug_printf("Wrong result of a valid call to GetEnv!\n");
return JNI_ERR;
}
/* Create data access lock */
! res = JVMTI_ENV_PTR(jvmti)->CreateRawMonitor(JVMTI_ENV_ARG(jvmti,"_access_lock"),&access_lock);
JVMTI_ERROR_CHECK("RawMonitorEnter in monitor_contended_entered failed with error code ", res);
/* Add capabilities */
! res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
! res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
/* Enable events */
init_callbacks();
! res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks));
JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
! res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res);
! res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res);
! res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_GARBAGE_COLLECTION_START,NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for gc start returned error", res);
! res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_GARBAGE_COLLECTION_FINISH,NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for gc finish returned error", res);
return JNI_OK;
}
--- 109,151 ----
if (strstr(options, "printdump")) {
printdump = 1;
}
}
! res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
if (res < 0) {
debug_printf("Wrong result of a valid call to GetEnv!\n");
return JNI_ERR;
}
/* Create data access lock */
! res = jvmti->CreateRawMonitor("_access_lock", &access_lock);
JVMTI_ERROR_CHECK("RawMonitorEnter in monitor_contended_entered failed with error code ", res);
/* Add capabilities */
! res = jvmti->GetPotentialCapabilities(&jvmti_caps);
JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
! res = jvmti->AddCapabilities(&jvmti_caps);
JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
/* Enable events */
init_callbacks();
! res = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
! res = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res);
! res = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res);
! res = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for gc start returned error", res);
! res = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL);
JVMTI_ERROR_CHECK("SetEventNotificationMode for gc finish returned error", res);
return JNI_OK;
}
*** 197,212 ****
JNIEXPORT void JNICALL
Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_jvmtiForceGC (JNIEnv * env, jclass cls) {
jvmtiError ret;
debug_printf("jvmti Force gc requested \n");
! ret = JVMTI_ENV_PTR(jvmti)->ForceGarbageCollection(JVMTI_ENV_ARG1(jvmti));
if (ret != JVMTI_ERROR_NONE) {
printf("Error: ForceGarbageCollection %d \n", ret);
iGlobalStatus = 2;
}
}
- #ifdef __cplusplus
}
- #endif
--- 177,190 ----
JNIEXPORT void JNICALL
Java_nsk_jvmti_unit_functions_ForceGarbageCollection_gc_jvmtiForceGC (JNIEnv * env, jclass cls) {
jvmtiError ret;
debug_printf("jvmti Force gc requested \n");
! ret = jvmti->ForceGarbageCollection();
if (ret != JVMTI_ERROR_NONE) {
printf("Error: ForceGarbageCollection %d \n", ret);
iGlobalStatus = 2;
}
}
}
< prev index next >