stable, still partial method calls
[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     public Foo z;
48
49     /*
50     public void ruinSomeFoos( Foo a, Foo b ) {
51         a.x = b.x;
52     }
53
54     static public void aStaticMethod( Foo p0, Foo p1 ) {
55         Foo f0 = new Foo();
56         Foo f1 = new Foo();
57         Foo f2 = new Foo();
58
59         f0.x = f1;
60         p0.x = f0;
61         p1.x = f1;
62         p1.x = f2;
63     }
64     */
65
66   static public void m1_( Foo p0 ) {
67     Foo g0 = new Foo();
68     Foo g1 = new Foo();
69
70     g0.x = p0;
71     p0.x = g1;
72   }
73
74   static public void m2_( Foo p0 ) {
75     Foo g0 = new Foo();
76
77     g0.x = p0;
78     g0.y = p0;
79   }
80
81   static public void m3_( Foo p0 ) {
82     Foo g0 = new Foo();
83
84     p0.x = g0;
85     p0.y = g0;
86   }
87
88   static public void m4_( Foo p0 ) {
89     p0.x = p0;
90   }
91
92   static public void m5_( Foo p0 ) {
93     Foo g0 = new Foo();
94     p0.x = g0;
95     g0.x = p0;
96   }
97
98   static public void m6_( Foo p0, Foo p1 ) {
99     Foo g0 = new Foo();
100     Foo g1 = new Foo();
101     Foo g2 = new Foo();
102     Foo g3 = new Foo();
103
104     g0.x = p0;
105     p0.x = g1;
106
107     g2.x = p1;
108     p1.x = g3;
109
110     p0.y = p1;
111   }
112
113   static public void m7_( Foo p0, Foo p1 ) {
114     Foo g0 = new Foo();
115     Foo g1 = new Foo();
116     Foo g2 = new Foo();
117     Foo g3 = new Foo();
118
119     g0.x = p0;
120     p0.x = g1;
121
122     g2.x = p1;
123     p1.x = g3;
124
125     p0.y = p1;
126     p0.z = p1;
127   }
128
129   static public void m8_( Foo p0, Foo p1 ) {
130     Foo g0 = new Foo();
131     Foo g1 = new Foo();
132     Foo g2 = new Foo();
133     Foo g3 = new Foo();
134
135     g0.x = p0;
136     p0.x = g1;
137
138     g2.x = p1;
139     p1.x = g3;
140
141     p0.y = p1;
142     p1.y = p0;
143   }
144 }
145
146
147 // this empty task should still create a non-empty
148 // ownership graph showing parameter allocation
149 // look for the parameter s as a label referencing
150 // a heap region that is multi-object, flagged, not summary
151 task Startup( StartupObject s{ initialstate } ) {
152     taskexit( s{ !initialstate } );
153 }
154
155 /*
156 task NewObjectA( Foo a{ f }, Foo b{ f } ) {
157
158     Foo c = new Foo();
159     Foo d = new Foo();
160
161     c.x = d;
162     a.x = c;
163
164     taskexit( a{ !f }, b{ !f } );
165 }
166
167 task NewObjectB( Foo a{ f }, Foo b{ f } ) {
168
169     Foo c = new Foo();
170     Foo d = new Foo();
171
172     a.x = c;
173     c.x = d;
174
175     taskexit( a{ !f }, b{ !f } );
176 }
177 */
178
179 /*
180 task NewObjectC( Foo a{ f }, Foo b{ f } ) {
181
182     Foo z = new Foo();
183     a.x = z;
184     a.y = z;
185
186     Foo c;
187
188     while( false ) {
189         c     = new Foo();
190         Foo f = new Foo();
191         c.x   = f;
192         c.y   = f;
193     }
194
195     taskexit( a{ !f }, b{ !f } );
196 }
197 */
198
199 /*
200 task forMethod( Foo p0{ f } ) {
201
202     Foo a0;
203     Foo a1;
204
205     while( false ) {    
206         a1 = a0;            
207         if( false ) {
208             a0 = new Foo();
209         }
210     }
211
212     Foo z = new Foo();
213     a1.x = z;
214     z.x  = a1;
215
216
217     taskexit( p0{ !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 NewObjectInMethod( 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 task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) {
237     v.b = v.bb;
238
239     taskexit( v{ !f }, w{ !f } );
240 }
241
242
243 task BackToItself( Parameter p0{ w } ) {
244
245     Penguin p = new Penguin();
246     p0.p = p;
247     p.h = p0.h;
248
249     while( false ) {
250         Parameter p1   = new Parameter();
251                   p1.h = new Foo();
252         Penguin   q    = new Penguin();
253         p1.p = q;
254         q.h  = p1.h;
255     }
256
257     taskexit( p0{ !w } );
258 }
259
260
261 task SummaryNodeTokens( Foo p0{ f } ) {
262
263     while( false ) {
264         Foo a = new Foo();
265         a.x   = new Foo();
266         a.x.x = new Foo();
267     }
268     
269     Foo b;
270     while( false ) {
271         Foo c = new Foo();
272         c.x = b;
273         b = c;
274     }
275
276     taskexit( p0{ !f } );
277 }
278
279
280 task strongUpdates( Foo p0{ f } ) {
281
282     Foo b = new Foo();
283
284     Foo a = new Foo();
285     if( false ) {
286         a.x = new Foo();
287         a.y = new Foo();
288     } else if( false ) {
289         a.x = new Foo();
290         a.y = new Foo();
291     }
292
293     // this should effect a strong update
294     a.x = b;
295
296
297     if( false ) {
298         p0.x = new Foo();
299         p0.y = new Foo();
300     } else if( false ) {
301         p0.x = new Foo();
302         p0.y = new Foo();
303     }
304
305     // p0 points to a multiple-object heap region
306     // so this should not make a strong update
307     p0.x = b;
308     
309     taskexit( p0{ !f } );
310 }
311
312
313 task methodTest( Foo p0{ f } ) {
314
315     Foo up0 = new Foo();
316     Foo up1 = new Foo();
317     Foo up2 = new Foo();
318
319     Foo a0;
320     Foo a1;
321
322     if( false ) {
323         a0    = new Foo();
324         up0.x = a0;     
325         a0.x  = new Foo();
326         //Foo temp = new Foo();
327     }
328
329     if( false ) {
330         a0    = new Foo();
331         a0.x  = new Foo();
332         a1    = a0;
333         up1.x = a0;
334     }
335
336     if( false ) {
337         a1    = new Foo();
338         up2.x = a1;
339     }
340
341     // Foo.test( a0, a1 );
342
343     taskexit( p0{ !f } );
344 }
345 */
346
347
348 task methodTest01_( Foo p0{ f }, Foo p1{ f } ) {
349
350   Foo a0before = new Foo();
351   if( false ) {
352     a0before.x = new Foo();
353   } else {
354     a0before.x = new Foo();
355   }
356
357   Foo a0after = new Foo();
358   if( false ) {
359     a0after.x = new Foo();
360   } else {
361     a0after.x = new Foo();
362   }
363
364   Foo.m1_( a0after );
365
366
367   taskexit( p0{ !f }, p1{ !f } );
368 }
369
370
371 task methodTest02_( Foo p0{ f }, Foo p1{ f } ) {
372
373   Foo a0before = new Foo();
374   if( false ) {
375     a0before.x = new Foo();
376   } else {
377     a0before.x = new Foo();
378   }
379
380   Foo a0after = new Foo();
381   if( false ) {
382     a0after.x = new Foo();
383   } else {
384     a0after.x = new Foo();
385   }
386
387   Foo.m2_( a0after );
388
389
390   taskexit( p0{ !f }, p1{ !f } );
391 }
392
393
394 task methodTest03_( Foo p0{ f }, Foo p1{ f } ) {
395
396   Foo a0before = new Foo();
397   if( false ) {
398     a0before.x = new Foo();
399   } else {
400     a0before.x = new Foo();
401   }
402
403   Foo a0after = new Foo();
404   if( false ) {
405     a0after.x = new Foo();
406   } else {
407     a0after.x = new Foo();
408   }
409
410   Foo.m3_( a0after );
411
412
413   taskexit( p0{ !f }, p1{ !f } );
414 }
415
416
417 task methodTest04_( Foo p0{ f }, Foo p1{ f } ) {
418
419   Foo a0before = new Foo();
420   if( false ) {
421     a0before.x = new Foo();
422   } else {
423     a0before.x = new Foo();
424   }
425
426   Foo a0after = new Foo();
427   if( false ) {
428     a0after.x = new Foo();
429   } else {
430     a0after.x = new Foo();
431   }
432
433   Foo.m4_( a0after );
434
435
436   taskexit( p0{ !f }, p1{ !f } );
437 }
438
439
440 task methodTest05_( Foo p0{ f }, Foo p1{ f } ) {
441
442   Foo a0before = new Foo();
443   if( false ) {
444     a0before.x = new Foo();
445   } else {
446     a0before.x = new Foo();
447   }
448
449   Foo a0after = new Foo();
450   if( false ) {
451     a0after.x = new Foo();
452   } else {
453     a0after.x = new Foo();
454   }
455
456   Foo.m5_( a0after );
457
458
459   taskexit( p0{ !f }, p1{ !f } );
460 }
461
462
463 task methodTest06_( Foo p0{ f }, Foo p1{ f } ) {
464
465   Foo a0before = new Foo();
466   if( false ) {
467     a0before.x = new Foo();
468   } else {
469     a0before.x = new Foo();
470   }
471
472   Foo a0after = new Foo();
473   if( false ) {
474     a0after.x = new Foo();
475   } else {
476     a0after.x = new Foo();
477   }
478
479   Foo a1before = new Foo();
480   if( false ) {
481     a1before.x = new Foo();
482   } else {
483     a1before.x = new Foo();
484   }
485
486   Foo a1after = new Foo();
487   if( false ) {
488     a1after.x = new Foo();
489   } else {
490     a1after.x = new Foo();
491   }
492
493   Foo.m6_( a0after, a1after );
494
495
496   taskexit( p0{ !f }, p1{ !f } );
497 }
498
499
500 task methodTest07_( Foo p0{ f }, Foo p1{ f } ) {
501
502   Foo a0before = new Foo();
503   if( false ) {
504     a0before.x = new Foo();
505   } else {
506     a0before.x = new Foo();
507   }
508
509   Foo a0after = new Foo();
510   if( false ) {
511     a0after.x = new Foo();
512   } else {
513     a0after.x = new Foo();
514   }
515
516   Foo a1before = new Foo();
517   if( false ) {
518     a1before.x = new Foo();
519   } else {
520     a1before.x = new Foo();
521   }
522
523   Foo a1after = new Foo();
524   if( false ) {
525     a1after.x = new Foo();
526   } else {
527     a1after.x = new Foo();
528   }
529
530   Foo.m7_( a0after, a1after );
531
532
533   taskexit( p0{ !f }, p1{ !f } );
534 }
535
536
537 task methodTest08_( Foo p0{ f }, Foo p1{ f } ) {
538
539   Foo a0before = new Foo();
540   if( false ) {
541     a0before.x = new Foo();
542   } else {
543     a0before.x = new Foo();
544   }
545
546   Foo a0after = new Foo();
547   if( false ) {
548     a0after.x = new Foo();
549   } else {
550     a0after.x = new Foo();
551   }
552
553   Foo a1before = new Foo();
554   if( false ) {
555     a1before.x = new Foo();
556   } else {
557     a1before.x = new Foo();
558   }
559
560   Foo a1after = new Foo();
561   if( false ) {
562     a1after.x = new Foo();
563   } else {
564     a1after.x = new Foo();
565   }
566
567   Foo.m8_( a0after, a1after );
568
569
570   taskexit( p0{ !f }, p1{ !f } );
571 }