< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassLoad/classload001/classload001.cpp

Print this page
rev 51942 : [mq]: refactor


  81 
  82     for(i=0; i<EXP_SIG_NUM; i++)
  83         clsEvents[i] = 0;
  84 
  85     for(i=0; i<UNEXP_SIG_NUM; i++)
  86         primClsEvents[i] = 0;
  87 }
  88 
  89 static int findSig(char *sig, int expected) {
  90     unsigned int i;
  91 
  92     for (i=0; i<((expected==1)?EXP_SIG_NUM:UNEXP_SIG_NUM); i++)
  93         if (sig != NULL &&
  94                 strcmp(((expected==1)?expSigs[i]:unexpSigs[i]), sig) == 0)
  95             return i; /* the signature found, return index */
  96 
  97     return -1; /* the signature not found */
  98 }
  99 
 100 static void lock(jvmtiEnv *jvmti_env, JNIEnv *jni_env) {
 101     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter,
 102             jvmti_env, countLock)))
 103         NSK_CPP_STUB2(FatalError, jni_env,
 104                 "failed to enter a raw monitor\n");
 105 }
 106 
 107 static void unlock(jvmtiEnv *jvmti_env, JNIEnv *jni_env) {
 108     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit,
 109         jvmti_env, countLock)))
 110         NSK_CPP_STUB2(FatalError, jni_env,
 111                 "failed to exit a raw monitor\n");
 112 }
 113 
 114 /** callback functions **/
 115 void JNICALL
 116 ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, jclass klass) {
 117     int i = 0;
 118     char *sig, *generic;
 119 
 120     lock(jvmti_env, env);
 121 
 122     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature,
 123             jvmti_env, klass, &sig, &generic))) {
 124         result = STATUS_FAILED;
 125         NSK_COMPLAIN0("TEST FAILURE: unable to obtain a class signature\n");
 126     }
 127 
 128     if ((i = findSig(sig, 1)) != -1) {
 129         clsEvents[i]++;
 130         NSK_DISPLAY1("CHECK PASSED: ClassLoad event received for the class \"%s\" as expected\n",
 131             sig);
 132     }
 133     else if ((i = findSig(sig, 0)) != -1) {
 134         result = STATUS_FAILED;
 135         primClsEvents[i]++;
 136         NSK_COMPLAIN1(
 137             "TEST FAILED: JVMTI_EVENT_CLASS_LOAD event received for\n"
 138             "\t a primitive class/array of primitive types with the signature \"%s\"\n",
 139             sig);
 140     }
 141 
 142     unlock(jvmti_env, env);
 143 }


 168 }
 169 JNIEXPORT jint JNICALL Agent_OnAttach_classload001(JavaVM *jvm, char *options, void *reserved) {
 170     return Agent_Initialize(jvm, options, reserved);
 171 }
 172 JNIEXPORT jint JNI_OnLoad_classload001(JavaVM *jvm, char *options, void *reserved) {
 173     return JNI_VERSION_1_8;
 174 }
 175 #endif
 176 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 177     /* init framework and parse options */
 178     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 179         return JNI_ERR;
 180 
 181     /* create JVMTI environment */
 182     if (!NSK_VERIFY((jvmti =
 183             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 184         return JNI_ERR;
 185 
 186     initCounters();
 187 
 188     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor,
 189             jvmti, "_counter_lock", &countLock)))
 190         return JNI_ERR;
 191 
 192     NSK_DISPLAY0("setting event callbacks ...\n");
 193     (void) memset(&callbacks, 0, sizeof(callbacks));
 194     callbacks.ClassLoad = &ClassLoad;
 195     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks,
 196             jvmti, &callbacks, sizeof(callbacks))))
 197         return JNI_ERR;
 198 
 199     NSK_DISPLAY0("setting event callbacks done\nenabling ClassLoad event ...\n");
 200     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
 201             jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL)))
 202         return JNI_ERR;
 203     NSK_DISPLAY0("the event enabled\n");
 204 
 205     return JNI_OK;
 206 }
 207 
 208 }


  81 
  82     for(i=0; i<EXP_SIG_NUM; i++)
  83         clsEvents[i] = 0;
  84 
  85     for(i=0; i<UNEXP_SIG_NUM; i++)
  86         primClsEvents[i] = 0;
  87 }
  88 
  89 static int findSig(char *sig, int expected) {
  90     unsigned int i;
  91 
  92     for (i=0; i<((expected==1)?EXP_SIG_NUM:UNEXP_SIG_NUM); i++)
  93         if (sig != NULL &&
  94                 strcmp(((expected==1)?expSigs[i]:unexpSigs[i]), sig) == 0)
  95             return i; /* the signature found, return index */
  96 
  97     return -1; /* the signature not found */
  98 }
  99 
 100 static void lock(jvmtiEnv *jvmti_env, JNIEnv *jni_env) {
 101     if (!NSK_JVMTI_VERIFY(jvmti_env->RawMonitorEnter(countLock)))
 102         jni_env->FatalError("failed to enter a raw monitor\n");


 103 }
 104 
 105 static void unlock(jvmtiEnv *jvmti_env, JNIEnv *jni_env) {
 106     if (!NSK_JVMTI_VERIFY(jvmti_env->RawMonitorExit(countLock)))
 107         jni_env->FatalError("failed to exit a raw monitor\n");


 108 }
 109 
 110 /** callback functions **/
 111 void JNICALL
 112 ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread, jclass klass) {
 113     int i = 0;
 114     char *sig, *generic;
 115 
 116     lock(jvmti_env, env);
 117 
 118     if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(klass, &sig, &generic))) {

 119         result = STATUS_FAILED;
 120         NSK_COMPLAIN0("TEST FAILURE: unable to obtain a class signature\n");
 121     }
 122 
 123     if ((i = findSig(sig, 1)) != -1) {
 124         clsEvents[i]++;
 125         NSK_DISPLAY1("CHECK PASSED: ClassLoad event received for the class \"%s\" as expected\n",
 126             sig);
 127     }
 128     else if ((i = findSig(sig, 0)) != -1) {
 129         result = STATUS_FAILED;
 130         primClsEvents[i]++;
 131         NSK_COMPLAIN1(
 132             "TEST FAILED: JVMTI_EVENT_CLASS_LOAD event received for\n"
 133             "\t a primitive class/array of primitive types with the signature \"%s\"\n",
 134             sig);
 135     }
 136 
 137     unlock(jvmti_env, env);
 138 }


 163 }
 164 JNIEXPORT jint JNICALL Agent_OnAttach_classload001(JavaVM *jvm, char *options, void *reserved) {
 165     return Agent_Initialize(jvm, options, reserved);
 166 }
 167 JNIEXPORT jint JNI_OnLoad_classload001(JavaVM *jvm, char *options, void *reserved) {
 168     return JNI_VERSION_1_8;
 169 }
 170 #endif
 171 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 172     /* init framework and parse options */
 173     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 174         return JNI_ERR;
 175 
 176     /* create JVMTI environment */
 177     if (!NSK_VERIFY((jvmti =
 178             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 179         return JNI_ERR;
 180 
 181     initCounters();
 182 
 183     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_counter_lock", &countLock)))

 184         return JNI_ERR;
 185 
 186     NSK_DISPLAY0("setting event callbacks ...\n");
 187     (void) memset(&callbacks, 0, sizeof(callbacks));
 188     callbacks.ClassLoad = &ClassLoad;
 189     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))

 190         return JNI_ERR;
 191 
 192     NSK_DISPLAY0("setting event callbacks done\nenabling ClassLoad event ...\n");
 193     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL)))

 194         return JNI_ERR;
 195     NSK_DISPLAY0("the event enabled\n");
 196 
 197     return JNI_OK;
 198 }
 199 
 200 }
< prev index next >