0

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:

  • Is it possible to add such a hook?
  • If possible, what are the correct tools/interfaces that I should use?
  • If there is no existing tools that do this, can I achieve this by modifying the JVM codebase?

Thanks.

Bojian Zheng
  • 2,167
  • 3
  • 13
  • 17
  • Can you be more specific on “heap access”? JVMTI supports watch points for fields, but you can’t really mean to intercept *every* access to *every* field? – Holger Sep 24 '18 at 09:02
  • @Holger But this is what I am hoping to do because I cannot bias towards certain objects and/or certain fields. – Bojian Zheng Sep 24 '18 at 15:17

1 Answers1

2

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

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130