32
33 /* ============================================================================= */
34
35 static jlong g_timeout = 0;
36
37 #define JAVA_LANG_STRING_CLASS_NAME "java/lang/String"
38 #define JAVA_IO_SERIALIZABLE_CLASS_NAME "java/io/Serializable"
39 #define JAVA_UTIL_CALENDAR_CLASS_NAME "java/util/Calendar"
40
41
42 /* ============================================================================= */
43
44 static void verifyReturnCodes(JNIEnv* jni, jvmtiEnv* jvmti)
45 {
46 jvmtiError retCode;
47 jlong tag;
48 jvmtiHeapCallbacks emptyHeapCallbacks;
49
50 NSK_DISPLAY0("FollowReferences: Invalid class:");
51
52 retCode = NSK_CPP_STUB6(FollowReferences,
53 jvmti,
54 (jint) 0, /* heap filter */
55 (jclass) &g_wrongHeapCallbacks , /* invalid class, but valid memory address */
56 NULL, /* inital object */
57 &g_wrongHeapCallbacks,
58 (const void *) &g_fakeUserData);
59
60 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_CLASS ) ) {
61 nsk_jvmti_setFailStatus();
62 }
63
64 NSK_DISPLAY0("FollowReferences: Invalid initial object:");
65 // When FollowReferences() is called with an invalid initial object
66 // the behaviour according to the jvmti spec is optional.
67 // It may return JVMTI_ERROR_INVALID_OBJECT and not follow any references.
68 // Or it may treat the object as NULL, and follow all references.
69 //
70 // We will accept both behaviours. We use empty callbacks since the existing
71 // callback marks the test as failed.
72
73 emptyHeapCallbacks.heap_iteration_callback = NULL;
74 emptyHeapCallbacks.heap_reference_callback = NULL;
75 emptyHeapCallbacks.primitive_field_callback = NULL;
76 emptyHeapCallbacks.array_primitive_value_callback = NULL;
77 emptyHeapCallbacks.string_primitive_value_callback = NULL;
78 retCode = NSK_CPP_STUB6(FollowReferences,
79 jvmti,
80 (jint) 0, // heap filter
81 NULL, // class
82 (jobject) &g_wrongHeapCallbacks, // invalid inital object
83 &emptyHeapCallbacks, // No callbacks
84 (const void *) &g_fakeUserData);
85
86 // Accept both JVMTI_ERROR_INVALID_OBJECT and JVMTI_ERROR_NONE
87 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT || retCode == JVMTI_ERROR_NONE ) ) {
88 nsk_jvmti_setFailStatus();
89 }
90
91 NSK_DISPLAY0("FollowReferences: Invalid callbacks:");
92
93 retCode = NSK_CPP_STUB6(FollowReferences,
94 jvmti,
95 (jint) 0, /* heap filter */
96 NULL, /* class */
97 NULL, /* inital object */
98 NULL,
99 (const void *) &g_fakeUserData);
100
101 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_NULL_POINTER ) ) {
102 nsk_jvmti_setFailStatus();
103 }
104
105 NSK_DISPLAY0("GetTag: Invalid object:");
106
107 retCode = NSK_CPP_STUB3(GetTag,
108 jvmti,
109 (jobject) &g_wrongHeapCallbacks, /* invalid inital object */
110 &tag);
111
112 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
113 nsk_jvmti_setFailStatus();
114 }
115
116 NSK_DISPLAY0("GetTag: NULL object pointer:");
117
118 retCode = NSK_CPP_STUB3(GetTag,
119 jvmti,
120 NULL,
121 &tag);
122
123 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
124 nsk_jvmti_setFailStatus();
125 }
126
127 NSK_DISPLAY0("GetTag: NULL tag pointer:");
128
129 retCode = NSK_CPP_STUB3(GetTag,
130 jvmti,
131 (jobject) &g_wrongHeapCallbacks,
132 NULL);
133
134 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_NULL_POINTER ) ) {
135 nsk_jvmti_setFailStatus();
136 }
137
138 NSK_DISPLAY0("SetTag: Invalid object:");
139
140 tag = 1;
141 retCode = NSK_CPP_STUB3(SetTag,
142 jvmti,
143 (jobject) &g_wrongHeapCallbacks, /* invalid inital object */
144 tag);
145
146 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
147 nsk_jvmti_setFailStatus();
148 }
149
150 NSK_DISPLAY0("SetTag: NULL object pointer:");
151
152 retCode = NSK_CPP_STUB3(GetTag,
153 jvmti,
154 NULL,
155 &tag);
156
157 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
158 nsk_jvmti_setFailStatus();
159 }
160
161 NSK_DISPLAY0("GetTag: NULL tag pointer:");
162
163 } /* verifyReturnCodes */
164
165 /* ============================================================================= */
166
167 static void checkNoObjIterated(JNIEnv* jni, jvmtiEnv* jvmti, const char * szClassName)
168 {
169 jvmtiError retCode;
170 jclass klass;
171
172 NSK_DISPLAY1("Verify, that no objects are returned if initial object is %s", szClassName);
173 if (!NSK_JNI_VERIFY(jni, (klass =
174 NSK_CPP_STUB2(FindClass, jni, szClassName)) != NULL)) {
175 nsk_jvmti_setFailStatus();
176 return;
177 }
178
179 retCode = NSK_CPP_STUB6(FollowReferences,
180 jvmti,
181 (jint) 0, /* heap filter */
182 klass, /* class */
183 NULL, /* inital object */
184 &g_wrongHeapCallbacks,
185 (const void *) &g_fakeUserData);
186
187 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_NONE ) ) {
188 nsk_jvmti_setFailStatus();
189 }
190
191 } /* checkNoObjIterated */
192
193 /* ============================================================================= */
194
195 /** Agent algorithm. */
196
197 static void JNICALL agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg)
198 {
199 NSK_DISPLAY0("Call FollowReferences() with invalid arguments and check return codes");
200
201 verifyReturnCodes(jni, jvmti);
235 {
236 jvmtiEnv* jvmti = NULL;
237
238 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) {
239 return JNI_ERR;
240 }
241
242 g_timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
243
244 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) {
245 return JNI_ERR;
246 }
247
248 jvmti_FollowRefObject_init();
249
250 {
251 jvmtiCapabilities caps;
252
253 memset(&caps, 0, sizeof(caps));
254 caps.can_tag_objects = 1;
255 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
256 return JNI_ERR;
257 }
258 }
259
260 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) {
261 return JNI_ERR;
262 }
263
264 return JNI_OK;
265
266 } /* Agent_OnLoad */
267
268
269 /* ============================================================================= */
270
271 }
|
32
33 /* ============================================================================= */
34
35 static jlong g_timeout = 0;
36
37 #define JAVA_LANG_STRING_CLASS_NAME "java/lang/String"
38 #define JAVA_IO_SERIALIZABLE_CLASS_NAME "java/io/Serializable"
39 #define JAVA_UTIL_CALENDAR_CLASS_NAME "java/util/Calendar"
40
41
42 /* ============================================================================= */
43
44 static void verifyReturnCodes(JNIEnv* jni, jvmtiEnv* jvmti)
45 {
46 jvmtiError retCode;
47 jlong tag;
48 jvmtiHeapCallbacks emptyHeapCallbacks;
49
50 NSK_DISPLAY0("FollowReferences: Invalid class:");
51
52 retCode = jvmti->FollowReferences((jint) 0, /* heap filter */
53 (jclass) &g_wrongHeapCallbacks , /* invalid class, but valid memory address */
54 NULL, /* inital object */
55 &g_wrongHeapCallbacks,
56 (const void *) &g_fakeUserData);
57
58 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_CLASS ) ) {
59 nsk_jvmti_setFailStatus();
60 }
61
62 NSK_DISPLAY0("FollowReferences: Invalid initial object:");
63 // When FollowReferences() is called with an invalid initial object
64 // the behaviour according to the jvmti spec is optional.
65 // It may return JVMTI_ERROR_INVALID_OBJECT and not follow any references.
66 // Or it may treat the object as NULL, and follow all references.
67 //
68 // We will accept both behaviours. We use empty callbacks since the existing
69 // callback marks the test as failed.
70
71 emptyHeapCallbacks.heap_iteration_callback = NULL;
72 emptyHeapCallbacks.heap_reference_callback = NULL;
73 emptyHeapCallbacks.primitive_field_callback = NULL;
74 emptyHeapCallbacks.array_primitive_value_callback = NULL;
75 emptyHeapCallbacks.string_primitive_value_callback = NULL;
76 retCode = jvmti->FollowReferences((jint) 0, // heap filter
77 NULL, // class
78 (jobject) &g_wrongHeapCallbacks, // invalid inital object
79 &emptyHeapCallbacks, // No callbacks
80 (const void *) &g_fakeUserData);
81
82 // Accept both JVMTI_ERROR_INVALID_OBJECT and JVMTI_ERROR_NONE
83 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT || retCode == JVMTI_ERROR_NONE ) ) {
84 nsk_jvmti_setFailStatus();
85 }
86
87 NSK_DISPLAY0("FollowReferences: Invalid callbacks:");
88
89 retCode = jvmti->FollowReferences((jint) 0, /* heap filter */
90 NULL, /* class */
91 NULL, /* inital object */
92 NULL,
93 (const void *) &g_fakeUserData);
94
95 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_NULL_POINTER ) ) {
96 nsk_jvmti_setFailStatus();
97 }
98
99 NSK_DISPLAY0("GetTag: Invalid object:");
100
101 retCode = jvmti->GetTag((jobject) &g_wrongHeapCallbacks, /* invalid inital object */
102 &tag);
103
104 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
105 nsk_jvmti_setFailStatus();
106 }
107
108 NSK_DISPLAY0("GetTag: NULL object pointer:");
109
110 retCode = jvmti->GetTag(NULL, &tag);
111
112 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
113 nsk_jvmti_setFailStatus();
114 }
115
116 NSK_DISPLAY0("GetTag: NULL tag pointer:");
117
118 retCode = jvmti->GetTag((jobject) &g_wrongHeapCallbacks, NULL);
119
120 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_NULL_POINTER ) ) {
121 nsk_jvmti_setFailStatus();
122 }
123
124 NSK_DISPLAY0("SetTag: Invalid object:");
125
126 tag = 1;
127 retCode = jvmti->SetTag((jobject) &g_wrongHeapCallbacks, /* invalid inital object */
128 tag);
129
130 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
131 nsk_jvmti_setFailStatus();
132 }
133
134 NSK_DISPLAY0("SetTag: NULL object pointer:");
135
136 retCode = jvmti->GetTag(NULL, &tag);
137
138 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_INVALID_OBJECT ) ) {
139 nsk_jvmti_setFailStatus();
140 }
141
142 NSK_DISPLAY0("GetTag: NULL tag pointer:");
143
144 } /* verifyReturnCodes */
145
146 /* ============================================================================= */
147
148 static void checkNoObjIterated(JNIEnv* jni, jvmtiEnv* jvmti, const char * szClassName)
149 {
150 jvmtiError retCode;
151 jclass klass;
152
153 NSK_DISPLAY1("Verify, that no objects are returned if initial object is %s", szClassName);
154 if (!NSK_JNI_VERIFY(jni, (klass = jni->FindClass(szClassName)) != NULL)) {
155 nsk_jvmti_setFailStatus();
156 return;
157 }
158
159 retCode = jvmti->FollowReferences((jint) 0, /* heap filter */
160 klass, /* class */
161 NULL, /* inital object */
162 &g_wrongHeapCallbacks,
163 (const void *) &g_fakeUserData);
164
165 if ( ! NSK_VERIFY(retCode == JVMTI_ERROR_NONE ) ) {
166 nsk_jvmti_setFailStatus();
167 }
168
169 } /* checkNoObjIterated */
170
171 /* ============================================================================= */
172
173 /** Agent algorithm. */
174
175 static void JNICALL agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg)
176 {
177 NSK_DISPLAY0("Call FollowReferences() with invalid arguments and check return codes");
178
179 verifyReturnCodes(jni, jvmti);
213 {
214 jvmtiEnv* jvmti = NULL;
215
216 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) {
217 return JNI_ERR;
218 }
219
220 g_timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
221
222 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) {
223 return JNI_ERR;
224 }
225
226 jvmti_FollowRefObject_init();
227
228 {
229 jvmtiCapabilities caps;
230
231 memset(&caps, 0, sizeof(caps));
232 caps.can_tag_objects = 1;
233 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
234 return JNI_ERR;
235 }
236 }
237
238 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) {
239 return JNI_ERR;
240 }
241
242 return JNI_OK;
243
244 } /* Agent_OnLoad */
245
246
247 /* ============================================================================= */
248
249 }
|