3787b57f232686162a46c6658d9a5b309bd65aec
[IRC.git] / Robust / src / Tests / OwnershipAnalysisTest / test01 / test01.java
1
2 public class Parameter {
3   flag w;
4   int a;
5   int b;
6   Parameter f;
7   Parameter g;
8   Penguin p;
9   Foo h;
10   
11   public Parameter() {}
12   
13   public void bar() { foo(); }
14   public void foo() { bar(); }
15
16   static public void proof( Fooz p0, Fooz p1 ) {
17     Fooz c = new Fooz();
18     Fooz d = new Fooz();
19
20     c.x  = d;
21     p0.x = c;
22     p1.x = d;
23   }
24 }
25
26 public class Fooz {
27   public Fooz() {}
28   public Fooz x;
29 }
30
31
32 public class Penguin {
33   int x;
34   int y;
35   Foo h;    
36   
37   public Penguin() { x = 0; y = 0; }
38   
39   public void bar() { x = 1; }
40 }
41
42 public class Voo {
43   flag f; int x; Baw b; Baw bb;
44   
45   public Voo() {}
46   
47   static Voo getAVoo( Voo bogus ) {
48     while( false ) {
49       if( false ) {
50         return new Voo();
51       } else {
52         return new Voo();
53       }
54     }
55     return new Voo();
56   }
57 }
58
59 public class Baw {
60   int y;
61   Foo f;
62   String s;
63
64   public Baw() {}
65   
66   public void doTheBaw( Voo v ) { v = new Voo(); }
67 }
68
69
70 public class Foo {
71   flag f;
72   
73   public Foo() {}
74   
75   public Foo x;
76   public Foo y;
77   public Foo z;
78   public Baw b;
79
80   public Foo getAFoo() {
81     return new Foo();
82   }
83
84   public Foo newFooChain( Foo a ) {
85     Foo b = new Foo();
86     b.x = a;
87     return b;
88   }
89
90   public void ruinSomeFoos( Foo a, Foo b ) {
91     a.x = b.x;
92   }
93   
94   static public void aStaticMethod( Foo p0, Foo p1 ) {
95     Foo f0 = new Foo();
96     Foo f1 = new Foo();
97     Foo f2 = new Foo();
98     
99     f0.x = f1;
100     p0.x = f0;
101     p1.x = f1;
102     p1.x = f2;
103   }
104   
105   static public void m1_( Foo p0 ) {
106     Foo g0 = new Foo();
107     Foo g1 = new Foo();
108     
109     g0.x = p0;
110     p0.x = g1;
111   }
112
113   static public void m2_( Foo p0 ) {
114     Foo g0 = new Foo();
115     
116     g0.x = p0;
117     g0.y = p0;
118   }
119   
120   static public void m3_( Foo p0 ) {
121     Foo g0 = new Foo();
122     
123     p0.x = g0;
124     p0.y = g0;
125   }
126
127   static public void m4_( Foo p0 ) {
128     p0.x = p0;
129   }
130
131   static public void m5_( Foo p0 ) {
132     Foo g0 = new Foo();
133     p0.x = g0;
134     g0.x = p0;
135   }
136
137   static public void m6_( Foo p0, Foo p1 ) {
138     Foo g0 = new Foo();
139     Foo g1 = new Foo();
140     Foo g2 = new Foo();
141     Foo g3 = new Foo();
142
143     g0.x = p0;
144     p0.x = g1;
145
146     g2.x = p1;
147     p1.x = g3;
148
149     p0.y = p1;
150   }
151
152   static public void m7_( Foo p0, Foo p1 ) {
153     Foo g0 = new Foo();
154     Foo g1 = new Foo();
155     Foo g2 = new Foo();
156     Foo g3 = new Foo();
157
158     g0.x = p0;
159     p0.x = g1;
160
161     g2.x = p1;
162     p1.x = g3;
163
164     p0.y = p1;
165     p0.z = p1;
166   }
167
168   static public void m8_( Foo p0, Foo p1 ) {
169     Foo g0 = new Foo();
170     Foo g1 = new Foo();
171     Foo g2 = new Foo();
172     Foo g3 = new Foo();
173
174     g0.x = p0;
175     p0.x = g1;
176
177     g2.x = p1;
178     p1.x = g3;
179
180     p0.y = p1;
181     p1.y = p0;
182   }
183
184   static public void m9_( Foo p0, Foo p1 ) {
185     Foo g0 = new Foo();
186
187     p1.x = p1.y;
188     p1.y = g0;
189   }
190 }
191
192
193
194 // this empty task should still create a non-empty
195 // ownership graph showing parameter allocation
196 // look for the parameter s as a label referencing
197 // a heap region that is multi-object, flagged, not summary
198 task Startup( StartupObject s{ initialstate } ) {
199
200   //Parameter p0 = new Parameter();
201
202   //int a, b, c;
203
204   Parameter.proof( null, null );
205
206   taskexit( s{ !initialstate } );
207 }
208
209 /*
210
211 task NewObjectA( Foo a{ f }, Foo b{ f } ) {
212
213     Foo c = new Foo();
214     Foo d = new Foo();
215
216     c.x = d;
217     a.x = c;
218
219     taskexit( a{ !f }, b{ !f } );
220 }
221
222
223 task NewObjectB( Foo a{ f }, Foo b{ f } ) {
224
225     Foo c = new Foo();
226     Foo d = new Foo();
227
228     a.x = c;
229     c.x = d;
230
231     taskexit( a{ !f }, b{ !f } );
232 }
233
234
235 task NewObjectC( Foo a{ f }, Foo b{ f } ) {
236
237     Foo z = new Foo();
238     a.x = z;
239     a.y = z;
240
241     Foo c;
242
243     while( false ) {
244         c     = new Foo();
245         Foo f = new Foo();
246         c.x   = f;
247         c.y   = f;
248     }
249
250     taskexit( a{ !f }, b{ !f } );
251 }
252
253
254 task forMethod( Foo p0{ f } ) {
255
256     Foo a0;
257     Foo a1;
258
259     while( false ) {    
260         a1 = a0;            
261         if( false ) {
262             a0 = new Foo();
263         }
264     }
265
266     Foo z = new Foo();
267     a1.x = z;
268     z.x  = a1;
269
270
271     taskexit( p0{ !f } );
272 }
273
274
275 // this task allocates a new object, so there should
276 // be a heap region for the parameter, and several
277 // heap regions for the allocation site, but the label
278 // merely points to the newest region
279 task NewObjectInMethod( Voo v{ f } ) {
280     Voo w = new Voo();
281     Baw b = new Baw();
282     b.doTheBaw( w );
283
284     taskexit( v{ !f } );
285 }
286
287
288 task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) {
289     v.b = v.bb;
290
291     taskexit( v{ !f }, w{ !f } );
292 }
293
294
295 task BackToItself( Parameter p0{ w } ) {
296
297     Penguin p = new Penguin();
298     p0.p = p;
299     p.h = p0.h;
300
301     while( false ) {
302         Parameter p1   = new Parameter();
303                   p1.h = new Foo();
304         Penguin   q    = new Penguin();
305         p1.p = q;
306         q.h  = p1.h;
307     }
308
309     taskexit( p0{ !w } );
310 }
311
312
313 task SummaryNodeTokens( Foo p0{ f } ) {
314
315     while( false ) {
316         Foo a = new Foo();
317         a.x   = new Foo();
318         a.x.x = new Foo();
319     }
320     
321     Foo b;
322     while( false ) {
323         Foo c = new Foo();
324         c.x = b;
325         b = c;
326     }
327
328     taskexit( p0{ !f } );
329 }
330 */
331
332 task strongUpdates( Foo p0{ f } ) {
333
334     Foo b = new Foo();
335
336     Foo a = new Foo();
337     if( false ) {
338       a.x = new Foo();
339       a.y = new Foo();
340     } else if( false ) {
341       a.x = new Foo();
342       a.y = new Foo();
343     }
344     
345
346     // this should effect a strong update
347     a.x = b;
348
349
350     if( false ) {
351         p0.x = new Foo();
352         p0.y = new Foo();
353     } else if( false ) {
354         p0.x = new Foo();
355         p0.y = new Foo();
356     }
357
358     // p0 points to a multiple-object heap region
359     // so this should not make a strong update
360     p0.x = b;
361
362
363     taskexit( p0{ !f } );
364 }
365
366 /*
367
368 task ObjectChainByMethodCalls( Foo a{ f } ) {
369
370   Foo f = a.getAFoo();
371   Foo g = a.newFooChain( f );
372   // g -> f
373
374   taskexit( a{ !f } );
375 }
376
377
378 task arrayAssignments( Foo a{ f } ) {
379
380   Foo f[] = new Foo[3];
381
382   Foo g = new Foo();
383   Foo h = new Foo();
384
385   f[1] = g;
386   f[2] = h;
387
388   Foo i = f[0];
389
390   taskexit( a{ !f } );
391 }
392
393
394 public class Zool {
395   public Zool() {}
396
397   public static void FooToBaw( Baw x, Foo y ) {
398     x.f.b = y.b;
399   }
400 }
401
402 task showPrunedEdgesInMethodCall( Foo a{ f } ) {
403
404   Foo b = new Foo();
405   b.x   = a;
406   b.y   = new Foo();
407   b.b   = new Baw();
408
409   Baw c = new Baw();
410   c.f   = new Foo();
411   c.f.b = new Baw();
412   
413   Zool.FooToBaw( c, b );
414
415   taskexit( a{ !f } );
416 }
417
418 task showStringIsImmutable( Foo a{ f } ) {
419
420   Baw x = new Baw();
421   Baw y = new Baw();
422
423   Foo f = new Foo();
424   String s = new String();
425
426   x.f = f;
427   y.f = f;
428
429   x.s = s;
430   y.s = s;
431
432   taskexit( a{ !f } );
433 }
434
435
436 task methodTest( Foo p0{ f } ) {
437
438     Foo up0 = new Foo();
439     Foo up1 = new Foo();
440     Foo up2 = new Foo();
441
442     Foo a0;
443     Foo a1;
444
445     if( false ) {
446         a0    = new Foo();
447         up0.x = a0;     
448         a0.x  = new Foo();
449         //Foo temp = new Foo();
450     }
451
452     if( false ) {
453         a0    = new Foo();
454         a0.x  = new Foo();
455         a1    = a0;
456         up1.x = a0;
457     }
458
459     if( false ) {
460         a1    = new Foo();
461         up2.x = a1;
462     }
463
464     // Foo.test( a0, a1 );
465
466     taskexit( p0{ !f } );
467 }
468
469
470 task getNewFromMethod( Foo p0{ f } ) { 
471   Voo g = Voo.getAVoo( null );
472
473   taskexit( p0{ !f } );
474 }
475
476
477 task methodTest01_( Foo p0{ f }, Foo p1{ f } ) {
478
479   Foo a0before = new Foo();
480   if( false ) {
481     a0before.x = new Foo();
482   } else {
483     a0before.x = new Foo();
484   }
485
486   Foo a0after = new Foo();
487   if( false ) {
488     a0after.x = new Foo();
489   } else {
490     a0after.x = new Foo();
491   }
492
493   Foo.m1_( a0after );
494
495
496   taskexit( p0{ !f }, p1{ !f } );
497 }
498
499
500 task methodTest02_( 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.m2_( a0after );
517
518
519   taskexit( p0{ !f }, p1{ !f } );
520 }
521
522
523 task methodTest03_( Foo p0{ f }, Foo p1{ f } ) {
524
525   Foo a0before = new Foo();
526   if( false ) {
527     a0before.x = new Foo();
528   } else {
529     a0before.x = new Foo();
530   }
531
532   Foo a0after = new Foo();
533   if( false ) {
534     a0after.x = new Foo();
535   } else {
536     a0after.x = new Foo();
537   }
538
539   Foo.m3_( a0after );
540
541
542   taskexit( p0{ !f }, p1{ !f } );
543 }
544
545
546 task methodTest04_( Foo p0{ f }, Foo p1{ f } ) {
547
548   Foo a0before = new Foo();
549   if( false ) {
550     a0before.x = new Foo();
551   } else {
552     a0before.x = new Foo();
553   }
554
555   Foo a0after = new Foo();
556   if( false ) {
557     a0after.x = new Foo();
558   } else {
559     a0after.x = new Foo();
560   }
561
562   Foo.m4_( a0after );
563
564
565   taskexit( p0{ !f }, p1{ !f } );
566 }
567
568
569 task methodTest05_( Foo p0{ f }, Foo p1{ f } ) {
570
571   Foo a0before = new Foo();
572   if( false ) {
573     a0before.x = new Foo();
574   } else {
575     a0before.x = new Foo();
576   }
577
578   Foo a0after = new Foo();
579   if( false ) {
580     a0after.x = new Foo();
581   } else {
582     a0after.x = new Foo();
583   }
584
585   Foo.m5_( a0after );
586
587
588   taskexit( p0{ !f }, p1{ !f } );
589 }
590
591
592 task methodTest06_( Foo p0{ f }, Foo p1{ f } ) {
593
594   Foo a0before = new Foo();
595   if( false ) {
596     a0before.x = new Foo();
597   } else {
598     a0before.x = new Foo();
599   }
600
601   Foo a0after = new Foo();
602   if( false ) {
603     a0after.x = new Foo();
604   } else {
605     a0after.x = new Foo();
606   }
607
608   Foo a1before = new Foo();
609   if( false ) {
610     a1before.x = new Foo();
611   } else {
612     a1before.x = new Foo();
613   }
614
615   Foo a1after = new Foo();
616   if( false ) {
617     a1after.x = new Foo();
618   } else {
619     a1after.x = new Foo();
620   }
621
622   //Foo.m6_( a0after, a1after );
623
624
625   taskexit( p0{ !f }, p1{ !f } );
626 }
627
628
629 task methodTest07_( Foo p0{ f }, Foo p1{ f } ) {
630
631   Foo a0before = new Foo();
632   if( false ) {
633     a0before.x = new Foo();
634   } else {
635     a0before.x = new Foo();
636   }
637
638   Foo a0after = new Foo();
639   if( false ) {
640     a0after.x = new Foo();
641   } else {
642     a0after.x = new Foo();
643   }
644
645   Foo a1before = new Foo();
646   if( false ) {
647     a1before.x = new Foo();
648   } else {
649     a1before.x = new Foo();
650   }
651
652   Foo a1after = new Foo();
653   if( false ) {
654     a1after.x = new Foo();
655   } else {
656     a1after.x = new Foo();
657   }
658
659   //Foo.m7_( a0after, a1after );
660
661
662   taskexit( p0{ !f }, p1{ !f } );
663 }
664
665
666 task methodTest08_( Foo p0{ f }, Foo p1{ f } ) {
667
668   Foo a0before = new Foo();
669   if( false ) {
670     a0before.x = new Foo();
671   } else {
672     a0before.x = new Foo();
673   }
674
675   Foo a0after = new Foo();
676   if( false ) {
677     a0after.x = new Foo();
678   } else {
679     a0after.x = new Foo();
680   }
681
682   Foo a1before = new Foo();
683   if( false ) {
684     a1before.x = new Foo();
685   } else {
686     a1before.x = new Foo();
687   }
688
689   Foo a1after = new Foo();
690   if( false ) {
691     a1after.x = new Foo();
692   } else {
693     a1after.x = new Foo();
694   }
695
696   //Foo.m8_( a0after, a1after );
697
698
699   taskexit( p0{ !f }, p1{ !f } );
700 }
701 */
702
703 /*
704 task methodTest09_( Foo p0{ f }, Foo p1{ f } ) {
705
706   Foo a0before = new Foo();
707   if( false ) {
708     a0before.x = new Foo();
709   } else {
710     a0before.x = new Foo();
711   }
712
713   Foo a0after = new Foo();
714   if( false ) {
715     a0after.x = new Foo();
716   } else {
717     a0after.x = new Foo();
718   }
719
720   Foo a1before = new Foo();
721   if( false ) {
722     a1before.x = new Foo();
723   } else {
724     a1before.x = new Foo();
725   }
726
727   Foo a1after = new Foo();
728   if( false ) {
729     a1after.x = new Foo();
730   } else {
731     a1after.x = new Foo();
732   }
733
734   Foo.m9_( a0after, a1after );
735
736
737   taskexit( p0{ !f }, p1{ !f } );
738 }
739 */