start of new file
[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     flag f;
40
41     public Foo() {}
42
43     public Foo x;
44
45     public void ruinSomeFoos( Foo a, Foo b ) {
46         a.x = b.x;
47     }
48
49     /*
50     static public void test( Foo p0, Foo p1 ) {
51         Foo f0 = new Foo();
52         Foo f1 = new Foo();
53         Foo f2 = new Foo();
54
55         f0.x = f1;
56         p0.x = f0;
57         p1.x = f1;
58         p1.x = f2;
59     }
60     */
61 }
62
63
64 // this empty task should still create a non-empty
65 // ownership graph showing parameter allocation
66 // look for the parameter s as a label referencing
67 // a heap region that is multi-object, flagged, not summary
68 task Startup( StartupObject s{ initialstate } ) {
69     
70     /*
71     while( false ) {
72         Foo a = new Foo();
73         a.x   = new Foo();
74         a.x.x = new Foo();
75
76         //Foo z = a.x;
77         //z.x = new Foo();
78     }
79     
80
81
82     Foo d = new Foo();
83     Foo e = new Foo();
84     Foo f = new Foo();
85     Foo g = new Foo();
86
87     d.x = e;
88     e.x = f;
89     f.x = g;
90
91
92     Foo h = new Foo();
93     Foo i = new Foo();
94     Foo j = new Foo();
95     Foo k = new Foo();
96
97     j.x = k;
98     i.x = j;
99     h.x = i;
100
101
102     
103
104     // to look like Foo a above
105     //d.x.x = f;
106
107
108     Foo b;
109     while( false ) {
110         Foo c = new Foo();
111         c.x = b;
112         b = c;
113     }
114     */
115
116     taskexit( s{ !initialstate } );
117 }
118
119
120 task basics( Foo p0{ f } ) {
121
122     //Foo a = new Foo();
123     //Foo b = new Foo();
124
125     Foo a = new Foo();
126     a.x   = new Foo();
127     a.x.x = new Foo();
128
129     //p0.x = a;
130     //a.x  = b;
131
132     taskexit( p0{ !f } );
133 }
134
135
136 task methodTest( Foo p0{ f } ) {
137
138     Foo up0 = new Foo();
139     Foo up1 = new Foo();
140     Foo up2 = new Foo();
141
142     Foo a0;
143     Foo a1;
144
145     if( false ) {
146         a0    = new Foo();
147         up0.x = a0;     
148         a0.x  = new Foo();
149         //Foo temp = new Foo();
150     }
151
152     if( false ) {
153         a0    = new Foo();
154         a0.x  = new Foo();
155         a1    = a0;
156         up1.x = a0;
157     }
158
159     if( false ) {
160         a1    = new Foo();
161         up2.x = a1;
162     }
163
164     // Foo.test( a0, a1 );
165
166     taskexit( p0{ !f } );
167 }
168
169
170
171
172 /*
173 task NewObject( Foo a{ f }, Foo b{ f } ) {
174
175     Foo c = new Foo();
176
177     a.x = c;
178
179     taskexit( a{ !f }, b{ !f } );
180 }
181 */
182
183 /*
184 task NewObjectA( Foo a{ f }, Foo b{ f } ) {
185
186     Foo c = new Foo();
187     Foo d = new Foo();
188
189     c.x = d;
190     a.x = c;
191
192     taskexit( a{ !f }, b{ !f } );
193 }
194
195 task NewObjectB( Foo a{ f }, Foo b{ f } ) {
196
197     Foo c = new Foo();
198     Foo d = new Foo();
199
200     a.x = c;
201     c.x = d;
202
203     taskexit( a{ !f }, b{ !f } );
204 }
205 */
206
207 /*
208 task NewObject2( Foo a{ f }, Foo b{ f } ) {
209
210     Foo c;
211
212     while( false ) {
213         c   = new Foo();
214         c.x = new Foo();
215     }
216
217     taskexit( a{ !f }, b{ !f } );
218 }
219 */
220
221
222 /*
223 // this task allocates a new object, so there should
224 // be a heap region for the parameter, and several
225 // heap regions for the allocation site, but the label
226 // merely points to the newest region
227 task NewObject( Voo v{ f } ) {
228     Voo w = new Voo();
229     Baw b = new Baw();
230     b.doTheBaw( w );
231
232     taskexit( v{ !f } );
233 }
234
235
236 // this task 
237 task Branch( Voo v{ f } ) {
238     Voo w = new Voo();
239     Baw j = new Baw();
240     Baw k = new Baw();
241
242     if( v.x == 0 ) {
243         w.b = j;
244     } else {
245         w.b = k;
246     }
247
248     taskexit( v{ !f } );
249 }
250
251
252 task NoAliasNewInLoop( Voo v{ f } ) {
253
254     for( int i = 0; i < 10; ++i ) {
255         Voo w = new Voo();
256         w.b   = new Baw();
257         w.b.f = new Foo();
258     }
259
260     taskexit( v{ !f } );
261 }
262
263
264 task NoAliasNewInLoopAnotherWay( Voo v{ f } ) {
265
266     for( int i = 0; i < 10; ++i ) {
267         Voo w = new Voo();
268         Baw b = new Baw();
269         Foo f = new Foo();
270
271         w.b = b;
272         b.f = f;
273     }
274
275     taskexit( v{ !f } );
276 }
277
278
279 task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) {
280     v.b = v.bb;
281
282     taskexit( v{ !f }, w{ !f } );
283 }
284 */