I'm searching a way to find a list of allocated objects inside the JVM.
I don't want to use a profiler as I want to see these object during runtime, inside the code itself. I wanna create a graph of all objects present inside the program and the interactions between each others.
Do you have a start of a way? I already searched for lots of reflection classes and profilers example but couldn't find something relevant for my case.
Thank you in advance
You could achieve this with JVMTI
. GetLoadedClasses
function is a good entry point
JavaVM *jvm;
jvmtiEnv *jvmti;
jvmtiError err;
env->GetJavaVM(&jvm);
jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_2);
jint classCount = 0;
jclass * classes;
// get all classes loaded by jvm
jvmti->GetLoadedClasses(&classCount, &classes);
You can also traverse heap and thus build a graph of objects.
Do you have a start of a way?
Yes, you can take a heap dump and analyse the heap dump.
Note: use a heap analyser which already exists would be simplest. eg visualvm, An application can have many millions of objects so a tool designed to do this will help you navigate the data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.