IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Irreducible loop

    hev发表于 2022-04-29 15:50:51
    love 0

    Control-flow graph

    (a) an if-then-else
    (b) a while loop
    (c) a natural loop with two exits, e.g. while with an if…break in the middle; non-structured but reducible
    (d) an irreducible CFG: a loop with two entry points, e.g. goto into a while or for loop

    Java case

    IrreducibleLoop.java

    public class IrreducibleLoop {
        public static void test(int loop) {
        }
    }

    IrreducibleLoop.jasm

    super public class IrreducibleLoop
        version 63:0
    {
      public Method "<init>":"()V" 
        stack 1 locals 1
      {
            aload_0;
            invokespecial    Method java/lang/Object."<init>":"()V";
            return;
      }
      public static Method test:"(I)V" 
        stack 2 locals 2
      {
        L0: iconst_0;
            istore_1;
            iload_0;
            ifne    L2;
        L1: stack_frame_type append;
            locals_map int;
            iload_1;
            iload_0;
            if_icmpge    L3;
        L2: stack_frame_type same;
            goto    L1;
        L3: stack_frame_type chop1;
            return;
      }
    
    } // end Class IrreducibleLoop

    Main.java

    public class Main {
        public static void main(String[] args) {
            for (int i = 0; i < 12000; i++) {
                IrreducibleLoop.test(0);
            }
        }
    }

    Run

    javac Main.java
    java -jar asmtools-core-7.0.b10-ea.jar jasm IrreducibleLoop.jasm
    java -XX:TieredStopAtLevel=1 -Xcomp -XX:CompileCommand=compileonly,IrreducibleLoop::* Main

    Refer

    https://en.wikipedia.org/wiki/Control-flow_graph



沪ICP备19023445号-2号
友情链接