What is the most future-proof way to perform Java bytecode instrumentation?
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)
精彩评论