rohanpadhye/JQF

if-then or if-else is executed

xxwxxwen opened this issue · 2 comments

When running JQF, how can we know if-then branch or if-else branch statement is truly executed?

In JVM bytecode, a branch is just a conditional jump instruction similar to assembly (e.g. JMP to if is 0 otherwise continue). We can find out whether this branch was taken or not by examining BranchEvent.getArm().

It may not map exactly to the then or else branches in source code, because the Java compiler javac may in its discretion choose to compile either block as the near-block (immediately after the JMP instruction) and the other block as the far-block (which requires jumping to a label) in JVM bytecode. It depends on whichever is convenient based on decomposing the branch condition to a check of zero. For example, both if (x == 0) { .. } else { ... } and if (x != 0) { .. } else { ... } compile down to JMP to <label> if x is 0, where the first case the <label> is the true branch and in the second case the <label> is the false branch.

@rohanpadhye Thank you for your reply!