< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetTag/settag001/settag001.cpp

Print this page
rev 52100 : 8212082: Remove the NSK_CPP_STUB macros for remaining vmTestbase/jvmti/[sS]*
Summary:
Reviewed-by:


  44 
  45 /** Agent algorithm. */
  46 static void JNICALL
  47 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
  48     NSK_DISPLAY0("Wait for object created\n");
  49     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
  50         return;
  51 
  52     /* perform testing */
  53     {
  54         jobject testedObject = NULL;
  55         jlong objectTag = 111;
  56 
  57         NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n");
  58         {
  59             jclass debugeeClass = NULL;
  60             jfieldID objectField = NULL;
  61 
  62             NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME);
  63             if (!NSK_JNI_VERIFY(jni, (debugeeClass =
  64                     NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL)) {
  65                 nsk_jvmti_setFailStatus();
  66                 return;
  67             }
  68             NSK_DISPLAY1("  ... found class: 0x%p\n", (void*)debugeeClass);
  69 
  70             NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME);
  71             if (!NSK_JNI_VERIFY(jni, (objectField =
  72                     NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass,
  73                                     OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) {
  74                 nsk_jvmti_setFailStatus();
  75                 return;
  76             }
  77             NSK_DISPLAY1("  ... got fieldID: 0x%p\n", (void*)objectField);
  78 
  79             NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME);
  80             if (!NSK_JNI_VERIFY(jni, (testedObject =
  81                     NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass,
  82                                                             objectField)) != NULL)) {
  83                 nsk_jvmti_setFailStatus();
  84                 return;
  85             }
  86             NSK_DISPLAY1("  ... got object: 0x%p\n", (void*)testedObject);
  87 
  88             NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject);
  89             if (!NSK_JNI_VERIFY(jni, (testedObject =
  90                     NSK_CPP_STUB2(NewGlobalRef, jni, testedObject)) != NULL)) {
  91                 nsk_jvmti_setFailStatus();
  92                 return;
  93             }
  94             NSK_DISPLAY1("  ... got reference: 0x%p\n", (void*)testedObject);
  95         }
  96 
  97         NSK_DISPLAY0(">>> Testcase #1: set tag for the tested object\n");
  98         {
  99             NSK_DISPLAY1("Set tag for object: 0x%p\n", (void*)testedObject);
 100             if (!NSK_JVMTI_VERIFY(
 101                     NSK_CPP_STUB3(SetTag, jvmti, testedObject, objectTag))) {
 102                 nsk_jvmti_setFailStatus();
 103                 return;
 104             }
 105             NSK_DISPLAY1("  ... tag set: %ld\n", (long)objectTag);
 106         }
 107 
 108         NSK_DISPLAY0(">>> Testcase #2: get tag of not changed object and compare with initial\n");
 109         {
 110             jlong tag = 222;
 111 
 112             NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject);
 113             if (!NSK_JVMTI_VERIFY(
 114                     NSK_CPP_STUB3(GetTag, jvmti, testedObject, &tag))) {
 115                 nsk_jvmti_setFailStatus();
 116                 return;
 117             }
 118             NSK_DISPLAY1("  ... got tag: %ld\n", (long)tag);
 119 
 120             if (tag != objectTag) {
 121                 NSK_COMPLAIN2("GetTag() returns different tag for not changed object:\n"
 122                               "#   got tag:  %ld\n"
 123                               "#   expected: %ld\n",
 124                               (long)tag, (long)objectTag);
 125                 nsk_jvmti_setFailStatus();
 126             } else {
 127                 NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n",
 128                               (long)tag, (long)objectTag);
 129             }
 130         }
 131 
 132         NSK_DISPLAY0(">>> Testcase #3: get tag of changed object and compare with initial\n");
 133         {
 134             jlong tag = 333;
 135 
 136             NSK_DISPLAY0("Let debugee to change object data\n");
 137             if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 138                 return;
 139             if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
 140                 return;
 141 
 142             NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject);
 143             if (!NSK_JVMTI_VERIFY(
 144                     NSK_CPP_STUB3(GetTag, jvmti, testedObject, &tag))) {
 145                 nsk_jvmti_setFailStatus();
 146                 return;
 147             }
 148             NSK_DISPLAY1("  ... got tag: %ld\n", (long)tag);
 149 
 150             if (tag != objectTag) {
 151                 NSK_COMPLAIN2("GetTag() returns different tag for changed object:\n"
 152                               "#   got tag:  %ld\n"
 153                               "#   expected: %ld\n",
 154                               (long)tag, (long)objectTag);
 155                 nsk_jvmti_setFailStatus();
 156             } else {
 157                 NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n",
 158                               (long)tag, (long)objectTag);
 159             }
 160         }
 161 
 162         NSK_DISPLAY0(">>> Clean used data\n");
 163         {
 164             NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject);
 165             NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedObject));
 166         }
 167     }
 168 
 169     NSK_DISPLAY0("Let debugee to finish\n");
 170     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 171         return;
 172 }
 173 
 174 /* ============================================================================= */
 175 
 176 /** Agent library initialization. */
 177 #ifdef STATIC_BUILD
 178 JNIEXPORT jint JNICALL Agent_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) {
 179     return Agent_Initialize(jvm, options, reserved);
 180 }
 181 JNIEXPORT jint JNICALL Agent_OnAttach_settag001(JavaVM *jvm, char *options, void *reserved) {
 182     return Agent_Initialize(jvm, options, reserved);
 183 }
 184 JNIEXPORT jint JNI_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) {
 185     return JNI_VERSION_1_8;


 188 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 189     jvmtiEnv* jvmti = NULL;
 190 
 191     /* init framework and parse options */
 192     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 193         return JNI_ERR;
 194 
 195     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 196 
 197     /* create JVMTI environment */
 198     if (!NSK_VERIFY((jvmti =
 199             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 200         return JNI_ERR;
 201 
 202     /* add required capabilities */
 203     {
 204         jvmtiCapabilities caps;
 205 
 206         memset(&caps, 0, sizeof(caps));
 207         caps.can_tag_objects = 1;
 208         if (!NSK_JVMTI_VERIFY(
 209                 NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
 210             return JNI_ERR;
 211         }
 212     }
 213 
 214     /* register agent proc and arg */
 215     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 216         return JNI_ERR;
 217 
 218     return JNI_OK;
 219 }
 220 
 221 /* ============================================================================= */
 222 
 223 }


  44 
  45 /** Agent algorithm. */
  46 static void JNICALL
  47 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
  48     NSK_DISPLAY0("Wait for object created\n");
  49     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
  50         return;
  51 
  52     /* perform testing */
  53     {
  54         jobject testedObject = NULL;
  55         jlong objectTag = 111;
  56 
  57         NSK_DISPLAY0(">>> Obtain tested object from a static field of debugee class\n");
  58         {
  59             jclass debugeeClass = NULL;
  60             jfieldID objectField = NULL;
  61 
  62             NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_CLASS_NAME);
  63             if (!NSK_JNI_VERIFY(jni, (debugeeClass =
  64                     jni->FindClass(DEBUGEE_CLASS_NAME)) != NULL)) {
  65                 nsk_jvmti_setFailStatus();
  66                 return;
  67             }
  68             NSK_DISPLAY1("  ... found class: 0x%p\n", (void*)debugeeClass);
  69 
  70             NSK_DISPLAY1("Find static field: %s\n", OBJECT_FIELD_NAME);
  71             if (!NSK_JNI_VERIFY(jni, (objectField =
  72                     jni->GetStaticFieldID(debugeeClass, OBJECT_FIELD_NAME, OBJECT_CLASS_SIG)) != NULL)) {

  73                 nsk_jvmti_setFailStatus();
  74                 return;
  75             }
  76             NSK_DISPLAY1("  ... got fieldID: 0x%p\n", (void*)objectField);
  77 
  78             NSK_DISPLAY1("Get object from static field: %s\n", OBJECT_FIELD_NAME);
  79             if (!NSK_JNI_VERIFY(jni, (testedObject =
  80                     jni->GetStaticObjectField(debugeeClass, objectField)) != NULL)) {

  81                 nsk_jvmti_setFailStatus();
  82                 return;
  83             }
  84             NSK_DISPLAY1("  ... got object: 0x%p\n", (void*)testedObject);
  85 
  86             NSK_DISPLAY1("Create global reference for object: 0x%p\n", (void*)testedObject);
  87             if (!NSK_JNI_VERIFY(jni, (testedObject = jni->NewGlobalRef(testedObject)) != NULL)) {

  88                 nsk_jvmti_setFailStatus();
  89                 return;
  90             }
  91             NSK_DISPLAY1("  ... got reference: 0x%p\n", (void*)testedObject);
  92         }
  93 
  94         NSK_DISPLAY0(">>> Testcase #1: set tag for the tested object\n");
  95         {
  96             NSK_DISPLAY1("Set tag for object: 0x%p\n", (void*)testedObject);
  97             if (!NSK_JVMTI_VERIFY(jvmti->SetTag(testedObject, objectTag))) {

  98                 nsk_jvmti_setFailStatus();
  99                 return;
 100             }
 101             NSK_DISPLAY1("  ... tag set: %ld\n", (long)objectTag);
 102         }
 103 
 104         NSK_DISPLAY0(">>> Testcase #2: get tag of not changed object and compare with initial\n");
 105         {
 106             jlong tag = 222;
 107 
 108             NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject);
 109             if (!NSK_JVMTI_VERIFY(jvmti->GetTag(testedObject, &tag))) {

 110                 nsk_jvmti_setFailStatus();
 111                 return;
 112             }
 113             NSK_DISPLAY1("  ... got tag: %ld\n", (long)tag);
 114 
 115             if (tag != objectTag) {
 116                 NSK_COMPLAIN2("GetTag() returns different tag for not changed object:\n"
 117                               "#   got tag:  %ld\n"
 118                               "#   expected: %ld\n",
 119                               (long)tag, (long)objectTag);
 120                 nsk_jvmti_setFailStatus();
 121             } else {
 122                 NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n",
 123                               (long)tag, (long)objectTag);
 124             }
 125         }
 126 
 127         NSK_DISPLAY0(">>> Testcase #3: get tag of changed object and compare with initial\n");
 128         {
 129             jlong tag = 333;
 130 
 131             NSK_DISPLAY0("Let debugee to change object data\n");
 132             if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 133                 return;
 134             if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
 135                 return;
 136 
 137             NSK_DISPLAY1("Get tag for object: 0x%p\n", (void*)testedObject);
 138             if (!NSK_JVMTI_VERIFY(jvmti->GetTag(testedObject, &tag))) {

 139                 nsk_jvmti_setFailStatus();
 140                 return;
 141             }
 142             NSK_DISPLAY1("  ... got tag: %ld\n", (long)tag);
 143 
 144             if (tag != objectTag) {
 145                 NSK_COMPLAIN2("GetTag() returns different tag for changed object:\n"
 146                               "#   got tag:  %ld\n"
 147                               "#   expected: %ld\n",
 148                               (long)tag, (long)objectTag);
 149                 nsk_jvmti_setFailStatus();
 150             } else {
 151                 NSK_DISPLAY2("SUCCESS: Got tag is equal to initial: %ld = %ld\n",
 152                               (long)tag, (long)objectTag);
 153             }
 154         }
 155 
 156         NSK_DISPLAY0(">>> Clean used data\n");
 157         {
 158             NSK_DISPLAY1("Delete object reference: 0x%p\n", (void*)testedObject);
 159             NSK_TRACE(jni->DeleteGlobalRef(testedObject));
 160         }
 161     }
 162 
 163     NSK_DISPLAY0("Let debugee to finish\n");
 164     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 165         return;
 166 }
 167 
 168 /* ============================================================================= */
 169 
 170 /** Agent library initialization. */
 171 #ifdef STATIC_BUILD
 172 JNIEXPORT jint JNICALL Agent_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) {
 173     return Agent_Initialize(jvm, options, reserved);
 174 }
 175 JNIEXPORT jint JNICALL Agent_OnAttach_settag001(JavaVM *jvm, char *options, void *reserved) {
 176     return Agent_Initialize(jvm, options, reserved);
 177 }
 178 JNIEXPORT jint JNI_OnLoad_settag001(JavaVM *jvm, char *options, void *reserved) {
 179     return JNI_VERSION_1_8;


 182 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 183     jvmtiEnv* jvmti = NULL;
 184 
 185     /* init framework and parse options */
 186     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 187         return JNI_ERR;
 188 
 189     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 190 
 191     /* create JVMTI environment */
 192     if (!NSK_VERIFY((jvmti =
 193             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 194         return JNI_ERR;
 195 
 196     /* add required capabilities */
 197     {
 198         jvmtiCapabilities caps;
 199 
 200         memset(&caps, 0, sizeof(caps));
 201         caps.can_tag_objects = 1;
 202         if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {

 203             return JNI_ERR;
 204         }
 205     }
 206 
 207     /* register agent proc and arg */
 208     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 209         return JNI_ERR;
 210 
 211     return JNI_OK;
 212 }
 213 
 214 /* ============================================================================= */
 215 
 216 }
< prev index next >