Object address, size and heap space / JVMTI and Serviceability agent cooperation

2012-03-05 Thread Crazy Java
Hi,


I am working on a project of visualizing the HotSpot heap. It is basically
a GCSpy rewrite and I am trying o write a HotSpot driver.

Just very quickly what the tool is providing - set of tiles per every heap
space (young, old and permanent generation), where every tile has a well
defined size (let's say 64kB). The visualization is then defined by the
color of every tile (the white means tile is absolutely free of objects and
100% red tile means the whole tile is used by objects).


To do that, I need 3 information:

   1. object size - how many bytes every object consumes in memory (not
   recursive/deep size)
   2. object address - to compute the heap fragmentation, I need to know
   the address of object (when using together with size, I should know the
   exact part of heap occupied by every object)
   3. heap spaces - what heap spaces are used and their addresses as well
   (to know what object belongs to what heap space)


I spend quite a lot of time trying to figure out how can we get those
information and there is a way to get all of them, however I need some
interactions of APIs:

   1. object size - can by determined by Java Agent, native agent, JVMTI
   and serviceability agent as well
   2. object address - the only way I found is by using the Serviceability
   agent
   3. heap spaces - again just Serviceability agent seems like having such
   a capability


Now the idea is to use JVMTI and Serviceability agent together. JVMTI will
call callbacks every time object is allocated (for "new" object allocation
bytecode instrumentationwill be used), deallocated or GC was finished and
the size and address information will be determined by Serviceability
Agent. For performance reasons it will be super inefficient to iterate
through the whole heap every time JVMTI generates callback. Well, the
problem is that even if I get notifications from JVMTI, I cannot determine
the address of object from JVMTI, so I don't know how to map the identity
of object from JVMTI to Serviceability agent.

So I should be able to just update the part of heap that is really needed
to be updated instead of whole heap and I have no idea how this could be
achieved.

Do you have any idea how could I get the object address and heap spaces
from JVMTI, or the callbacks (JVMTI callbacks like objectAlloc(),
GCFinished(), ...) from Serviceability agent, or how to connect those APIs
to work together?


Thanks very much,
Martin Skurla


Clarification on SA support for Windows & JDK6

2012-03-14 Thread Crazy Java
Hi,


I would like to clarify if the Serviceability agent is supported in Windows
platform running JDK6. According to http://netbeans.dzone.com/vvm-sa-plugin,
"JDK versions supported: 6u17 and later on Solaris and Linux (SA binaries
are not yet shipped with jdk6 on Windows)". However on my laptop (JDK6u30 &
Win 7) I am successfully running the Serviceability agent (sa-jdi.jar is in
the JDK's lib directory).

So is the serviceability agent officially supported on Win & JDK 6 and if
yes, starting from which JDK 6 update?


Thanks,
Martin Skurla


Listening to heap size changes / reallocation

2012-03-14 Thread Crazy Java
Hi,


I was searching through the SA source code, but I didn't find a way how
could I be notified when the heap (generations, spaces, memregions) will be
changed. The point is I am visualizing the HotSpot heap and I have
information about all the object sizes and addresses (using some native
code and tricks in native agent). Using Serviceability agent I also have
information about the heap separation (generations) and their addresses.

So I should be able to visualize the heap. However when objects will be
created, there is a possibility of allocating more memory for the heap by
the VM (because there could be not enough memory to allocate the object).
And so the addresses of heap (let's say young or old generation) could
change because of that.

The question is if it is possible to register some kind of listener for
that. Or if the already acquired heap representation objects from SA will
be automatically updated (I don't think so, but good idea). Or I need to
get the heap representation objects every time (for every object allocation
seems like total overkill).

I also found a class called MemRegion, maybe this can help?


Thanks very much,
Martin Skurla