Detection of Loops in Java Bytecode - Distinguishing back edge types -
background:
before asking question, wish state have checked following links:
identify loops in java byte code
http://blog.jamesdbloom.com/javacodetobytecode_partone.html
i can detect loops in bytecode (class files) using dominator analysis algorithm-based approach of detecting edges on control-flow graphs (https://en.wikipedia.org/wiki/control_flow_graph).
my problem:
after detection of loops, can end having 2 loops (defined 2 distinct edges) sharing same loop head. can created following 2 cases have realized: (case 1) in source code, have or while loop continue statement, (case 2) in source code, have 2 loops - outer loop do-while , inner loop; , no instructions between these loops.
my question following: by looking @ bytecode, how can distinguish between these 2 cases?
my thoughts:
in do-while loop (that without continue statements), don't expect go-to statement goes loop head, in other words, creating edge.
for while or loop (that again without continue statements), appears there can go-to statement (i not sure if there must one). compiler generates (i using standard 1.7 compiler) go-to instruction outside of loop, not edge unlike mentioned in given links (this go-to statement creates control-flow head of loop, not jump end of loop).
so, guess is, (repeating, in case of 2 edges), if 1 of them edge created go-to statement, there 1 loop in source code , includes continue statement (case 1). otherwise, there 2 loops in source code (case 2).
thank you.
when 2 loops equivalent can take simplest one.
e.g. there no way tell difference between while (true)
, do { } while (true)
, for (;;)
if have do { something(); } while (false)
loop might not appear in byte code @ all.
Comments
Post a Comment