< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/VMDeath/vmdeath001/vmdeath001.cpp

Print this page
rev 52185 : [mq]: refactor


  31 
  32 #include "nsk_tools.h"
  33 #include "JVMTITools.h"
  34 #include "jvmti_tools.h"
  35 
  36 extern "C" {
  37 
  38 #define PASSED  0
  39 #define STATUS_FAILED  2
  40 
  41 static jvmtiEnv *jvmti = NULL;
  42 static jvmtiEventCallbacks callbacks;
  43 
  44 /** callback functions **/
  45 void JNICALL
  46 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
  47     jvmtiPhase phase;
  48 
  49     NSK_DISPLAY0("CHECK PASSED: VMDeath event received\n");
  50 
  51     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase,
  52             jvmti, &phase)))
  53         exit(95 + STATUS_FAILED);
  54 
  55     if (phase != JVMTI_PHASE_LIVE) {
  56         NSK_COMPLAIN1("TEST FAILED: VMDeath event received during non-live phase %s\n",
  57             TranslatePhase(phase));
  58         exit(95 + STATUS_FAILED);
  59     }
  60     else
  61         NSK_DISPLAY0("CHECK PASSED: VMDeath event received during the live phase as expected\n");
  62 
  63     exit(95 + PASSED);
  64 }
  65 /************************/
  66 
  67 #ifdef STATIC_BUILD
  68 JNIEXPORT jint JNICALL Agent_OnLoad_vmdeath001(JavaVM *jvm, char *options, void *reserved) {
  69     return Agent_Initialize(jvm, options, reserved);
  70 }
  71 JNIEXPORT jint JNICALL Agent_OnAttach_vmdeath001(JavaVM *jvm, char *options, void *reserved) {
  72     return Agent_Initialize(jvm, options, reserved);
  73 }
  74 JNIEXPORT jint JNI_OnLoad_vmdeath001(JavaVM *jvm, char *options, void *reserved) {
  75     return JNI_VERSION_1_8;
  76 }
  77 #endif
  78 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
  79     /* init framework and parse options */
  80     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
  81         return JNI_ERR;
  82 
  83     /* create JVMTI environment */
  84     if (!NSK_VERIFY((jvmti =
  85             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
  86         return JNI_ERR;
  87 
  88     NSK_DISPLAY0("setting event callbacks ...\n");
  89     (void) memset(&callbacks, 0, sizeof(callbacks));
  90     callbacks.VMDeath = &VMDeath;
  91     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks,
  92             jvmti, &callbacks, sizeof(callbacks))))
  93         return JNI_ERR;
  94 
  95     NSK_DISPLAY0("setting event callbacks done\nenabling VMDeath event ...\n");
  96     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
  97             jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
  98         return JNI_ERR;
  99     NSK_DISPLAY0("enabling VMDeath event done\n");
 100 
 101     return JNI_OK;
 102 }
 103 
 104 }


  31 
  32 #include "nsk_tools.h"
  33 #include "JVMTITools.h"
  34 #include "jvmti_tools.h"
  35 
  36 extern "C" {
  37 
  38 #define PASSED  0
  39 #define STATUS_FAILED  2
  40 
  41 static jvmtiEnv *jvmti = NULL;
  42 static jvmtiEventCallbacks callbacks;
  43 
  44 /** callback functions **/
  45 void JNICALL
  46 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
  47     jvmtiPhase phase;
  48 
  49     NSK_DISPLAY0("CHECK PASSED: VMDeath event received\n");
  50 
  51     if (!NSK_JVMTI_VERIFY(jvmti->GetPhase(&phase)))

  52         exit(95 + STATUS_FAILED);
  53 
  54     if (phase != JVMTI_PHASE_LIVE) {
  55         NSK_COMPLAIN1("TEST FAILED: VMDeath event received during non-live phase %s\n",
  56             TranslatePhase(phase));
  57         exit(95 + STATUS_FAILED);
  58     }
  59     else
  60         NSK_DISPLAY0("CHECK PASSED: VMDeath event received during the live phase as expected\n");
  61 
  62     exit(95 + PASSED);
  63 }
  64 /************************/
  65 
  66 #ifdef STATIC_BUILD
  67 JNIEXPORT jint JNICALL Agent_OnLoad_vmdeath001(JavaVM *jvm, char *options, void *reserved) {
  68     return Agent_Initialize(jvm, options, reserved);
  69 }
  70 JNIEXPORT jint JNICALL Agent_OnAttach_vmdeath001(JavaVM *jvm, char *options, void *reserved) {
  71     return Agent_Initialize(jvm, options, reserved);
  72 }
  73 JNIEXPORT jint JNI_OnLoad_vmdeath001(JavaVM *jvm, char *options, void *reserved) {
  74     return JNI_VERSION_1_8;
  75 }
  76 #endif
  77 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
  78     /* init framework and parse options */
  79     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
  80         return JNI_ERR;
  81 
  82     /* create JVMTI environment */
  83     if (!NSK_VERIFY((jvmti =
  84             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
  85         return JNI_ERR;
  86 
  87     NSK_DISPLAY0("setting event callbacks ...\n");
  88     (void) memset(&callbacks, 0, sizeof(callbacks));
  89     callbacks.VMDeath = &VMDeath;
  90     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))

  91         return JNI_ERR;
  92 
  93     NSK_DISPLAY0("setting event callbacks done\nenabling VMDeath event ...\n");
  94     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))

  95         return JNI_ERR;
  96     NSK_DISPLAY0("enabling VMDeath event done\n");
  97 
  98     return JNI_OK;
  99 }
 100 
 101 }
< prev index next >