1

I am looking at the JVMTI API(http://docs.oracle.com/javase/6/docs/platform/jvmti/jvmti.html) in order to get the current heap at a given state.

In order to do this, I would like to use the FollowReferences (http://docs.oracle.com/javase/6/docs/platform/jvmti/jvmti.html#FollowReferences) method which takes as argument a pointer to a jvmtiHeapCallbacks structure which define several callbacks and especially a Heap Reference Callback.

This callback must be of the following form:

    typedef jint (JNICALL *jvmtiHeapReferenceCallback)
                 (jvmtiHeapReferenceKind reference_kind, 
                  const jvmtiHeapReferenceInfo* reference_info, 
                  jlong class_tag, 
                  jlong referrer_class_tag, 
                  jlong size, 
                  jlong* tag_ptr, 
                  jlong* referrer_tag_ptr, 
                  jint length, 
                  void* user_data);

I don't understand how I can use the class_tag? In the API, I haven't be able to find a fonction converting a class_tag to a jclass. I have looked several exemples and could not get usage of the class_tag.

In the API, there is a SetTag and GetTag functions but they appear to be for jobject and not for jclass.

trincot
  • 317,000
  • 35
  • 244
  • 286
Piervit
  • 11
  • 2

1 Answers1

0

The class_tag is the tag of the actual class object (classes can be tagged with SetTag, like any other object). So, you can get the actual class with jvmti#GetObjectsWithTag on the class_tag. If the class has not been tagged, then class_tag will be zero. However, you could still get the class object by using GetObjectsWithTag on referrer_tag_ptr, and then using the jni GetObjectClass method.

Note that (at least on most implementations I have seen) GetObjectsWithTag is pretty slow. If speed is an issue, you would get better preformance by batching it up and asking for a bunch of objects at once (GetObjectsWithTag takes a pointer to an buffer full of tags).

npr
  • 126
  • 1
  • 10