I am using the JVMTI call FollowReferences to find all objects (and their sizes) referenced by a single object, by specifying initial_object in the call "jvmtiError FollowReferences(jvmtiEnv* env, jint heap_filter, jclass klass, jobject initial_object, const jvmtiHeapCallbacks* callbacks, const void* user_data)".
The object passed in is a valid object, but tracing through my callback function (only using jvmtiHeapReferenceCallback), it seams that pretty much all of the heap's objects are traversed, no matter if they are directly or indirectly referenced by my object or not. That seems to contradict the spec: "This function initiates a traversal over the objects that are directly and indirectly reachable from the specified object ". And that's exactly what I'm trying to accomplish so I don't have the overhead of traversing the whole heap. Is there anything I am missing, or are there some other parameters to be set?
JVM version (on Windows XP): java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
The initial object is just that and it really depends on the return from the callbacks if all reachable objects all visited. That is, from your initial object you will get a reference to its class, from there to its class loader, from the class loader to all classes that it has loaded, etc.