java - Operand stack underrun -


i have program generate bytecode java file. , simple test() method

public void test() {     boolean = false;     if (a || true)     {          boolean b = false;     } } 

, generate follow piece of bytecode

public void test()   code:    7:   iconst_0    8:   istore_1    9:   iload_1    10:  ifne    13    13:  iconst_0    14:  istore_2    15:  return 

when execute class, keep getting operand stack underrun in test(), couldn't figure out why because generated bytecode looks (to me)

could me debug this?

(here's did trace stack

public void test()   code:    7:   iconst_0  (1 on stack)    8:   istore_1  (0 on stack)    9:   iload_1  (1 on stack)    10:  ifne    13  (0 on stack)    13:  iconst_0  (1 on stack)    14:  istore_2  (0 on stack)    15:  return 

so yeah, stack looks fine me!)

edit: here's generated bytecode javac

public void test();   code:    0:   iconst_0    1:   istore_1    2:   iload_1    3:   ifne    6    6:   iconst_0    7:   istore_2    8:   return 

when try this

public class maindump implements opcodes {      public static byte[] dump() throws exception {          classwriter cw = new classwriter(0);         fieldvisitor fv;         methodvisitor mv;         annotationvisitor av0;          cw.visit(v1_7, acc_public + acc_super, "main", null, "java/lang/object", null);          cw.visitsource("main.java", null);          {             mv = cw.visitmethod(acc_public, "<init>", "()v", null, null);             mv.visitcode();             label l0 = new label();             mv.visitlabel(l0);             mv.visitlinenumber(1, l0);             mv.visitvarinsn(aload, 0);             mv.visitmethodinsn(invokespecial, "java/lang/object", "<init>", "()v");             mv.visitinsn(return);             label l1 = new label();             mv.visitlabel(l1);             mv.visitlocalvariable("this", "lmain;", null, l0, l1, 0);             mv.visitmaxs(1, 1);             mv.visitend();         }         {             mv = cw.visitmethod(acc_public, "test", "()v", null, null);             mv.visitcode();             mv.visitinsn(iconst_0);             mv.visitvarinsn(istore, 1);             mv.visitvarinsn(iload, 1);             label l2 = new label();             mv.visitjumpinsn(ifeq, l2);             mv.visitinsn(iconst_0);             mv.visitvarinsn(istore, 2);             mv.visitlabel(l2);             mv.visitframe(opcodes.f_append, 1, new object[]{opcodes.integer}, 0, null);             mv.visitinsn(return);             mv.visitmaxs(1, 3);             mv.visitend();         }         cw.visitend();          return cw.tobytearray();     }      public static void main(string... ignored) throws exception {         method defineclass = classloader.class.getdeclaredmethod("defineclass", byte[].class, int.class, int.class);         defineclass.setaccessible(true);          byte[] dump = dump();         defineclass.invoke(thread.currentthread().getcontextclassloader(), dump, 0, dump.length);         new main().test();     } } 

this works, if drop stack frame adjustment, error

exception in thread "main" java.lang.verifyerror: expecting stackmap frame @ branch target 8 exception details:   location:     main.test()v @3: ifeq   reason:     expected stackmap frame @ location.   bytecode:     0000000: 033c 1b99 0005 033d b1   

in short, java 7, stack operations not enough pass validity.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -