@@ -18,6 +18,11 @@ public class NonBridge
18
18
public object Link ;
19
19
}
20
20
21
+ public class NonBridge2 : NonBridge
22
+ {
23
+ public object Link2 ;
24
+ }
25
+
21
26
class Driver {
22
27
const int OBJ_COUNT = 200 * 1000 ;
23
28
const int LINK_COUNT = 2 ;
@@ -207,6 +212,32 @@ static void Spider () {
207
212
c . Links . Add ( last_level ) ;
208
213
}
209
214
215
+ /*
216
+ * Simulates a graph with two nested cycles that is produces by
217
+ * the async state machine when `async Task M()` method gets its
218
+ * continuation rooted by an Action held by RunnableImplementor
219
+ * (ie. the task continuation is hooked through the SynchronizationContext
220
+ * implentation and rooted only by Android bridge objects).
221
+ */
222
+ static void NestedCycles ( )
223
+ {
224
+ Bridge runnableImplementor = new Bridge ( ) ;
225
+ Bridge byteArrayOutputStream = new Bridge ( ) ;
226
+ NonBridge2 action = new NonBridge2 ( ) ;
227
+ NonBridge displayClass = new NonBridge ( ) ;
228
+ NonBridge2 asyncStateMachineBox = new NonBridge2 ( ) ;
229
+ NonBridge2 asyncStreamWriter = new NonBridge2 ( ) ;
230
+
231
+ runnableImplementor . Links . Add ( action ) ;
232
+ action . Link = displayClass ;
233
+ action . Link2 = asyncStateMachineBox ;
234
+ displayClass . Link = action ;
235
+ asyncStateMachineBox . Link = asyncStreamWriter ;
236
+ asyncStateMachineBox . Link2 = action ;
237
+ asyncStreamWriter . Link = byteArrayOutputStream ;
238
+ asyncStreamWriter . Link2 = asyncStateMachineBox ;
239
+ }
240
+
210
241
static void RunTest ( ThreadStart setup )
211
242
{
212
243
var t = new Thread ( setup ) ;
@@ -231,6 +262,7 @@ static int Main ()
231
262
RunTest ( SetupDeadList ) ;
232
263
RunTest ( SetupSelfLinks ) ;
233
264
RunTest ( Spider ) ;
265
+ RunTest ( NestedCycles ) ;
234
266
235
267
for ( int i = 0 ; i < 0 ; ++ i ) {
236
268
GC . Collect ( ) ;
0 commit comments