1 /*
2 * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include <string.h>
25 #include "jvmti.h"
26 #include "agent_common.h"
27 #include "jni_tools.h"
28 #include "jvmti_tools.h"
29 #include "JVMTITools.h"
30
31 extern "C" {
32
33 /* ============================================================================= */
34
35 /* scaffold objects */
36 static jvmtiEnv *jvmti = NULL;
37 static jlong timeout = 0;
38 static jrawMonitorID syncLock = NULL;
39
40 /* constant names */
41 #define STEP_NUMBER 3
42 #define EXPECTED_CLASS_NAME "Lnsk/jvmti/scenarios/events/EM02/em02t005a;"
43 #define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1)
44 #define NUMBER_OF_INVOCATIONS 1000
45
46 static int eventCount[JVMTI_EVENT_COUNT];
47 static int newEventCount[JVMTI_EVENT_COUNT];
48
49 /* ============================================================================= */
50
51 static void
showEventStatistics(int step)52 showEventStatistics(int step) {
53 int i;
54 const char* str;
55 int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0];
56
57 NSK_DISPLAY0("\n");
58 NSK_DISPLAY1("Event statistics for %d step:\n", step);
59 NSK_DISPLAY0("-----------------------------\n");
60 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
61 if (currentCounts[i] > 0) {
62 str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL));
63 NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]);
64 }
65 }
66 }
67
68 /* ========================================================================== */
69
checkEvents(int step)70 int checkEvents(int step) {
71 int i;
72 jvmtiEvent curr;
73 bool result = true;
74 int *currentCounts;
75 int isExpected = 0;
76
77 switch (step) {
78 case 1:
79 currentCounts = &eventCount[0];
80 break;
81
82 case 2:
83 case 3:
84 currentCounts = &newEventCount[0];
85 break;
86
87 default:
88 NSK_COMPLAIN1("Unexpected step no: %d\n", step);
89 return false;
90 }
91
92 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
93
94 curr = (jvmtiEvent) (i + JVMTI_MIN_EVENT_TYPE_VAL);
95
96 switch (step) {
97 case 1:
98 isExpected = ((curr == JVMTI_EVENT_VM_INIT)
99 || (curr == JVMTI_EVENT_VM_OBJECT_ALLOC));
100 break;
101
102 case 2:
103 isExpected = (curr == JVMTI_EVENT_VM_OBJECT_ALLOC);
104 break;
105
106 case 3:
107 isExpected = (curr == JVMTI_EVENT_VM_DEATH);
108 break;
109 }
110
111 if (isExpected) {
112 if (currentCounts[i] < 0) {
113 NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be non-negative\n",
114 currentCounts[i],
115 TranslateEvent(curr));
116 result = false;
117 }
118
119 } else {
120
121 if (currentCounts[i] > 0) {
122 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
123 TranslateEvent(curr),
124 currentCounts[i]);
125 result = false;
126 }
127 }
128 }
129
130 return result;
131 }
132
133 static void
changeCount(jvmtiEvent event,int * currentCounts)134 changeCount(jvmtiEvent event, int *currentCounts) {
135
136 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
137 nsk_jvmti_setFailStatus();
138
139 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
140
141 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
142 nsk_jvmti_setFailStatus();
143
144 }
145
146 /* ============================================================================= */
147
148 /* callbacks */
149 JNIEXPORT void JNICALL
cbVMInit(jvmtiEnv * jvmti,JNIEnv * jni_env,jthread thread)150 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
151 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
152 }
153
154 JNIEXPORT void JNICALL
cbVMDeath(jvmtiEnv * jvmti,JNIEnv * jni_env)155 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
156 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
157 showEventStatistics(STEP_NUMBER);
158 if (!checkEvents(STEP_NUMBER))
159 nsk_jvmti_setFailStatus();
160
161 if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
162 nsk_jvmti_setFailStatus();
163
164 }
165
166 void JNICALL
cbException(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jlocation location,jobject exception,jmethodID catch_method,jlocation catch_location)167 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
168 jmethodID method, jlocation location, jobject exception,
169 jmethodID catch_method, jlocation catch_location) {
170
171 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
172 }
173
174 void JNICALL
cbExceptionCatch(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jlocation location,jobject exception)175 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
176 jmethodID method, jlocation location, jobject exception) {
177
178 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
179 }
180
181 void JNICALL
cbSingleStep(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jlocation location)182 cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
183 jmethodID method, jlocation location) {
184
185 changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]);
186 }
187
188 void JNICALL
cbFramePop(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jboolean was_popped_by_exception)189 cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
190 jmethodID method, jboolean was_popped_by_exception) {
191 changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]);
192 }
193
194 void JNICALL
cbBreakpoint(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jlocation location)195 cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
196 jmethodID method, jlocation location) {
197 changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]);
198 }
199
200 void JNICALL
cbFieldAccess(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jlocation location,jclass field_klass,jobject object,jfieldID field)201 cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
202 jmethodID method, jlocation location, jclass field_klass,
203 jobject object, jfieldID field) {
204
205 changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]);
206 }
207
208 void JNICALL
cbFieldModification(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jlocation location,jclass field_klass,jobject object,jfieldID field,char signature_type,jvalue new_value)209 cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
210 jmethodID method, jlocation location, jclass field_klass,
211 jobject object, jfieldID field, char signature_type,
212 jvalue new_value) {
213
214 changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]);
215 }
216
217 void JNICALL
cbMethodEntry(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method)218 cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
219 jmethodID method) {
220
221 changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]);
222 }
223
224 void JNICALL
cbMethodExit(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,jboolean was_popped_by_exception,jvalue return_value)225 cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
226 jmethodID method, jboolean was_popped_by_exception,
227 jvalue return_value) {
228
229 changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]);
230 }
231
232 void JNICALL
cbNativeMethodBind(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jmethodID method,void * address,void ** new_address_ptr)233 cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread,
234 jmethodID method, void* address, void** new_address_ptr) {
235 changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]);
236 }
237
238 void JNICALL
cbMonitorWait(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jobject object,jlong tout)239 cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
240 jobject object, jlong tout) {
241
242 changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]);
243 }
244
245 void JNICALL
cbMonitorWaited(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jobject object,jboolean timed_out)246 cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
247 jobject object, jboolean timed_out) {
248
249 changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]);
250 }
251
252 JNIEXPORT void JNICALL
cbMonitorContendedEnter(jvmtiEnv * jvmti,JNIEnv * jni_env,jthread thread,jobject object)253 cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread,
254 jobject object) {
255
256 changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]);
257 }
258
259 void JNICALL
cbMonitorContendedEntered(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jobject object)260 cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
261 jobject object) {
262
263 changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]);
264 }
265
266 void JNICALL
cbCompiledMethodLoad(jvmtiEnv * jvmti_env,jmethodID method,jint code_size,const void * code_addr,jint map_length,const jvmtiAddrLocationMap * map,const void * compile_info)267 cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size,
268 const void* code_addr, jint map_length,
269 const jvmtiAddrLocationMap* map, const void* compile_info) {
270 changeCount(JVMTI_EVENT_COMPILED_METHOD_LOAD, &eventCount[0]);
271 }
272
273 void JNICALL
cbCompiledMethodUnload(jvmtiEnv * jvmti_env,jmethodID method,const void * code_addr)274 cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method,
275 const void* code_addr) {
276 changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]);
277 }
278
279 void JNICALL
cbGarbageCollectionStart(jvmtiEnv * jvmti_env)280 cbGarbageCollectionStart(jvmtiEnv *jvmti_env) {
281 changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]);
282 }
283
284 void JNICALL
cbGarbageCollectionFinish(jvmtiEnv * jvmti_env)285 cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) {
286 changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]);
287 }
288
289 void JNICALL
cbObjectFree(jvmtiEnv * jvmti_env,jlong tag)290 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
291
292 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
293 }
294
295 void JNICALL
cbVMObjectAlloc(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jobject object,jclass object_klass,jlong size)296 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
297 jobject object, jclass object_klass, jlong size) {
298
299 char *sign_ptr;
300 char *gen_ptr;
301
302 jvmtiPhase phase;
303
304 if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(object_klass, &sign_ptr, &gen_ptr))) {
305 nsk_jvmti_setFailStatus();
306 return;
307 }
308
309 if (strcmp(sign_ptr, EXPECTED_CLASS_NAME) == 0) {
310 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
311 }
312
313 if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
314 nsk_jvmti_setFailStatus();
315 }
316
317 if (phase != JVMTI_PHASE_LIVE) {
318 NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n",
319 TranslateEvent(JVMTI_EVENT_VM_OBJECT_ALLOC),
320 TranslatePhase(phase),
321 phase,
322 sign_ptr);
323 nsk_jvmti_setFailStatus();
324 }
325
326 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)sign_ptr))) {
327 nsk_jvmti_setFailStatus();
328 }
329 if (gen_ptr != NULL)
330 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)gen_ptr))) {
331 nsk_jvmti_setFailStatus();
332 }
333 }
334
335 void JNICALL
cbNewVMObjectAlloc(jvmtiEnv * jvmti_env,JNIEnv * jni_env,jthread thread,jobject object,jclass object_klass,jlong size)336 cbNewVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
337 jobject object, jclass object_klass, jlong size) {
338
339 char *sign_ptr;
340 char *gen_ptr;
341
342 jvmtiPhase phase;
343
344 if (!NSK_JVMTI_VERIFY(jvmti_env->GetClassSignature(object_klass, &sign_ptr, &gen_ptr))) {
345 nsk_jvmti_setFailStatus();
346 return;
347 }
348
349 if (strcmp(sign_ptr, EXPECTED_CLASS_NAME) == 0) {
350 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &newEventCount[0]);
351 }
352
353 if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
354 nsk_jvmti_setFailStatus();
355 }
356
357 if (phase != JVMTI_PHASE_LIVE) {
358 NSK_COMPLAIN4("%25s was sent during %s(%d)\n\tclass: %s\n",
359 TranslateEvent(JVMTI_EVENT_VM_OBJECT_ALLOC),
360 TranslatePhase(phase),
361 phase,
362 sign_ptr);
363 nsk_jvmti_setFailStatus();
364 }
365
366 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)sign_ptr))) {
367 nsk_jvmti_setFailStatus();
368 }
369 if (gen_ptr != NULL)
370 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)gen_ptr))) {
371 nsk_jvmti_setFailStatus();
372 }
373 }
374
375 /* ============================================================================= */
376
enableEvent(jvmtiEvent event)377 static bool enableEvent(jvmtiEvent event) {
378
379 if (nsk_jvmti_isOptionalEvent(event)
380 && (event != JVMTI_EVENT_VM_OBJECT_ALLOC)) {
381 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
382 jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
383 NSK_COMPLAIN1("Unexpected error enabling %s\n",
384 TranslateEvent(event));
385 return false;
386 }
387 } else {
388 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
389 NSK_COMPLAIN1("Unexpected error enabling %s\n",
390 TranslateEvent(event));
391 return false;
392 }
393 }
394
395 return true;
396 }
397
398 /**
399 * Enable or disable tested events.
400 */
enableEventList()401 static bool enableEventList() {
402
403 int i, result;
404
405 result = enableEvent(JVMTI_EVENT_VM_INIT);
406
407 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
408
409 /* enabling optional events */
410 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
411 jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL);
412
413 if (nsk_jvmti_isOptionalEvent(event))
414 result = result && enableEvent(event);
415 }
416
417 if (!result) {
418 nsk_jvmti_setFailStatus();
419 return false;
420 }
421
422 return true;
423 }
424
425 /* ============================================================================= */
426
setCallBacks(int step)427 static bool setCallBacks(int step) {
428
429 int i;
430
431 jvmtiEventCallbacks eventCallbacks;
432 memset(&eventCallbacks, 0, sizeof(eventCallbacks));
433
434 switch (step) {
435 case 1:
436 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
437 eventCount[i] = 0;
438 }
439
440 eventCallbacks.VMInit = cbVMInit;
441 eventCallbacks.Exception = cbException;
442 eventCallbacks.ExceptionCatch = cbExceptionCatch;
443 eventCallbacks.SingleStep = cbSingleStep;
444 eventCallbacks.FramePop = cbFramePop;
445 eventCallbacks.Breakpoint = cbBreakpoint;
446 eventCallbacks.FieldAccess = cbFieldAccess;
447 eventCallbacks.FieldModification = cbFieldModification;
448 eventCallbacks.MethodEntry = cbMethodEntry;
449 eventCallbacks.MethodExit = cbMethodExit;
450 eventCallbacks.NativeMethodBind = cbNativeMethodBind;
451 eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad;
452 eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload;
453 eventCallbacks.MonitorWait = cbMonitorWait;
454 eventCallbacks.MonitorWaited = cbMonitorWaited;
455 eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter;
456 eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered;
457 eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart;
458 eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish;
459 eventCallbacks.ObjectFree = cbObjectFree;
460 eventCallbacks.VMObjectAlloc = cbVMObjectAlloc;
461 break;
462
463 case 2:
464 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
465 newEventCount[i] = 0;
466 }
467
468 eventCallbacks.VMObjectAlloc = cbNewVMObjectAlloc;
469 break;
470
471 case 3:
472 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
473 newEventCount[i] = 0;
474 }
475
476 eventCallbacks.VMDeath = cbVMDeath;
477 break;
478
479 }
480 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
481 return false;
482
483 return true;
484 }
485
486 /* ============================================================================= */
487
488 /** Agent algorithm. */
489 static void JNICALL
agentProc(jvmtiEnv * jvmti,JNIEnv * agentJNI,void * arg)490 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
491
492 int i;
493
494 for (i = 1; i <= STEP_NUMBER; i++) {
495
496 if (!nsk_jvmti_waitForSync(timeout))
497 return;
498
499 if (i < STEP_NUMBER) {
500 showEventStatistics(i);
501 if (!checkEvents(i))
502 nsk_jvmti_setFailStatus();
503
504 if (!setCallBacks(i + 1)) {
505 return;
506 }
507 }
508
509 if (!nsk_jvmti_resumeSync())
510 return;
511 }
512
513 }
514
515 /* ============================================================================= */
516
517 /** Agent library initialization. */
518 #ifdef STATIC_BUILD
Agent_OnLoad_em02t005(JavaVM * jvm,char * options,void * reserved)519 JNIEXPORT jint JNICALL Agent_OnLoad_em02t005(JavaVM *jvm, char *options, void *reserved) {
520 return Agent_Initialize(jvm, options, reserved);
521 }
Agent_OnAttach_em02t005(JavaVM * jvm,char * options,void * reserved)522 JNIEXPORT jint JNICALL Agent_OnAttach_em02t005(JavaVM *jvm, char *options, void *reserved) {
523 return Agent_Initialize(jvm, options, reserved);
524 }
JNI_OnLoad_em02t005(JavaVM * jvm,char * options,void * reserved)525 JNIEXPORT jint JNI_OnLoad_em02t005(JavaVM *jvm, char *options, void *reserved) {
526 return JNI_VERSION_1_8;
527 }
528 #endif
Agent_Initialize(JavaVM * jvm,char * options,void * reserved)529 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
530
531 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
532 return JNI_ERR;
533
534 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
535
536 jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved);
537 if (!NSK_VERIFY(jvmti != NULL))
538 return JNI_ERR;
539
540
541 if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
542 nsk_jvmti_setFailStatus();
543 return JNI_ERR;
544 }
545
546 {
547 jvmtiCapabilities caps;
548 memset(&caps, 0, sizeof(caps));
549
550 caps.can_generate_vm_object_alloc_events = 1;
551 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
552 return JNI_ERR;
553 }
554
555 if (!setCallBacks(1)) {
556 return JNI_ERR;
557 }
558
559 if (!enableEventList()) {
560 return JNI_ERR;
561 }
562
563 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
564 return JNI_ERR;
565
566 return JNI_OK;
567 }
568
569 /* ============================================================================= */
570
571
572 }
573