]> gitweb.factorcode.org Git - factor.git/blob - core/memory/memory-tests.factor
VM: make save-image throw exception on error (#1090)
[factor.git] / core / memory / memory-tests.factor
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 ;
5 IN: memory.tests
6
7 [ save-image-and-exit ] must-fail
8
9 [ "does/not/exist" save-image ] must-fail
10
11 [
12     os windows? "C:\\windows\\hello-windows" "/usr/bin/hello-unix" ?
13     save-image
14 ] must-fail
15
16 ! Tests for 'instances'
17 [ [ ] instances ] must-infer
18 2 [ [ [ 3 throw ] instances ] must-fail ] times
19
20 ! Tests for 'become'
21 { } [ { } { } become ] unit-test
22
23 ! Become something when it's on the data stack.
24 { "replacer" } [
25     "original" dup 1array { "replacer" } become
26 ] unit-test
27
28 ! Nested in aging
29 { "replacer" } [
30     "original" [ 5 [ 1array ] times ] [ 1array ] bi
31     minor-gc
32     { "replacer" } become 5 [ first ] times
33 ] unit-test
34
35 ! Also when it is nested in nursery
36 { "replacer" } [
37     minor-gc
38     "original" [ 5 [ 1array ] times ] [ 1array ] bi { "replacer" } become
39     5 [ first ] times
40 ] unit-test
41
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
45
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 ;
53
54 : leak-loop ( -- ) 100 [ leak-step ] times ;
55
56 { } [ leak-loop ] unit-test
57
58 ! Bug: allocation of large objects directly into tenured space
59 ! can proceed past the high water mark.
60 !
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.
68 SYMBOL: foo
69
70 { } [
71     gc
72
73     data-room tenured>> size>>
74
75     10 [
76         4 [ 120 1024 * f <array> ] replicate foo set-global
77         100 [ 256 1024 * f <array> drop ] times
78     ] times
79
80     data-room tenured>> size>>
81     assert=
82 ] unit-test
83
84 ! Perform one gc cycle. Then increase the stack height by 100 and
85 ! force a gc cycle again.
86 SYMBOL: foo-var
87
88 : perform ( -- )
89     { 1 2 3 } { 4 5 6 } <effect> drop ;
90
91 : deep-stack-minor-gc ( n -- )
92     dup [
93         dup 0 > [ 1 - deep-stack-minor-gc ] [
94             drop 100000 [ perform ] times
95         ] if
96     ] dip foo-var set ;
97
98 { } [
99     minor-gc 100 deep-stack-minor-gc
100 ] unit-test
101
102 ! Bug #1289
103 TUPLE: tup2 a b c d ;
104
105 : inner ( k -- n )
106     20 f <array> 20 f <array> assert=
107     ! Allocates a byte array so large that the next allocation will
108     ! trigger a gc.
109     drop 2097103 <byte-array> ;
110
111 : outer ( -- lag )
112     9 iota [ inner ] map
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.
115     0 9 1 tup2 boa ;
116
117 { } [
118     outer drop
119 ] unit-test