Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to read the memory of a running java application?

Tags:

java

memory

jvm

I'd like to learn how, or if its possible at all to programmaticly interact with a black-box java application(by reading its data). Has there been any previous research/work on doing this sort of thing?

I'd imagine that running on a JVM significantly complicates things.

@anon: Doing this with any JVM is relevant. Do you have to know or control the specifics of how the JVM allocates memory to extract data from a java application?

like image 201
Ari Ronen Avatar asked Jun 29 '10 03:06

Ari Ronen


People also ask

How do you analyze memory in Java?

Check the overall memory usage of the appjvisualvm is one of the memory analysis tools for Java used to analyze the runtime behavior of a Java application. It traces a running Java program, checking its memory and CPU consumption. Also, it is used to create a memory heap dump to analyze the objects in the heap.

How do I get system memory in Java?

How to get total Memory in Java. You can use Runtime. getRuntime. totalMemory() to get total memory from JVM which represents the current heap size of JVM which is a combination of used memory currently occupied by objects and free memory available for new objects.

What is runtime memory in Java?

The Runtime#maxMemory method returns the maximum memory that the JVM will attempt to use. Once the JVM memory usage reaches this value, then it will not allocate more memory and instead, and it will garbage collect more frequently.

Does Java have reserve memory?

Typically, the JVM allocates new memory until the heap is full, in which case it garbage collects, freeing up non-referenced objects. If you allocated 14GB for the heap, chances are it will consume that much memory.


2 Answers

You could look into java.lang.instrument. As long as you understand the class structure of the application, it will let you modify the methods in an already-running JVM and you may be able to concoct a way that allows you to extract or insert data enough to communicate (depends on the methods available, of course).

like image 73
G__ Avatar answered Oct 15 '22 08:10

G__


The Sable group at McGill University has contributed a lot of research to the Java world.

Much of the work is getting rather dated, but you might find some help in their EVolve project which has the goal of visualizing object-oriented programs. Some of their projects appear to be actively maintained (such as Soot, their Java optimization framework), so you might find luck contacting them directly

like image 21
Chadwick Avatar answered Oct 15 '22 08:10

Chadwick