51
52 void JNICALL startedThreadFunction(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
53 char threadName[MAX_STRING_LENGTH];
54
55 if (!nsk_jvmti_aod_getThreadName(jvmti, NULL, threadName)) {
56 nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
57 return;
58 }
59
60 NSK_DISPLAY2("%s: thread started from agent is running (thread name: '%s')\n", agentName, threadName);
61
62 threadWasExecuted = 1;
63 }
64
65 int startNewThread(jvmtiEnv* jvmti, JNIEnv* jni) {
66 jthread thread;
67
68 if (!NSK_VERIFY((thread = nsk_jvmti_aod_createThreadWithName(jni, STARTED_THREAD_NAME)) != NULL))
69 return NSK_FALSE;
70
71 if (!NSK_JVMTI_VERIFY(jvmti->RunAgentThread(thread, startedThreadFunction, NULL, JVMTI_THREAD_NORM_PRIORITY ))) {
72 return NSK_FALSE;
73 }
74
75 NSK_DISPLAY1("%s: new thread was started\n", agentName);
76
77 return NSK_TRUE;
78 }
79
80 void JNICALL threadEndHandler(jvmtiEnv *jvmti,
81 JNIEnv* jni,
82 jthread thread) {
83 char threadName[MAX_STRING_LENGTH];
84
85 if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) {
86 nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
87 return;
88 }
89
90 NSK_DISPLAY2("%s: ThreadEnd event was received for thread '%s'\n", agentName, threadName);
91
137 #endif
138 {
139 jvmtiEventCallbacks eventCallbacks;
140 jvmtiEnv* jvmti;
141 JNIEnv* jni;
142
143 if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL))
144 return JNI_ERR;
145
146 agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
147
148 if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
149 return JNI_ERR;
150
151 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL))
152 return JNI_ERR;
153
154 memset(&eventCallbacks,0, sizeof(eventCallbacks));
155 eventCallbacks.ThreadEnd = threadEndHandler;
156 eventCallbacks.ThreadStart = threadStartHandler;
157 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))) ) {
158 return JNI_ERR;
159 }
160
161 if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) {
162 return JNI_ERR;
163 }
164
165 NSK_DISPLAY1("%s: initialization was done\n", agentName);
166
167 if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
168 return JNI_ERR;
169
170 NSK_DISPLAY1("%s: starting new thread\n", agentName);
171
172 if (!NSK_VERIFY(startNewThread(jvmti, jni)))
173 return JNI_ERR;
174
175 return JNI_OK;
176 }
177
|
51
52 void JNICALL startedThreadFunction(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
53 char threadName[MAX_STRING_LENGTH];
54
55 if (!nsk_jvmti_aod_getThreadName(jvmti, NULL, threadName)) {
56 nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
57 return;
58 }
59
60 NSK_DISPLAY2("%s: thread started from agent is running (thread name: '%s')\n", agentName, threadName);
61
62 threadWasExecuted = 1;
63 }
64
65 int startNewThread(jvmtiEnv* jvmti, JNIEnv* jni) {
66 jthread thread;
67
68 if (!NSK_VERIFY((thread = nsk_jvmti_aod_createThreadWithName(jni, STARTED_THREAD_NAME)) != NULL))
69 return NSK_FALSE;
70
71 if (!NSK_JVMTI_VERIFY(jvmti->RunAgentThread(thread, startedThreadFunction, NULL, JVMTI_THREAD_NORM_PRIORITY))) {
72 return NSK_FALSE;
73 }
74
75 NSK_DISPLAY1("%s: new thread was started\n", agentName);
76
77 return NSK_TRUE;
78 }
79
80 void JNICALL threadEndHandler(jvmtiEnv *jvmti,
81 JNIEnv* jni,
82 jthread thread) {
83 char threadName[MAX_STRING_LENGTH];
84
85 if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) {
86 nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
87 return;
88 }
89
90 NSK_DISPLAY2("%s: ThreadEnd event was received for thread '%s'\n", agentName, threadName);
91
137 #endif
138 {
139 jvmtiEventCallbacks eventCallbacks;
140 jvmtiEnv* jvmti;
141 JNIEnv* jni;
142
143 if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL))
144 return JNI_ERR;
145
146 agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
147
148 if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
149 return JNI_ERR;
150
151 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL))
152 return JNI_ERR;
153
154 memset(&eventCallbacks,0, sizeof(eventCallbacks));
155 eventCallbacks.ThreadEnd = threadEndHandler;
156 eventCallbacks.ThreadStart = threadStartHandler;
157 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)))) {
158 return JNI_ERR;
159 }
160
161 if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) {
162 return JNI_ERR;
163 }
164
165 NSK_DISPLAY1("%s: initialization was done\n", agentName);
166
167 if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
168 return JNI_ERR;
169
170 NSK_DISPLAY1("%s: starting new thread\n", agentName);
171
172 if (!NSK_VERIFY(startNewThread(jvmti, jni)))
173 return JNI_ERR;
174
175 return JNI_OK;
176 }
177
|