test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t001/em02t001.cpp
changeset 52081 ca7ddf0a1d47
parent 51774 79dc492c00ab
child 52293 d01d4bd7c5b3
equal deleted inserted replaced
52080:a2c72b476c9f 52081:ca7ddf0a1d47
    66     jint threads_count = 0;
    66     jint threads_count = 0;
    67     jthread returnValue = NULL;
    67     jthread returnValue = NULL;
    68     int i;
    68     int i;
    69 
    69 
    70     /* get all live threads */
    70     /* get all live threads */
    71     if (!NSK_JVMTI_VERIFY(
    71     if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&threads_count, &threads)))
    72            NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads)))
       
    73         return NULL;
    72         return NULL;
    74 
    73 
    75     if (!NSK_VERIFY(threads != NULL))
    74     if (!NSK_VERIFY(threads != NULL))
    76         return NULL;
    75         return NULL;
    77 
    76 
    79     for (i = 0; i < threads_count; i++) {
    78     for (i = 0; i < threads_count; i++) {
    80         if (!NSK_VERIFY(threads[i] != NULL))
    79         if (!NSK_VERIFY(threads[i] != NULL))
    81             break;
    80             break;
    82 
    81 
    83         /* get thread information */
    82         /* get thread information */
    84         if (!NSK_JVMTI_VERIFY(
    83         if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(threads[i], &info)))
    85                 NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info)))
       
    86             break;
    84             break;
    87 
    85 
    88         /* find by name */
    86         /* find by name */
    89         if (info.name != NULL && (strcmp(info.name, threadName) == 0)) {
    87         if (info.name != NULL && (strcmp(info.name, threadName) == 0)) {
    90             returnValue = threads[i];
    88             returnValue = threads[i];
    91         }
    89         }
    92     }
    90     }
    93 
    91 
    94     /* deallocate threads list */
    92     /* deallocate threads list */
    95     if (!NSK_JVMTI_VERIFY(
    93     if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)threads)))
    96             NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads)))
       
    97         return NULL;
    94         return NULL;
    98 
    95 
    99     return returnValue;
    96     return returnValue;
   100 }
    97 }
   101 
    98 
   106                     const char* signature) {
   103                     const char* signature) {
   107 
   104 
   108     jfieldID fieldID;
   105     jfieldID fieldID;
   109     jclass klass = NULL;
   106     jclass klass = NULL;
   110 
   107 
   111     if (!NSK_JNI_VERIFY(jni, (klass =
   108     if (!NSK_JNI_VERIFY(jni, (klass = jni->FindClass(className)) != NULL))
   112             NSK_CPP_STUB2(FindClass, jni, className)) != NULL))
       
   113         return NULL;
   109         return NULL;
   114 
   110 
   115     if (!NSK_JNI_VERIFY(jni, (fieldID =
   111     if (!NSK_JNI_VERIFY(jni, (fieldID =
   116             NSK_CPP_STUB4(GetStaticFieldID, jni, klass, objFieldName,
   112             jni->GetStaticFieldID(klass, objFieldName, signature)) != NULL))
   117                                 signature)) != NULL))
       
   118         return NULL;
   113         return NULL;
   119 
   114 
   120     return NSK_CPP_STUB3(GetStaticObjectField, jni, klass, fieldID);
   115     return jni->GetStaticObjectField(klass, fieldID);
   121 }
   116 }
   122 
   117 
   123 /* ============================================================================= */
   118 /* ============================================================================= */
   124 
   119 
   125 static int prepare() {
   120 static int prepare() {
   128         NSK_COMPLAIN1("<%s> thread not found\n", MAIN_THREAD_NAME);
   123         NSK_COMPLAIN1("<%s> thread not found\n", MAIN_THREAD_NAME);
   129         return NSK_FALSE;
   124         return NSK_FALSE;
   130     }
   125     }
   131 
   126 
   132     /* make thread accessable for a long time */
   127     /* make thread accessable for a long time */
   133     if (!NSK_JNI_VERIFY(jni, (mainThread =
   128     if (!NSK_JNI_VERIFY(jni, (mainThread = jni->NewGlobalRef(mainThread)) != NULL))
   134             NSK_CPP_STUB2(NewGlobalRef, jni, mainThread)) != NULL))
       
   135         return NSK_FALSE;
   129         return NSK_FALSE;
   136 
   130 
   137     if (!NSK_VERIFY((startObject =
   131     if (!NSK_VERIFY((startObject =
   138             getStaticObjField(DEBUGEE_CLASS_NAME, START_FIELD_NAME,
   132             getStaticObjField(DEBUGEE_CLASS_NAME, START_FIELD_NAME,
   139                                     OBJECT_FIELD_SIG)) != NULL))
   133                                     OBJECT_FIELD_SIG)) != NULL))
   140         return NSK_FALSE;
   134         return NSK_FALSE;
   141 
   135 
   142     /*make object accessable for a long time*/
   136     /*make object accessable for a long time*/
   143     if (!NSK_JNI_VERIFY(jni, (startObject =
   137     if (!NSK_JNI_VERIFY(jni, (startObject = jni->NewGlobalRef(startObject)) != NULL))
   144             NSK_CPP_STUB2(NewGlobalRef, jni, startObject)) != NULL))
       
   145         return NSK_FALSE;
   138         return NSK_FALSE;
   146 
   139 
   147 
   140 
   148     if (!NSK_VERIFY((endObject =
   141     if (!NSK_VERIFY((endObject =
   149             getStaticObjField(DEBUGEE_CLASS_NAME, END_FIELD_NAME,
   142             getStaticObjField(DEBUGEE_CLASS_NAME, END_FIELD_NAME,
   150                                     OBJECT_FIELD_SIG)) != NULL))
   143                                     OBJECT_FIELD_SIG)) != NULL))
   151         return NSK_FALSE;
   144         return NSK_FALSE;
   152 
   145 
   153     /*make object accessable for a long time*/
   146     /*make object accessable for a long time*/
   154     if (!NSK_JNI_VERIFY(jni, (endObject =
   147     if (!NSK_JNI_VERIFY(jni, (endObject = jni->NewGlobalRef(endObject)) != NULL))
   155             NSK_CPP_STUB2(NewGlobalRef, jni, endObject)) != NULL))
       
   156         return NSK_FALSE;
   148         return NSK_FALSE;
   157 
   149 
   158 
   150 
   159     if (!NSK_VERIFY((debuggeeThread =
   151     if (!NSK_VERIFY((debuggeeThread =
   160             (jthread)getStaticObjField(DEBUGEE_CLASS_NAME, THREAD_FIELD_NAME,
   152             (jthread)getStaticObjField(DEBUGEE_CLASS_NAME, THREAD_FIELD_NAME,
   161                                     THREAD_FIELD_SIG)) != NULL))
   153                                     THREAD_FIELD_SIG)) != NULL))
   162         return NSK_FALSE;
   154         return NSK_FALSE;
   163 
   155 
   164     /* make thread accessable for a long time */
   156     /* make thread accessable for a long time */
   165     if (!NSK_JNI_VERIFY(jni, (debuggeeThread =
   157     if (!NSK_JNI_VERIFY(jni, (debuggeeThread = jni->NewGlobalRef(debuggeeThread)) != NULL))
   166             NSK_CPP_STUB2(NewGlobalRef, jni, debuggeeThread)) != NULL))
       
   167         return NSK_FALSE;
   158         return NSK_FALSE;
   168 
   159 
   169     return NSK_TRUE;
   160     return NSK_TRUE;
   170 }
   161 }
   171 
   162 
   174 static int
   165 static int
   175 clean() {
   166 clean() {
   176 
   167 
   177     /* disable MonitorContendedEnter event */
   168     /* disable MonitorContendedEnter event */
   178     if (!NSK_JVMTI_VERIFY(
   169     if (!NSK_JVMTI_VERIFY(
   179             NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE,
   170             jvmti->SetEventNotificationMode(
   180                 JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL)))
   171                 JVMTI_DISABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL)))
   181         nsk_jvmti_setFailStatus();
   172         nsk_jvmti_setFailStatus();
   182 
   173 
   183     /* dispose global references */
   174     /* dispose global references */
   184     NSK_CPP_STUB2(DeleteGlobalRef, jni, startObject);
   175     jni->DeleteGlobalRef(startObject);
   185     NSK_CPP_STUB2(DeleteGlobalRef, jni, endObject);
   176     jni->DeleteGlobalRef(endObject);
   186     NSK_CPP_STUB2(DeleteGlobalRef, jni, debuggeeThread);
   177     jni->DeleteGlobalRef(debuggeeThread);
   187     NSK_CPP_STUB2(DeleteGlobalRef, jni, mainThread);
   178     jni->DeleteGlobalRef(mainThread);
   188 
   179 
   189     startObject = NULL;
   180     startObject = NULL;
   190     endObject = NULL;
   181     endObject = NULL;
   191     debuggeeThread = NULL;
   182     debuggeeThread = NULL;
   192     mainThread = NULL;
   183     mainThread = NULL;
   217 
   208 
   218 /* get thread information */
   209 /* get thread information */
   219 static void
   210 static void
   220 showThreadInfo(jthread thread) {
   211 showThreadInfo(jthread thread) {
   221     jvmtiThreadInfo info;
   212     jvmtiThreadInfo info;
   222     if (!NSK_JVMTI_VERIFY(
   213     if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(thread, &info)))
   223             NSK_CPP_STUB3(GetThreadInfo, jvmti, thread, &info)))
       
   224         return;
   214         return;
   225 
   215 
   226     NSK_DISPLAY2("\tthread (%s): %p\n", info.name, thread);
   216     NSK_DISPLAY2("\tthread (%s): %p\n", info.name, thread);
   227 }
   217 }
   228 
   218 
   229 /* ============================================================================= */
   219 /* ============================================================================= */
   230 
   220 
   231 static void
   221 static void
   232 changeCount(jvmtiEvent event, int *currentCounts) {
   222 changeCount(jvmtiEvent event, int *currentCounts) {
   233 
   223 
   234     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
   224     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
   235         nsk_jvmti_setFailStatus();
   225         nsk_jvmti_setFailStatus();
   236 
   226 
   237     currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
   227     currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
   238 
   228 
   239     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
   229     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
   240         nsk_jvmti_setFailStatus();
   230         nsk_jvmti_setFailStatus();
   241 
   231 
   242 }
   232 }
   243 
   233 
   244 /* ============================================================================= */
   234 /* ============================================================================= */
   325     showEventStatistics(STEP_AMOUNT);
   315     showEventStatistics(STEP_AMOUNT);
   326     if (!checkEvents(STEP_AMOUNT)) {
   316     if (!checkEvents(STEP_AMOUNT)) {
   327         nsk_jvmti_setFailStatus();
   317         nsk_jvmti_setFailStatus();
   328     }
   318     }
   329 
   319 
   330     if (!NSK_JVMTI_VERIFY(
   320     if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
   331             NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
       
   332         nsk_jvmti_setFailStatus();
   321         nsk_jvmti_setFailStatus();
   333 
   322 
   334 }
   323 }
   335 
   324 
   336 void JNICALL
   325 void JNICALL
   418 
   407 
   419     if (expectedThread == NULL || expectedObject == NULL)
   408     if (expectedThread == NULL || expectedObject == NULL)
   420         return;
   409         return;
   421 
   410 
   422     /* check if event is for tested thread and for tested object */
   411     /* check if event is for tested thread and for tested object */
   423     if (NSK_CPP_STUB3(IsSameObject, jni_env, expectedThread, thread) &&
   412     if (jni_env->IsSameObject(expectedThread, thread) &&
   424             NSK_CPP_STUB3(IsSameObject, jni_env, expectedObject, object)) {
   413             jni_env->IsSameObject(expectedObject, object)) {
   425 
   414 
   426         NSK_DISPLAY1("--->%-40s is received\n", TranslateEvent(event));
   415         NSK_DISPLAY1("--->%-40s is received\n", TranslateEvent(event));
   427 
   416 
   428         showThreadInfo(thread);
   417         showThreadInfo(thread);
   429         if (NSK_CPP_STUB3(IsSameObject, jni_env, expectedObject, endObject))
   418         if (jni_env->IsSameObject(expectedObject, endObject))
   430             NSK_DISPLAY0("\tobject: 'endingMonitor'\n");
   419             NSK_DISPLAY0("\tobject: 'endingMonitor'\n");
   431         else
   420         else
   432             NSK_DISPLAY0("\tobject: 'startingMonitor'\n");
   421             NSK_DISPLAY0("\tobject: 'startingMonitor'\n");
   433 
   422 
   434         changeCount(event, &eventCount[0]);
   423         changeCount(event, &eventCount[0]);
   504 
   493 
   505     if (expectedThread == NULL || expectedObject == NULL)
   494     if (expectedThread == NULL || expectedObject == NULL)
   506         return;
   495         return;
   507 
   496 
   508     /* check if event is for tested thread and for tested object */
   497     /* check if event is for tested thread and for tested object */
   509     if (NSK_CPP_STUB3(IsSameObject, jni_env, expectedThread, thread) &&
   498     if (jni_env->IsSameObject(expectedThread, thread) &&
   510             NSK_CPP_STUB3(IsSameObject, jni_env, expectedObject, object)) {
   499             jni_env->IsSameObject(expectedObject, object)) {
   511 
   500 
   512         NSK_DISPLAY1("--->%-40s is received (new callbacks)\n", TranslateEvent(event));
   501         NSK_DISPLAY1("--->%-40s is received (new callbacks)\n", TranslateEvent(event));
   513 
   502 
   514         showThreadInfo(thread);
   503         showThreadInfo(thread);
   515         if (NSK_CPP_STUB3(IsSameObject, jni_env, expectedObject, endObject))
   504         if (jni_env->IsSameObject(expectedObject, endObject))
   516             NSK_DISPLAY0("\tobject: 'endingMonitor'\n");
   505             NSK_DISPLAY0("\tobject: 'endingMonitor'\n");
   517         else
   506         else
   518             NSK_DISPLAY0("\tobject: 'startingMonitor'\n");
   507             NSK_DISPLAY0("\tobject: 'startingMonitor'\n");
   519 
   508 
   520 
   509 
   570             && (event != JVMTI_EVENT_MONITOR_CONTENDED_ENTER)
   559             && (event != JVMTI_EVENT_MONITOR_CONTENDED_ENTER)
   571             && (event != JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)
   560             && (event != JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)
   572             && (event != JVMTI_EVENT_MONITOR_WAIT)
   561             && (event != JVMTI_EVENT_MONITOR_WAIT)
   573             && (event != JVMTI_EVENT_MONITOR_WAITED)) {
   562             && (event != JVMTI_EVENT_MONITOR_WAITED)) {
   574         if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
   563         if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
   575                 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
   564                 jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
   576                     JVMTI_ENABLE, event, NULL))) {
       
   577             NSK_COMPLAIN1("Unexpected error enabling %s\n",
   565             NSK_COMPLAIN1("Unexpected error enabling %s\n",
   578                 TranslateEvent(event));
   566                 TranslateEvent(event));
   579             return NSK_FALSE;
   567             return NSK_FALSE;
   580         }
   568         }
   581     } else {
   569     } else {
   582         if (!NSK_JVMTI_VERIFY(
   570         if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
   583                 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
       
   584                     JVMTI_ENABLE, event, NULL))) {
       
   585             NSK_COMPLAIN1("Unexpected error enabling %s\n",
   571             NSK_COMPLAIN1("Unexpected error enabling %s\n",
   586                 TranslateEvent(event));
   572                 TranslateEvent(event));
   587             return NSK_FALSE;
   573             return NSK_FALSE;
   588         }
   574         }
   589     }
   575     }
   677 
   663 
   678             eventCallbacks.VMDeath                   = cbVMDeath;
   664             eventCallbacks.VMDeath                   = cbVMDeath;
   679             break;
   665             break;
   680 
   666 
   681     }
   667     }
   682     if (!NSK_JVMTI_VERIFY(
   668     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
   683             NSK_CPP_STUB3(SetEventCallbacks, jvmti,
       
   684                                 &eventCallbacks,
       
   685                                 sizeof(eventCallbacks))))
       
   686         return NSK_FALSE;
   669         return NSK_FALSE;
   687 
   670 
   688     return NSK_TRUE;
   671     return NSK_TRUE;
   689 }
   672 }
   690 
   673 
   769     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
   752     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
   770 
   753 
   771     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
   754     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
   772         return JNI_ERR;
   755         return JNI_ERR;
   773 
   756 
   774     if (!NSK_JVMTI_VERIFY(
   757     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
   775             NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
       
   776         nsk_jvmti_setFailStatus();
   758         nsk_jvmti_setFailStatus();
   777         return JNI_ERR;
   759         return JNI_ERR;
   778     }
   760     }
   779 
   761 
   780     {
   762     {
   781         jvmtiCapabilities caps;
   763         jvmtiCapabilities caps;
   782         memset(&caps, 0, sizeof(caps));
   764         memset(&caps, 0, sizeof(caps));
   783 
   765 
   784         caps.can_generate_monitor_events = 1;
   766         caps.can_generate_monitor_events = 1;
   785         if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
   767         if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
   786             return JNI_ERR;
   768             return JNI_ERR;
   787     }
   769     }
   788 
   770 
   789     if (!setCallBacks(1)) {
   771     if (!setCallBacks(1)) {
   790         return JNI_ERR;
   772         return JNI_ERR;