Changed allocation depth to default to minimum possible so graphs are
[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 p;
7     Foo h;
8
9     public Parameter() { a = 0; b = 0; f = null; g = null; }
10
11     public void bar() { foo(); }
12     public void foo() { bar(); }
13 }
14
15 public class Penguin {
16     int x, y;
17     Foo h;    
18
19     public Penguin() { x = 0; y = 0; }
20
21     public void bar() { x = 1; }
22 }
23
24 public class Voo {
25     flag f; int x; Baw b; Baw bb;
26
27     public Voo() {}
28 }
29
30 public class Baw {
31     int y;
32     Foo f;
33
34     public Baw() {}
35
36     public void doTheBaw( Voo v ) { v = new Voo(); }
37 }
38 */
39
40 public class Foo {
41     flag f;
42
43     public Foo() {}
44
45     public Foo x;
46     public Foo y;
47
48     /*
49     public void ruinSomeFoos( Foo a, Foo b ) {
50         a.x = b.x;
51     }
52
53     static public void aStaticMethod( Foo p0, Foo p1 ) {
54         Foo f0 = new Foo();
55         Foo f1 = new Foo();
56         Foo f2 = new Foo();
57
58         f0.x = f1;
59         p0.x = f0;
60         p1.x = f1;
61         p1.x = f2;
62     }
63     */
64 }
65
66
67 // this empty task should still create a non-empty
68 // ownership graph showing parameter allocation
69 // look for the parameter s as a label referencing
70 // a heap region that is multi-object, flagged, not summary
71 task Startup( StartupObject s{ initialstate } ) {
72     taskexit( s{ !initialstate } );
73 }
74
75 /*
76 task NewObjectA( Foo a{ f }, Foo b{ f } ) {
77
78     Foo c = new Foo();
79     Foo d = new Foo();
80
81     c.x = d;
82     a.x = c;
83
84     taskexit( a{ !f }, b{ !f } );
85 }
86
87 task NewObjectB( Foo a{ f }, Foo b{ f } ) {
88
89     Foo c = new Foo();
90     Foo d = new Foo();
91
92     a.x = c;
93     c.x = d;
94
95     taskexit( a{ !f }, b{ !f } );
96 }
97 */
98
99 /*
100 task NewObjectC( Foo a{ f }, Foo b{ f } ) {
101
102     Foo z = new Foo();
103     a.x = z;
104     a.y = z;
105
106     Foo c;
107
108     while( false ) {
109         c     = new Foo();
110         Foo f = new Foo();
111         c.x   = f;
112         c.y   = f;
113     }
114
115     taskexit( a{ !f }, b{ !f } );
116 }
117 */
118
119
120 task forMethod( Foo p0{ f } ) {
121
122     Foo a0;
123     Foo a1;
124
125     while( false ) {    
126         a1 = a0;            
127         if( false ) {
128             a0 = new Foo();
129         }
130     }
131
132     Foo z = new Foo();
133     a1.x = z;
134     z.x  = a1;
135
136
137     taskexit( p0{ !f } );
138 }
139
140
141
142 /*
143 // this task allocates a new object, so there should
144 // be a heap region for the parameter, and several
145 // heap regions for the allocation site, but the label
146 // merely points to the newest region
147 task NewObjectInMethod( Voo v{ f } ) {
148     Voo w = new Voo();
149     Baw b = new Baw();
150     b.doTheBaw( w );
151
152     taskexit( v{ !f } );
153 }
154
155
156 task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) {
157     v.b = v.bb;
158
159     taskexit( v{ !f }, w{ !f } );
160 }
161
162
163 task BackToItself( Parameter p0{ w } ) {
164
165     Penguin p = new Penguin();
166     p0.p = p;
167     p.h = p0.h;
168
169     while( false ) {
170         Parameter p1   = new Parameter();
171                   p1.h = new Foo();
172         Penguin   q    = new Penguin();
173         p1.p = q;
174         q.h  = p1.h;
175     }
176
177     taskexit( p0{ !w } );
178 }
179
180
181 task SummaryNodeTokens( Foo p0{ f } ) {
182
183     while( false ) {
184         Foo a = new Foo();
185         a.x   = new Foo();
186         a.x.x = new Foo();
187     }
188     
189     Foo b;
190     while( false ) {
191         Foo c = new Foo();
192         c.x = b;
193         b = c;
194     }
195
196     taskexit( p0{ !f } );
197 }
198
199
200 task strongUpdates( Foo p0{ f } ) {
201
202     Foo b = new Foo();
203
204     Foo a = new Foo();
205     if( false ) {
206         a.x = new Foo();
207         a.y = new Foo();
208     } else if( false ) {
209         a.x = new Foo();
210         a.y = new Foo();
211     }
212
213     // this should effect a strong update
214     a.x = b;
215
216
217     if( false ) {
218         p0.x = new Foo();
219         p0.y = new Foo();
220     } else if( false ) {
221         p0.x = new Foo();
222         p0.y = new Foo();
223     }
224
225     // p0 points to a multiple-object heap region
226     // so this should not make a strong update
227     p0.x = b;
228     
229     taskexit( p0{ !f } );
230 }
231
232
233 task methodTest( Foo p0{ f } ) {
234
235     Foo up0 = new Foo();
236     Foo up1 = new Foo();
237     Foo up2 = new Foo();
238
239     Foo a0;
240     Foo a1;
241
242     if( false ) {
243         a0    = new Foo();
244         up0.x = a0;     
245         a0.x  = new Foo();
246         //Foo temp = new Foo();
247     }
248
249     if( false ) {
250         a0    = new Foo();
251         a0.x  = new Foo();
252         a1    = a0;
253         up1.x = a0;
254     }
255
256     if( false ) {
257         a1    = new Foo();
258         up2.x = a1;
259     }
260
261     // Foo.test( a0, a1 );
262
263     taskexit( p0{ !f } );
264 }
265 */