34 extern "C" {
35
36 #define EXP_OBJ_NUMBER 1
37
38 static JNIEnv *jni = NULL;
39 static jvmtiEnv *jvmti = NULL;
40 static jvmtiEventCallbacks callbacks;
41 static jvmtiCapabilities caps;
42
43 static jlong timeout = 0;
44 static jobject referrer = NULL;
45 static const char* SUBCLASS_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP05/ap05t001Subclass;";
46 static const int EXPECTED_STATIC_FIELDS_COUNT = 8;
47 /* 8 ones declared in ap05t001Superclass + 8 ones declared in ap05t001Subclass */
48 static const int EXPECTED_INSTANCE_FIELDS_COUNT = 16;
49 static const long CLS_TAG = 1l, REFERRER_TAG = 2l, REFERREE_TAG = 10l;
50 static int staticFieldsCount = 0, instanceFieldsCount = 0;
51
52 /* jvmtiHeapRootCallback */
53 jvmtiIterationControl JNICALL
54 heapRootCallback( jvmtiHeapRootKind root_kind,
55 jlong class_tag,
56 jlong size,
57 jlong* tag_ptr,
58 void* user_data) {
59 return JVMTI_ITERATION_CONTINUE;
60 }
61
62 /* jvmtiStackReferenceCallback */
63 jvmtiIterationControl JNICALL
64 stackReferenceCallback( jvmtiHeapRootKind root_kind,
65 jlong class_tag,
66 jlong size,
67 jlong* tag_ptr,
68 jlong thread_tag,
69 jint depth,
70 jmethodID method,
71 jint slot,
72 void* user_data) {
73 return JVMTI_ITERATION_CONTINUE;
74 }
75
76
77 /* jvmtiObjectReferenceCallback */
78 jvmtiIterationControl JNICALL
79 objectReferenceCallback( jvmtiObjectReferenceKind reference_kind,
80 jlong class_tag,
81 jlong size,
82 jlong* tag_ptr,
83 jlong referrer_tag,
84 jint referrer_index,
85 void* user_data) {
86
87 if (*tag_ptr == REFERREE_TAG && (referrer_tag == CLS_TAG || referrer_tag == REFERRER_TAG)) {
88 NSK_DISPLAY4("objectReferenceCallback: reference kind=%s, referrer_index=%d, referrer_tag=%d, referree_tag=%d\n",
89 TranslateObjectRefKind(reference_kind), (int)referrer_index, (long)referrer_tag, (long)*tag_ptr);
90 if (reference_kind == JVMTI_REFERENCE_FIELD) {
91 instanceFieldsCount++;
92 } else if (reference_kind == JVMTI_REFERENCE_STATIC_FIELD) {
93 staticFieldsCount++;
94 }
95 }
96 return JVMTI_ITERATION_CONTINUE;
97 }
98
99
100 /************************/
101
102 JNIEXPORT void JNICALL
103 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t001_setTag( JNIEnv* jni,
104 jobject obj,
105 jobject target,
106 jlong tag ) {
107
108 if (!NSK_JVMTI_VERIFY(jvmti->SetTag(target, tag))) {
109 nsk_jvmti_setFailStatus();
110 }
111 }
112
113 JNIEXPORT void JNICALL
114 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t001_setReferrer( JNIEnv* jni, jclass klass, jobject ref) {
115 if (!NSK_JNI_VERIFY(jni, (referrer = jni->NewGlobalRef(ref)) != NULL))
116 nsk_jvmti_setFailStatus();
117 }
118
119 static void JNICALL
120 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
121
122 jclass debugeeClass = NULL;
123
124 NSK_DISPLAY0("Wait for debugee start\n\n");
125 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
126 return;
127
128 do {
129 staticFieldsCount = 0;
130 instanceFieldsCount = 0;
131 NSK_DISPLAY0("\nCalling IterateOverReachableObjects\n");
132 if (!NSK_JVMTI_VERIFY(jvmti->IterateOverReachableObjects(heapRootCallback,
133 stackReferenceCallback,
134 objectReferenceCallback,
|
34 extern "C" {
35
36 #define EXP_OBJ_NUMBER 1
37
38 static JNIEnv *jni = NULL;
39 static jvmtiEnv *jvmti = NULL;
40 static jvmtiEventCallbacks callbacks;
41 static jvmtiCapabilities caps;
42
43 static jlong timeout = 0;
44 static jobject referrer = NULL;
45 static const char* SUBCLASS_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP05/ap05t001Subclass;";
46 static const int EXPECTED_STATIC_FIELDS_COUNT = 8;
47 /* 8 ones declared in ap05t001Superclass + 8 ones declared in ap05t001Subclass */
48 static const int EXPECTED_INSTANCE_FIELDS_COUNT = 16;
49 static const long CLS_TAG = 1l, REFERRER_TAG = 2l, REFERREE_TAG = 10l;
50 static int staticFieldsCount = 0, instanceFieldsCount = 0;
51
52 /* jvmtiHeapRootCallback */
53 jvmtiIterationControl JNICALL
54 heapRootCallback(jvmtiHeapRootKind root_kind,
55 jlong class_tag,
56 jlong size,
57 jlong* tag_ptr,
58 void* user_data) {
59 return JVMTI_ITERATION_CONTINUE;
60 }
61
62 /* jvmtiStackReferenceCallback */
63 jvmtiIterationControl JNICALL
64 stackReferenceCallback(jvmtiHeapRootKind root_kind,
65 jlong class_tag,
66 jlong size,
67 jlong* tag_ptr,
68 jlong thread_tag,
69 jint depth,
70 jmethodID method,
71 jint slot,
72 void* user_data) {
73 return JVMTI_ITERATION_CONTINUE;
74 }
75
76
77 /* jvmtiObjectReferenceCallback */
78 jvmtiIterationControl JNICALL
79 objectReferenceCallback(jvmtiObjectReferenceKind reference_kind,
80 jlong class_tag,
81 jlong size,
82 jlong* tag_ptr,
83 jlong referrer_tag,
84 jint referrer_index,
85 void* user_data) {
86
87 if (*tag_ptr == REFERREE_TAG && (referrer_tag == CLS_TAG || referrer_tag == REFERRER_TAG)) {
88 NSK_DISPLAY4("objectReferenceCallback: reference kind=%s, referrer_index=%d, referrer_tag=%d, referree_tag=%d\n",
89 TranslateObjectRefKind(reference_kind), (int)referrer_index, (long)referrer_tag, (long)*tag_ptr);
90 if (reference_kind == JVMTI_REFERENCE_FIELD) {
91 instanceFieldsCount++;
92 } else if (reference_kind == JVMTI_REFERENCE_STATIC_FIELD) {
93 staticFieldsCount++;
94 }
95 }
96 return JVMTI_ITERATION_CONTINUE;
97 }
98
99
100 /************************/
101
102 JNIEXPORT void JNICALL
103 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t001_setTag(JNIEnv* jni,
104 jobject obj,
105 jobject target,
106 jlong tag) {
107
108 if (!NSK_JVMTI_VERIFY(jvmti->SetTag(target, tag))) {
109 nsk_jvmti_setFailStatus();
110 }
111 }
112
113 JNIEXPORT void JNICALL
114 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t001_setReferrer(JNIEnv* jni, jclass klass, jobject ref) {
115 if (!NSK_JNI_VERIFY(jni, (referrer = jni->NewGlobalRef(ref)) != NULL))
116 nsk_jvmti_setFailStatus();
117 }
118
119 static void JNICALL
120 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
121
122 jclass debugeeClass = NULL;
123
124 NSK_DISPLAY0("Wait for debugee start\n\n");
125 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
126 return;
127
128 do {
129 staticFieldsCount = 0;
130 instanceFieldsCount = 0;
131 NSK_DISPLAY0("\nCalling IterateOverReachableObjects\n");
132 if (!NSK_JVMTI_VERIFY(jvmti->IterateOverReachableObjects(heapRootCallback,
133 stackReferenceCallback,
134 objectReferenceCallback,
|