1 USING: accessors arrays byte-arrays effects kernel
2 kernel.private math memory namespaces quotations sequences
4 FROM: tools.memory => data-room code-room ;
7 [ save-image-and-exit ] must-fail
9 [ "does/not/exist" save-image ] must-fail
11 ! TODO: Disabled to get clean build and revisit.
13 ! os windows? "C:\\windows\\hello-windows" "/usr/bin/hello-unix" ?
17 ! Tests for 'instances'
18 [ [ ] instances ] must-infer
19 2 [ [ [ 3 throw ] instances ] must-fail ] times
22 { } [ { } { } become ] unit-test
24 ! Become something when it's on the data stack.
26 "original" dup 1array { "replacer" } become
31 "original" [ 5 [ 1array ] times ] [ 1array ] bi
33 { "replacer" } become 5 [ first ] times
36 ! Also when it is nested in nursery
39 "original" [ 5 [ 1array ] times ] [ 1array ] bi { "replacer" } become
43 ! Bug found on Windows build box, having too many words in the
44 ! image breaks 'become'
45 { } [ 100000 [ f <uninterned-word> ] replicate { } { } become drop ] unit-test
47 ! Bug: code heap collection had to be done when data heap was
48 ! full, not just when code heap was full. If the code heap
49 ! contained dead code blocks referring to large data heap
50 ! objects, those large objects would continue to live on even
51 ! if the code blocks were not reachable, as long as the code
52 ! heap did not fill up.
53 : leak-step ( -- ) 800000 f <array> 1quotation call( -- obj ) drop ;
55 : leak-loop ( -- ) 100 [ leak-step ] times ;
57 { } [ leak-loop ] long-unit-test
59 ! Bug: allocation of large objects directly into tenured space
60 ! can proceed past the high water mark.
62 ! Suppose the nursery and aging spaces are mostly comprised of
63 ! reachable objects. When doing a full GC, objects from young
64 ! generations ere promoted *before* unreachable objects in
65 ! tenured space are freed by the sweep phase. So if large object
66 ! allocation filled up the heap past the high water mark, this
67 ! promotion might trigger heap growth, even if most of those
68 ! large objects are unreachable.
74 data-room tenured>> size>>
77 4 [ 120 1024 * f <array> ] replicate foo set-global
78 100 [ 256 1024 * f <array> drop ] times
81 data-room tenured>> size>>
85 ! Perform one gc cycle. Then increase the stack height by 100 and
86 ! force a gc cycle again.
90 { 1 2 3 } { 4 5 6 } <effect> drop ;
92 : deep-stack-minor-gc ( n -- )
94 dup 0 > [ 1 - deep-stack-minor-gc ] [
95 drop 100000 [ perform ] times
100 minor-gc 100 deep-stack-minor-gc
104 TUPLE: tup2 a b c d ;
107 20 f <array> 20 f <array> assert=
108 ! Allocates a byte array so large that the next allocation will
110 drop 2097103 <byte-array> ;
113 9 <iota> [ inner ] map
114 ! D 0 is scrubbed, but if the branch calling 'inner' was
115 ! called, then both D 0 and D 1 should have been scrubbed.