Sanyam Goel
Sanyam Goel

Reputation: 2180

Shortcomings of instrumenting compiled code before loading

Can anybody put lime light on what possible problems might emerge if an application created instruments class files before loading them using custom loader. I have created a java application that does the same thing.

I read class files in the form of byte arrays Then I instrument using asm library and then Load them through custom class loader.

Is this procedure prone to failure if yes why??

Upvotes: 1

Views: 77

Answers (1)

Jörg W Mittag
Jörg W Mittag

Reputation: 369633

The main problem with this is that it ties your application to the JVM. The Java community works very hard on keeping the JLS and the JVMS separate, so that Java could theoretically be used without the JVM, and there are two fairly widespread platforms where Java is actually used without the JVM: Android and GWT. If you don't expect to ever need to run on a platform that doesn't understand Java byte code, then you are fine.

Note that static byte code manipulation stuff is perfectly okay. You can cross compile JVM byte code to Dalvik byte code after manipulating it. But if you wanted to do that at runtime, you would have to include the JVM-to-Dalvik cross compiler in your application … and it still wouldn't work because the Dalvik VM simply doesn't support dynamic byte code loading the same way the JVM does.

Upvotes: 1

Related Questions