Stand-alone Bytecode Verifier

后端 未结 3 832
醉梦人生
醉梦人生 2020-12-16 04:17

In my bytecode instrumentation project, I stumble frequently on VerifyErrors. However, the default java Verifier gives little information on which instruction resulted in th

相关标签:
3条回答
  • 2020-12-16 04:48

    As with any project involving JVM bytecode, I would first check to see whether the BCEL has anything that might be useful for you. Also, perhaps FindBugs may help - though I'm not sure whether it assumes verifiable bytecode to start with or not.

    0 讨论(0)
  • 2020-12-16 04:49

    ASM CheckClassAdaptor.verify() gives great feedback: http://asm.ow2.org/

    0 讨论(0)
  • 2020-12-16 04:59

    I was also looking for something that would report potential verify errors, but especially IncompatibleClassChangeErrors. I wrote a little test project with one API class and another client class calling API methods, plus a main class to run a verifier; then changed the API, recompiling it but not the client, and checked to see what could be caught. Used -target 7 though no special JDK 7 features for now.

    First and most obviously, Class.forName can find certain errors in the client class's signature, but it does not seem to check method bodies for calls to nonexistent API methods and the like, even if you call getDeclaredMethods; the errors are reported by the VM only when the problematic line of code is actually run.

    JustIce in BCEL 5.2 seems to be easiest;

    org.apache.bcel.verifier.Verifier.main(new String[] {clazz});
    

    does the job:

    Pass 3a, method number 1 ['public void m()']:
    VERIFIED_REJECTED
    Instruction invokestatic[184](3) 4 constraint violated:
      Referenced method 'x' with expected signature '()V' not found in class 'API'.
      ....
    

    I tried ASM 4.0, but

    org.objectweb.asm.util.CheckClassAdapter.main(new String[] {clazz});
    

    does not work; perhaps it checks the format of methods, but not linkage. Inlining main and passing checkDataFlow=true does not help.

    Searching, I also found https://kenai.com/hg/maxine~maxine/file/8429d3ebc036/com.oracle.max.vm/test/test/com/sun/max/vm/verifier/CommandLineVerifier.java but I could not find any way to make this work; the accompanying unit test throws a ClassNotFoundException when run.

    0 讨论(0)
提交回复
热议问题