1 USING: accessors byte-arrays effects kernel kernel.private math memory
2 prettyprint io sequences tools.test words namespaces layouts classes
3 classes.builtin arrays quotations system ;
4 FROM: tools.memory => data-room code-room ;
7 [ save-image-and-exit ] must-fail
9 [ "does/not/exist" save-image ] must-fail
12 os windows? "C:\\windows\\hello-windows" "/usr/bin/hello-unix" ?
16 ! Tests for 'instances'
17 [ [ ] instances ] must-infer
18 2 [ [ [ 3 throw ] instances ] must-fail ] times
21 { } [ { } { } become ] unit-test
23 ! Become something when it's on the data stack.
25 "original" dup 1array { "replacer" } become
30 "original" [ 5 [ 1array ] times ] [ 1array ] bi
32 { "replacer" } become 5 [ first ] times
35 ! Also when it is nested in nursery
38 "original" [ 5 [ 1array ] times ] [ 1array ] bi { "replacer" } become
42 ! Bug found on Windows build box, having too many words in the
43 ! image breaks 'become'
44 { } [ 100000 [ f <uninterned-word> ] replicate { } { } become drop ] unit-test
46 ! Bug: code heap collection had to be done when data heap was
47 ! full, not just when code heap was full. If the code heap
48 ! contained dead code blocks referring to large data heap
49 ! objects, those large objects would continue to live on even
50 ! if the code blocks were not reachable, as long as the code
51 ! heap did not fill up.
52 : leak-step ( -- ) 800000 f <array> 1quotation call( -- obj ) drop ;
54 : leak-loop ( -- ) 100 [ leak-step ] times ;
56 { } [ leak-loop ] unit-test
58 ! Bug: allocation of large objects directly into tenured space
59 ! can proceed past the high water mark.
61 ! Suppose the nursery and aging spaces are mostly comprised of
62 ! reachable objects. When doing a full GC, objects from young
63 ! generations ere promoted *before* unreachable objects in
64 ! tenured space are freed by the sweep phase. So if large object
65 ! allocation filled up the heap past the high water mark, this
66 ! promotion might trigger heap growth, even if most of those
67 ! large objects are unreachable.
73 data-room tenured>> size>>
76 4 [ 120 1024 * f <array> ] replicate foo set-global
77 100 [ 256 1024 * f <array> drop ] times
80 data-room tenured>> size>>
84 ! Perform one gc cycle. Then increase the stack height by 100 and
85 ! force a gc cycle again.
89 { 1 2 3 } { 4 5 6 } <effect> drop ;
91 : deep-stack-minor-gc ( n -- )
93 dup 0 > [ 1 - deep-stack-minor-gc ] [
94 drop 100000 [ perform ] times
99 minor-gc 100 deep-stack-minor-gc
103 TUPLE: tup2 a b c d ;
106 20 f <array> 20 f <array> assert=
107 ! Allocates a byte array so large that the next allocation will
109 drop 2097103 <byte-array> ;
113 ! D 0 is scrubbed, but if the branch calling 'inner' was
114 ! called, then both D 0 and D 1 should have been scrubbed.