49 char * generic; |
49 char * generic; |
50 |
50 |
51 className = NULL; |
51 className = NULL; |
52 generic = NULL; |
52 generic = NULL; |
53 redefineNumber=0; |
53 redefineNumber=0; |
54 if ( !NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, |
54 if ( !NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(klass, &className, &generic)) ) { |
55 klass, &className, &generic)) ) { |
|
56 NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); |
55 NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); |
57 nsk_jvmti_agentFailed(); |
56 nsk_jvmti_agentFailed(); |
58 } else { |
57 } else { |
59 if( (strcmp(className, CLASS_NAME) == 0 ) ) { |
58 if( (strcmp(className, CLASS_NAME) == 0 ) ) { |
60 jfieldID fieldId; |
59 jfieldID fieldId; |
61 if ( ! NSK_JNI_VERIFY(jni, (fieldId = NSK_CPP_STUB4(GetStaticFieldID, |
60 if ( ! NSK_JNI_VERIFY(jni, (fieldId = jni->GetStaticFieldID(klass, FIELDNAME, TYPE) ) != NULL ) ) { |
62 jni, klass, FIELDNAME, TYPE) ) != NULL ) ) { |
|
63 NSK_DISPLAY0(" Agent :: Failed to get FieldId.\n"); |
61 NSK_DISPLAY0(" Agent :: Failed to get FieldId.\n"); |
64 nsk_jvmti_agentFailed(); |
62 nsk_jvmti_agentFailed(); |
65 } else { |
63 } else { |
66 if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetFieldAccessWatch, |
64 if ( ! NSK_JVMTI_VERIFY(jvmti_env->SetFieldAccessWatch(klass, fieldId) ) ) { |
67 jvmti_env, klass, fieldId) ) ) { |
|
68 NSK_DISPLAY0(" Agent :: Failed to set watch point on a field.\n"); |
65 NSK_DISPLAY0(" Agent :: Failed to set watch point on a field.\n"); |
69 nsk_jvmti_agentFailed(); |
66 nsk_jvmti_agentFailed(); |
70 } else { |
67 } else { |
71 nsk_jvmti_enableNotification(jvmti_env, JVMTI_EVENT_FIELD_ACCESS, NULL); |
68 nsk_jvmti_enableNotification(jvmti_env, JVMTI_EVENT_FIELD_ACCESS, NULL); |
72 if (! NSK_JNI_VERIFY(jni, |
69 if (! NSK_JNI_VERIFY(jni, |
73 ( watchFieldClass = (jclass) |
70 ( watchFieldClass = (jclass) |
74 NSK_CPP_STUB2(NewGlobalRef, jni, klass) ) |
71 jni->NewGlobalRef(klass) ) |
75 != NULL ) ) { |
72 != NULL ) ) { |
76 NSK_DISPLAY0(" Agent :: Failed to get global reference for class.\n"); |
73 NSK_DISPLAY0(" Agent :: Failed to get global reference for class.\n"); |
77 nsk_jvmti_agentFailed(); |
74 nsk_jvmti_agentFailed(); |
78 } |
75 } |
79 NSK_DISPLAY0(" Agent :: SetFieldAccessWatch.\n"); |
76 NSK_DISPLAY0(" Agent :: SetFieldAccessWatch.\n"); |
82 NSK_DISPLAY1(" Agent :: Leaving callbackClassPrepare for class = %s .\n", className); |
79 NSK_DISPLAY1(" Agent :: Leaving callbackClassPrepare for class = %s .\n", className); |
83 } |
80 } |
84 } |
81 } |
85 |
82 |
86 if ( className != NULL ) { |
83 if ( className != NULL ) { |
87 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { |
84 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char *)className))) { |
88 NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); |
85 NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); |
89 nsk_jvmti_agentFailed(); |
86 nsk_jvmti_agentFailed(); |
90 } |
87 } |
91 } |
88 } |
92 |
89 |
93 if ( generic != NULL ) { |
90 if ( generic != NULL ) { |
94 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)generic))) { |
91 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char *)generic))) { |
95 NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); |
92 NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); |
96 nsk_jvmti_agentFailed(); |
93 nsk_jvmti_agentFailed(); |
97 } |
94 } |
98 } |
95 } |
99 return; |
96 return; |
114 className = NULL; |
111 className = NULL; |
115 generic = NULL; |
112 generic = NULL; |
116 if (redefineNumber != 0 ) { |
113 if (redefineNumber != 0 ) { |
117 return; |
114 return; |
118 } |
115 } |
119 if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti_env, |
116 if ( ! NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(field_klass, &className, &generic)) ) { |
120 field_klass, &className, &generic)) ) { |
|
121 NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); |
117 NSK_DISPLAY0(" Agent :: Failed get class signature.\n"); |
122 nsk_jvmti_agentFailed(); |
118 nsk_jvmti_agentFailed(); |
123 } else { |
119 } else { |
124 if( (strcmp(className, CLASS_NAME) == 0 ) ) { |
120 if( (strcmp(className, CLASS_NAME) == 0 ) ) { |
125 jvmtiThreadInfo info; |
121 jvmtiThreadInfo info; |
131 } else { |
127 } else { |
132 NSK_DISPLAY0(" Agent :: Failed to redefine.\n"); |
128 NSK_DISPLAY0(" Agent :: Failed to redefine.\n"); |
133 nsk_jvmti_agentFailed(); |
129 nsk_jvmti_agentFailed(); |
134 } |
130 } |
135 NSK_DISPLAY0(" Agent :: Before attempting thread suspend.\n"); |
131 NSK_DISPLAY0(" Agent :: Before attempting thread suspend.\n"); |
136 if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadInfo, jvmti_env, thread , &info)) ) { |
132 if ( ! NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info))) { |
137 NSK_DISPLAY0(" Agent :: error getting thread info "); |
133 NSK_DISPLAY0(" Agent :: error getting thread info "); |
138 nsk_jvmti_agentFailed(); |
134 nsk_jvmti_agentFailed(); |
139 } else { |
135 } else { |
140 NSK_DISPLAY1(" Agent :: Thread Name = %s .\n", info.name); |
136 NSK_DISPLAY1(" Agent :: Thread Name = %s .\n", info.name); |
141 } |
137 } |
142 if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB2(SuspendThread, jvmti_env, thread)) ) { |
138 if ( ! NSK_JVMTI_VERIFY(jvmti_env->SuspendThread(thread))) { |
143 NSK_DISPLAY0(" Agent :: Failed to suspend thread.\n"); |
139 NSK_DISPLAY0(" Agent :: Failed to suspend thread.\n"); |
144 nsk_jvmti_agentFailed(); |
140 nsk_jvmti_agentFailed(); |
145 } |
141 } |
146 } |
142 } |
147 } |
143 } |
148 |
144 |
149 if ( className != NULL ) { |
145 if ( className != NULL ) { |
150 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)className))) { |
146 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char *)className))) { |
151 NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); |
147 NSK_DISPLAY1(" Agent :: #error failed to Deallocate className = %s.", className); |
152 nsk_jvmti_agentFailed(); |
148 nsk_jvmti_agentFailed(); |
153 } |
149 } |
154 } |
150 } |
155 |
151 |
156 if ( generic != NULL ) { |
152 if ( generic != NULL ) { |
157 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char *)generic))) { |
153 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char *)generic))) { |
158 NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); |
154 NSK_DISPLAY1(" Agent :: #error failed to Deallocate class signature = %s.", generic); |
159 nsk_jvmti_agentFailed(); |
155 nsk_jvmti_agentFailed(); |
160 } |
156 } |
161 } |
157 } |
162 } |
158 } |
171 JNIEXPORT jint JNI_OnLoad_hs204t003(JavaVM *jvm, char *options, void *reserved) { |
167 JNIEXPORT jint JNI_OnLoad_hs204t003(JavaVM *jvm, char *options, void *reserved) { |
172 return JNI_VERSION_1_8; |
168 return JNI_VERSION_1_8; |
173 } |
169 } |
174 #endif |
170 #endif |
175 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { |
171 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { |
176 if ( ! NSK_VERIFY ( JNI_OK == NSK_CPP_STUB3(GetEnv, vm, |
172 if ( ! NSK_VERIFY ( JNI_OK == vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1) ) ) { |
177 (void **)&jvmti, JVMTI_VERSION_1_1) ) ) { |
|
178 NSK_DISPLAY0("Agent :: Could not load JVMTI interface \n"); |
173 NSK_DISPLAY0("Agent :: Could not load JVMTI interface \n"); |
179 return JNI_ERR; |
174 return JNI_ERR; |
180 } else { |
175 } else { |
181 jvmtiCapabilities caps; |
176 jvmtiCapabilities caps; |
182 jvmtiEventCallbacks eventCallbacks; |
177 jvmtiEventCallbacks eventCallbacks; |
187 } |
182 } |
188 caps.can_redefine_classes = 1; |
183 caps.can_redefine_classes = 1; |
189 caps.can_generate_field_access_events = 1; |
184 caps.can_generate_field_access_events = 1; |
190 caps.can_pop_frame = 1; |
185 caps.can_pop_frame = 1; |
191 caps.can_suspend = 1; |
186 caps.can_suspend = 1; |
192 if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2( AddCapabilities, jvmti, &caps)) ) { |
187 if ( ! NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)) ) { |
193 NSK_DISPLAY0(" Agent :: Failed add required capabilities\n."); |
188 NSK_DISPLAY0(" Agent :: Failed add required capabilities\n."); |
194 return JNI_ERR; |
189 return JNI_ERR; |
195 } |
190 } |
196 memset(&eventCallbacks, 0, sizeof(eventCallbacks)); |
191 memset(&eventCallbacks, 0, sizeof(eventCallbacks)); |
197 eventCallbacks.ClassPrepare = callbackClassPrepare; |
192 eventCallbacks.ClassPrepare = callbackClassPrepare; |
198 eventCallbacks.FieldAccess = callbackFieldAccess; |
193 eventCallbacks.FieldAccess = callbackFieldAccess; |
199 if (!NSK_JVMTI_VERIFY( NSK_CPP_STUB3(SetEventCallbacks, jvmti, |
194 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks) ) ) ) { |
200 &eventCallbacks, sizeof(eventCallbacks) ) ) ) { |
|
201 NSK_DISPLAY0(" Agent :: Error occured while setting event call back \n"); |
195 NSK_DISPLAY0(" Agent :: Error occured while setting event call back \n"); |
202 return JNI_ERR; |
196 return JNI_ERR; |
203 } |
197 } |
204 nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL); |
198 nsk_jvmti_enableNotification(jvmti, JVMTI_EVENT_CLASS_PREPARE, NULL); |
205 } |
199 } |
211 jobject object, |
205 jobject object, |
212 jthread thread) { |
206 jthread thread) { |
213 jboolean retvalue; |
207 jboolean retvalue; |
214 jint state; |
208 jint state; |
215 retvalue = JNI_FALSE; |
209 retvalue = JNI_FALSE; |
216 if (! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadState, jvmti, thread, &state)) ){ |
210 if (! NSK_JVMTI_VERIFY(jvmti->GetThreadState(thread, &state))) { |
217 NSK_DISPLAY0(" Agent :: Error getting thread state.\n"); |
211 NSK_DISPLAY0(" Agent :: Error getting thread state.\n"); |
218 nsk_jvmti_agentFailed(); |
212 nsk_jvmti_agentFailed(); |
219 } else { |
213 } else { |
220 if ( state & JVMTI_THREAD_STATE_SUSPENDED) { |
214 if ( state & JVMTI_THREAD_STATE_SUSPENDED) { |
221 NSK_DISPLAY0(" Agent :: Thread state = JVMTI_THREAD_STATE_SUSPENDED.\n"); |
215 NSK_DISPLAY0(" Agent :: Thread state = JVMTI_THREAD_STATE_SUSPENDED.\n"); |
222 if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(PopFrame, jvmti, thread) ) ) { |
216 if ( ! NSK_JVMTI_VERIFY ( jvmti->PopFrame(thread) ) ) { |
223 NSK_DISPLAY0("#error Agent :: Jvmti failed to do popFrame.\n"); |
217 NSK_DISPLAY0("#error Agent :: Jvmti failed to do popFrame.\n"); |
224 nsk_jvmti_agentFailed(); |
218 nsk_jvmti_agentFailed(); |
225 } else { |
219 } else { |
226 if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB2(ResumeThread, jvmti, thread)) ) { |
220 if ( ! NSK_JVMTI_VERIFY ( jvmti->ResumeThread(thread) ) ) { |
227 NSK_DISPLAY0(" Agent :: Error occured in resuming a thread.\n"); |
221 NSK_DISPLAY0(" Agent :: Error occured in resuming a thread.\n"); |
228 nsk_jvmti_agentFailed(); |
222 nsk_jvmti_agentFailed(); |
229 } else { |
223 } else { |
230 jfieldID fieldId; |
224 jfieldID fieldId = jni->GetStaticFieldID(watchFieldClass, FIELDNAME, TYPE); |
231 if ( ! NSK_JNI_VERIFY(jni, (fieldId = NSK_CPP_STUB4(GetStaticFieldID, |
225 if ( ! NSK_JNI_VERIFY(jni, fieldId != NULL ) ) { |
232 jni, watchFieldClass, FIELDNAME, TYPE) ) != NULL ) ) { |
|
233 NSK_DISPLAY0(" Agent :: Failed to get FieldId before droping watchers.\n"); |
226 NSK_DISPLAY0(" Agent :: Failed to get FieldId before droping watchers.\n"); |
234 nsk_jvmti_agentFailed(); |
227 nsk_jvmti_agentFailed(); |
235 } else { |
228 } else { |
236 if ( ! NSK_JVMTI_VERIFY ( NSK_CPP_STUB3(ClearFieldAccessWatch, |
229 if ( ! NSK_JVMTI_VERIFY ( jvmti->ClearFieldAccessWatch(watchFieldClass, fieldId) ) ) { |
237 jvmti, watchFieldClass, fieldId)) ) { |
|
238 NSK_DISPLAY0(" Agent :: failed to drop field watces.\n"); |
230 NSK_DISPLAY0(" Agent :: failed to drop field watces.\n"); |
239 nsk_jvmti_agentFailed(); |
231 nsk_jvmti_agentFailed(); |
240 } else { |
232 } else { |
241 NSK_DISPLAY0(" Agent :: Sucessfully droped watches.\n"); |
233 NSK_DISPLAY0(" Agent :: Sucessfully droped watches.\n"); |
242 retvalue = JNI_TRUE; |
234 retvalue = JNI_TRUE; |