当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Pick up JVM method invocation

问题描述:

How can i log all method calls with it arguments, performed by JVM at runtime, and maybe there is a possiblity to change method arguments, do some stuff before method is called, without changing JVM code itself?

I already had run through

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

but i am a newbie in how JVM is constructed in it nitty-gritty details, and my main question - is this a right way to start with this code(the code of Dtrace)? Maybe you can give me an article to read?

And also - can i do the same things on ART or dalvik? (not only debuggable applications, with the help of JDWP).

And one more thing - JMVTI is too slow, it takes nearly 300µs on calling handler.

Edited:

links, i got:

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

网友答案:

Technically it is possible on JVM using own javaagent. Alternatively you can use AspectJ framework and its Load Time Weaver to simplify this process.

Check this article for sample and repository for some code: https://bitbucket.org/espinosa/methodcallspy0

Unfortunately Dalvik/ART doesn't support javaagent so this will work only on 'real' JVM, but not on android.

分享给朋友:
您可能感兴趣的文章:
随机阅读: