strong updates, everything ready to do method calls
[IRC.git] / Robust / src / Tests / OwnershipAnalysisTest / test01 / test01.java
1 public class Parameter {
2     flag w;
3     int a, b;
4     Parameter f, g;
5     Penguin penguin;
6
7     public Parameter() { a = 0; b = 0; f = null; g = null; }
8
9     public void bar() { foo(); }
10     public void foo() { bar(); }
11 }
12
13 public class Penguin {
14     int x, y;
15
16     public Penguin() { x = 0; y = 0; }
17
18     public void bar() { x = 1; }
19 }
20
21 public class Voo {
22     flag f; int x; Baw b; Baw bb;
23
24     public Voo() {}
25 }
26
27 public class Baw {
28     int y;
29     Foo f;
30
31     public Baw() {}
32
33     public void doTheBaw( Voo v ) { v = new Voo(); }
34 }
35
36 public class Foo {
37     flag f;
38
39     public Foo() {}
40
41     public Foo x;
42     public Foo y;
43
44     public void ruinSomeFoos( Foo a, Foo b ) {
45         a.x = b.x;
46     }
47
48     static public void aStaticMethod( Foo p0, Foo p1 ) {
49         Foo f0 = new Foo();
50         Foo f1 = new Foo();
51         Foo f2 = new Foo();
52
53         f0.x = f1;
54         p0.x = f0;
55         p1.x = f1;
56         p1.x = f2;
57     }
58 }
59
60
61 // this empty task should still create a non-empty
62 // ownership graph showing parameter allocation
63 // look for the parameter s as a label referencing
64 // a heap region that is multi-object, flagged, not summary
65 task Startup( StartupObject s{ initialstate } ) {
66     taskexit( s{ !initialstate } );
67 }
68
69
70 task NewObjectA( Foo a{ f }, Foo b{ f } ) {
71
72     Foo c = new Foo();
73     Foo d = new Foo();
74
75     c.x = d;
76     a.x = c;
77
78     taskexit( a{ !f }, b{ !f } );
79 }
80
81 task NewObjectB( Foo a{ f }, Foo b{ f } ) {
82
83     Foo c = new Foo();
84     Foo d = new Foo();
85
86     a.x = c;
87     c.x = d;
88
89     taskexit( a{ !f }, b{ !f } );
90 }
91
92 task NewObjectC( Foo a{ f }, Foo b{ f } ) {
93
94     Foo c;
95
96     while( false ) {
97         c   = new Foo();
98         c.x = new Foo();
99     }
100
101     taskexit( a{ !f }, b{ !f } );
102 }
103
104
105
106
107 // this task allocates a new object, so there should
108 // be a heap region for the parameter, and several
109 // heap regions for the allocation site, but the label
110 // merely points to the newest region
111 task NewObjectInMethod( Voo v{ f } ) {
112     Voo w = new Voo();
113     Baw b = new Baw();
114     b.doTheBaw( w );
115
116     taskexit( v{ !f } );
117 }
118
119
120 task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) {
121     v.b = v.bb;
122
123     taskexit( v{ !f }, w{ !f } );
124 }
125
126
127 task SummaryNodeTokens( Foo p0{ f } ) {
128
129     while( false ) {
130         Foo a = new Foo();
131         a.x   = new Foo();
132         a.x.x = new Foo();
133     }
134     
135     Foo b;
136     while( false ) {
137         Foo c = new Foo();
138         c.x = b;
139         b = c;
140     }
141
142     taskexit( p0{ !f } );
143 }
144
145
146 task strongUpdates( Foo p0{ f } ) {
147
148     Foo b = new Foo();
149
150     Foo a = new Foo();
151     if( false ) {
152         a.x = new Foo();
153         a.y = new Foo();
154     } else if( false ) {
155         a.x = new Foo();
156         a.y = new Foo();
157     }
158
159     // this should effect a strong update
160     a.x = b;
161
162
163     if( false ) {
164         p0.x = new Foo();
165         p0.y = new Foo();
166     } else if( false ) {
167         p0.x = new Foo();
168         p0.y = new Foo();
169     }
170
171     // p0 points to a multiple-object heap region
172     // so this should not make a strong update
173     p0.x = b;
174     
175     taskexit( p0{ !f } );
176 }
177
178
179 task methodTest( Foo p0{ f } ) {
180
181     Foo up0 = new Foo();
182     Foo up1 = new Foo();
183     Foo up2 = new Foo();
184
185     Foo a0;
186     Foo a1;
187
188     if( false ) {
189         a0    = new Foo();
190         up0.x = a0;     
191         a0.x  = new Foo();
192         //Foo temp = new Foo();
193     }
194
195     if( false ) {
196         a0    = new Foo();
197         a0.x  = new Foo();
198         a1    = a0;
199         up1.x = a0;
200     }
201
202     if( false ) {
203         a1    = new Foo();
204         up2.x = a1;
205     }
206
207     // Foo.test( a0, a1 );
208
209     taskexit( p0{ !f } );
210 }