41
42 /** Agent algorithm. */
43 static void JNICALL
44 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
45
46 NSK_DISPLAY0("Wait for thread to start\n");
47 if (!nsk_jvmti_waitForSync(timeout))
48 return;
49
50 /* perform testing */
51 {
52 jthread testedThread = NULL;
53
54 NSK_DISPLAY1("Find thread: %s\n", THREAD_NAME);
55 if (!NSK_VERIFY((testedThread =
56 nsk_jvmti_threadByName(THREAD_NAME)) != NULL))
57 return;
58 NSK_DISPLAY1(" ... found thread: %p\n", (void*)testedThread);
59
60 NSK_DISPLAY1("Suspend thread: %p\n", (void*)testedThread);
61 if (!NSK_JVMTI_VERIFY(
62 NSK_CPP_STUB2(SuspendThread, jvmti, testedThread))) {
63 nsk_jvmti_setFailStatus();
64 return;
65 }
66
67 NSK_DISPLAY0("Let thread to run and finish\n");
68 if (!nsk_jvmti_resumeSync())
69 return;
70
71 NSK_DISPLAY1("Get state vector for thread: %p\n", (void*)testedThread);
72 {
73 jint state = 0;
74
75 if (!NSK_JVMTI_VERIFY(
76 NSK_CPP_STUB3(GetThreadState, jvmti, testedThread, &state))) {
77 nsk_jvmti_setFailStatus();
78 }
79 NSK_DISPLAY2(" ... got state vector: %s (%d)\n",
80 TranslateState(state), (int)state);
81
82 if ((state & JVMTI_THREAD_STATE_SUSPENDED) == 0) {
83 NSK_COMPLAIN2("SuspendThread() does not turn on flag SUSPENDED:\n"
84 "# state: %s (%d)\n",
85 TranslateState(state), (int)state);
86 nsk_jvmti_setFailStatus();
87 }
88 }
89
90 NSK_DISPLAY1("Resume thread: %p\n", (void*)testedThread);
91 if (!NSK_JVMTI_VERIFY(
92 NSK_CPP_STUB2(ResumeThread, jvmti, testedThread))) {
93 nsk_jvmti_setFailStatus();
94 }
95
96 NSK_DISPLAY0("Wait for thread to finish\n");
97 if (!nsk_jvmti_waitForSync(timeout))
98 return;
99
100 NSK_DISPLAY0("Delete thread reference\n");
101 NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, testedThread));
102 }
103
104 NSK_DISPLAY0("Let debugee to finish\n");
105 if (!nsk_jvmti_resumeSync())
106 return;
107 }
108
109 /* ============================================================================= */
110
111 /** Agent library initialization. */
112 #ifdef STATIC_BUILD
113 JNIEXPORT jint JNICALL Agent_OnLoad_suspendthrd001(JavaVM *jvm, char *options, void *reserved) {
114 return Agent_Initialize(jvm, options, reserved);
115 }
116 JNIEXPORT jint JNICALL Agent_OnAttach_suspendthrd001(JavaVM *jvm, char *options, void *reserved) {
117 return Agent_Initialize(jvm, options, reserved);
118 }
119 JNIEXPORT jint JNI_OnLoad_suspendthrd001(JavaVM *jvm, char *options, void *reserved) {
120 return JNI_VERSION_1_8;
121 }
122 #endif
123 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
124 jvmtiEnv* jvmti = NULL;
125
126 /* init framework and parse options */
127 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
128 return JNI_ERR;
129
130 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
131
132 /* create JVMTI environment */
133 if (!NSK_VERIFY((jvmti =
134 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
135 return JNI_ERR;
136
137 /* add specific capabilities for suspending thread */
138 {
139 jvmtiCapabilities suspendCaps;
140 memset(&suspendCaps, 0, sizeof(suspendCaps));
141 suspendCaps.can_suspend = 1;
142 if (!NSK_JVMTI_VERIFY(
143 NSK_CPP_STUB2(AddCapabilities, jvmti, &suspendCaps)))
144 return JNI_ERR;
145 }
146
147 /* register agent proc and arg */
148 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
149 return JNI_ERR;
150
151 return JNI_OK;
152 }
153
154 /* ============================================================================= */
155
156 }
|
41
42 /** Agent algorithm. */
43 static void JNICALL
44 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
45
46 NSK_DISPLAY0("Wait for thread to start\n");
47 if (!nsk_jvmti_waitForSync(timeout))
48 return;
49
50 /* perform testing */
51 {
52 jthread testedThread = NULL;
53
54 NSK_DISPLAY1("Find thread: %s\n", THREAD_NAME);
55 if (!NSK_VERIFY((testedThread =
56 nsk_jvmti_threadByName(THREAD_NAME)) != NULL))
57 return;
58 NSK_DISPLAY1(" ... found thread: %p\n", (void*)testedThread);
59
60 NSK_DISPLAY1("Suspend thread: %p\n", (void*)testedThread);
61 if (!NSK_JVMTI_VERIFY(jvmti->SuspendThread(testedThread))) {
62 nsk_jvmti_setFailStatus();
63 return;
64 }
65
66 NSK_DISPLAY0("Let thread to run and finish\n");
67 if (!nsk_jvmti_resumeSync())
68 return;
69
70 NSK_DISPLAY1("Get state vector for thread: %p\n", (void*)testedThread);
71 {
72 jint state = 0;
73
74 if (!NSK_JVMTI_VERIFY(jvmti->GetThreadState(testedThread, &state))) {
75 nsk_jvmti_setFailStatus();
76 }
77 NSK_DISPLAY2(" ... got state vector: %s (%d)\n",
78 TranslateState(state), (int)state);
79
80 if ((state & JVMTI_THREAD_STATE_SUSPENDED) == 0) {
81 NSK_COMPLAIN2("SuspendThread() does not turn on flag SUSPENDED:\n"
82 "# state: %s (%d)\n",
83 TranslateState(state), (int)state);
84 nsk_jvmti_setFailStatus();
85 }
86 }
87
88 NSK_DISPLAY1("Resume thread: %p\n", (void*)testedThread);
89 if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(testedThread))) {
90 nsk_jvmti_setFailStatus();
91 }
92
93 NSK_DISPLAY0("Wait for thread to finish\n");
94 if (!nsk_jvmti_waitForSync(timeout))
95 return;
96
97 NSK_DISPLAY0("Delete thread reference\n");
98 NSK_TRACE(jni->DeleteGlobalRef(testedThread));
99 }
100
101 NSK_DISPLAY0("Let debugee to finish\n");
102 if (!nsk_jvmti_resumeSync())
103 return;
104 }
105
106 /* ============================================================================= */
107
108 /** Agent library initialization. */
109 #ifdef STATIC_BUILD
110 JNIEXPORT jint JNICALL Agent_OnLoad_suspendthrd001(JavaVM *jvm, char *options, void *reserved) {
111 return Agent_Initialize(jvm, options, reserved);
112 }
113 JNIEXPORT jint JNICALL Agent_OnAttach_suspendthrd001(JavaVM *jvm, char *options, void *reserved) {
114 return Agent_Initialize(jvm, options, reserved);
115 }
116 JNIEXPORT jint JNI_OnLoad_suspendthrd001(JavaVM *jvm, char *options, void *reserved) {
117 return JNI_VERSION_1_8;
118 }
119 #endif
120 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
121 jvmtiEnv* jvmti = NULL;
122
123 /* init framework and parse options */
124 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
125 return JNI_ERR;
126
127 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
128
129 /* create JVMTI environment */
130 if (!NSK_VERIFY((jvmti =
131 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
132 return JNI_ERR;
133
134 /* add specific capabilities for suspending thread */
135 {
136 jvmtiCapabilities suspendCaps;
137 memset(&suspendCaps, 0, sizeof(suspendCaps));
138 suspendCaps.can_suspend = 1;
139 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&suspendCaps)))
140 return JNI_ERR;
141 }
142
143 /* register agent proc and arg */
144 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
145 return JNI_ERR;
146
147 return JNI_OK;
148 }
149
150 /* ============================================================================= */
151
152 }
|