This discussion is archived
1 Reply Latest reply: Jan 31, 2010 3:15 PM by 843810 RSS

How to get the classname of an object when iterating the heap?

843810 Newbie
Currently Being Moderated
The definition of the heap object call back function when iterating the heap is as following.
typedef jvmtiIterationControl (JNICALL *jvmtiHeapObjectCallback)
    (jlong class_tag, 
     jlong size, 
     jlong* tag_ptr, 
     void* user_data);
How can I get the classname in this function? What does the class_tag represent? Can I get the classname from the class_tag?
  • 1. Re: How to get the classname of an object when iterating the heap?
    843810 Newbie
    Currently Being Moderated
    Assuming that you tagged the object, its tag will be in tag_ptr. Then you can use GetObjectsWithTags to get the actual jobject with that tag, and finally use the JNI call GetObjectClass to get the objects class as a jclass. Finally, use jvmti->GetClassSignature to get the actual class name as a string.

    If you tagged the object's class, class_tag will have it. You can probably use this to skip a step, and get the jclass directly with GetObjectsWithTag.