1 | #!perl |
---|
2 | # Copyright (C) 2001-2009, Parrot Foundation. |
---|
3 | # $Id: gc.t 40810 2009-08-26 01:46:42Z dukeleto $ |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | use lib qw( . lib ../lib ../../lib ); |
---|
8 | use Test::More; |
---|
9 | use Parrot::Test tests => 11; |
---|
10 | |
---|
11 | =head1 NAME |
---|
12 | |
---|
13 | t/op/gc.t - Garbage Collection |
---|
14 | |
---|
15 | =head1 SYNOPSIS |
---|
16 | |
---|
17 | % prove t/op/gc_perl.t |
---|
18 | |
---|
19 | =head1 DESCRIPTION |
---|
20 | |
---|
21 | NOTE: These tests are currently being converted to use only PIR |
---|
22 | and Test::More, and are then being migrated over to gc.t, |
---|
23 | after which this file will disappear ... |
---|
24 | |
---|
25 | Tests garbage collection with the C<interpinfo> operation and various |
---|
26 | GC related bugs |
---|
27 | |
---|
28 | =cut |
---|
29 | |
---|
30 | pir_output_is( <<'CODE', <<OUTPUT, "vanishing singleton PMC" ); |
---|
31 | .sub main :main |
---|
32 | $P16 = new 'Env' |
---|
33 | $P16['Foo'] = 'bar' |
---|
34 | $I16 = 100 |
---|
35 | $I17 = 0 |
---|
36 | |
---|
37 | loop: |
---|
38 | sweep 1 |
---|
39 | _rand() |
---|
40 | $I17 += 1 |
---|
41 | if $I17 <= $I16 goto loop |
---|
42 | say "ok" |
---|
43 | .end |
---|
44 | |
---|
45 | .sub _rand |
---|
46 | $P16 = new 'Env' |
---|
47 | $P5 = $P16['Foo'] |
---|
48 | if $P5 != 'bar' goto err |
---|
49 | .return() |
---|
50 | err: |
---|
51 | say "singleton destroyed .Env = ." |
---|
52 | $P16 = new 'Env' |
---|
53 | $S16 = typeof $P16 |
---|
54 | say $S16 |
---|
55 | .end |
---|
56 | |
---|
57 | CODE |
---|
58 | ok |
---|
59 | OUTPUT |
---|
60 | |
---|
61 | pir_output_is( <<'CODE', <<OUTPUT, "vanishing return continuation in method calls" ); |
---|
62 | .sub main :main |
---|
63 | .local pmc o, cl |
---|
64 | cl = newclass "Foo" |
---|
65 | |
---|
66 | new o, "Foo" |
---|
67 | print "ok\n" |
---|
68 | end |
---|
69 | .end |
---|
70 | |
---|
71 | .namespace ["Foo"] |
---|
72 | .sub init :vtable :method |
---|
73 | print "init\n" |
---|
74 | sweep 1 |
---|
75 | new $P6, 'String' |
---|
76 | set $P6, "hi" |
---|
77 | self."do_inc"() |
---|
78 | sweep 1 |
---|
79 | .end |
---|
80 | |
---|
81 | .sub do_inc :method |
---|
82 | sweep 1 |
---|
83 | inc self |
---|
84 | sweep 1 |
---|
85 | print "back from _inc\n" |
---|
86 | .end |
---|
87 | |
---|
88 | .sub __increment :method |
---|
89 | print "inc\n" |
---|
90 | sweep 1 |
---|
91 | .end |
---|
92 | CODE |
---|
93 | init |
---|
94 | inc |
---|
95 | back from _inc |
---|
96 | ok |
---|
97 | OUTPUT |
---|
98 | |
---|
99 | pasm_output_is( <<'CODE', <<OUTPUT, "failing if regsave is not marked" ); |
---|
100 | newclass P9, "Source" |
---|
101 | newclass P10, "Source::Buffer" |
---|
102 | new P12, "Source" |
---|
103 | |
---|
104 | set S20, P12 |
---|
105 | print S20 |
---|
106 | set S20, P12 |
---|
107 | print S20 |
---|
108 | end |
---|
109 | |
---|
110 | .namespace ["Source"] |
---|
111 | .pcc_sub __get_string: # buffer |
---|
112 | get_params "0", P2 |
---|
113 | getprop P12, "buffer", P2 |
---|
114 | sweep 1 |
---|
115 | unless_null P12, buffer_ok |
---|
116 | new P12, "Source::Buffer" |
---|
117 | new P14, 'String' |
---|
118 | set P14, "hello\n" |
---|
119 | setprop P12, "buf", P14 |
---|
120 | setprop P2, "buffer", P12 |
---|
121 | buffer_ok: |
---|
122 | set_returns "0", P12 |
---|
123 | returncc |
---|
124 | |
---|
125 | .namespace ["Source::Buffer"] |
---|
126 | .pcc_sub __get_string: |
---|
127 | get_params "0", P2 |
---|
128 | sweep 1 |
---|
129 | getprop P12, "buf", P2 |
---|
130 | set S16, P12 |
---|
131 | set_returns "0", S16 |
---|
132 | returncc |
---|
133 | CODE |
---|
134 | hello |
---|
135 | hello |
---|
136 | OUTPUT |
---|
137 | |
---|
138 | # this is a stripped down version of imcc/t/syn/pcc_16 |
---|
139 | # s. also src/pmc/retcontinuation.pmc |
---|
140 | pasm_output_is( <<'CODE', <<OUTPUT, "coro context and invalid return continuations" ); |
---|
141 | .pcc_sub main: |
---|
142 | .const 'Sub' P0 = "co1" |
---|
143 | set I20, 0 |
---|
144 | l: |
---|
145 | get_results '' |
---|
146 | set_args '' |
---|
147 | invokecc P0 |
---|
148 | inc I20 |
---|
149 | lt I20, 3, l |
---|
150 | print "done\n" |
---|
151 | end |
---|
152 | .pcc_sub co1: |
---|
153 | get_params '' |
---|
154 | set P17, P1 |
---|
155 | col: |
---|
156 | print "coro\n" |
---|
157 | sweep 1 |
---|
158 | yield |
---|
159 | branch col |
---|
160 | |
---|
161 | CODE |
---|
162 | coro |
---|
163 | coro |
---|
164 | coro |
---|
165 | done |
---|
166 | OUTPUT |
---|
167 | |
---|
168 | pir_output_is( <<'CODE', <<OUTPUT, "Recursion and exceptions" ); |
---|
169 | |
---|
170 | # this did segfault with GC_DEBUG |
---|
171 | |
---|
172 | .sub main :main |
---|
173 | .local pmc n |
---|
174 | $P0 = getinterp |
---|
175 | $P0."recursion_limit"(10) |
---|
176 | newclass $P0, "b" |
---|
177 | $P0 = new "b" |
---|
178 | $P1 = new 'Integer' |
---|
179 | $P1 = 0 |
---|
180 | n = $P0."b11"($P1) |
---|
181 | print "ok 1\n" |
---|
182 | print n |
---|
183 | print "\n" |
---|
184 | .end |
---|
185 | .namespace ["b"] |
---|
186 | .sub b11 :method |
---|
187 | .param pmc n |
---|
188 | .local pmc n1 |
---|
189 | # new_pad -1 |
---|
190 | # store_lex -1, "n", n |
---|
191 | n1 = new 'Integer' |
---|
192 | n1 = n + 1 |
---|
193 | push_eh catch |
---|
194 | n = self."b11"(n1) |
---|
195 | # store_lex -1, "n", n |
---|
196 | pop_eh |
---|
197 | catch: |
---|
198 | # n = find_lex "n" |
---|
199 | .return(n) |
---|
200 | .end |
---|
201 | CODE |
---|
202 | ok 1 |
---|
203 | 9 |
---|
204 | OUTPUT |
---|
205 | |
---|
206 | pasm_output_is( <<'CODE', <<OUTPUT, "write barrier 1" ); |
---|
207 | null I2 |
---|
208 | set I3, 100 |
---|
209 | lp3: |
---|
210 | null I0 |
---|
211 | set I1, 1000 |
---|
212 | new P1, 'ResizablePMCArray' |
---|
213 | lp1: |
---|
214 | new P2, 'ResizablePMCArray' |
---|
215 | new P0, 'Integer' |
---|
216 | set P0, I0 |
---|
217 | set P2[0], P0 |
---|
218 | set P1[I0], P2 |
---|
219 | if I0, not_0 |
---|
220 | needs_destroy P0 |
---|
221 | # force marking past P2[0] |
---|
222 | sweep 0 |
---|
223 | not_0: |
---|
224 | new P3, 'Undef' |
---|
225 | new P4, 'Undef' |
---|
226 | inc I0 |
---|
227 | lt I0, I1, lp1 |
---|
228 | |
---|
229 | null I0 |
---|
230 | # trace 1 |
---|
231 | lp2: |
---|
232 | set P2, P1[I0] |
---|
233 | set P2, P2[0] |
---|
234 | eq P2, I0, ok |
---|
235 | print "nok\n" |
---|
236 | print "I0: " |
---|
237 | print I0 |
---|
238 | print " P2: " |
---|
239 | print P2 |
---|
240 | print " type: " |
---|
241 | typeof S0, P2 |
---|
242 | print S0 |
---|
243 | print " I2: " |
---|
244 | print I2 |
---|
245 | print "\n" |
---|
246 | exit 1 |
---|
247 | ok: |
---|
248 | inc I0 |
---|
249 | lt I0, I1, lp2 |
---|
250 | inc I2 |
---|
251 | lt I2, I3, lp3 |
---|
252 | print "ok\n" |
---|
253 | end |
---|
254 | CODE |
---|
255 | ok |
---|
256 | OUTPUT |
---|
257 | |
---|
258 | pasm_output_is( <<'CODE', <<OUTPUT, "write barrier 2 - hash" ); |
---|
259 | null I2 |
---|
260 | set I3, 100 |
---|
261 | lp3: |
---|
262 | null I0 |
---|
263 | set I1, 100 |
---|
264 | new P1, 'Hash' |
---|
265 | lp1: |
---|
266 | new P2, 'Hash' |
---|
267 | new P0, 'Integer' |
---|
268 | set P0, I0 |
---|
269 | set S0, I0 |
---|
270 | set P2["first"], P0 |
---|
271 | set P1[S0], P2 |
---|
272 | if I0, not_0 |
---|
273 | new P0, 'Integer' |
---|
274 | needs_destroy P0 |
---|
275 | null P0 |
---|
276 | # force full sweep |
---|
277 | sweep 0 |
---|
278 | not_0: |
---|
279 | new P3, 'Undef' |
---|
280 | new P4, 'Undef' |
---|
281 | inc I0 |
---|
282 | lt I0, I1, lp1 |
---|
283 | |
---|
284 | null I0 |
---|
285 | # trace 1 |
---|
286 | lp2: |
---|
287 | set S0, I0 |
---|
288 | set P2, P1[S0] |
---|
289 | set P2, P2["first"] |
---|
290 | eq P2, I0, ok |
---|
291 | print "nok\n" |
---|
292 | print "I0: " |
---|
293 | print I0 |
---|
294 | print " P2: " |
---|
295 | print P2 |
---|
296 | print " type: " |
---|
297 | typeof S0, P2 |
---|
298 | print S0 |
---|
299 | print " I2: " |
---|
300 | print I2 |
---|
301 | print "\n" |
---|
302 | exit 1 |
---|
303 | ok: |
---|
304 | inc I0 |
---|
305 | lt I0, I1, lp2 |
---|
306 | inc I2 |
---|
307 | lt I2, I3, lp3 |
---|
308 | print "ok\n" |
---|
309 | end |
---|
310 | CODE |
---|
311 | ok |
---|
312 | OUTPUT |
---|
313 | |
---|
314 | pir_output_is( <<'CODE', <<'OUTPUT', "verify pmc proxy object marking" ); |
---|
315 | .sub main :main |
---|
316 | .local pmc cl, s, t |
---|
317 | cl = subclass "String", "X" |
---|
318 | addattribute cl, "o3" |
---|
319 | addattribute cl, "o4" |
---|
320 | s = new "X" |
---|
321 | $P0 = new 'String' |
---|
322 | $S0 = "ok" . " 3\n" |
---|
323 | $P0 = $S0 |
---|
324 | setattribute s, "o3", $P0 |
---|
325 | $P0 = new 'String' |
---|
326 | $S0 = "ok" . " 4\n" |
---|
327 | $P0 = $S0 |
---|
328 | setattribute s, "o4", $P0 |
---|
329 | null $P0 |
---|
330 | null $S0 |
---|
331 | null cl |
---|
332 | sweep 1 |
---|
333 | s = "ok 1\n" |
---|
334 | print s |
---|
335 | .local int i |
---|
336 | i = 0 |
---|
337 | lp: |
---|
338 | t = new "X" |
---|
339 | inc i |
---|
340 | if i < 1000 goto lp |
---|
341 | t = "ok 2\n" |
---|
342 | print s |
---|
343 | print t |
---|
344 | $P0 = getattribute s, "o3" |
---|
345 | print $P0 |
---|
346 | $P0 = getattribute s, "o4" |
---|
347 | print $P0 |
---|
348 | .end |
---|
349 | CODE |
---|
350 | ok 1 |
---|
351 | ok 1 |
---|
352 | ok 2 |
---|
353 | ok 3 |
---|
354 | ok 4 |
---|
355 | OUTPUT |
---|
356 | |
---|
357 | pir_output_is( <<'CODE', <<'OUTPUT', "AddrRegistry 1" ); |
---|
358 | .sub main :main |
---|
359 | .local pmc a, reg, nil |
---|
360 | reg = new 'AddrRegistry' |
---|
361 | a = new 'String' |
---|
362 | null nil |
---|
363 | $I0 = reg[a] |
---|
364 | if $I0 == 0 goto ok1 |
---|
365 | print "not " |
---|
366 | ok1: |
---|
367 | print "ok 1\n" |
---|
368 | reg[a] = nil |
---|
369 | $I0 = reg[a] |
---|
370 | if $I0 == 1 goto ok2 |
---|
371 | print "not " |
---|
372 | ok2: |
---|
373 | print "ok 2\n" |
---|
374 | reg[a] = nil |
---|
375 | $I0 = reg[a] |
---|
376 | if $I0 == 2 goto ok3 |
---|
377 | print "not " |
---|
378 | ok3: |
---|
379 | print "ok 3\n" |
---|
380 | |
---|
381 | delete reg[a] |
---|
382 | $I0 = reg[a] |
---|
383 | if $I0 == 1 goto ok4 |
---|
384 | print "not " |
---|
385 | ok4: |
---|
386 | print "ok 4\n" |
---|
387 | delete reg[a] |
---|
388 | $I0 = reg[a] |
---|
389 | if $I0 == 0 goto ok5 |
---|
390 | print "not " |
---|
391 | ok5: |
---|
392 | print "ok 5\n" |
---|
393 | .end |
---|
394 | CODE |
---|
395 | ok 1 |
---|
396 | ok 2 |
---|
397 | ok 3 |
---|
398 | ok 4 |
---|
399 | ok 5 |
---|
400 | OUTPUT |
---|
401 | |
---|
402 | pir_output_is( <<'CODE', <<'OUTPUT', "AddrRegistry 2" ); |
---|
403 | .sub main :main |
---|
404 | .local pmc a, b, reg, nil |
---|
405 | null nil |
---|
406 | reg = new 'AddrRegistry' |
---|
407 | a = new 'String' |
---|
408 | b = new 'String' |
---|
409 | $I0 = elements reg |
---|
410 | print $I0 |
---|
411 | reg[a] = nil |
---|
412 | $I0 = elements reg |
---|
413 | print $I0 |
---|
414 | reg[a] = nil |
---|
415 | $I0 = elements reg |
---|
416 | print $I0 |
---|
417 | reg[b] = nil |
---|
418 | $I0 = elements reg |
---|
419 | print $I0 |
---|
420 | print "\n" |
---|
421 | .end |
---|
422 | CODE |
---|
423 | 0112 |
---|
424 | OUTPUT |
---|
425 | |
---|
426 | pir_output_is( <<'CODE', <<'OUTPUT', "AddrRegistry 2" ); |
---|
427 | .sub main :main |
---|
428 | .local pmc a, b, c, reg, nil, it |
---|
429 | null nil |
---|
430 | reg = new 'AddrRegistry' |
---|
431 | a = new 'String' |
---|
432 | a = "k1" |
---|
433 | b = new 'String' |
---|
434 | b = "k2" |
---|
435 | c = new 'String' |
---|
436 | c = "k3" |
---|
437 | reg[a] = nil |
---|
438 | reg[b] = nil |
---|
439 | reg[c] = nil |
---|
440 | |
---|
441 | $P1 = new ['ResizablePMCArray'] |
---|
442 | it = iter reg |
---|
443 | loop: |
---|
444 | unless it goto done |
---|
445 | $P0 = shift it |
---|
446 | $S0 = $P0 |
---|
447 | push $P1, $S0 |
---|
448 | goto loop |
---|
449 | done: |
---|
450 | $P1.'sort'() |
---|
451 | $S1 = join '', $P1 |
---|
452 | print $S1 |
---|
453 | print "\n" |
---|
454 | .end |
---|
455 | CODE |
---|
456 | k1k2k3 |
---|
457 | OUTPUT |
---|
458 | |
---|
459 | =head1 SEE ALSO |
---|
460 | |
---|
461 | F<examples/benchmarks/primes.c>, |
---|
462 | F<examples/benchmarks/primes.pasm>, |
---|
463 | F<examples/benchmarks/primes.pl>, |
---|
464 | F<examples/benchmarks/primes2_i.pasm>, |
---|
465 | F<examples/benchmarks/primes2.c>, |
---|
466 | F<examples/benchmarks/primes2.py>. |
---|
467 | |
---|
468 | =cut |
---|
469 | |
---|
470 | # Local Variables: |
---|
471 | # mode: cperl |
---|
472 | # cperl-indent-level: 4 |
---|
473 | # fill-column: 100 |
---|
474 | # End: |
---|
475 | # vim: expandtab shiftwidth=4: |
---|