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