开发者

What is the most future-proof way to perform Java bytecode instrumentation?

开发者 https://www.devze.com 2023-02-06 16:19 出处:网络
I wish to perform Java bytecode instrumentation from JDK 1.5 onwards. Is the开发者_如何学编程re a way to do this that works across most JVMs and is supported in future versions of the JDK?I suggest yo

I wish to perform Java bytecode instrumentation from JDK 1.5 onwards. Is the开发者_如何学编程re a way to do this that works across most JVMs and is supported in future versions of the JDK?


I suggest you use a library which abstracts away the reading/writing of raw byte code. Like ASM. This way any future changes may be fixed by updating the library. Also many of these have gone through many version changes already and have a structure which is farily version proof.

Having said that, there are very few byte code changes between JVM versions. Given the chance to change the byte code or to put in work around, the later appears to always be used. e.g. Java has supported inner classes accessing private member of outer classes for many years, however the JVM doesn't support this directly (instead a work around is used by the compiler)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号