44
45 NSK_DISPLAY1("VMObjectAlloc events received: %d\n", eventsCount);
46
47 if (eventsCount == 0) {
48 NSK_DISPLAY0("# WARNING: no VMObjectAlloc events\n");
49 NSK_DISPLAY0("# (VM might not allocate such objects at all)\n");
50 }
51
52 return NSK_TRUE;
53 }
54
55 /* ========================================================================== */
56
57 JNIEXPORT void JNICALL
58 VMObjectAlloc(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jobject object,
59 jclass object_klass, jlong size) {
60 char *signature, *generic;
61
62 eventsCount++;
63
64 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti,
65 object_klass, &signature, &generic))) {
66 nsk_jvmti_setFailStatus();
67 return;
68 }
69
70 NSK_DISPLAY2("VMObjectAlloc: \"%s\", size=%d\n", signature, size);
71
72 if (signature != NULL)
73 NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)signature);
74
75 if (generic != NULL)
76 NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)generic);
77
78 }
79
80 /* ========================================================================== */
81
82 /* agent algorithm */
83 static void JNICALL
84 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
85
86 /* wait for debuggee start */
87 if (!nsk_jvmti_waitForSync(timeout))
88 return;
89
90 /* testcase #1: check if any VMObjectAlloc events received*/
91 NSK_DISPLAY0("Testcase #1: check if any VMObjectAlloc events received\n");
92 if (!checkVMObjectAllocEvents())
93 nsk_jvmti_setFailStatus();
94
95 /* resume debugee after last sync */
96 if (!nsk_jvmti_resumeSync())
113 #endif
114 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
115 jvmtiEnv* jvmti = NULL;
116 jvmtiCapabilities caps;
117 jvmtiEventCallbacks callbacks;
118
119 /* init framework and parse options */
120 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
121 return JNI_ERR;
122
123 timeout = nsk_jvmti_getWaitTime() * 60000;
124 NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
125
126 /* create JVMTI environment */
127 if (!NSK_VERIFY((jvmti =
128 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
129 return JNI_ERR;
130
131 memset(&caps, 0, sizeof(caps));
132 caps.can_generate_vm_object_alloc_events = 1;
133 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
134 return JNI_ERR;
135 }
136
137 memset(&callbacks, 0, sizeof(callbacks));
138 callbacks.VMObjectAlloc= &VMObjectAlloc;
139 if (!NSK_JVMTI_VERIFY(
140 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
141 &callbacks, sizeof(callbacks))))
142 return JNI_ERR;
143
144 /* enable VMObjectAlloc event */
145 if (!NSK_JVMTI_VERIFY(
146 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE,
147 JVMTI_EVENT_VM_OBJECT_ALLOC, NULL)))
148 return JNI_ERR;
149
150 /* register agent proc and arg */
151 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
152 return JNI_ERR;
153
154 return JNI_OK;
155 }
156
157 /* ========================================================================== */
158
159 }
|
44
45 NSK_DISPLAY1("VMObjectAlloc events received: %d\n", eventsCount);
46
47 if (eventsCount == 0) {
48 NSK_DISPLAY0("# WARNING: no VMObjectAlloc events\n");
49 NSK_DISPLAY0("# (VM might not allocate such objects at all)\n");
50 }
51
52 return NSK_TRUE;
53 }
54
55 /* ========================================================================== */
56
57 JNIEXPORT void JNICALL
58 VMObjectAlloc(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jobject object,
59 jclass object_klass, jlong size) {
60 char *signature, *generic;
61
62 eventsCount++;
63
64 if (!NSK_JVMTI_VERIFY(jvmti->GetClassSignature(object_klass, &signature, &generic))) {
65 nsk_jvmti_setFailStatus();
66 return;
67 }
68
69 NSK_DISPLAY2("VMObjectAlloc: \"%s\", size=%d\n", signature, size);
70
71 if (signature != NULL)
72 jvmti->Deallocate((unsigned char*)signature);
73
74 if (generic != NULL)
75 jvmti->Deallocate((unsigned char*)generic);
76
77 }
78
79 /* ========================================================================== */
80
81 /* agent algorithm */
82 static void JNICALL
83 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
84
85 /* wait for debuggee start */
86 if (!nsk_jvmti_waitForSync(timeout))
87 return;
88
89 /* testcase #1: check if any VMObjectAlloc events received*/
90 NSK_DISPLAY0("Testcase #1: check if any VMObjectAlloc events received\n");
91 if (!checkVMObjectAllocEvents())
92 nsk_jvmti_setFailStatus();
93
94 /* resume debugee after last sync */
95 if (!nsk_jvmti_resumeSync())
112 #endif
113 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
114 jvmtiEnv* jvmti = NULL;
115 jvmtiCapabilities caps;
116 jvmtiEventCallbacks callbacks;
117
118 /* init framework and parse options */
119 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
120 return JNI_ERR;
121
122 timeout = nsk_jvmti_getWaitTime() * 60000;
123 NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
124
125 /* create JVMTI environment */
126 if (!NSK_VERIFY((jvmti =
127 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
128 return JNI_ERR;
129
130 memset(&caps, 0, sizeof(caps));
131 caps.can_generate_vm_object_alloc_events = 1;
132 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
133 return JNI_ERR;
134 }
135
136 memset(&callbacks, 0, sizeof(callbacks));
137 callbacks.VMObjectAlloc= &VMObjectAlloc;
138 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
139 return JNI_ERR;
140
141 /* enable VMObjectAlloc event */
142 if (!NSK_JVMTI_VERIFY(
143 jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL)))
144 return JNI_ERR;
145
146 /* register agent proc and arg */
147 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
148 return JNI_ERR;
149
150 return JNI_OK;
151 }
152
153 /* ========================================================================== */
154
155 }
|