44 ClassUnload(jvmtiEnv jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass, ...) {
45 /*
46 * With the CMS GC the event can be posted on
47 * a ConcurrentGC thread that is not a JavaThread.
48 * In this case the thread argument can be NULL, so that,
49 * we should not expect the thread argument to be non-NULL.
50 */
51 if (klass == NULL) {
52 nsk_jvmti_setFailStatus();
53 NSK_COMPLAIN0("ClassUnload: 'klass' input parameter is NULL.\n");
54
55 }
56 NSK_DISPLAY0("Received ClassUnload event.\n");
57 if (eventEnabled == JNI_TRUE) {
58 eventReceived1 = JNI_TRUE;
59 } else {
60 eventReceived2 = JNI_TRUE;
61 }
62
63 /* Notify main agent thread */
64 if (!NSK_JVMTI_VERIFY(
65 NSK_CPP_STUB2(RawMonitorEnter, jvmti, eventMon))) {
66 nsk_jvmti_setFailStatus();
67 }
68 if (!NSK_JVMTI_VERIFY(
69 NSK_CPP_STUB2(RawMonitorNotify, jvmti, eventMon))) {
70 nsk_jvmti_setFailStatus();
71 }
72 if (!NSK_JVMTI_VERIFY(
73 NSK_CPP_STUB2(RawMonitorExit, jvmti, eventMon))) {
74 nsk_jvmti_setFailStatus();
75 }
76 }
77
78 jboolean isClassUnloadingEnabled() {
79 jint extCount, i;
80 jvmtiExtensionFunctionInfo* extList;
81 jboolean found = JNI_FALSE;
82 jboolean enabled = JNI_FALSE;
83 jvmtiError err;
84
85 NSK_DISPLAY0("Get extension functions list\n");
86
87 if (!NSK_JVMTI_VERIFY(
88 NSK_CPP_STUB3(GetExtensionFunctions, jvmti, &extCount, &extList))) {
89 nsk_jvmti_setFailStatus();
90 return JNI_FALSE;
91 }
92
93 for (i = 0; i < extCount; i++) {
94 if (strcmp(extList[i].id, (char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled") == 0) {
95 found = JNI_TRUE;
96
97 err = (*extList[i].func)(jvmti, &enabled);
98 if (err != JVMTI_ERROR_NONE) {
99 NSK_COMPLAIN1("Error during invocation of IsClassUnloadingEnabled function: %d\n", err);
100 nsk_jvmti_setFailStatus();
101 return JNI_FALSE;
102 }
103 }
104 }
105 if (found == JNI_FALSE) {
106 NSK_COMPLAIN0("IsClassUnloadingEnabled was not found among extension functions.\n");
107 nsk_jvmti_setFailStatus();
108 return JNI_FALSE;
109 }
110
111 return enabled;
112 }
113
114 jboolean enableClassUnloadEvent (jboolean enable) {
115 jint extCount, i;
116 jvmtiExtensionEventInfo* extList;
117 jboolean found = JNI_FALSE;
118
119 NSK_DISPLAY0("Get extension events list\n");
120 if (!NSK_JVMTI_VERIFY(
121 NSK_CPP_STUB3(GetExtensionEvents, jvmti, &extCount, &extList))) {
122 nsk_jvmti_setFailStatus();
123 return JNI_FALSE;
124 }
125
126 for (i = 0; i < extCount; i++) {
127 if (strcmp(extList[i].id, (char*)"com.sun.hotspot.events.ClassUnload") == 0) {
128 found = JNI_TRUE;
129
130 if (!NSK_JVMTI_VERIFY(
131 NSK_CPP_STUB3(SetExtensionEventCallback, jvmti, extList[i].extension_event_index,
132 enable ? (jvmtiExtensionEvent)ClassUnload : NULL ))) {
133 nsk_jvmti_setFailStatus();
134 return JNI_FALSE;
135 }
136 eventEnabled = enable;
137 if (enable == JNI_TRUE) {
138 NSK_DISPLAY1("%s callback enabled\n", extList[i].id);
139 } else {
140 NSK_DISPLAY1("%s callback disabled\n", extList[i].id);
141 }
142 }
143 }
144 if (found == JNI_FALSE) {
145 NSK_COMPLAIN0("ClassUnload event was not found among extension events.\n");
146 nsk_jvmti_setFailStatus();
147 return JNI_FALSE;
148 }
149 return JNI_TRUE;
150 }
151
158 do {
159 if (isClassUnloadingEnabled() == JNI_FALSE) {
160 NSK_COMPLAIN0("ClassUnloadingEnabled returned false.\n");
161 nsk_jvmti_setFailStatus();
162 }
163
164 NSK_DISPLAY0("Wait for loading of ex03t001a class.\n");
165 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
166 return;
167
168 if (enableClassUnloadEvent(JNI_TRUE) == JNI_FALSE) {
169 NSK_COMPLAIN0("Cannot set up ClassUnload event callback.\n");
170 break;
171 }
172
173 NSK_DISPLAY0("Let debugee to unload ex03t001a class.\n");
174 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
175 break;
176
177 /* Wait for notifying from event's thread */
178 if (!NSK_JVMTI_VERIFY(
179 NSK_CPP_STUB2(RawMonitorEnter, jvmti, eventMon))) {
180 nsk_jvmti_setFailStatus();
181 }
182 if (!NSK_JVMTI_VERIFY(
183 NSK_CPP_STUB3(RawMonitorWait, jvmti, eventMon, timeout))) {
184 nsk_jvmti_setFailStatus();
185 }
186 if (!NSK_JVMTI_VERIFY(
187 NSK_CPP_STUB2(RawMonitorExit, jvmti, eventMon))) {
188 nsk_jvmti_setFailStatus();
189 }
190
191 NSK_DISPLAY0("Wait for loading of ex03t001b class.\n");
192 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
193 return;
194
195 if (enableClassUnloadEvent(JNI_FALSE) == JNI_FALSE) {
196 NSK_COMPLAIN0("Cannot set off ClassUnload event callback.\n");
197 break;
198 }
199
200 NSK_DISPLAY0("Let debugee to unload ex03t001b class.\n");
201 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
202 return;
203
204 /* Wait during 10 secs for notifying from event's thread */
205 if (!NSK_JVMTI_VERIFY(
206 NSK_CPP_STUB2(RawMonitorEnter, jvmti, eventMon))) {
207 nsk_jvmti_setFailStatus();
208 }
209 if (!NSK_JVMTI_VERIFY(
210 NSK_CPP_STUB3(RawMonitorWait, jvmti, eventMon, 10000))) {
211 nsk_jvmti_setFailStatus();
212 }
213 if (!NSK_JVMTI_VERIFY(
214 NSK_CPP_STUB2(RawMonitorExit, jvmti, eventMon))) {
215 nsk_jvmti_setFailStatus();
216 }
217
218 if (eventReceived1 == JNI_FALSE) {
219 nsk_jvmti_setFailStatus();
220 NSK_COMPLAIN0("Expected ClassUnload event was not received.\n");
221 }
222
223 if (eventReceived2 == JNI_TRUE) {
224 nsk_jvmti_setFailStatus();
225 NSK_COMPLAIN0("Received unexpected ClassUnload event.\n");
226 }
227
228 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
229 return;
230
231 } while (0);
232
233 NSK_TRACE(NSK_CPP_STUB2(DestroyRawMonitor, jvmti, eventMon));
234
235 NSK_DISPLAY0("Let debugee to finish\n");
236 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
237 return;
238 }
239
240 /* ============================================================================= */
241
242 /** Agent library initialization. */
243 #ifdef STATIC_BUILD
244 JNIEXPORT jint JNICALL Agent_OnLoad_ex03t001(JavaVM *jvm, char *options, void *reserved) {
245 return Agent_Initialize(jvm, options, reserved);
246 }
247 JNIEXPORT jint JNICALL Agent_OnAttach_ex03t001(JavaVM *jvm, char *options, void *reserved) {
248 return Agent_Initialize(jvm, options, reserved);
249 }
250 JNIEXPORT jint JNI_OnLoad_ex03t001(JavaVM *jvm, char *options, void *reserved) {
251 return JNI_VERSION_1_8;
252 }
253 #endif
254 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
255
256 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
257 return JNI_ERR;
258
259 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
260
261 if (!NSK_VERIFY((jvmti =
262 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
263 return JNI_ERR;
264
265 if (!NSK_JVMTI_VERIFY(
266 NSK_CPP_STUB3(CreateRawMonitor, jvmti, "eventMon", &eventMon))) {
267 return JNI_ERR;
268 }
269
270 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
271 return JNI_ERR;
272
273 return JNI_OK;
274 }
275
276 /* ============================================================================= */
277
278 }
|
44 ClassUnload(jvmtiEnv jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass, ...) {
45 /*
46 * With the CMS GC the event can be posted on
47 * a ConcurrentGC thread that is not a JavaThread.
48 * In this case the thread argument can be NULL, so that,
49 * we should not expect the thread argument to be non-NULL.
50 */
51 if (klass == NULL) {
52 nsk_jvmti_setFailStatus();
53 NSK_COMPLAIN0("ClassUnload: 'klass' input parameter is NULL.\n");
54
55 }
56 NSK_DISPLAY0("Received ClassUnload event.\n");
57 if (eventEnabled == JNI_TRUE) {
58 eventReceived1 = JNI_TRUE;
59 } else {
60 eventReceived2 = JNI_TRUE;
61 }
62
63 /* Notify main agent thread */
64 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(eventMon))) {
65 nsk_jvmti_setFailStatus();
66 }
67 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorNotify(eventMon))) {
68 nsk_jvmti_setFailStatus();
69 }
70 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(eventMon))) {
71 nsk_jvmti_setFailStatus();
72 }
73 }
74
75 jboolean isClassUnloadingEnabled() {
76 jint extCount, i;
77 jvmtiExtensionFunctionInfo* extList;
78 jboolean found = JNI_FALSE;
79 jboolean enabled = JNI_FALSE;
80 jvmtiError err;
81
82 NSK_DISPLAY0("Get extension functions list\n");
83
84 if (!NSK_JVMTI_VERIFY(jvmti->GetExtensionFunctions(&extCount, &extList))) {
85 nsk_jvmti_setFailStatus();
86 return JNI_FALSE;
87 }
88
89 for (i = 0; i < extCount; i++) {
90 if (strcmp(extList[i].id, (char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled") == 0) {
91 found = JNI_TRUE;
92
93 err = (*extList[i].func)(jvmti, &enabled);
94 if (err != JVMTI_ERROR_NONE) {
95 NSK_COMPLAIN1("Error during invocation of IsClassUnloadingEnabled function: %d\n", err);
96 nsk_jvmti_setFailStatus();
97 return JNI_FALSE;
98 }
99 }
100 }
101 if (found == JNI_FALSE) {
102 NSK_COMPLAIN0("IsClassUnloadingEnabled was not found among extension functions.\n");
103 nsk_jvmti_setFailStatus();
104 return JNI_FALSE;
105 }
106
107 return enabled;
108 }
109
110 jboolean enableClassUnloadEvent (jboolean enable) {
111 jint extCount, i;
112 jvmtiExtensionEventInfo* extList;
113 jboolean found = JNI_FALSE;
114
115 NSK_DISPLAY0("Get extension events list\n");
116 if (!NSK_JVMTI_VERIFY(jvmti->GetExtensionEvents(&extCount, &extList))) {
117 nsk_jvmti_setFailStatus();
118 return JNI_FALSE;
119 }
120
121 for (i = 0; i < extCount; i++) {
122 if (strcmp(extList[i].id, (char*)"com.sun.hotspot.events.ClassUnload") == 0) {
123 found = JNI_TRUE;
124
125 if (!NSK_JVMTI_VERIFY(
126 jvmti->SetExtensionEventCallback(extList[i].extension_event_index,
127 enable ? (jvmtiExtensionEvent)ClassUnload : NULL ))) {
128 nsk_jvmti_setFailStatus();
129 return JNI_FALSE;
130 }
131 eventEnabled = enable;
132 if (enable == JNI_TRUE) {
133 NSK_DISPLAY1("%s callback enabled\n", extList[i].id);
134 } else {
135 NSK_DISPLAY1("%s callback disabled\n", extList[i].id);
136 }
137 }
138 }
139 if (found == JNI_FALSE) {
140 NSK_COMPLAIN0("ClassUnload event was not found among extension events.\n");
141 nsk_jvmti_setFailStatus();
142 return JNI_FALSE;
143 }
144 return JNI_TRUE;
145 }
146
153 do {
154 if (isClassUnloadingEnabled() == JNI_FALSE) {
155 NSK_COMPLAIN0("ClassUnloadingEnabled returned false.\n");
156 nsk_jvmti_setFailStatus();
157 }
158
159 NSK_DISPLAY0("Wait for loading of ex03t001a class.\n");
160 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
161 return;
162
163 if (enableClassUnloadEvent(JNI_TRUE) == JNI_FALSE) {
164 NSK_COMPLAIN0("Cannot set up ClassUnload event callback.\n");
165 break;
166 }
167
168 NSK_DISPLAY0("Let debugee to unload ex03t001a class.\n");
169 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
170 break;
171
172 /* Wait for notifying from event's thread */
173 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(eventMon))) {
174 nsk_jvmti_setFailStatus();
175 }
176 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(eventMon, timeout))) {
177 nsk_jvmti_setFailStatus();
178 }
179 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(eventMon))) {
180 nsk_jvmti_setFailStatus();
181 }
182
183 NSK_DISPLAY0("Wait for loading of ex03t001b class.\n");
184 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
185 return;
186
187 if (enableClassUnloadEvent(JNI_FALSE) == JNI_FALSE) {
188 NSK_COMPLAIN0("Cannot set off ClassUnload event callback.\n");
189 break;
190 }
191
192 NSK_DISPLAY0("Let debugee to unload ex03t001b class.\n");
193 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
194 return;
195
196 /* Wait during 10 secs for notifying from event's thread */
197 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(eventMon))) {
198 nsk_jvmti_setFailStatus();
199 }
200 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(eventMon, 10000))) {
201 nsk_jvmti_setFailStatus();
202 }
203 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(eventMon))) {
204 nsk_jvmti_setFailStatus();
205 }
206
207 if (eventReceived1 == JNI_FALSE) {
208 nsk_jvmti_setFailStatus();
209 NSK_COMPLAIN0("Expected ClassUnload event was not received.\n");
210 }
211
212 if (eventReceived2 == JNI_TRUE) {
213 nsk_jvmti_setFailStatus();
214 NSK_COMPLAIN0("Received unexpected ClassUnload event.\n");
215 }
216
217 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
218 return;
219
220 } while (0);
221
222 NSK_TRACE(jvmti->DestroyRawMonitor(eventMon));
223
224 NSK_DISPLAY0("Let debugee to finish\n");
225 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
226 return;
227 }
228
229 /* ============================================================================= */
230
231 /** Agent library initialization. */
232 #ifdef STATIC_BUILD
233 JNIEXPORT jint JNICALL Agent_OnLoad_ex03t001(JavaVM *jvm, char *options, void *reserved) {
234 return Agent_Initialize(jvm, options, reserved);
235 }
236 JNIEXPORT jint JNICALL Agent_OnAttach_ex03t001(JavaVM *jvm, char *options, void *reserved) {
237 return Agent_Initialize(jvm, options, reserved);
238 }
239 JNIEXPORT jint JNI_OnLoad_ex03t001(JavaVM *jvm, char *options, void *reserved) {
240 return JNI_VERSION_1_8;
241 }
242 #endif
243 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
244
245 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
246 return JNI_ERR;
247
248 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
249
250 if (!NSK_VERIFY((jvmti =
251 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
252 return JNI_ERR;
253
254 if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("eventMon", &eventMon))) {
255 return JNI_ERR;
256 }
257
258 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
259 return JNI_ERR;
260
261 return JNI_OK;
262 }
263
264 /* ============================================================================= */
265
266 }
|