test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA04/ma04t002/ma04t002.cpp
changeset 52184 672bc2213cef
parent 51774 79dc492c00ab
equal deleted inserted replaced
52183:e3c221bc1711 52184:672bc2213cef
    79     jfieldID fid = NULL;
    79     jfieldID fid = NULL;
    80 
    80 
    81     NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n");
    81     NSK_DISPLAY0("Obtain tested object from a static field of debugee class\n");
    82 
    82 
    83     NSK_DISPLAY1("Find class: %s\n", CLASS_NAME);
    83     NSK_DISPLAY1("Find class: %s\n", CLASS_NAME);
    84     if (!NSK_JNI_VERIFY(jni, (testedClass =
    84     if (!NSK_JNI_VERIFY(jni, (testedClass = jni->FindClass(CLASS_NAME)) != NULL))
    85             NSK_CPP_STUB2(FindClass, jni, CLASS_NAME)) != NULL))
    85         return NSK_FALSE;
    86         return NSK_FALSE;
    86 
    87 
    87     if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass) jni->NewGlobalRef(testedClass)) != NULL))
    88     if (!NSK_JNI_VERIFY(jni, (testedClass = (jclass)
       
    89             NSK_CPP_STUB2(NewGlobalRef, jni, testedClass)) != NULL))
       
    90         return NSK_FALSE;
    88         return NSK_FALSE;
    91 
    89 
    92     NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE);
    90     NSK_DISPLAY2("Find field: %s:%s\n", FIELD_NAME, FIELD_SIGNATURE);
    93     if (!NSK_JNI_VERIFY(jni, (fid =
    91     if (!NSK_JNI_VERIFY(jni, (fid =
    94             NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass,
    92             jni->GetStaticFieldID(testedClass, FIELD_NAME, FIELD_SIGNATURE)) != NULL))
    95                 FIELD_NAME, FIELD_SIGNATURE)) != NULL))
    93         return NSK_FALSE;
    96         return NSK_FALSE;
    94 
    97 
    95     if (!NSK_JNI_VERIFY(jni, (testedObject = jni->GetStaticObjectField(testedClass, fid)) != NULL))
    98     if (!NSK_JNI_VERIFY(jni, (testedObject =
       
    99             NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL))
       
   100         return NSK_FALSE;
    96         return NSK_FALSE;
   101 
    97 
   102     NSK_DISPLAY2("Find class instance: %s:%s\n",
    98     NSK_DISPLAY2("Find class instance: %s:%s\n",
   103         INSTANCE_NAME, INSTANCE_SIGNATURE);
    99         INSTANCE_NAME, INSTANCE_SIGNATURE);
   104     if (!NSK_JNI_VERIFY(jni, (fid =
   100     if (!NSK_JNI_VERIFY(jni, (fid =
   105             NSK_CPP_STUB4(GetStaticFieldID, jni, testedClass,
   101             jni->GetStaticFieldID(testedClass, INSTANCE_NAME, INSTANCE_SIGNATURE)) != NULL))
   106                 INSTANCE_NAME, INSTANCE_SIGNATURE)) != NULL))
       
   107         return NSK_FALSE;
   102         return NSK_FALSE;
   108 
   103 
   109     if (!NSK_JNI_VERIFY(jni, (testedInstance =
   104     if (!NSK_JNI_VERIFY(jni, (testedInstance =
   110             NSK_CPP_STUB3(GetStaticObjectField, jni, testedClass, fid)) != NULL))
   105             jni->GetStaticObjectField(testedClass, fid)) != NULL))
   111         return NSK_FALSE;
   106         return NSK_FALSE;
   112 
   107 
   113     return NSK_TRUE;
   108     return NSK_TRUE;
   114 }
   109 }
   115 
   110 
   129     }
   124     }
   130 
   125 
   131     NSK_DISPLAY0("Testcase #1: check that there are no tagged objects\n");
   126     NSK_DISPLAY0("Testcase #1: check that there are no tagged objects\n");
   132 
   127 
   133     ObjectsCount = 0;
   128     ObjectsCount = 0;
   134     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti,
   129     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) {
   135             JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) {
       
   136         nsk_jvmti_setFailStatus();
   130         nsk_jvmti_setFailStatus();
   137         return;
   131         return;
   138     }
   132     }
   139     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   133     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   140     if (ObjectsCount != 0) {
   134     if (ObjectsCount != 0) {
   142             ObjectsCount);
   136             ObjectsCount);
   143         nsk_jvmti_setFailStatus();
   137         nsk_jvmti_setFailStatus();
   144     }
   138     }
   145 
   139 
   146     ObjectsCount = 0;
   140     ObjectsCount = 0;
   147     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti,
   141     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) {
   148             JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) {
       
   149         nsk_jvmti_setFailStatus();
   142         nsk_jvmti_setFailStatus();
   150         return;
   143         return;
   151     }
   144     }
   152     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   145     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   153     if (ObjectsCount != 0) {
   146     if (ObjectsCount != 0) {
   155             ObjectsCount);
   148             ObjectsCount);
   156         nsk_jvmti_setFailStatus();
   149         nsk_jvmti_setFailStatus();
   157     }
   150     }
   158 
   151 
   159     ObjectsCount = 0;
   152     ObjectsCount = 0;
   160     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti,
   153     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverInstancesOfClass(testedClass,
   161             testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) {
   154                                                              JVMTI_HEAP_OBJECT_EITHER,
       
   155                                                              heap_object_callback,
       
   156                                                              &dummy))) {
   162         nsk_jvmti_setFailStatus();
   157         nsk_jvmti_setFailStatus();
   163         return;
   158         return;
   164     }
   159     }
   165     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   160     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   166     if (ObjectsCount != 0) {
   161     if (ObjectsCount != 0) {
   168             ObjectsCount);
   163             ObjectsCount);
   169         nsk_jvmti_setFailStatus();
   164         nsk_jvmti_setFailStatus();
   170     }
   165     }
   171 
   166 
   172     ObjectsCount = 0;
   167     ObjectsCount = 0;
   173     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti,
   168     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverInstancesOfClass(testedClass,
   174             testedClass, JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) {
   169                                                              JVMTI_HEAP_OBJECT_TAGGED,
       
   170                                                              heap_object_callback,
       
   171                                                              &dummy))) {
   175         nsk_jvmti_setFailStatus();
   172         nsk_jvmti_setFailStatus();
   176         return;
   173         return;
   177     }
   174     }
   178     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   175     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   179     if (ObjectsCount != 0) {
   176     if (ObjectsCount != 0) {
   180         NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n",
   177         NSK_COMPLAIN1("Some class instances were unexpectedly tagged: %d\n",
   181             ObjectsCount);
   178             ObjectsCount);
   182         nsk_jvmti_setFailStatus();
   179         nsk_jvmti_setFailStatus();
   183     }
   180     }
   184 
   181 
   185     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedObject,
   182     if (!NSK_JVMTI_VERIFY(jvmti->SetTag(testedObject, SAMPLE_TAG))) {
   186             SAMPLE_TAG))) {
       
   187         nsk_jvmti_setFailStatus();
   183         nsk_jvmti_setFailStatus();
   188         return;
   184         return;
   189     }
   185     }
   190 
   186 
   191     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
   187     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
   195 
   191 
   196 
   192 
   197     NSK_DISPLAY0("Testcase #2: check that there is only one object tagged\n");
   193     NSK_DISPLAY0("Testcase #2: check that there is only one object tagged\n");
   198 
   194 
   199     ObjectsCount = 0;
   195     ObjectsCount = 0;
   200     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti,
   196     if (!NSK_JVMTI_VERIFY(
   201             JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) {
   197             jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) {
   202         nsk_jvmti_setFailStatus();
   198         nsk_jvmti_setFailStatus();
   203         return;
   199         return;
   204     }
   200     }
   205     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   201     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   206     if (ObjectsCount != 1) {
   202     if (ObjectsCount != 1) {
   207         NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount);
   203         NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount);
   208         nsk_jvmti_setFailStatus();
   204         nsk_jvmti_setFailStatus();
   209     }
   205     }
   210 
   206 
   211     ObjectsCount = 0;
   207     ObjectsCount = 0;
   212     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti,
   208     if (!NSK_JVMTI_VERIFY(
   213             JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) {
   209             jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_TAGGED, heap_object_callback, &dummy))) {
   214         nsk_jvmti_setFailStatus();
   210         nsk_jvmti_setFailStatus();
   215         return;
   211         return;
   216     }
   212     }
   217     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   213     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   218     if (ObjectsCount != 1) {
   214     if (ObjectsCount != 1) {
   219         NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount);
   215         NSK_COMPLAIN1("Expected 1 object to be tagged: %d\n", ObjectsCount);
   220         nsk_jvmti_setFailStatus();
   216         nsk_jvmti_setFailStatus();
   221     }
   217     }
   222 
   218 
   223     ObjectsCount = 0;
   219     ObjectsCount = 0;
   224     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti,
   220     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) {
   225             JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) {
       
   226         nsk_jvmti_setFailStatus();
   221         nsk_jvmti_setFailStatus();
   227         return;
   222         return;
   228     }
   223     }
   229     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   224     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   230     if (ObjectsCount != 0) {
   225     if (ObjectsCount != 0) {
   231         NSK_COMPLAIN1("Some tagged objects were unexpectedly shown as untagged: %d\n",
   226         NSK_COMPLAIN1("Some tagged objects were unexpectedly shown as untagged: %d\n",
   232             ObjectsCount);
   227             ObjectsCount);
   233         nsk_jvmti_setFailStatus();
   228         nsk_jvmti_setFailStatus();
   234     }
   229     }
   235 
   230 
   236     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetTag, jvmti, testedInstance,
   231     if (!NSK_JVMTI_VERIFY(jvmti->SetTag(testedInstance, SAMPLE_TAG))) {
   237             SAMPLE_TAG))) {
       
   238         nsk_jvmti_setFailStatus();
   232         nsk_jvmti_setFailStatus();
   239         return;
   233         return;
   240     }
   234     }
   241 
   235 
   242     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
   236     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
   246 
   240 
   247 
   241 
   248     NSK_DISPLAY0("Testcase #3: check that there is only one class object tagged\n");
   242     NSK_DISPLAY0("Testcase #3: check that there is only one class object tagged\n");
   249 
   243 
   250     ObjectsCount = 0;
   244     ObjectsCount = 0;
   251     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti,
   245     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverInstancesOfClass(testedClass,
   252             testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) {
   246                                                              JVMTI_HEAP_OBJECT_EITHER,
       
   247                                                              heap_object_callback,
       
   248                                                              &dummy))) {
   253         nsk_jvmti_setFailStatus();
   249         nsk_jvmti_setFailStatus();
   254         return;
   250         return;
   255     }
   251     }
   256     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   252     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   257     if (ObjectsCount != 1) {
   253     if (ObjectsCount != 1) {
   259             ObjectsCount);
   255             ObjectsCount);
   260         nsk_jvmti_setFailStatus();
   256         nsk_jvmti_setFailStatus();
   261     }
   257     }
   262 
   258 
   263     ObjectsCount = 0;
   259     ObjectsCount = 0;
   264     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(IterateOverInstancesOfClass, jvmti,
   260     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverInstancesOfClass(testedClass,
   265             testedClass, JVMTI_HEAP_OBJECT_EITHER, heap_object_callback, &dummy))) {
   261                                                              JVMTI_HEAP_OBJECT_EITHER,
       
   262                                                              heap_object_callback,
       
   263                                                              &dummy))) {
   266         nsk_jvmti_setFailStatus();
   264         nsk_jvmti_setFailStatus();
   267         return;
   265         return;
   268     }
   266     }
   269     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   267     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   270     if (ObjectsCount != 1) {
   268     if (ObjectsCount != 1) {
   272             ObjectsCount);
   270             ObjectsCount);
   273         nsk_jvmti_setFailStatus();
   271         nsk_jvmti_setFailStatus();
   274     }
   272     }
   275 
   273 
   276     ObjectsCount = 0;
   274     ObjectsCount = 0;
   277     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(IterateOverHeap, jvmti,
   275     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) {
   278             JVMTI_HEAP_OBJECT_UNTAGGED, heap_object_callback, &dummy))) {
       
   279         nsk_jvmti_setFailStatus();
   276         nsk_jvmti_setFailStatus();
   280         return;
   277         return;
   281     }
   278     }
   282     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   279     NSK_DISPLAY1("ObjectsCount = %d\n", ObjectsCount);
   283     if (ObjectsCount != 0) {
   280     if (ObjectsCount != 0) {
   285             ObjectsCount);
   282             ObjectsCount);
   286         nsk_jvmti_setFailStatus();
   283         nsk_jvmti_setFailStatus();
   287     }
   284     }
   288 
   285 
   289 
   286 
   290     NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedClass));
   287     NSK_TRACE(jni->DeleteGlobalRef(testedClass));
   291 
   288 
   292     if (!nsk_jvmti_resumeSync())
   289     if (!nsk_jvmti_resumeSync())
   293         return;
   290         return;
   294 }
   291 }
   295 
   292 
   324         return JNI_ERR;
   321         return JNI_ERR;
   325 
   322 
   326     memset(&caps, 0, sizeof(caps));
   323     memset(&caps, 0, sizeof(caps));
   327     caps.can_tag_objects = 1;
   324     caps.can_tag_objects = 1;
   328     caps.can_generate_object_free_events = 1;
   325     caps.can_generate_object_free_events = 1;
   329     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
   326     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
   330         return JNI_ERR;
   327         return JNI_ERR;
   331     }
   328     }
   332 
   329 
   333     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
   330     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
   334         return JNI_ERR;
   331         return JNI_ERR;
   335 
   332 
   336     memset(&callbacks, 0, sizeof(callbacks));
   333     memset(&callbacks, 0, sizeof(callbacks));
   337     if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
   334     if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
   338         return JNI_ERR;
   335         return JNI_ERR;
   339 
   336 
   340     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
   337     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL)))
   341             jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL)))
       
   342         return JNI_ERR;
   338         return JNI_ERR;
   343 
   339 
   344     return JNI_OK;
   340     return JNI_OK;
   345 }
   341 }
   346 
   342