44 static jobject referrer = NULL;
45 static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP09/ap09t001;";
46 static const long OBJECT_TAG = 1l;
47 static const long CLASS_TAG = 2l;
48 static const long LOADER_TAG = 3l;
49 static const long DOMAIN_TAG = 4l;
50 static const long INSTANCE_FIELD_TAG = 5l;
51 static const long STATIC_FIELD_TAG = 6l;
52 static const long ARRAY_TAG = 7l;
53 static const long INTERFACE_TAG = 8l;
54 static int classFound = 0;
55 static int loaderFound = 0;
56 static int domainFound = 0;
57 static int instanceFieldFound = 0;
58 static int staticFieldFound = 0;
59 static int arrayFound = 0;
60 static int interfaceFound = 0;
61
62 /* jvmtiHeapRootCallback */
63 jvmtiIterationControl JNICALL
64 heapRootCallback( jvmtiHeapRootKind root_kind,
65 jlong class_tag,
66 jlong size,
67 jlong* tag_ptr,
68 void* user_data) {
69 return JVMTI_ITERATION_CONTINUE;
70 }
71
72 /* jvmtiStackReferenceCallback */
73 jvmtiIterationControl JNICALL
74 stackReferenceCallback( jvmtiHeapRootKind root_kind,
75 jlong class_tag,
76 jlong size,
77 jlong* tag_ptr,
78 jlong thread_tag,
79 jint depth,
80 jmethodID method,
81 jint slot,
82 void* user_data) {
83 return JVMTI_ITERATION_CONTINUE;
84 }
85
86
87 /* jvmtiObjectReferenceCallback */
88 jvmtiIterationControl JNICALL
89 objectReferenceCallback( jvmtiObjectReferenceKind reference_kind,
90 jlong class_tag,
91 jlong size,
92 jlong* tag_ptr,
93 jlong referrer_tag,
94 jint referrer_index,
95 void* user_data) {
96
97 if (*tag_ptr != 0 && referrer_tag != 0) {
98 NSK_DISPLAY4("objectReferenceCallback: reference kind=%s, referrer_index=%d, referrer_tag=%d, referree_tag=%d\n",
99 TranslateObjectRefKind(reference_kind), (int)referrer_index, (long)referrer_tag, (long)*tag_ptr);
100
101 if (reference_kind == JVMTI_REFERENCE_CLASS && *tag_ptr == CLASS_TAG) {
102 classFound++;
103 }
104 if (reference_kind == JVMTI_REFERENCE_CLASS_LOADER && *tag_ptr == LOADER_TAG) {
105 loaderFound++;
106 }
107 if (reference_kind == JVMTI_REFERENCE_INTERFACE && *tag_ptr == INTERFACE_TAG) {
108 interfaceFound++;
109 }
110 if (reference_kind == JVMTI_REFERENCE_PROTECTION_DOMAIN && *tag_ptr == DOMAIN_TAG) {
111 domainFound++;
112 }
113 if (reference_kind == JVMTI_REFERENCE_ARRAY_ELEMENT && *tag_ptr == STATIC_FIELD_TAG && referrer_tag == ARRAY_TAG) {
114 arrayFound++;
115 }
116 if (reference_kind == JVMTI_REFERENCE_STATIC_FIELD && *tag_ptr == ARRAY_TAG) {
117 staticFieldFound++;
118 }
119 if (reference_kind == JVMTI_REFERENCE_FIELD && *tag_ptr == INSTANCE_FIELD_TAG) {
120 instanceFieldFound++;
121 }
122 }
123 return JVMTI_ITERATION_CONTINUE;
124 }
125
126
127 /************************/
128
129 JNIEXPORT void JNICALL
130 Java_nsk_jvmti_scenarios_allocation_AP09_ap09t001_setTag( JNIEnv* jni,
131 jobject obj,
132 jobject target,
133 jlong tag ) {
134
135 if (!NSK_JVMTI_VERIFY(jvmti->SetTag(target, tag))) {
136 nsk_jvmti_setFailStatus();
137 }
138 }
139
140 JNIEXPORT void JNICALL
141 Java_nsk_jvmti_scenarios_allocation_AP09_ap09t001_setReferrer( JNIEnv* jni, jclass klass, jobject ref) {
142 if (!NSK_JNI_VERIFY(jni, (referrer = jni->NewGlobalRef(ref)) != NULL))
143 nsk_jvmti_setFailStatus();
144 }
145
146 static void JNICALL
147 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
148
149 jclass debugeeClass = NULL;
150
151 NSK_DISPLAY0("Wait for debugee start\n\n");
152 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
153 return;
154
155 do {
156 NSK_DISPLAY0("\nCalling IterateOverObjectsReachableFromObject\n");
157 if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(referrer,
158 objectReferenceCallback,
159 NULL /*user_data*/))) {
160 nsk_jvmti_setFailStatus();
161 }
|
44 static jobject referrer = NULL;
45 static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP09/ap09t001;";
46 static const long OBJECT_TAG = 1l;
47 static const long CLASS_TAG = 2l;
48 static const long LOADER_TAG = 3l;
49 static const long DOMAIN_TAG = 4l;
50 static const long INSTANCE_FIELD_TAG = 5l;
51 static const long STATIC_FIELD_TAG = 6l;
52 static const long ARRAY_TAG = 7l;
53 static const long INTERFACE_TAG = 8l;
54 static int classFound = 0;
55 static int loaderFound = 0;
56 static int domainFound = 0;
57 static int instanceFieldFound = 0;
58 static int staticFieldFound = 0;
59 static int arrayFound = 0;
60 static int interfaceFound = 0;
61
62 /* jvmtiHeapRootCallback */
63 jvmtiIterationControl JNICALL
64 heapRootCallback(jvmtiHeapRootKind root_kind,
65 jlong class_tag,
66 jlong size,
67 jlong* tag_ptr,
68 void* user_data) {
69 return JVMTI_ITERATION_CONTINUE;
70 }
71
72 /* jvmtiStackReferenceCallback */
73 jvmtiIterationControl JNICALL
74 stackReferenceCallback(jvmtiHeapRootKind root_kind,
75 jlong class_tag,
76 jlong size,
77 jlong* tag_ptr,
78 jlong thread_tag,
79 jint depth,
80 jmethodID method,
81 jint slot,
82 void* user_data) {
83 return JVMTI_ITERATION_CONTINUE;
84 }
85
86
87 /* jvmtiObjectReferenceCallback */
88 jvmtiIterationControl JNICALL
89 objectReferenceCallback(jvmtiObjectReferenceKind reference_kind,
90 jlong class_tag,
91 jlong size,
92 jlong* tag_ptr,
93 jlong referrer_tag,
94 jint referrer_index,
95 void* user_data) {
96
97 if (*tag_ptr != 0 && referrer_tag != 0) {
98 NSK_DISPLAY4("objectReferenceCallback: reference kind=%s, referrer_index=%d, referrer_tag=%d, referree_tag=%d\n",
99 TranslateObjectRefKind(reference_kind), (int)referrer_index, (long)referrer_tag, (long)*tag_ptr);
100
101 if (reference_kind == JVMTI_REFERENCE_CLASS && *tag_ptr == CLASS_TAG) {
102 classFound++;
103 }
104 if (reference_kind == JVMTI_REFERENCE_CLASS_LOADER && *tag_ptr == LOADER_TAG) {
105 loaderFound++;
106 }
107 if (reference_kind == JVMTI_REFERENCE_INTERFACE && *tag_ptr == INTERFACE_TAG) {
108 interfaceFound++;
109 }
110 if (reference_kind == JVMTI_REFERENCE_PROTECTION_DOMAIN && *tag_ptr == DOMAIN_TAG) {
111 domainFound++;
112 }
113 if (reference_kind == JVMTI_REFERENCE_ARRAY_ELEMENT && *tag_ptr == STATIC_FIELD_TAG && referrer_tag == ARRAY_TAG) {
114 arrayFound++;
115 }
116 if (reference_kind == JVMTI_REFERENCE_STATIC_FIELD && *tag_ptr == ARRAY_TAG) {
117 staticFieldFound++;
118 }
119 if (reference_kind == JVMTI_REFERENCE_FIELD && *tag_ptr == INSTANCE_FIELD_TAG) {
120 instanceFieldFound++;
121 }
122 }
123 return JVMTI_ITERATION_CONTINUE;
124 }
125
126
127 /************************/
128
129 JNIEXPORT void JNICALL
130 Java_nsk_jvmti_scenarios_allocation_AP09_ap09t001_setTag(JNIEnv* jni,
131 jobject obj,
132 jobject target,
133 jlong tag) {
134
135 if (!NSK_JVMTI_VERIFY(jvmti->SetTag(target, tag))) {
136 nsk_jvmti_setFailStatus();
137 }
138 }
139
140 JNIEXPORT void JNICALL
141 Java_nsk_jvmti_scenarios_allocation_AP09_ap09t001_setReferrer(JNIEnv* jni, jclass klass, jobject ref) {
142 if (!NSK_JNI_VERIFY(jni, (referrer = jni->NewGlobalRef(ref)) != NULL))
143 nsk_jvmti_setFailStatus();
144 }
145
146 static void JNICALL
147 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
148
149 jclass debugeeClass = NULL;
150
151 NSK_DISPLAY0("Wait for debugee start\n\n");
152 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
153 return;
154
155 do {
156 NSK_DISPLAY0("\nCalling IterateOverObjectsReachableFromObject\n");
157 if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(referrer,
158 objectReferenceCallback,
159 NULL /*user_data*/))) {
160 nsk_jvmti_setFailStatus();
161 }
|