test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM01/em01t001/em01t001.cpp
changeset 52081 ca7ddf0a1d47
parent 51774 79dc492c00ab
child 52293 d01d4bd7c5b3
equal deleted inserted replaced
52080:a2c72b476c9f 52081:ca7ddf0a1d47
    52 /* ============================================================================= */
    52 /* ============================================================================= */
    53 
    53 
    54 static void
    54 static void
    55 changeCount(jvmtiEvent event) {
    55 changeCount(jvmtiEvent event) {
    56 
    56 
    57     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
    57     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
    58         nsk_jvmti_setFailStatus();
    58         nsk_jvmti_setFailStatus();
    59 
    59 
    60     eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
    60     eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
    61 
    61 
    62     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
    62     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
    63         nsk_jvmti_setFailStatus();
    63         nsk_jvmti_setFailStatus();
    64 
    64 
    65 }
    65 }
    66 
    66 
    67 /* ============================================================================= */
    67 /* ============================================================================= */
    90 
    90 
    91     char *className;
    91     char *className;
    92     char *generic;
    92     char *generic;
    93     jvmtiPhase phase;
    93     jvmtiPhase phase;
    94 
    94 
    95     if (!NSK_JVMTI_VERIFY(
    95     if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(klass, &className, &generic))) {
    96             NSK_CPP_STUB4(GetClassSignature, jvmti_env, klass,
       
    97                                 &className, &generic))) {
       
    98         nsk_jvmti_setFailStatus();
    96         nsk_jvmti_setFailStatus();
    99         return;
    97         return;
   100     }
    98     }
   101 
    99 
   102     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   100     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   105                             TranslateEvent(event),
   103                             TranslateEvent(event),
   106                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   104                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   107                             className);
   105                             className);
   108     }
   106     }
   109 
   107 
   110     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   108     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   111         nsk_jvmti_setFailStatus();
   109         nsk_jvmti_setFailStatus();
   112     }
   110     }
   113 
   111 
   114     if (phase != currentPhase) {
   112     if (phase != currentPhase) {
   115         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   113         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   123                     phase,
   121                     phase,
   124                     className);
   122                     className);
   125         nsk_jvmti_setFailStatus();
   123         nsk_jvmti_setFailStatus();
   126     }
   124     }
   127 
   125 
   128     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   126     if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)className))) {
   129             jvmti_env, (unsigned char*)className))) {
       
   130         nsk_jvmti_setFailStatus();
   127         nsk_jvmti_setFailStatus();
   131     }
   128     }
   132     if (generic != NULL)
   129     if (generic != NULL)
   133         if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   130         if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)generic))) {
   134                 jvmti_env, (unsigned char*)generic))) {
       
   135             nsk_jvmti_setFailStatus();
   131             nsk_jvmti_setFailStatus();
   136         }
   132         }
   137 }
   133 }
   138 
   134 
   139 void
   135 void
   143     char *className;
   139     char *className;
   144     char *generic;
   140     char *generic;
   145     jvmtiPhase phase;
   141     jvmtiPhase phase;
   146 
   142 
   147 
   143 
   148     if (!NSK_JNI_VERIFY(jni_env, (classObject =
   144     if (!NSK_JNI_VERIFY(jni_env, (classObject = jni_env->GetObjectClass(thread)) != NULL)) {
   149             NSK_CPP_STUB2(GetObjectClass, jni_env, thread)) != NULL)) {
   145         nsk_jvmti_setFailStatus();
   150         nsk_jvmti_setFailStatus();
   146         return;
   151         return;
   147     }
   152     }
   148 
   153 
   149     if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(classObject, &className, &generic))) {
   154     if (!NSK_JVMTI_VERIFY(
       
   155             NSK_CPP_STUB4(GetClassSignature, jvmti_env, classObject,
       
   156                                 &className, &generic))) {
       
   157         nsk_jvmti_setFailStatus();
   150         nsk_jvmti_setFailStatus();
   158         return;
   151         return;
   159     }
   152     }
   160 
   153 
   161     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   154     if (strcmp(className, EXPECTED_CLASS_NAME) == 0) {
   164                             TranslateEvent(event),
   157                             TranslateEvent(event),
   165                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   158                             eventCount[event - JVMTI_MIN_EVENT_TYPE_VAL],
   166                             className);
   159                             className);
   167     }
   160     }
   168 
   161 
   169     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   162     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   170         nsk_jvmti_setFailStatus();
   163         nsk_jvmti_setFailStatus();
   171     }
   164     }
   172 
   165 
   173     if (phase != currentPhase) {
   166     if (phase != currentPhase) {
   174         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   167         NSK_DISPLAY2("Unexpected phase %s, but supposed %s",
   182                     phase,
   175                     phase,
   183                     className);
   176                     className);
   184         nsk_jvmti_setFailStatus();
   177         nsk_jvmti_setFailStatus();
   185     }
   178     }
   186 
   179 
   187     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   180     if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)className))) {
   188             jvmti_env, (unsigned char*)className))) {
       
   189         nsk_jvmti_setFailStatus();
   181         nsk_jvmti_setFailStatus();
   190     }
   182     }
   191     if (generic != NULL)
   183     if (generic != NULL)
   192         if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
   184         if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)generic))) {
   193                 jvmti_env, (unsigned char*)generic))) {
       
   194             nsk_jvmti_setFailStatus();
   185             nsk_jvmti_setFailStatus();
   195         }
   186         }
   196 }
   187 }
   197 
   188 
   198 JNIEXPORT void JNICALL
   189 JNIEXPORT void JNICALL
   199 cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   190 cbVMStart(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   200 
   191 
   201     jvmtiPhase phase;
   192     jvmtiPhase phase;
   202 
   193 
   203     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   194     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   204         nsk_jvmti_setFailStatus();
   195         nsk_jvmti_setFailStatus();
   205     }
   196     }
   206 
   197 
   207     if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) {
   198     if ((phase != JVMTI_PHASE_START) && (phase != JVMTI_PHASE_LIVE)) {
   208         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   199         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   219 JNIEXPORT void JNICALL
   210 JNIEXPORT void JNICALL
   220 cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) {
   211 cbVMInit(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) {
   221 
   212 
   222     jvmtiPhase phase;
   213     jvmtiPhase phase;
   223 
   214 
   224     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   215     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   225         nsk_jvmti_setFailStatus();
   216         nsk_jvmti_setFailStatus();
   226     }
   217     }
   227 
   218 
   228     if (phase != JVMTI_PHASE_LIVE) {
   219     if (phase != JVMTI_PHASE_LIVE) {
   229         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   220         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   240 JNIEXPORT void JNICALL
   231 JNIEXPORT void JNICALL
   241 cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   232 cbVMDeath(jvmtiEnv* jvmti_env, JNIEnv* jni_env) {
   242 
   233 
   243     jvmtiPhase phase;
   234     jvmtiPhase phase;
   244 
   235 
   245     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti_env, &phase))) {
   236     if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
   246         nsk_jvmti_setFailStatus();
   237         nsk_jvmti_setFailStatus();
   247     }
   238     }
   248 
   239 
   249     if (phase != JVMTI_PHASE_LIVE) {
   240     if (phase != JVMTI_PHASE_LIVE) {
   250         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   241         NSK_COMPLAIN3("%25s was sent during %s(%d)\n",
   255     }
   246     }
   256 
   247 
   257     currentPhase = JVMTI_PHASE_DEAD;
   248     currentPhase = JVMTI_PHASE_DEAD;
   258     changeCount(JVMTI_EVENT_VM_DEATH);
   249     changeCount(JVMTI_EVENT_VM_DEATH);
   259 
   250 
   260     if (!NSK_JVMTI_VERIFY(
   251     if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
   261             NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
       
   262         nsk_jvmti_setFailStatus();
   252         nsk_jvmti_setFailStatus();
   263 
   253 
   264 }
   254 }
   265 
   255 
   266 JNIEXPORT void JNICALL
   256 JNIEXPORT void JNICALL
   292 /* ============================================================================= */
   282 /* ============================================================================= */
   293 
   283 
   294 static int
   284 static int
   295 enableEvent(jvmtiEventMode enable, jvmtiEvent event) {
   285 enableEvent(jvmtiEventMode enable, jvmtiEvent event) {
   296     NSK_DISPLAY1("enabling %s\n", TranslateEvent(event));
   286     NSK_DISPLAY1("enabling %s\n", TranslateEvent(event));
   297     if (!NSK_JVMTI_VERIFY(
   287     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(enable, event, NULL))) {
   298             NSK_CPP_STUB4(SetEventNotificationMode, jvmti, enable,
       
   299                                             event, NULL))) {
       
   300         nsk_jvmti_setFailStatus();
   288         nsk_jvmti_setFailStatus();
   301         return NSK_FALSE;
   289         return NSK_FALSE;
   302     }
   290     }
   303 
   291 
   304     return NSK_TRUE;
   292     return NSK_TRUE;
   367     eventCallbacks.ClassLoad    = cbClassLoad;
   355     eventCallbacks.ClassLoad    = cbClassLoad;
   368     eventCallbacks.ClassPrepare = cbClassPrepare;
   356     eventCallbacks.ClassPrepare = cbClassPrepare;
   369     eventCallbacks.ThreadStart  = cbThreadStart;
   357     eventCallbacks.ThreadStart  = cbThreadStart;
   370     eventCallbacks.ThreadEnd    = cbThreadEnd;
   358     eventCallbacks.ThreadEnd    = cbThreadEnd;
   371 
   359 
   372     if (!NSK_JVMTI_VERIFY(
   360     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
   373             NSK_CPP_STUB3(SetEventCallbacks, jvmti,
       
   374                                 &eventCallbacks,
       
   375                                 sizeof(eventCallbacks))))
       
   376         return NSK_FALSE;
   361         return NSK_FALSE;
   377 
   362 
   378     return NSK_TRUE;
   363     return NSK_TRUE;
   379 }
   364 }
   380 
   365 
   444     classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10);
   429     classLoaderCount = nsk_jvmti_findOptionIntValue(CLASS_LOADER_COUNT_PARAM, 10);
   445 
   430 
   446     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
   431     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
   447         return JNI_ERR;
   432         return JNI_ERR;
   448 
   433 
   449     if (!NSK_JVMTI_VERIFY(
   434     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
   450             NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
       
   451         nsk_jvmti_setFailStatus();
   435         nsk_jvmti_setFailStatus();
   452         return JNI_ERR;
   436         return JNI_ERR;
   453     }
   437     }
   454 
   438 
   455     if (!setCallBacks()) {
   439     if (!setCallBacks()) {