2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/op/gc.t - Garbage collection
15 Tests garbage collection with the C<interpinfo> operation and various
20 .include 'interpinfo.pasm'
23 .include 'test_more.pir'
28 sweep_0_need_destroy_obj()
29 sweep_0_need_destroy_destroy_obj()
32 collect_toggle_nested()
33 vanishing_singleton_PMC()
34 vanishing_ret_continuation()
36 recursion_and_exceptions()
43 coro_context_ret_continuation()
49 $I1 = interpinfo .INTERPINFO_GC_MARK_RUNS # How many GC mark runs have we done already?
51 $I2 = interpinfo .INTERPINFO_GC_MARK_RUNS # Should be one more now
58 $I1 = interpinfo .INTERPINFO_GC_MARK_RUNS # How many GC mark runs have we done already?
60 $I2 = interpinfo .INTERPINFO_GC_MARK_RUNS # Should be same
66 # sweep 0, with object that needs destroy/destroy
67 .sub sweep_0_need_destroy_obj
69 $I1 = interpinfo .INTERPINFO_GC_MARK_RUNS # How many GC mark runs have we done already?
72 $I2 = interpinfo .INTERPINFO_GC_MARK_RUNS # Should be one more now
74 is($I3,1, "sweep_0_need_destroy_obj")
78 # sweep 0, with object that needs destroy/destroy
79 .sub sweep_0_need_destroy_destroy_obj
82 $I1 = interpinfo .INTERPINFO_GC_MARK_RUNS # How many GC mark runs have we done already?
83 $P0 = new 'Undef' #kill object
85 $I2 = interpinfo .INTERPINFO_GC_MARK_RUNS # Should be one more now
88 $I4 = interpinfo .INTERPINFO_GC_MARK_RUNS # Should be same as last
90 is($I3,1, "sweep_0_need_destroy_destroy_obj")
91 is($I5,0, "sweep_0_need_destroy_destroy_obj")
96 $I1 = interpinfo .INTERPINFO_GC_COLLECT_RUNS # How many garbage collections have we done already?
98 $I2 = interpinfo .INTERPINFO_GC_COLLECT_RUNS # Should be one more now
100 is($I3,1, "collect_count")
105 $I1 = interpinfo .INTERPINFO_GC_COLLECT_RUNS
108 $I2 = interpinfo .INTERPINFO_GC_COLLECT_RUNS
110 is($I3,0, "collect_toggle")
114 $I4 = interpinfo .INTERPINFO_GC_COLLECT_RUNS
116 is($I6,1, "collect_toggle")
120 .sub collect_toggle_nested
121 $I1 = interpinfo .INTERPINFO_GC_COLLECT_RUNS
125 collect # This shouldn't do anything... #'
126 $I2 = interpinfo .INTERPINFO_GC_COLLECT_RUNS
128 is($I3,0, "collect_toggle_nested")
131 collect # ... but this should
132 $I4 = interpinfo .INTERPINFO_GC_COLLECT_RUNS
134 is($I6,1, "collect_toggle_nested")
139 .sub vanishing_singleton_PMC
149 if $I17 <= $I16 goto loop
155 is($P5, 'bar', "_rand")
156 if $P5 != 'bar' goto err
159 print "singleton destroyed .Env = ."
164 # END: vanishing_singleton_PMC
167 # vanishing return continuation in method calls
169 .sub init :vtable :method
170 ok(1, "entered init()")
182 ok(1, "leaving do_inc")
185 .sub increment :vtable :method
186 ok(1, "in __increment")
191 .sub vanishing_ret_continuation
195 ok(1, "end vanishing_return_continuation")
198 # END: vanishing_return_continuation
202 #Fail if regsave is not marked
203 .namespace ['Source']
204 .sub get_string :method :vtable # buffer
206 $P2 = getprop "buffer", $P4
208 unless_null $P2, buffer_ok
209 $P2 = new ['Source'; 'Buffer']
212 $P2 = setprop 'buf', $P3
213 $P4 = setprop 'buffer', $P2
218 .namespace ['Source'; 'Buffer']
219 .sub get_string :method :vtable
222 $P2 = getprop "buf", $P4
230 $P0 = newclass 'Source'
231 $P1 = newclass ['Source'; 'Buffer']
237 $S1 = $P2 #why are we doing this twice?
241 # end regsave_marked()
244 # Recursion and exceptions
245 # NOTE: this did segfault with GC_DEBUG
246 .sub recursion_and_exceptions
249 $P0."recursion_limit"(10)
255 ok(1, "recursion_and_exceptions")
256 is(n,8, "recursion_and_exceptions")
263 # store_lex -1, "n", n
266 push_eh catch # we're going to catch an exception when recursion_depth
269 # store_lex -1, "n", n
284 $P1 = new 'ResizablePMCArray'
286 $P2 = new 'ResizablePMCArray'
293 # force marking past $P2[0]
324 ok(1, "leaving write_barrier_1")
328 # write barrier 2 - hash
379 ok(1, "leaving write_barrier_2")
386 .local pmc a, reg, nil
387 reg = new 'AddrRegistry'
423 .sub addr_registry_2_int
424 .local pmc a, b, reg, nil
426 reg = new 'AddrRegistry'
430 is($I0, 0, "addr_registry_2_int")
433 is($I0, 1, "addr_registry_2_int")
436 is($I0, 1, "addr_registry_2_int")
439 is($I0, 2, "addr_registry_2_int")
444 .sub addr_registry_2_str
445 .local pmc a, b, c, reg, nil, it
447 reg = new 'AddrRegistry'
458 $P1 = new ['ResizablePMCArray']
472 # verify pmc proxy object marking
473 .sub pmc_proxy_obj_mark
475 cl = subclass "String", "X"
476 addattribute cl, "o3"
477 addattribute cl, "o4"
482 setattribute s, "o3", $P0
486 setattribute s, "o4", $P0
502 $P0 = getattribute s, "o3"
504 $P0 = getattribute s, "o4"
509 # coro context and invalid return continuations
510 # this is a stripped down version of imcc/t/syn/pcc_16
512 .sub coro_context_ret_continuation
513 .const 'Sub' $P0 = "co1"
536 F<examples/benchmarks/primes.c>,
537 F<examples/benchmarks/primes.pasm>,
538 F<examples/benchmarks/primes.pl>,
539 F<examples/benchmarks/primes2_i.pasm>,
540 F<examples/benchmarks/primes2.c>,
541 F<examples/benchmarks/primes2.py>.
547 # vim: expandtab shiftwidth=4 ft=pir: