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