Obtaining methods executed at least once?
Andreas Sewe
sewe at st.informatik.tu-darmstadt.de
Wed May 16 07:39:10 PDT 2012
Hi,
> 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.
Yes, I only care about that.
The question is whether I can force interpretation for all methods (so
that the counts are incremented) by doing -XX:-UseCompiler?
> 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.
>
> You could try the Serviceability Agent. See this example that I just
> made: https://gist.github.com/2710667#file_print_invoked_methods.java
>
> It can attach to your target Java process, and extract all invoked methods.
Neat. :-)
> Caveat:
>
> 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.
Yes, that's fine. Thanks.
Best wishes,
Andreas
More information about the hotspot-dev
mailing list