javac - How to easily create Java bytecode dependent regression tests? -
i have identified bug in application (which processes bytecode using soot) arises on specific bytecode instructions.
i want create test specific case. however, i'm not able reliably write test code, compile expected bytecode, trigger bug.
this attempt trigger bug:
public void updaterhsonifeq() { int x = 15; int y = aircraftcontrol.readsensor(0); // fixme != in bytecode instead of == if (x == y) { aircraftcontrol.readsensor(y); } else { aircraftcontrol.readsensor(x); } } the problem is, compiler changes branch logic inverting comparison , switching 2 branches. can see in bytecode below, != comparison instead of ==. however, bug i'm testing triggered ==.
public void updaterhsonifeq(); 0 bipush 15 2 istore_1 [x] 3 iconst_0 4 invokestatic aircraftcontrol.readsensor(int) : int [17] 7 istore_2 [y] 8 iload_1 [x] 9 iload_2 [y] 10 if_icmpne 21 <============================== should if_icmpeq 13 iload_2 [y] 14 invokestatic aircraftcontrol.readsensor(int) : int [17] 17 pop 18 goto 26 21 iload_1 [x] 22 invokestatic aircraftcontrol.readsensor(int) : int [17] 25 pop 26 return is there way write test cases need result in predictable bytecode easily? possible @ given there different java compilers, versions thereof etc?
if want specific bytecode instructions, obvious , reliable approach write directly in bytecode.
i've written open source assembler available here. simple cases, can jasmin, better documented. have disassembler, if need minor tweaks, can compile java class, disassemble, make tweak , reassemble.
Comments
Post a Comment