Back to Project Page Home

Escape Analysis Demonstration

We apply ITA control flow escape analysis combined with intraprocedural escape analysis to the following code, using Class1.method1 as the entry point.

Code

class Class1 {
    Class4 field1;
    
    
    Class1() {}

    void method1() {
        try {
            method2(new Class1());
        } catch(Class2 exception) {
            exception.method1();
            Class4 local = method7(exception);
            if(local != null) {
                local.method1();
            }
            field1 = new Class4();
            if(exception instanceof Class3) {
                ((Class3) exception).method3(field1);
                
            }
            throw exception;
        }
    }
    
    static void method2(Class1 arg) {
        arg.method3();
    }

    void method3()  {
        method4(null);
    }

    void method4(Class3 arg) {
        method5(arg);
    }

    Class3 method5(Class3 arg) {
        Class3 local = method6();
        Class3.method2(this);
        throw local;
    }

    Class3 method6() {
        Class3 local = new Class3();
        local.field4.method1();
        return local;
    }


    Class4 method7(Class2 arg) {
        return null;
    }
}


class Class2 extends java.lang.RuntimeException {
    boolean field2;
    Class2 field3;

    Class2() {}

    Class4 method1() {
        field2 = true;
        return null;
    }
  
}

class Class3 extends Class2 {
    Class4 field4;
    static Class4 field5;
    
    Class3() {
        field4 = new Class4();
    }

    /**
     * overrides method7 in parent class
     */
    Class4 method1() {
        return null;
    }

    static void method2(Class1 arg) {
        field5 = null;
    }

    final void method3(Class4 arg) {
        field5 = arg;
    }
}


class Class4 {
    char[] field5;

    Class4() {}

    void method1() {}
}