Hi Andreas,
There are a couple of ways off the top of my head. Their viability depends on the original purpose of getting the list of executed methods.
HotSpot keeps the invocation count (at least in the interpreter) for all Java methods. It may not be precise, because it'll decay periodically, or it may be set to certain values for triggering standard compilation, etc. But if you only care about zero and non-zero, this counter would be sufficient.
The problem is: how to get the list of invoked methods?
There's no flag within the VM that I'm aware of that would print the list of invoked methods, unfortunately.
It can attach to your target Java process, and extract all invoked methods.
Caveat:
1. If you're on JDK6, you may need to include these two VM flags in your target Java application:
-XX:-UseFastEmptyMethods -XX:-UseFastAccessorMethods
Otherwise empty methods and accessor methods will not show up in the list, because the "fast" version doesn't increment the invocation counter for these methods.
In JDK7 these two flags default to false, so you don't have to bother setting them to false explicitly.
2. If any of your classes are unloaded when you use this tool, then their methods won't show up in the output.
3. If you'd like the list to be printed before process exit, then an easy way to do this is to set up a shutdown hook with a Java agent, and make this hook run the tool above (in a new process). You may miss some methods that are only run in the shutdown hook, but I guess that's an acceptable tradeoff.
- Kris
On Wed, May 16, 2012 at 6:11 PM, David Holmes
<david.holmes-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> wrote:
Andreas,
I've cc'd this to hotspot-dev which is the right place to ask.
Please drop the discuss list from further replies.
David
On 16/05/2012 6:56 PM, Andreas Sewe wrote:
Hi all,
I hope this is the right mailing list to ask such questions (if not,
please point me to the right one), as I couldn't find an obvious
analogue to lists like jikesrvm-researchers.
Is the a way (preferably using "diagnostic" rather than "develop"
options) to obtain a list of all methods executed at least once?
Currently I am considering "-XX:-UseInterpreter -XX:+LogCompilation",
but this seems to be an awfully indirect way to achieve my goal -- and
it may not even give correct results if the only call of m() is inlined
during compilation.
Any help is greatly appreciated.
Best wishes,
Andreas