简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM