Bojian Zheng
Bojian Zheng

Reputation: 2797

JVM: Add a hook to Heap Access

I am hoping to do a profiling analysis on my Java project. To get the results I want to add a "hook" to the JVM so that every time a heap access occurs, the "hook" is called and does some tracing. I have been looking into JVMTI but this does not seem to give me what I expect.

I have several questions:

Thanks.

Upvotes: 0

Views: 132

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533492

I want to add a "hook" to the JVM so that every time a heap access occurs

You can't really do this in the Java as the hook itself would access the heap and cal itself. Even if you work around this, it would make the program impossibly slow.

What you can do is use the debugging interface to breakpoint after each instruction, inspect the instruction and see if it accessed the heap or not. This would be perhaps 10,000x slower than normal.

An alternative is to translate the bytecode using Instrumentation to trace each memory access. This might be only a few hundred times slower.

To do what you propose efficiently, you could use https://software.intel.com/en-us/articles/intel-performance-counter-monitor which used by tools such as perf on Linux. This requires in-depth knowledge of the processor you are using

Upvotes: 2

Related Questions