Example 0 - [Java] [Ideal] [EA] [CG]
This is probably the simplest example possible. A single object is allocated inside the method and an arithmetic operation is performed on the fields to return a value.
                        
public static int method0(boolean cond, int x, int y) {
    MyPair o = new MyPair(x, y);

    return o.p1 + o.p2;
}
                        
                        
Example 1 - [Java] [Ideal] [EA] [CG]
This is another simple example, however, there are two allocation points for the object and because of that we reach one of the Scalar Replacement constraints of C2. The EA doesn't have any problem identifying that the objects don't escape.
                        
public static int method0(boolean cond, int x, int y) {
    MyPair o = new MyPair(/*p1=*/0,/*p2=*/0);

    if (cond) {
        o = new MyPair(x, y);
    }

    return o.getP1();
}
                        
                        
Example 2 - [Java] [Ideal] [EA] [CG]
The goal of this example is to illustrate once more a method with parameters and that the "return" node will reference it.
                        
public static int method0(boolean cond, int x, int y) {
    MyPair o = new MyPair(/*p1=*/0,/*p2=*/0);

    if (cond) {
        EscapeAnalysis.global_escape = o;
    }

    return o.getP1();
}
                        
                        
Example 0 - [Java] [Ideal] [EA] [CG]
description
                            
                                java