< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/multienv/MA10/ma10t002/ma10t002.cpp

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


  37 /* scaffold objects */
  38 static jlong timeout = 0;
  39 
  40 /* test objects */
  41 static jthread thread = NULL;
  42 
  43 /* event counts */
  44 static int MethodEntryEventsCount = 0;
  45 
  46 /* ========================================================================== */
  47 
  48 /** callback functions **/
  49 
  50 static void JNICALL
  51 MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
  52         jthread thread, jmethodID method) {
  53     char *name = NULL;
  54     char *signature = NULL;
  55 
  56     MethodEntryEventsCount++;
  57     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName,
  58             jvmti_env, method, &name, &signature, NULL))) {
  59         nsk_jvmti_setFailStatus();
  60         return;
  61     }
  62     NSK_DISPLAY2("MethodEntry event: %s%s\n", name, signature);
  63     if (name != NULL)
  64         NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name);
  65     if (signature != NULL)
  66         NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature);
  67 }
  68 
  69 /* ========================================================================== */
  70 
  71 static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) {
  72     const char* THREAD_NAME = "Debuggee Thread";
  73     jvmtiThreadInfo info;
  74     jthread *threads = NULL;
  75     jint threads_count = 0;
  76     int i;
  77 
  78     NSK_DISPLAY0("Prepare: find tested thread\n");
  79 
  80     /* get all live threads */
  81     if (!NSK_JVMTI_VERIFY(
  82            NSK_CPP_STUB3(GetAllThreads, jvmti, &threads_count, &threads)))
  83         return NSK_FALSE;
  84 
  85     if (!NSK_VERIFY(threads_count > 0 && threads != NULL))
  86         return NSK_FALSE;
  87 
  88     /* find tested thread */
  89     for (i = 0; i < threads_count; i++) {
  90         if (!NSK_VERIFY(threads[i] != NULL))
  91             return NSK_FALSE;
  92 
  93         /* get thread information */
  94         if (!NSK_JVMTI_VERIFY(
  95                 NSK_CPP_STUB3(GetThreadInfo, jvmti, threads[i], &info)))
  96             return NSK_FALSE;
  97 
  98         NSK_DISPLAY3("    thread #%d (%s): %p\n", i, info.name, threads[i]);
  99 
 100         /* find by name */
 101         if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) {
 102             thread = threads[i];
 103         }
 104     }
 105 
 106     if (!NSK_JNI_VERIFY(jni, (thread =
 107             NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL))
 108         return NSK_FALSE;
 109 
 110     /* deallocate threads list */
 111     if (!NSK_JVMTI_VERIFY(
 112             NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threads)))
 113         return NSK_FALSE;
 114 
 115     return NSK_TRUE;
 116 }
 117 
 118 /* ========================================================================== */
 119 
 120 /** Agent algorithm. */
 121 static void JNICALL
 122 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
 123 
 124     if (!nsk_jvmti_waitForSync(timeout))
 125         return;
 126 
 127     if (!prepare(jvmti, jni)) {
 128         nsk_jvmti_setFailStatus();
 129         return;
 130     }
 131 
 132     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
 133             jvmti, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, thread)))
 134         nsk_jvmti_setFailStatus();
 135 
 136     /* resume debugee and wait for sync */
 137     if (!nsk_jvmti_resumeSync())
 138         return;
 139     if (!nsk_jvmti_waitForSync(timeout))
 140         return;
 141 
 142     NSK_DISPLAY1("MethodEntry events received: %d\n",
 143         MethodEntryEventsCount);
 144     if (!NSK_VERIFY(MethodEntryEventsCount != 0))
 145         nsk_jvmti_setFailStatus();
 146 
 147     NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, thread));
 148 
 149     if (!nsk_jvmti_resumeSync())
 150         return;
 151 }
 152 
 153 /* ========================================================================== */
 154 
 155 /** Agent library initialization. */
 156 #ifdef STATIC_BUILD
 157 JNIEXPORT jint JNICALL Agent_OnLoad_ma10t002(JavaVM *jvm, char *options, void *reserved) {
 158     return Agent_Initialize(jvm, options, reserved);
 159 }
 160 JNIEXPORT jint JNICALL Agent_OnAttach_ma10t002(JavaVM *jvm, char *options, void *reserved) {
 161     return Agent_Initialize(jvm, options, reserved);
 162 }
 163 JNIEXPORT jint JNI_OnLoad_ma10t002(JavaVM *jvm, char *options, void *reserved) {
 164     return JNI_VERSION_1_8;
 165 }
 166 #endif
 167 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 168     jvmtiEnv* jvmti = NULL;
 169     jvmtiCapabilities caps;
 170     jvmtiEventCallbacks callbacks;
 171 
 172     NSK_DISPLAY0("Agent_OnLoad\n");
 173 
 174     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 175         return JNI_ERR;
 176 
 177     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 178 
 179     if (!NSK_VERIFY((jvmti =
 180             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 181         return JNI_ERR;
 182 
 183     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 184         return JNI_ERR;
 185 
 186     memset(&caps, 0, sizeof(caps));
 187     caps.can_generate_method_entry_events = 1;
 188     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
 189         return JNI_ERR;
 190     }
 191 
 192     memset(&callbacks, 0, sizeof(callbacks));
 193     callbacks.MethodEntry = &MethodEntry;
 194     if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
 195         return JNI_ERR;
 196 
 197     return JNI_OK;
 198 }
 199 
 200 /* ========================================================================== */
 201 
 202 }


  37 /* scaffold objects */
  38 static jlong timeout = 0;
  39 
  40 /* test objects */
  41 static jthread thread = NULL;
  42 
  43 /* event counts */
  44 static int MethodEntryEventsCount = 0;
  45 
  46 /* ========================================================================== */
  47 
  48 /** callback functions **/
  49 
  50 static void JNICALL
  51 MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
  52         jthread thread, jmethodID method) {
  53     char *name = NULL;
  54     char *signature = NULL;
  55 
  56     MethodEntryEventsCount++;
  57     if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &signature, NULL))) {

  58         nsk_jvmti_setFailStatus();
  59         return;
  60     }
  61     NSK_DISPLAY2("MethodEntry event: %s%s\n", name, signature);
  62     if (name != NULL)
  63         jvmti_env->Deallocate((unsigned char*)name);
  64     if (signature != NULL)
  65         jvmti_env->Deallocate((unsigned char*)signature);
  66 }
  67 
  68 /* ========================================================================== */
  69 
  70 static int prepare(jvmtiEnv* jvmti, JNIEnv* jni) {
  71     const char* THREAD_NAME = "Debuggee Thread";
  72     jvmtiThreadInfo info;
  73     jthread *threads = NULL;
  74     jint threads_count = 0;
  75     int i;
  76 
  77     NSK_DISPLAY0("Prepare: find tested thread\n");
  78 
  79     /* get all live threads */
  80     if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&threads_count, &threads)))

  81         return NSK_FALSE;
  82 
  83     if (!NSK_VERIFY(threads_count > 0 && threads != NULL))
  84         return NSK_FALSE;
  85 
  86     /* find tested thread */
  87     for (i = 0; i < threads_count; i++) {
  88         if (!NSK_VERIFY(threads[i] != NULL))
  89             return NSK_FALSE;
  90 
  91         /* get thread information */
  92         if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(threads[i], &info)))

  93             return NSK_FALSE;
  94 
  95         NSK_DISPLAY3("    thread #%d (%s): %p\n", i, info.name, threads[i]);
  96 
  97         /* find by name */
  98         if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) {
  99             thread = threads[i];
 100         }
 101     }
 102 
 103     if (!NSK_JNI_VERIFY(jni, (thread = jni->NewGlobalRef(thread)) != NULL))

 104         return NSK_FALSE;
 105 
 106     /* deallocate threads list */
 107     if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)threads)))

 108         return NSK_FALSE;
 109 
 110     return NSK_TRUE;
 111 }
 112 
 113 /* ========================================================================== */
 114 
 115 /** Agent algorithm. */
 116 static void JNICALL
 117 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
 118 
 119     if (!nsk_jvmti_waitForSync(timeout))
 120         return;
 121 
 122     if (!prepare(jvmti, jni)) {
 123         nsk_jvmti_setFailStatus();
 124         return;
 125     }
 126 
 127     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, thread)))

 128         nsk_jvmti_setFailStatus();
 129 
 130     /* resume debugee and wait for sync */
 131     if (!nsk_jvmti_resumeSync())
 132         return;
 133     if (!nsk_jvmti_waitForSync(timeout))
 134         return;
 135 
 136     NSK_DISPLAY1("MethodEntry events received: %d\n",
 137         MethodEntryEventsCount);
 138     if (!NSK_VERIFY(MethodEntryEventsCount != 0))
 139         nsk_jvmti_setFailStatus();
 140 
 141     NSK_TRACE(jni->DeleteGlobalRef(thread));
 142 
 143     if (!nsk_jvmti_resumeSync())
 144         return;
 145 }
 146 
 147 /* ========================================================================== */
 148 
 149 /** Agent library initialization. */
 150 #ifdef STATIC_BUILD
 151 JNIEXPORT jint JNICALL Agent_OnLoad_ma10t002(JavaVM *jvm, char *options, void *reserved) {
 152     return Agent_Initialize(jvm, options, reserved);
 153 }
 154 JNIEXPORT jint JNICALL Agent_OnAttach_ma10t002(JavaVM *jvm, char *options, void *reserved) {
 155     return Agent_Initialize(jvm, options, reserved);
 156 }
 157 JNIEXPORT jint JNI_OnLoad_ma10t002(JavaVM *jvm, char *options, void *reserved) {
 158     return JNI_VERSION_1_8;
 159 }
 160 #endif
 161 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 162     jvmtiEnv* jvmti = NULL;
 163     jvmtiCapabilities caps;
 164     jvmtiEventCallbacks callbacks;
 165 
 166     NSK_DISPLAY0("Agent_OnLoad\n");
 167 
 168     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 169         return JNI_ERR;
 170 
 171     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 172 
 173     if (!NSK_VERIFY((jvmti =
 174             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 175         return JNI_ERR;
 176 
 177     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 178         return JNI_ERR;
 179 
 180     memset(&caps, 0, sizeof(caps));
 181     caps.can_generate_method_entry_events = 1;
 182     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
 183         return JNI_ERR;
 184     }
 185 
 186     memset(&callbacks, 0, sizeof(callbacks));
 187     callbacks.MethodEntry = &MethodEntry;
 188     if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
 189         return JNI_ERR;
 190 
 191     return JNI_OK;
 192 }
 193 
 194 /* ========================================================================== */
 195 
 196 }
< prev index next >