104 if (!nsk_jvmti_resumeSync())
105 return;
106 }
107
108 /* ============================================================================= */
109
110 /**
111 * Prepare data:
112 * - get threads array from static field
113 * - get each thread from array
114 * - make global refs
115 */
116 static int prepare() {
117 jclass debugeeClass = NULL;
118 jfieldID threadsFieldID = NULL;
119 jobjectArray threadsArray = NULL;
120 jsize threadsArrayLength = 0;
121 jsize i;
122
123 /* find debugee class */
124 if (!NSK_JNI_VERIFY(jni, (debugeeClass =
125 NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL))
126 return NSK_FALSE;
127
128 /* find static field with threads array */
129 if (!NSK_JNI_VERIFY(jni, (threadsFieldID =
130 NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass,
131 THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL))
132 return NSK_FALSE;
133
134 /* get threads array from static field */
135 if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray)
136 NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL))
137 return NSK_FALSE;
138
139 /* check array length */
140 if (!NSK_JNI_VERIFY(jni, (threadsArrayLength =
141 NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT))
142 return NSK_FALSE;
143
144 /* get each thread from array */
145 for (i = 0; i < THREADS_COUNT; i++) {
146 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
147 NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL))
148 return NSK_FALSE;
149 }
150
151 /* make global references to threads */
152 for (i = 0; i < THREADS_COUNT; i++) {
153 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
154 NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL))
155 return NSK_FALSE;
156 }
157
158 return NSK_TRUE;
159 }
160
161 /**
162 * Testcase: check threads state for given suspension
163 *
164 * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
165 */
166 static int checkThreads(const char* kind) {
167 int i;
168
169 /* check each thread */
170 for (i = 0; i < THREADS_COUNT; i++) {
171 jthread thread = threadsList[i];
172 jint state = JVMTI_THREAD_STATE_NOT_STARTED;
173
174 NSK_DISPLAY2(" thread #%d (%s):\n", i, threadsName[i]);
175
176 /* get thread state */
177 if (!NSK_JVMTI_VERIFY(
178 NSK_CPP_STUB3(GetThreadState, jvmti, threadsList[i], &state))) {
179 nsk_jvmti_setFailStatus();
180 return NSK_TRUE;
181 }
182
183 /* display thread state */
184 NSK_DISPLAY2(" state=%s (%d)\n",
185 TranslateState(state), (int)state);
186
187 /* check thread state */
188 if ((state & threadsState[i]) == 0) {
189 if (state == JVMTI_THREAD_STATE_NOT_STARTED) {
190 NSK_DISPLAY1("state of thread #%d is NOT_STARTED\n", kind);
191 } else {
192 NSK_COMPLAIN7("Unexpected state of %s thread #%d (%s):\n"
193 "# got: %s (%d), expected: %s (%d)\n",
194 kind, i, threadsName[i],
195 TranslateState(state), (int)state,
196 TranslateState(threadsState[i]), (int)threadsState[i]);
197 nsk_jvmti_setFailStatus();
198 }
216 if (state & JVMTI_THREAD_STATE_IN_NATIVE) {
217 NSK_COMPLAIN3("Unexpected NATIVE state flag for %s thread #%d: %d\n",
218 kind, i, (int)state);
219 nsk_jvmti_setFailStatus();
220 }
221 }
222
223 /* test may continue */
224 return NSK_TRUE;
225 }
226
227 /**
228 * Clean data:
229 * - dispose global references to tested threads
230 */
231 static int clean() {
232 int i;
233
234 /* dispose global references to threads */
235 for (i = 0; i < THREADS_COUNT; i++) {
236 NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i]));
237 }
238
239 return NSK_TRUE;
240 }
241
242 /* ============================================================================= */
243
244 /** Agent library initialization. */
245 #ifdef STATIC_BUILD
246 JNIEXPORT jint JNICALL Agent_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) {
247 return Agent_Initialize(jvm, options, reserved);
248 }
249 JNIEXPORT jint JNICALL Agent_OnAttach_sp01t001(JavaVM *jvm, char *options, void *reserved) {
250 return Agent_Initialize(jvm, options, reserved);
251 }
252 JNIEXPORT jint JNI_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) {
253 return JNI_VERSION_1_8;
254 }
255 #endif
256 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
104 if (!nsk_jvmti_resumeSync())
105 return;
106 }
107
108 /* ============================================================================= */
109
110 /**
111 * Prepare data:
112 * - get threads array from static field
113 * - get each thread from array
114 * - make global refs
115 */
116 static int prepare() {
117 jclass debugeeClass = NULL;
118 jfieldID threadsFieldID = NULL;
119 jobjectArray threadsArray = NULL;
120 jsize threadsArrayLength = 0;
121 jsize i;
122
123 /* find debugee class */
124 if (!NSK_JNI_VERIFY(jni, (debugeeClass = jni->FindClass(DEBUGEE_CLASS_NAME)) != NULL))
125 return NSK_FALSE;
126
127 /* find static field with threads array */
128 if (!NSK_JNI_VERIFY(jni, (threadsFieldID =
129 jni->GetStaticFieldID(debugeeClass, THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL))
130 return NSK_FALSE;
131
132 /* get threads array from static field */
133 if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray)
134 jni->GetStaticObjectField(debugeeClass, threadsFieldID)) != NULL))
135 return NSK_FALSE;
136
137 /* check array length */
138 if (!NSK_JNI_VERIFY(jni, (threadsArrayLength =
139 jni->GetArrayLength(threadsArray)) == THREADS_COUNT))
140 return NSK_FALSE;
141
142 /* get each thread from array */
143 for (i = 0; i < THREADS_COUNT; i++) {
144 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
145 jni->GetObjectArrayElement(threadsArray, i)) != NULL))
146 return NSK_FALSE;
147 }
148
149 /* make global references to threads */
150 for (i = 0; i < THREADS_COUNT; i++) {
151 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
152 jni->NewGlobalRef(threadsList[i])) != NULL))
153 return NSK_FALSE;
154 }
155
156 return NSK_TRUE;
157 }
158
159 /**
160 * Testcase: check threads state for given suspension
161 *
162 * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
163 */
164 static int checkThreads(const char* kind) {
165 int i;
166
167 /* check each thread */
168 for (i = 0; i < THREADS_COUNT; i++) {
169 jthread thread = threadsList[i];
170 jint state = JVMTI_THREAD_STATE_NOT_STARTED;
171
172 NSK_DISPLAY2(" thread #%d (%s):\n", i, threadsName[i]);
173
174 /* get thread state */
175 if (!NSK_JVMTI_VERIFY(jvmti->GetThreadState(threadsList[i], &state))) {
176 nsk_jvmti_setFailStatus();
177 return NSK_TRUE;
178 }
179
180 /* display thread state */
181 NSK_DISPLAY2(" state=%s (%d)\n",
182 TranslateState(state), (int)state);
183
184 /* check thread state */
185 if ((state & threadsState[i]) == 0) {
186 if (state == JVMTI_THREAD_STATE_NOT_STARTED) {
187 NSK_DISPLAY1("state of thread #%d is NOT_STARTED\n", kind);
188 } else {
189 NSK_COMPLAIN7("Unexpected state of %s thread #%d (%s):\n"
190 "# got: %s (%d), expected: %s (%d)\n",
191 kind, i, threadsName[i],
192 TranslateState(state), (int)state,
193 TranslateState(threadsState[i]), (int)threadsState[i]);
194 nsk_jvmti_setFailStatus();
195 }
213 if (state & JVMTI_THREAD_STATE_IN_NATIVE) {
214 NSK_COMPLAIN3("Unexpected NATIVE state flag for %s thread #%d: %d\n",
215 kind, i, (int)state);
216 nsk_jvmti_setFailStatus();
217 }
218 }
219
220 /* test may continue */
221 return NSK_TRUE;
222 }
223
224 /**
225 * Clean data:
226 * - dispose global references to tested threads
227 */
228 static int clean() {
229 int i;
230
231 /* dispose global references to threads */
232 for (i = 0; i < THREADS_COUNT; i++) {
233 NSK_TRACE(jni->DeleteGlobalRef(threadsList[i]));
234 }
235
236 return NSK_TRUE;
237 }
238
239 /* ============================================================================= */
240
241 /** Agent library initialization. */
242 #ifdef STATIC_BUILD
243 JNIEXPORT jint JNICALL Agent_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) {
244 return Agent_Initialize(jvm, options, reserved);
245 }
246 JNIEXPORT jint JNICALL Agent_OnAttach_sp01t001(JavaVM *jvm, char *options, void *reserved) {
247 return Agent_Initialize(jvm, options, reserved);
248 }
249 JNIEXPORT jint JNI_OnLoad_sp01t001(JavaVM *jvm, char *options, void *reserved) {
250 return JNI_VERSION_1_8;
251 }
252 #endif
253 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|