test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t002/em01t002.cpp
changeset 52081 ca7ddf0a1d47
parent 51774 79dc492c00ab
child 52284 1f402d1f630f
equal deleted inserted replaced
52080:a2c72b476c9f 52081:ca7ddf0a1d47
    63                         jobject o, jobject loader, jstring className) {
    63                         jobject o, jobject loader, jstring className) {
    64     jclass klass;
    64     jclass klass;
    65     jmethodID methodID;
    65     jmethodID methodID;
    66     jclass loadedClass;
    66     jclass loadedClass;
    67 
    67 
    68     if (!NSK_JNI_VERIFY(jni_env, (klass =
    68     if (!NSK_JNI_VERIFY(jni_env, (klass = jni_env->GetObjectClass(loader)) != NULL)) {
    69             NSK_CPP_STUB2(GetObjectClass, jni_env, loader)) != NULL)) {
       
    70         nsk_jvmti_setFailStatus();
    69         nsk_jvmti_setFailStatus();
    71         return NULL;
    70         return NULL;
    72     }
    71     }
    73 
    72 
    74     if (!NSK_JNI_VERIFY(jni_env, (methodID =
    73     if (!NSK_JNI_VERIFY(jni_env,
    75             NSK_CPP_STUB4(GetMethodID, jni_env, klass, "loadClass",
    74             (methodID = jni_env->GetMethodID(
    76                         "(Ljava/lang/String;)Ljava/lang/Class;")) != NULL)) {
    75                 klass, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;")) != NULL)) {
    77         nsk_jvmti_setFailStatus();
    76         nsk_jvmti_setFailStatus();
    78         return NULL;
    77         return NULL;
    79     }
    78     }
    80 
    79 
    81     if (!NSK_JNI_VERIFY(jni_env, (loadedClass = (jclass)
    80     if (!NSK_JNI_VERIFY(jni_env, (loadedClass = (jclass)
    82             NSK_CPP_STUB4(CallObjectMethod, jni_env, loader, methodID,
    81             jni_env->CallObjectMethod(loader, methodID, className)) != NULL)) {
    83                                     className)) != NULL)) {
       
    84         nsk_jvmti_setFailStatus();
    82         nsk_jvmti_setFailStatus();
    85         return NULL;
    83         return NULL;
    86     }
    84     }
    87 
    85 
    88     return loadedClass;
    86     return loadedClass;
    97 Java_nsk_jvmti_scenarios_events_EM01_em01t002_prepareClass(JNIEnv *jni_env,
    95 Java_nsk_jvmti_scenarios_events_EM01_em01t002_prepareClass(JNIEnv *jni_env,
    98                         jobject o, jclass klass) {
    96                         jobject o, jclass klass) {
    99     jfieldID fieldID;
    97     jfieldID fieldID;
   100 
    98 
   101     if (!NSK_JNI_VERIFY(jni_env, (fieldID =
    99     if (!NSK_JNI_VERIFY(jni_env, (fieldID =
   102             NSK_CPP_STUB4(GetStaticFieldID, jni_env, klass,
   100             jni_env->GetStaticFieldID(klass, "toProvokePreparation", "I")) != NULL)) {
   103                         "toProvokePreparation", "I")) != NULL)) {
       
   104         nsk_jvmti_setFailStatus();
   101         nsk_jvmti_setFailStatus();
   105         return NSK_FALSE;
   102         return NSK_FALSE;
   106     }
   103     }
   107 
   104 
   108     return NSK_TRUE;
   105     return NSK_TRUE;
   117 Java_nsk_jvmti_scenarios_events_EM01_em01t002_startThread(JNIEnv *jni_env,
   114 Java_nsk_jvmti_scenarios_events_EM01_em01t002_startThread(JNIEnv *jni_env,
   118                         jobject o, jobject thread) {
   115                         jobject o, jobject thread) {
   119     jclass klass;
   116     jclass klass;
   120     jmethodID methodID;
   117     jmethodID methodID;
   121 
   118 
   122     if (!NSK_JNI_VERIFY(jni_env, (klass =
   119     if (!NSK_JNI_VERIFY(jni_env, (klass = jni_env->GetObjectClass(thread)) != NULL)) {
   123             NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) {
       
   124         nsk_jvmti_setFailStatus();
   120         nsk_jvmti_setFailStatus();
   125         return NSK_FALSE;
   121         return NSK_FALSE;
   126     }
   122     }
   127 
   123 
   128     if (!NSK_JNI_VERIFY(jni_env, (methodID =
   124     if (!NSK_JNI_VERIFY(jni_env, (methodID =
   129             NSK_CPP_STUB4(GetMethodID, jni_env, klass, "start", "()V")) != NULL)) {
   125             jni_env->GetMethodID(klass, "start", "()V")) != NULL)) {
   130         nsk_jvmti_setFailStatus();
   126         nsk_jvmti_setFailStatus();
   131         return NSK_FALSE;
   127         return NSK_FALSE;
   132     }
   128     }
   133 
   129 
   134     if (!NSK_JNI_VERIFY_VOID(jni_env,
   130     if (!NSK_JNI_VERIFY_VOID(jni_env,jni_env->CallVoidMethod(thread, methodID)) ) {
   135             NSK_CPP_STUB3(CallVoidMethod, jni_env, thread, methodID)) ) {
       
   136         nsk_jvmti_setFailStatus();
   131         nsk_jvmti_setFailStatus();
   137         return NSK_FALSE;
   132         return NSK_FALSE;
   138     }
   133     }
   139 
   134 
   140     return NSK_TRUE;
   135     return NSK_TRUE;
   144 /* ============================================================================= */
   139 /* ============================================================================= */
   145 
   140 
   146 static void
   141 static void
   147 changeCount(jvmtiEvent event) {
   142 changeCount(jvmtiEvent event) {
   148 
   143 
   149     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
   144     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
   150         nsk_jvmti_setFailStatus();
   145         nsk_jvmti_setFailStatus();
   151 
   146 
   152     eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
   147     eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
   153 
   148 
   154     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
   149     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
   155         nsk_jvmti_setFailStatus();
   150         nsk_jvmti_setFailStatus();
   156 
   151 
   157 }
   152 }
   158 
   153 
   159 /* ============================================================================= */
   154 /* ============================================================================= */
   182 
   177 
   183     char *className;
   178     char *className;
   184     char *generic;
   179     char *generic;
   185     jvmtiPhase phase;
   180     jvmtiPhase phase;
   186 
   181 
   187     if (!NSK_JVMTI_VERIFY(
   182     if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(klass, &className, &generic))) {
   188             NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass,
       
   189                                 &className, &generic))) {
       
   190         nsk_jvmti_setFailStatus();
   183         nsk_jvmti_setFailStatus();
   191         return;
   184         return;
   192     }
   185     }
   193 
   186 
   194     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   187     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   197                             TranslateEvent(event),
   190                             TranslateEvent(event),
   198                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   191                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   199                             className);
   192                             className);
   200     }
   193     }
   201 
   194 
   202     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   195     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   203         nsk_jvmti_setFailStatus();
   196         nsk_jvmti_setFailStatus();
   204     }
   197     }
   205 
   198 
   206     if (phase != currentPhase) {
   199     if (phase != currentPhase) {
   207         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   200         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   215                     phase,
   208                     phase,
   216                     className);
   209                     className);
   217         nsk_jvmti_setFailStatus();
   210         nsk_jvmti_setFailStatus();
   218     }
   211     }
   219 
   212 
   220     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   213     if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)className))) {
   221             jvmti_env, (unsigned char*)className))) {
       
   222         nsk_jvmti_setFailStatus();
   214         nsk_jvmti_setFailStatus();
   223     }
   215     }
   224     if (generic != NULL)
   216     if (generic != NULL)
   225         if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   217         if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)generic))) {
   226                 jvmti_env, (unsigned char*)generic))) {
       
   227             nsk_jvmti_setFailStatus();
   218             nsk_jvmti_setFailStatus();
   228         }
   219         }
   229 }
   220 }
   230 
   221 
   231 void
   222 void
   235     char *className;
   226     char *className;
   236     char *generic;
   227     char *generic;
   237     jvmtiPhase phase;
   228     jvmtiPhase phase;
   238 
   229 
   239 
   230 
   240     if (!NSK_JNI_VERIFY(jni_env, (classObject =
   231     if (!NSK_JNI_VERIFY(jni_env, (classObject = jni_env->GetObjectClass(thread)) != NULL)) {
   241             NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) {
   232         nsk_jvmti_setFailStatus();
   242         nsk_jvmti_setFailStatus();
   233         return;
   243         return;
   234     }
   244     }
   235 
   245 
   236     if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(classObject, &className, &generic))) {
   246     if (!NSK_JVMTI_VERIFY(
       
   247             NSK_CPP_STUB4(GetClassSignature, jvmti_env, classObject,
       
   248                                 &className, &generic))) {
       
   249         nsk_jvmti_setFailStatus();
   237         nsk_jvmti_setFailStatus();
   250         return;
   238         return;
   251     }
   239     }
   252 
   240 
   253     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   241     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   256                             TranslateEvent(event),
   244                             TranslateEvent(event),
   257                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   245                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   258                             className);
   246                             className);
   259     }
   247     }
   260 
   248 
   261     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   249     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   262         nsk_jvmti_setFailStatus();
   250         nsk_jvmti_setFailStatus();
   263     }
   251     }
   264 
   252 
   265     if (phase != currentPhase) {
   253     if (phase != currentPhase) {
   266         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   254         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   274                     phase,
   262                     phase,
   275                     className);
   263                     className);
   276         nsk_jvmti_setFailStatus();
   264         nsk_jvmti_setFailStatus();
   277     }
   265     }
   278 
   266 
   279     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   267     if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)className))) {
   280             jvmti_env, (unsigned char*)className))) {
       
   281         nsk_jvmti_setFailStatus();
   268         nsk_jvmti_setFailStatus();
   282     }
   269     }
   283     if (generic != NULL)
   270     if (generic != NULL)
   284         if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   271         if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)generic))) {
   285                 jvmti_env, (unsigned char*)generic))) {
       
   286             nsk_jvmti_setFailStatus();
   272             nsk_jvmti_setFailStatus();
   287         }
   273         }
   288 }
   274 }
   289 
   275 
   290 JNIEXPORT void JNICALL
   276 JNIEXPORT void JNICALL
   291 cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   277 cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   292 
   278 
   293     jvmtiPhase phase;
   279     jvmtiPhase phase;
   294 
   280 
   295     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   281     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   296         nsk_jvmti_setFailStatus();
   282         nsk_jvmti_setFailStatus();
   297     }
   283     }
   298 
   284 
   299     if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) {
   285     if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) {
   300         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   286         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   311 JNIEXPORT void JNICALL
   297 JNIEXPORT void JNICALL
   312 cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) {
   298 cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) {
   313 
   299 
   314     jvmtiPhase phase;
   300     jvmtiPhase phase;
   315 
   301 
   316     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   302     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   317         nsk_jvmti_setFailStatus();
   303         nsk_jvmti_setFailStatus();
   318     }
   304     }
   319 
   305 
   320     if (phase != JVMTI_PHASE_LIVE) {
   306     if (phase != JVMTI_PHASE_LIVE) {
   321         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   307         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   332 JNIEXPORT void JNICALL
   318 JNIEXPORT void JNICALL
   333 cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   319 cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   334 
   320 
   335     jvmtiPhase phase;
   321     jvmtiPhase phase;
   336 
   322 
   337     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   323     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   338         nsk_jvmti_setFailStatus();
   324         nsk_jvmti_setFailStatus();
   339     }
   325     }
   340 
   326 
   341     if (phase != JVMTI_PHASE_LIVE) {
   327     if (phase != JVMTI_PHASE_LIVE) {
   342         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   328         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   347     }
   333     }
   348 
   334 
   349     currentPhase = JVMTI_PHASE_DEAD;
   335     currentPhase = JVMTI_PHASE_DEAD;
   350     changeCount(JVMTI_EVENT_VM_DEATH);
   336     changeCount(JVMTI_EVENT_VM_DEATH);
   351 
   337 
   352     if (!NSK_JVMTI_VERIFY(
   338     if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
   353             NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
       
   354         nsk_jvmti_setFailStatus();
   339         nsk_jvmti_setFailStatus();
   355 
   340 
   356 }
   341 }
   357 
   342 
   358 JNIEXPORT void JNICALL
   343 JNIEXPORT void JNICALL
   391     } else {
   376     } else {
   392         NSK_DISPLAY1("disabling %s\n", TranslateEvent(event));
   377         NSK_DISPLAY1("disabling %s\n", TranslateEvent(event));
   393     }
   378     }
   394 
   379 
   395 
   380 
   396     if (!NSK_JVMTI_VERIFY(
   381     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(enable, event, NULL))) {
   397             NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable,
       
   398                                             event, NULL))) {
       
   399         nsk_jvmti_setFailStatus();
   382         nsk_jvmti_setFailStatus();
   400         return NSK_FALSE;
   383         return NSK_FALSE;
   401     }
   384     }
   402 
   385 
   403     return NSK_TRUE;
   386     return NSK_TRUE;
   466     eventCallbacks.ClassLoad    = cbClassLoad;
   449     eventCallbacks.ClassLoad    = cbClassLoad;
   467     eventCallbacks.ClassPrepare = cbClassPrepare;
   450     eventCallbacks.ClassPrepare = cbClassPrepare;
   468     eventCallbacks.ThreadStart  = cbThreadStart;
   451     eventCallbacks.ThreadStart  = cbThreadStart;
   469     eventCallbacks.ThreadEnd    = cbThreadEnd;
   452     eventCallbacks.ThreadEnd    = cbThreadEnd;
   470 
   453 
   471     if (!NSK_JVMTI_VERIFY(
   454     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
   472             NSK_CPP_STUB3(SetEventCallbacks, jvmti,
       
   473                                 &eventCallbacks,
       
   474                                 sizeof(eventCallbacks))))
       
   475         return NSK_FALSE;
   455         return NSK_FALSE;
   476 
   456 
   477     return NSK_TRUE;
   457     return NSK_TRUE;
   478 }
   458 }
   479 
   459 
   542     classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10);
   522     classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10);
   543 
   523 
   544     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
   524     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
   545         return JNI_ERR;
   525         return JNI_ERR;
   546 
   526 
   547     if (!NSK_JVMTI_VERIFY(
   527     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
   548             NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
       
   549         nsk_jvmti_setFailStatus();
   528         nsk_jvmti_setFailStatus();
   550         return JNI_ERR;
   529         return JNI_ERR;
   551     }
   530     }
   552 
   531 
   553     if (!setCallBacks()) {
   532     if (!setCallBacks()) {