< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/sp07t002.cpp

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


  49 static jmethodID methodThrower = NULL;
  50 static jint MAX_LADDER = 0;
  51 static int sampleCount = 0;
  52 static jint frameCount = 0;
  53 static jvmtiFrameInfo frameBuffer[MAX_DEPTH];
  54 
  55 /* ========================================================================== */
  56 
  57 static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) {
  58     const char* THREAD_NAME = "Debuggee Thread";
  59     jvmtiThreadInfo info;
  60     jthread *threads = NULL;
  61     jint threads_count = 0;
  62     jclass klass = NULL;
  63     jfieldID fid = NULL;
  64     int i;
  65 
  66     NSK_DISPLAY0("Prepare: find tested thread\n");
  67 
  68     /* get all live threads */
  69     if (!NSK_JVMTI_VERIFY(
  70            NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads)))
  71         return NSK_FALSE;
  72 
  73     if (!NSK_VERIFY(threads_count > 0 && threads != NULL))
  74         return NSK_FALSE;
  75 
  76     /* find tested thread */
  77     for (i = 0; i < threads_count; i++) {
  78         if (!NSK_VERIFY(threads[i] != NULL))
  79             return NSK_FALSE;
  80 
  81         /* get thread information */
  82         if (!NSK_JVMTI_VERIFY(
  83                 NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info)))
  84             return NSK_FALSE;
  85 
  86         NSK_DISPLAY3("    thread #%d (%s): %p\n", i, info.name, threads[i]);
  87 
  88         /* find by name */
  89         if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) {
  90             thread = threads[i];
  91         }
  92 
  93         if (info.name != NULL) {
  94             if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(
  95                     Deallocate, jvmti, (unsigned char*)info.name)))
  96                 return NSK_FALSE;
  97         }
  98     }
  99 
 100     /* deallocate threads list */
 101     if (!NSK_JVMTI_VERIFY(
 102             NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads)))
 103         return NSK_FALSE;
 104 
 105     if (thread == NULL) {
 106         NSK_COMPLAIN0("Debuggee thread not found");
 107         return NSK_FALSE;
 108     }
 109 
 110     /* get tested thread class */
 111     if (!NSK_JNI_VERIFY(jni, (klass =
 112             NSK_CPP_STUB2(GetObjectClass, jni, thread)) != NULL))
 113         return NSK_FALSE;
 114 
 115     /* get tested thread field 'MAX_LADDER' */
 116     if (!NSK_JNI_VERIFY(jni, (fid =
 117             NSK_CPP_STUB4(GetStaticFieldID, jni, klass,
 118                 "MAX_LADDER", "I")) != NULL))
 119         return NSK_FALSE;
 120 
 121     MAX_LADDER = NSK_CPP_STUB3(GetStaticIntField, jni, klass, fid);
 122     NSK_DISPLAY1("MAX_LADDER: %d\n", MAX_LADDER);
 123 
 124     /* get tested thread field 'depth' */
 125     if (!NSK_JNI_VERIFY(jni, (field =
 126             NSK_CPP_STUB4(GetFieldID, jni, klass, "depth", "I")) != NULL))
 127         return NSK_FALSE;
 128 
 129     /* get tested thread method 'run' */
 130     if (!NSK_JNI_VERIFY(jni, (methodRun =
 131             NSK_CPP_STUB4(GetMethodID, jni, klass, "run", "()V")) != NULL))
 132         return NSK_FALSE;
 133 
 134     /* get tested thread method 'catcher' */
 135     if (!NSK_JNI_VERIFY(jni, (methodCatcher =
 136             NSK_CPP_STUB4(GetMethodID, jni, klass, "catcher", "(II)V")) != NULL))
 137         return NSK_FALSE;
 138 
 139     /* get tested thread method 'thrower' */
 140     if (!NSK_JNI_VERIFY(jni, (methodThrower=
 141             NSK_CPP_STUB4(GetMethodID, jni, klass, "thrower", "(I)V")) != NULL))
 142         return NSK_FALSE;
 143 
 144     if (!NSK_JVMTI_VERIFY(
 145             NSK_CPP_STUB3(CreateRawMonitor, jvmti, "waitLock", &waitLock)))
 146         return NSK_FALSE;
 147 
 148     return NSK_TRUE;
 149 }
 150 
 151 /* ============================================================================= */
 152 
 153 static int wait_for(jvmtiEnv* jvmti, jlong millis) {
 154 
 155     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, waitLock)))
 156         return NSK_FALSE;
 157 
 158     if (!NSK_JVMTI_VERIFY(
 159             NSK_CPP_STUB3(RawMonitorWait, jvmti, waitLock, millis)))
 160         nsk_jvmti_setFailStatus();
 161 
 162     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, waitLock)))
 163         return NSK_FALSE;
 164 
 165     return NSK_TRUE;
 166 }
 167 
 168 static int displayFrameInfo(jvmtiEnv* jvmti, jint i) {
 169     char buffer[32];
 170     char *name = NULL;
 171     char *signature = NULL;
 172 
 173     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, jvmti,
 174             frameBuffer[frameCount-1-i].method, &name, &signature, NULL)))
 175         return NSK_FALSE;
 176 
 177     NSK_DISPLAY4("    [%d] method: %s%s, location: %s\n", i, name,
 178         signature, jlong_to_string(frameBuffer[frameCount-1-i].location, buffer));
 179     if (name != NULL)
 180         NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)name);
 181     if (signature != NULL)
 182         NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature);
 183 
 184     return NSK_TRUE;
 185 }
 186 
 187 static int complainFrameInfo(jvmtiEnv* jvmti, jint i, jmethodID method) {
 188     char buffer[32];
 189     char *name = NULL;
 190     char *signature = NULL;
 191 
 192     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, jvmti,
 193             frameBuffer[frameCount-1-i].method, &name, &signature, NULL)))
 194         return NSK_FALSE;
 195 
 196     NSK_COMPLAIN3("    got method: %s%s, location: %s\n", name, signature,
 197         jlong_to_string(frameBuffer[frameCount-1-i].location, buffer));
 198     if (name != NULL)
 199         NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)name);
 200     if (signature != NULL)
 201         NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature);
 202 
 203     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName, jvmti,
 204             method, &name, &signature, NULL)))
 205         return NSK_FALSE;
 206 
 207     NSK_COMPLAIN2("    expected method: %s%s\n", name, signature);
 208 
 209     return NSK_TRUE;
 210 }
 211 
 212 static int checkStackTrace(jvmtiEnv* jvmti, JNIEnv* jni) {
 213     int res = NSK_TRUE;
 214     jmethodID method = NULL;
 215     jint depth;
 216     jint i;
 217     int displayFlag =
 218         (nsk_getVerboseMode() && (sampleCount % DISPLAYING_FREQUENCY) == 0);
 219 
 220     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(SuspendThread, jvmti, thread)))
 221         return NSK_FALSE;
 222 
 223     depth = NSK_CPP_STUB3(GetIntField, jni, thread, field);
 224 
 225     /* get stack trace */
 226     if (!NSK_JVMTI_VERIFY(
 227             NSK_CPP_STUB6(GetStackTrace, jvmti, thread,
 228                 0, MAX_DEPTH, frameBuffer, &frameCount))) {
 229         res = NSK_FALSE;
 230     }
 231 
 232     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(ResumeThread, jvmti, thread)))
 233         res = NSK_FALSE;
 234 
 235     if (res) {
 236         if (displayFlag) {
 237             NSK_DISPLAY3("Sample #%d, frameCount: %d, depth: %d\n",
 238                 sampleCount, frameCount, depth);
 239         }
 240         for (i = 0; i < frameCount; i++) {
 241             if (displayFlag && !displayFrameInfo(jvmti, i))
 242                 res = NSK_FALSE;
 243             if (i == 0) {
 244                 method = methodRun;
 245             } else if (i <= (depth + 1)) {
 246                 method = methodCatcher;
 247             } else if (i <= (MAX_LADDER + 2)) {
 248                 method = methodThrower;
 249             } else {
 250                 continue;
 251             }
 252             if (!NSK_VERIFY(frameBuffer[frameCount-1-i].method == method)) {


 305 }
 306 #endif
 307 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 308     jvmtiEnv* jvmti = NULL;
 309     jvmtiCapabilities caps;
 310 
 311     /* init framework and parse options */
 312     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 313         return JNI_ERR;
 314 
 315     timeout = nsk_jvmti_getWaitTime() * 60000;
 316     NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
 317 
 318     /* create JVMTI environment */
 319     if (!NSK_VERIFY((jvmti =
 320             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 321         return JNI_ERR;
 322 
 323     memset(&caps, 0, sizeof(caps));
 324     caps.can_suspend = 1;
 325     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
 326         return JNI_ERR;
 327 
 328     /* register agent proc and arg */
 329     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 330         return JNI_ERR;
 331 
 332     return JNI_OK;
 333 }
 334 
 335 /* ========================================================================== */
 336 
 337 }


  49 static jmethodID methodThrower = NULL;
  50 static jint MAX_LADDER = 0;
  51 static int sampleCount = 0;
  52 static jint frameCount = 0;
  53 static jvmtiFrameInfo frameBuffer[MAX_DEPTH];
  54 
  55 /* ========================================================================== */
  56 
  57 static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) {
  58     const char* THREAD_NAME = "Debuggee Thread";
  59     jvmtiThreadInfo info;
  60     jthread *threads = NULL;
  61     jint threads_count = 0;
  62     jclass klass = NULL;
  63     jfieldID fid = NULL;
  64     int i;
  65 
  66     NSK_DISPLAY0("Prepare: find tested thread\n");
  67 
  68     /* get all live threads */
  69     if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&threads_count, &threads)))

  70         return NSK_FALSE;
  71 
  72     if (!NSK_VERIFY(threads_count > 0 && threads != NULL))
  73         return NSK_FALSE;
  74 
  75     /* find tested thread */
  76     for (i = 0; i < threads_count; i++) {
  77         if (!NSK_VERIFY(threads[i] != NULL))
  78             return NSK_FALSE;
  79 
  80         /* get thread information */
  81         if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(threads[i], &info)))

  82             return NSK_FALSE;
  83 
  84         NSK_DISPLAY3("    thread #%d (%s): %p\n", i, info.name, threads[i]);
  85 
  86         /* find by name */
  87         if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) {
  88             thread = threads[i];
  89         }
  90 
  91         if (info.name != NULL) {
  92             if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)info.name)))

  93                 return NSK_FALSE;
  94         }
  95     }
  96 
  97     /* deallocate threads list */
  98     if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)threads)))

  99         return NSK_FALSE;
 100 
 101     if (thread == NULL) {
 102         NSK_COMPLAIN0("Debuggee thread not found");
 103         return NSK_FALSE;
 104     }
 105 
 106     /* get tested thread class */
 107     if (!NSK_JNI_VERIFY(jni, (klass = jni->GetObjectClass(thread)) != NULL))

 108         return NSK_FALSE;
 109 
 110     /* get tested thread field 'MAX_LADDER' */
 111     if (!NSK_JNI_VERIFY(jni, (fid = jni->GetStaticFieldID(klass, "MAX_LADDER", "I")) != NULL))


 112         return NSK_FALSE;
 113 
 114     MAX_LADDER = jni->GetStaticIntField(klass, fid);
 115     NSK_DISPLAY1("MAX_LADDER: %d\n", MAX_LADDER);
 116 
 117     /* get tested thread field 'depth' */
 118     if (!NSK_JNI_VERIFY(jni, (field = jni->GetFieldID(klass, "depth", "I")) != NULL))

 119         return NSK_FALSE;
 120 
 121     /* get tested thread method 'run' */
 122     if (!NSK_JNI_VERIFY(jni, (methodRun = jni->GetMethodID(klass, "run", "()V")) != NULL))

 123         return NSK_FALSE;
 124 
 125     /* get tested thread method 'catcher' */
 126     if (!NSK_JNI_VERIFY(jni, (methodCatcher =
 127             jni->GetMethodID(klass, "catcher", "(II)V")) != NULL))
 128         return NSK_FALSE;
 129 
 130     /* get tested thread method 'thrower' */
 131     if (!NSK_JNI_VERIFY(jni, (methodThrower= jni->GetMethodID(klass, "thrower", "(I)V")) != NULL))

 132         return NSK_FALSE;
 133 
 134     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("waitLock", &waitLock)))

 135         return NSK_FALSE;
 136 
 137     return NSK_TRUE;
 138 }
 139 
 140 /* ============================================================================= */
 141 
 142 static int wait_for(jvmtiEnv* jvmti, jlong millis) {
 143 
 144     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(waitLock)))
 145         return NSK_FALSE;
 146 
 147     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(waitLock, millis)))

 148         nsk_jvmti_setFailStatus();
 149 
 150     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(waitLock)))
 151         return NSK_FALSE;
 152 
 153     return NSK_TRUE;
 154 }
 155 
 156 static int displayFrameInfo(jvmtiEnv* jvmti, jint i) {
 157     char buffer[32];
 158     char *name = NULL;
 159     char *signature = NULL;
 160 
 161     if (!NSK_JVMTI_VERIFY(jvmti->GetMethodName(frameBuffer[frameCount-1-i].method, &name, &signature, NULL)))

 162         return NSK_FALSE;
 163 
 164     NSK_DISPLAY4("    [%d] method: %s%s, location: %s\n", i, name,
 165         signature, jlong_to_string(frameBuffer[frameCount-1-i].location, buffer));
 166     if (name != NULL)
 167         jvmti->Deallocate((unsigned char*)name);
 168     if (signature != NULL)
 169         jvmti->Deallocate((unsigned char*)signature);
 170 
 171     return NSK_TRUE;
 172 }
 173 
 174 static int complainFrameInfo(jvmtiEnv* jvmti, jint i, jmethodID method) {
 175     char buffer[32];
 176     char *name = NULL;
 177     char *signature = NULL;
 178 
 179     if (!NSK_JVMTI_VERIFY(jvmti->GetMethodName(frameBuffer[frameCount-1-i].method, &name, &signature, NULL)))

 180         return NSK_FALSE;
 181 
 182     NSK_COMPLAIN3("    got method: %s%s, location: %s\n", name, signature,
 183         jlong_to_string(frameBuffer[frameCount-1-i].location, buffer));
 184     if (name != NULL)
 185         jvmti->Deallocate((unsigned char*)name);
 186     if (signature != NULL)
 187         jvmti->Deallocate((unsigned char*)signature);
 188 
 189     if (!NSK_JVMTI_VERIFY(jvmti->GetMethodName(method, &name, &signature, NULL)))

 190         return NSK_FALSE;
 191 
 192     NSK_COMPLAIN2("    expected method: %s%s\n", name, signature);
 193 
 194     return NSK_TRUE;
 195 }
 196 
 197 static int checkStackTrace(jvmtiEnv* jvmti, JNIEnv* jni) {
 198     int res = NSK_TRUE;
 199     jmethodID method = NULL;
 200     jint depth;
 201     jint i;
 202     int displayFlag =
 203         (nsk_getVerboseMode() && (sampleCount % DISPLAYING_FREQUENCY) == 0);
 204 
 205     if (!NSK_JVMTI_VERIFY(jvmti->SuspendThread(thread)))
 206         return NSK_FALSE;
 207 
 208     depth = jni->GetIntField(thread, field);
 209 
 210     /* get stack trace */
 211     if (!NSK_JVMTI_VERIFY(jvmti->GetStackTrace(thread, 0, MAX_DEPTH, frameBuffer, &frameCount))) {


 212         res = NSK_FALSE;
 213     }
 214 
 215     if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(thread)))
 216         res = NSK_FALSE;
 217 
 218     if (res) {
 219         if (displayFlag) {
 220             NSK_DISPLAY3("Sample #%d, frameCount: %d, depth: %d\n",
 221                 sampleCount, frameCount, depth);
 222         }
 223         for (i = 0; i < frameCount; i++) {
 224             if (displayFlag && !displayFrameInfo(jvmti, i))
 225                 res = NSK_FALSE;
 226             if (i == 0) {
 227                 method = methodRun;
 228             } else if (i <= (depth + 1)) {
 229                 method = methodCatcher;
 230             } else if (i <= (MAX_LADDER + 2)) {
 231                 method = methodThrower;
 232             } else {
 233                 continue;
 234             }
 235             if (!NSK_VERIFY(frameBuffer[frameCount-1-i].method == method)) {


 288 }
 289 #endif
 290 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 291     jvmtiEnv* jvmti = NULL;
 292     jvmtiCapabilities caps;
 293 
 294     /* init framework and parse options */
 295     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 296         return JNI_ERR;
 297 
 298     timeout = nsk_jvmti_getWaitTime() * 60000;
 299     NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
 300 
 301     /* create JVMTI environment */
 302     if (!NSK_VERIFY((jvmti =
 303             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 304         return JNI_ERR;
 305 
 306     memset(&caps, 0, sizeof(caps));
 307     caps.can_suspend = 1;
 308     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
 309         return JNI_ERR;
 310 
 311     /* register agent proc and arg */
 312     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 313         return JNI_ERR;
 314 
 315     return JNI_OK;
 316 }
 317 
 318 /* ========================================================================== */
 319 
 320 }
< prev index next >