test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.cpp
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
41 #define METHOD_NAME "display" |
41 #define METHOD_NAME "display" |
42 |
42 |
43 static jint redefineNumber = 0; |
43 static jint redefineNumber = 0; |
44 static jvmtiEnv * jvmti = NULL; |
44 static jvmtiEnv * jvmti = NULL; |
45 |
45 |
46 typedef enum { |
46 static volatile bool thread_suspend_error = false; |
47 suspend_error = -1, |
|
48 not_suspended, |
|
49 suspended |
|
50 } thread_suspend_status_t; |
|
51 |
|
52 static volatile thread_suspend_status_t thread_suspend_status = not_suspended; |
|
53 |
47 |
54 void JNICALL callbackMethodExit(jvmtiEnv *jvmti_env, |
48 void JNICALL callbackMethodExit(jvmtiEnv *jvmti_env, |
55 JNIEnv* jni_env, |
49 JNIEnv* jni_env, |
56 jthread thread, |
50 jthread thread, |
57 jmethodID method, |
51 jmethodID method, |
73 if (nsk_jvmti_redefineClass(jvmti_env, cls,fileName) == NSK_TRUE) { |
67 if (nsk_jvmti_redefineClass(jvmti_env, cls,fileName) == NSK_TRUE) { |
74 nsk_printf(" Agent:: redefine class success ..\n"); |
68 nsk_printf(" Agent:: redefine class success ..\n"); |
75 nsk_printf("Agent::SUSPENDING>> \n"); |
69 nsk_printf("Agent::SUSPENDING>> \n"); |
76 err=jvmti_env->SuspendThread(thread); |
70 err=jvmti_env->SuspendThread(thread); |
77 if (err == JVMTI_ERROR_NONE) { |
71 if (err == JVMTI_ERROR_NONE) { |
78 thread_suspend_status = suspended; |
72 // we don't get here until we are resumed |
79 nsk_printf("Agent:: Thread successfully suspended..\n"); |
73 nsk_printf("Agent:: Thread successfully suspended and was resumed\n"); |
80 } else if (err == JVMTI_ERROR_THREAD_SUSPENDED) { |
74 } else { |
81 thread_suspend_status = suspend_error; |
75 thread_suspend_error = true; |
82 nsk_printf(" ## Error occured %s \n",TranslateError(err)); |
76 nsk_printf(" ## Error occured %s \n",TranslateError(err)); |
83 } |
77 } |
84 } |
78 } |
85 } |
79 } |
86 } |
80 } |
173 return JNI_FALSE; |
167 return JNI_FALSE; |
174 } |
168 } |
175 |
169 |
176 err = jvmti->ResumeThread(thread); |
170 err = jvmti->ResumeThread(thread); |
177 if (err == JVMTI_ERROR_NONE) { |
171 if (err == JVMTI_ERROR_NONE) { |
178 thread_suspend_status = not_suspended; |
|
179 retvalue = JNI_TRUE; |
172 retvalue = JNI_TRUE; |
180 nsk_printf(" Agent:: Thread Resumed.. \n"); |
173 nsk_printf(" Agent:: Thread Resumed.. \n"); |
181 } else { |
174 } else { |
182 nsk_printf(" Agent:: Failed.. to Resume the thread.\n"); |
175 nsk_printf(" Agent:: Failed.. to Resume the thread.\n"); |
183 retvalue = JNI_FALSE; |
176 retvalue = JNI_FALSE; |
187 |
180 |
188 JNIEXPORT jboolean JNICALL |
181 JNIEXPORT jboolean JNICALL |
189 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_isThreadSuspended(JNIEnv* jni, |
182 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_isThreadSuspended(JNIEnv* jni, |
190 jclass clas, |
183 jclass clas, |
191 jthread thread) { |
184 jthread thread) { |
192 if (suspend_error == thread_suspend_status) { |
185 if (thread_suspend_error) { |
193 jclass ex_class = jni->FindClass("java/lang/IllegalThreadStateException"); |
186 jclass ex_class = jni->FindClass("java/lang/IllegalThreadStateException"); |
194 jni->ThrowNew(ex_class, "Thread has failed to self suspend"); |
187 jni->ThrowNew(ex_class, "Thread has failed to self suspend"); |
195 return JNI_FALSE; |
188 return JNI_FALSE; |
196 } |
189 } |
197 |
190 |
198 return suspended == thread_suspend_status; |
191 // There is an inherent race here if the suspend fails for some reason but |
199 } |
192 // thread_suspend_error is not yet set. But as long as we report the suspend |
200 |
193 // state correctly there is no problem as the Java code will simply loop and call |
201 } |
194 // this again until we see thread_suspend_error is true. |
|
195 |
|
196 jint state = 0; |
|
197 // No errors possible here: thread is valid, and state is not NULL |
|
198 jvmti->GetThreadState(thread, &state); |
|
199 return (state & JVMTI_THREAD_STATE_SUSPENDED) != 0; |
|
200 } |
|
201 |
|
202 } // extern C |