How can I access Java heap objects without a link?

I would like to get a link to all objects in the Java heap, even if I don't have a link to these objects in my active thread. I don’t need objects without a link (those queued for garbage collection), but I would like to get everything that is still in use.

The goal is to serialize and store all objects in order to implement an unstable execution state. I understand that the rabbit hole goes deep when it comes to different types of transition state, but simply persisting objects and loaded class definitions would be useful for me.

Is there any way to access the heap for this to happen? Can I ignore a more direct approach?

+3
source share
3 answers

I looked into the instrument package . A tool for the classes that interest you, so ctor registers the instantiated instance. Perhaps you can do it through AspectJ if you don't want to use java.lang.instrument, or if objects are created using something you can control (container or IoC factories), then you can do something good, less magical .

+3
source

, API- java. * javax. *. , Sun HotSpotDiagnosticMXBean, , .

+1

Source: https://habr.com/ru/post/1716983/


All Articles