Added reachability to simple edge cases.
[IRC.git] / Robust / src / Tests / OwnershipAnalysisTest / test01 / test01.java
1
2 public class Parameter {
3     flag w;
4     int a, b;
5     Parameter f, g;
6     Penguin penguin;
7
8     public Parameter() { a = 0; b = 0; f = null; g = null; }
9
10     public void bar() { foo(); }
11     public void foo() { bar(); }
12 }
13
14 public class Penguin {
15     int x, y;
16
17     public Penguin() { x = 0; y = 0; }
18
19     public void bar() { x = 1; }
20 }
21
22 public class Voo {
23     flag f; int x; Baw b; Baw bb;
24
25     public Voo() {}
26 }
27
28 public class Baw {
29     int y;
30     Foo f;
31
32     public Baw() {}
33
34     public void doTheBaw( Voo v ) { v = new Voo(); }
35 }
36
37
38 public class Foo {
39     public Foo() {}
40
41     public Foo x;
42
43     public void ruinSomeFoos( Foo a, Foo b ) {
44         a.x = b.x;
45     }
46 }
47
48
49 // this empty task should still create a non-empty
50 // ownership graph showing parameter allocation
51 // look for the parameter s as a label referencing
52 // a heap region that is multi-object, flagged, not summary
53 task Startup( StartupObject s{ initialstate } ) {
54
55     while( false ) {
56         Foo a = new Foo();
57         a.x   = new Foo();
58         a.x.x = new Foo();
59     }
60
61     taskexit( s{ !initialstate } );
62 }
63
64
65 // this task allocates a new object, so there should
66 // be a heap region for the parameter, and several
67 // heap regions for the allocation site, but the label
68 // merely points to the newest region
69 task NewObject( Voo v{ f } ) {
70     Voo w = new Voo();
71     Baw b = new Baw();
72     b.doTheBaw( w );
73
74     taskexit( v{ !f } );
75 }
76
77
78 // this task 
79 task Branch( Voo v{ f } ) {
80     Voo w = new Voo();
81     Baw j = new Baw();
82     Baw k = new Baw();
83
84     if( v.x == 0 ) {
85         w.b = j;
86     } else {
87         w.b = k;
88     }
89
90     taskexit( v{ !f } );
91 }
92
93
94 task NoAliasNewInLoop( Voo v{ f } ) {
95
96     for( int i = 0; i < 10; ++i ) {
97         Voo w = new Voo();
98         w.b   = new Baw();
99         w.b.f = new Foo();
100     }
101
102     taskexit( v{ !f } );
103 }
104
105
106 task NoAliasNewInLoopAnotherWay( Voo v{ f } ) {
107
108     for( int i = 0; i < 10; ++i ) {
109         Voo w = new Voo();
110         Baw b = new Baw();
111         Foo f = new Foo();
112
113         w.b = b;
114         b.f = f;
115     }
116
117     taskexit( v{ !f } );
118 }
119
120
121 task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) {
122     v.b = v.bb;
123
124     taskexit( v{ !f }, w{ !f } );
125 }