48
49 volatile int threadStartReceived = 0;
50 volatile int threadWasExecuted = 0;
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 }
123 }
124 }
125
126 #ifdef STATIC_BUILD
127 JNIEXPORT jint JNI_OnLoad_attach039Agent00(JavaVM *jvm, char *options, void *reserved) {
128 return JNI_VERSION_1_8;
129 }
130 #endif
131
132 JNIEXPORT jint JNICALL
133 #ifdef STATIC_BUILD
134 Agent_OnAttach_attach039Agent00(JavaVM *vm, char *optionsString, void *reserved)
135 #else
136 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)
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
|
48
49 volatile int threadStartReceived = 0;
50 volatile int threadWasExecuted = 0;
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 thread = nsk_jvmti_aod_createThreadWithName(jni, STARTED_THREAD_NAME);
69 if (!NSK_VERIFY(thread != NULL))
70 return NSK_FALSE;
71
72 if (!NSK_JVMTI_VERIFY(jvmti->RunAgentThread(thread, startedThreadFunction, NULL, JVMTI_THREAD_NORM_PRIORITY))) {
73 return NSK_FALSE;
74 }
75
76 NSK_DISPLAY1("%s: new thread was started\n", agentName);
77
78 return NSK_TRUE;
79 }
80
81 void JNICALL threadEndHandler(jvmtiEnv *jvmti,
82 JNIEnv* jni,
83 jthread thread) {
84 char threadName[MAX_STRING_LENGTH];
85
86 if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) {
87 nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
88 return;
89 }
124 }
125 }
126
127 #ifdef STATIC_BUILD
128 JNIEXPORT jint JNI_OnLoad_attach039Agent00(JavaVM *jvm, char *options, void *reserved) {
129 return JNI_VERSION_1_8;
130 }
131 #endif
132
133 JNIEXPORT jint JNICALL
134 #ifdef STATIC_BUILD
135 Agent_OnAttach_attach039Agent00(JavaVM *vm, char *optionsString, void *reserved)
136 #else
137 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)
138 #endif
139 {
140 jvmtiEventCallbacks eventCallbacks;
141 jvmtiEnv* jvmti;
142 JNIEnv* jni;
143
144 options = (Options*) nsk_aod_createOptions(optionsString);
145 if (!NSK_VERIFY(options != NULL))
146 return JNI_ERR;
147
148 agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
149
150 jni = (JNIEnv*) nsk_aod_createJNIEnv(vm);
151 if (jni == NULL)
152 return JNI_ERR;
153
154 jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved);
155 if (!NSK_VERIFY(jvmti != NULL))
156 return JNI_ERR;
157
158 memset(&eventCallbacks,0, sizeof(eventCallbacks));
159 eventCallbacks.ThreadEnd = threadEndHandler;
160 eventCallbacks.ThreadStart = threadStartHandler;
161 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)))) {
162 return JNI_ERR;
163 }
164
165 if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) {
166 return JNI_ERR;
167 }
168
169 NSK_DISPLAY1("%s: initialization was done\n", agentName);
170
171 if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
172 return JNI_ERR;
173
174 NSK_DISPLAY1("%s: starting new thread\n", agentName);
175
|