Java – Get a JVM method call

Get a JVM method call… here is a solution to the problem.

Get a JVM method call

How do I log all method calls and their parameters, executed by the JVM at runtime, perhaps with the possibility of changing method parameters, doing something before calling the method, without changing the JVM code itself?

I’m already done running

  1. Instrument ( http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html)
  2. DTrace and its code ( http://github.com/dtrace4linux/linux ).

But I’m a newbie and don’t know the specifics of the JVM, and my main question is – is it the right way to start with this code (Dtrace’s code)? Maybe you can give me an article to read?

And – can I do the same on ART or dalvik? (Not only debuggable applications, with the help of JDWP).

One more thing – JMVTI is so slow that it takes almost 300μs to invoke the handler.

Edit:

Link, I get:

https://code.google.com/p/droidbox/

http://mostly-about-java.blogspot.ru/2012/12/methodcallspy-building-own-method_3.html?m=1

https://github.com/JakeWharton/hugo

https://www.yourkit.com

Solution

Technically, you can use your own javaagent on the JVM Or you can use the AspectJ framework and it Load Time Weaver to simplify this process.

Check this article for some code examples and repositories: https://bitbucket.org/espinosa/methodcallspy0

Unfortunately, Dalvik/ART does not support javaagents, so this only works on the “real” JVM, but not on android.

Related Problems and Solutions