< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA08/ma08t001/ma08t001.cpp

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


  43 static jthread threadForInterrupt = NULL;
  44 
  45 /* ========================================================================== */
  46 
  47 static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) {
  48     const char* STOP_THREAD_NAME = "DebuggeeThreadForStop";
  49     const char* INTERRUPT_THREAD_NAME = "DebuggeeThreadForInterrupt";
  50     const char* THREAD_DEATH_CLASS_NAME = "java/lang/ThreadDeath";
  51     const char* THREAD_DEATH_CTOR_NAME = "<init>";
  52     const char* THREAD_DEATH_CTOR_SIGNATURE = "()V";
  53     jvmtiThreadInfo info;
  54     jthread *threads = NULL;
  55     jint threads_count = 0;
  56     jclass cls = NULL;
  57     jmethodID ctor = NULL;
  58     int i;
  59 
  60     NSK_DISPLAY0("Prepare: find tested thread\n");
  61 
  62     /* get all live threads */
  63     if (!NSK_JVMTI_VERIFY(
  64            NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads)))
  65         return NSK_FALSE;
  66 
  67     if (!NSK_VERIFY(threads_count > 0 && threads != NULL))
  68         return NSK_FALSE;
  69 
  70     /* find tested thread */
  71     for (i = 0; i < threads_count; i++) {
  72         if (!NSK_VERIFY(threads[i] != NULL))
  73             return NSK_FALSE;
  74 
  75         /* get thread information */
  76         if (!NSK_JVMTI_VERIFY(
  77                 NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info)))
  78             return NSK_FALSE;
  79 
  80         NSK_DISPLAY3("    thread #%d (%s): %p\n", i, info.name, threads[i]);
  81 
  82         /* find by name */
  83         if (info.name != NULL) {
  84             if (strcmp(info.name, STOP_THREAD_NAME) == 0) {
  85                 threadForStop = threads[i];
  86             } else if (strcmp(info.name, INTERRUPT_THREAD_NAME) == 0) {
  87                 threadForInterrupt = threads[i];
  88             }
  89         }
  90     }
  91 
  92     /* deallocate threads list */
  93     if (!NSK_JVMTI_VERIFY(
  94             NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads)))
  95         return NSK_FALSE;
  96 
  97     if (threadForStop == NULL) {
  98         NSK_COMPLAIN0("DebuggeeThreadForStop not found");
  99         return NSK_FALSE;
 100     }
 101 
 102     if (threadForInterrupt == NULL) {
 103         NSK_COMPLAIN0("DebuggeeThreadForInterrupt not found");
 104         return NSK_FALSE;
 105     }
 106 
 107     NSK_DISPLAY0("Prepare: create new instance of ThreadDeath exception\n");
 108 
 109     if (!NSK_JNI_VERIFY(jni, (cls =
 110             NSK_CPP_STUB2(FindClass, jni, THREAD_DEATH_CLASS_NAME)) != NULL))
 111         return NSK_FALSE;
 112 
 113     if (!NSK_JNI_VERIFY(jni, (ctor =
 114             NSK_CPP_STUB4(GetMethodID, jni, cls,
 115                 THREAD_DEATH_CTOR_NAME, THREAD_DEATH_CTOR_SIGNATURE)) != NULL))
 116         return NSK_FALSE;
 117 
 118     if (!NSK_JNI_VERIFY(jni, (threadDeath =
 119             NSK_CPP_STUB3(NewObject, jni, cls, ctor)) != NULL))
 120         return NSK_FALSE;
 121 
 122     return NSK_TRUE;
 123 }
 124 
 125 /* ========================================================================== */
 126 
 127 /** Agent algorithm. */
 128 static void JNICALL
 129 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
 130 
 131     if (!nsk_jvmti_waitForSync(timeout))
 132         return;
 133 
 134     if (!prepare(jvmti, jni)) {
 135         nsk_jvmti_setFailStatus();
 136         return;
 137     }
 138 
 139     NSK_DISPLAY0("Testcase #1: call StopThread\n");
 140     if (!NSK_VERIFY(threadForStop != NULL)) {
 141         nsk_jvmti_setFailStatus();
 142     } else {
 143         if (!NSK_JVMTI_VERIFY(
 144                 NSK_CPP_STUB3(StopThread, jvmti, threadForStop, threadDeath)))
 145             nsk_jvmti_setFailStatus();
 146     }
 147 
 148     NSK_DISPLAY0("Testcase #2: call InterruptThread\n");
 149     if (!NSK_VERIFY(threadForInterrupt != NULL)) {
 150         nsk_jvmti_setFailStatus();
 151     } else {
 152         if (!NSK_JVMTI_VERIFY(
 153                 NSK_CPP_STUB2(InterruptThread, jvmti, threadForInterrupt)))
 154             nsk_jvmti_setFailStatus();
 155     }
 156 
 157     /* resume debugee and wait for sync */
 158     if (!nsk_jvmti_resumeSync())
 159         return;
 160     if (!nsk_jvmti_waitForSync(timeout))
 161         return;
 162 
 163     if (!nsk_jvmti_resumeSync())
 164         return;
 165 }
 166 
 167 /* ========================================================================== */
 168 
 169 /** Agent library initialization. */
 170 #ifdef STATIC_BUILD
 171 JNIEXPORT jint JNICALL Agent_OnLoad_ma08t001(JavaVM *jvm, char *options, void *reserved) {
 172     return Agent_Initialize(jvm, options, reserved);
 173 }


 182     jvmtiEnv* jvmti = NULL;
 183     jvmtiCapabilities caps;
 184     jvmtiEventCallbacks callbacks;
 185 
 186     NSK_DISPLAY0("Agent_OnLoad\n");
 187 
 188     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 189         return JNI_ERR;
 190 
 191     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 192 
 193     if (!NSK_VERIFY((jvmti =
 194             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 195         return JNI_ERR;
 196 
 197     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 198         return JNI_ERR;
 199 
 200     memset(&caps, 0, sizeof(caps));
 201     caps.can_signal_thread = 1;
 202     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
 203         return JNI_ERR;
 204     }
 205 
 206     memset(&callbacks, 0, sizeof(callbacks));
 207     if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
 208         return JNI_ERR;
 209 
 210     return JNI_OK;
 211 }
 212 
 213 /* ========================================================================== */
 214 
 215 }


  43 static jthread threadForInterrupt = NULL;
  44 
  45 /* ========================================================================== */
  46 
  47 static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) {
  48     const char* STOP_THREAD_NAME = "DebuggeeThreadForStop";
  49     const char* INTERRUPT_THREAD_NAME = "DebuggeeThreadForInterrupt";
  50     const char* THREAD_DEATH_CLASS_NAME = "java/lang/ThreadDeath";
  51     const char* THREAD_DEATH_CTOR_NAME = "<init>";
  52     const char* THREAD_DEATH_CTOR_SIGNATURE = "()V";
  53     jvmtiThreadInfo info;
  54     jthread *threads = NULL;
  55     jint threads_count = 0;
  56     jclass cls = NULL;
  57     jmethodID ctor = NULL;
  58     int i;
  59 
  60     NSK_DISPLAY0("Prepare: find tested thread\n");
  61 
  62     /* get all live threads */
  63     if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&threads_count, &threads)))

  64         return NSK_FALSE;
  65 
  66     if (!NSK_VERIFY(threads_count > 0 && threads != NULL))
  67         return NSK_FALSE;
  68 
  69     /* find tested thread */
  70     for (i = 0; i < threads_count; i++) {
  71         if (!NSK_VERIFY(threads[i] != NULL))
  72             return NSK_FALSE;
  73 
  74         /* get thread information */
  75         if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(threads[i], &info)))

  76             return NSK_FALSE;
  77 
  78         NSK_DISPLAY3("    thread #%d (%s): %p\n", i, info.name, threads[i]);
  79 
  80         /* find by name */
  81         if (info.name != NULL) {
  82             if (strcmp(info.name, STOP_THREAD_NAME) == 0) {
  83                 threadForStop = threads[i];
  84             } else if (strcmp(info.name, INTERRUPT_THREAD_NAME) == 0) {
  85                 threadForInterrupt = threads[i];
  86             }
  87         }
  88     }
  89 
  90     /* deallocate threads list */
  91     if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)threads)))

  92         return NSK_FALSE;
  93 
  94     if (threadForStop == NULL) {
  95         NSK_COMPLAIN0("DebuggeeThreadForStop not found");
  96         return NSK_FALSE;
  97     }
  98 
  99     if (threadForInterrupt == NULL) {
 100         NSK_COMPLAIN0("DebuggeeThreadForInterrupt not found");
 101         return NSK_FALSE;
 102     }
 103 
 104     NSK_DISPLAY0("Prepare: create new instance of ThreadDeath exception\n");
 105 
 106     if (!NSK_JNI_VERIFY(jni, (cls = jni->FindClass(THREAD_DEATH_CLASS_NAME)) != NULL))

 107         return NSK_FALSE;
 108 
 109     if (!NSK_JNI_VERIFY(jni, (ctor =
 110             jni->GetMethodID(cls, THREAD_DEATH_CTOR_NAME, THREAD_DEATH_CTOR_SIGNATURE)) != NULL))

 111         return NSK_FALSE;
 112 
 113     if (!NSK_JNI_VERIFY(jni, (threadDeath = jni->NewObject(cls, ctor)) != NULL))

 114         return NSK_FALSE;
 115 
 116     return NSK_TRUE;
 117 }
 118 
 119 /* ========================================================================== */
 120 
 121 /** Agent algorithm. */
 122 static void JNICALL
 123 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
 124 
 125     if (!nsk_jvmti_waitForSync(timeout))
 126         return;
 127 
 128     if (!prepare(jvmti, jni)) {
 129         nsk_jvmti_setFailStatus();
 130         return;
 131     }
 132 
 133     NSK_DISPLAY0("Testcase #1: call StopThread\n");
 134     if (!NSK_VERIFY(threadForStop != NULL)) {
 135         nsk_jvmti_setFailStatus();
 136     } else {
 137         if (!NSK_JVMTI_VERIFY(jvmti->StopThread(threadForStop, threadDeath)))

 138             nsk_jvmti_setFailStatus();
 139     }
 140 
 141     NSK_DISPLAY0("Testcase #2: call InterruptThread\n");
 142     if (!NSK_VERIFY(threadForInterrupt != NULL)) {
 143         nsk_jvmti_setFailStatus();
 144     } else {
 145         if (!NSK_JVMTI_VERIFY(jvmti->InterruptThread(threadForInterrupt)))

 146             nsk_jvmti_setFailStatus();
 147     }
 148 
 149     /* resume debugee and wait for sync */
 150     if (!nsk_jvmti_resumeSync())
 151         return;
 152     if (!nsk_jvmti_waitForSync(timeout))
 153         return;
 154 
 155     if (!nsk_jvmti_resumeSync())
 156         return;
 157 }
 158 
 159 /* ========================================================================== */
 160 
 161 /** Agent library initialization. */
 162 #ifdef STATIC_BUILD
 163 JNIEXPORT jint JNICALL Agent_OnLoad_ma08t001(JavaVM *jvm, char *options, void *reserved) {
 164     return Agent_Initialize(jvm, options, reserved);
 165 }


 174     jvmtiEnv* jvmti = NULL;
 175     jvmtiCapabilities caps;
 176     jvmtiEventCallbacks callbacks;
 177 
 178     NSK_DISPLAY0("Agent_OnLoad\n");
 179 
 180     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 181         return JNI_ERR;
 182 
 183     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 184 
 185     if (!NSK_VERIFY((jvmti =
 186             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 187         return JNI_ERR;
 188 
 189     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 190         return JNI_ERR;
 191 
 192     memset(&caps, 0, sizeof(caps));
 193     caps.can_signal_thread = 1;
 194     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
 195         return JNI_ERR;
 196     }
 197 
 198     memset(&callbacks, 0, sizeof(callbacks));
 199     if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
 200         return JNI_ERR;
 201 
 202     return JNI_OK;
 203 }
 204 
 205 /* ========================================================================== */
 206 
 207 }
< prev index next >