/
gc-maps-tests.factor
192 lines (157 loc) · 4.03 KB
/
gc-maps-tests.factor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
USING: accessors alien.c-types arrays bit-arrays byte-arrays
classes.struct compiler.cfg compiler.cfg.instructions
compiler.cfg.stack-frame compiler.cfg.utilities
compiler.codegen.gc-maps compiler.codegen.relocation cpu.architecture
cpu.x86 kernel layouts make math namespaces sequences
specialized-arrays system tools.test ;
QUALIFIED: vm
SPECIALIZED-ARRAY: uint
IN: compiler.codegen.gc-maps.tests
SINGLETON: fake-cpu
fake-cpu \ cpu set
M: fake-cpu gc-root-offset ;
[
init-relocation
V{ } clone return-addresses set
V{ } clone gc-maps set
50 <byte-array> %
<gc-map> gc-map-here
50 <byte-array> %
T{ gc-map
{ gc-roots V{ 1 3 } }
{ derived-roots V{ { 2 4 } } }
} gc-map-here
emit-gc-maps
] B{ } make
"result" set
{ 0 } [ "result" get length 16 mod ] unit-test
[
100 <byte-array> %
! The below data is 29 bytes -- 15 bytes padding needed to
! align
15 <byte-array> %
! Bitmap - 1 byte
?{
! gc-roots
f t f t
} underlying>> %
! Derived pointers - 12 bytes
uint-array{ -1 -1 4 } underlying>> %
! Return addresses - 4 bytes
uint-array{ 100 } underlying>> %
! GC info footer - 12 bytes
S{ vm:gc-info
{ gc-root-count 4 }
{ derived-root-count 3 }
{ return-address-count 1 }
} (underlying)>> %
] B{ } make
"expect" set
{ t } [ "result" get length "expect" get length = ] unit-test
{ t } [ "result" get "expect" get = ] unit-test
! Fix the gc root offset calculations
SINGLETON: linux-x86.64
M: linux-x86.64 reserved-stack-space 0 ;
M: linux-x86.64 gc-root-offset
n>> spill-offset cell + cell /i ;
: cfg-w-spill-area-base ( base -- cfg )
stack-frame new swap >>spill-area-base
{ } insns>cfg swap >>stack-frame ;
: array>spill-slots ( seq -- spills )
[ spill-slot boa ] map ;
: <gc-map/spills> ( spills -- gc-map )
array>spill-slots { } gc-map boa ;
cpu x86.64? [
linux-x86.64 \ cpu set
! gc-root-offsets
{ { 1 3 } } [
0 cfg-w-spill-area-base cfg [
{ 0 16 } <gc-map/spills> gc-root-offsets
] with-variable
] unit-test
{ { 6 10 } } [
32 cfg-w-spill-area-base cfg [
{ 8 40 } <gc-map/spills> gc-root-offsets
] with-variable
] unit-test
{ 5 B{ 18 } } [
0 cfg-w-spill-area-base cfg [
{ 0 24 } <gc-map/spills> 1array
[ emit-gc-info-bitmap ] B{ } make
] with-variable
] unit-test
{ 9 B{ 32 1 } } [
32 cfg-w-spill-area-base cfg [
{ 0 24 } <gc-map/spills> 1array
[ emit-gc-info-bitmap ] B{ } make
] with-variable
] unit-test
fake-cpu \ cpu set
] when
! largest-spill-slot
{
5 0 4 1
} [
{ { 4 } } largest-spill-slot
{ { } } largest-spill-slot
{ { 2 3 } { 0 } } largest-spill-slot
{ { 0 } } largest-spill-slot
] unit-test
! gc-map-needed?
{ f } [
T{ gc-map } gc-map-needed?
] unit-test
! emit-gc-info-bitmap
{
0 V{ }
} [
{ T{ gc-map } } [ emit-gc-info-bitmap ] V{ } make
] unit-test
! ! derived-root-offsets
{
V{ { 2 4 } }
} [
T{ gc-map { derived-roots V{ { 2 4 } } } }
derived-root-offsets
] unit-test
! emit-base-tables
{
3 B{ 255 255 255 255 255 255 255 255 4 0 0 0 }
} [
{ T{ gc-map { derived-roots V{ { 2 4 } } } } }
[ emit-base-tables ] B{ } make
] unit-test
! serialize-gc-maps
{
B{ 0 0 0 0 }
} [
{ } return-addresses set serialize-gc-maps
] unit-test
{
B{ 123 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 }
} [
{ 123 } return-addresses set
{ T{ gc-map } } gc-maps set
serialize-gc-maps
] unit-test
! gc-info + ret-addr + 9bits (5+2+2) = 20 + 4 + 2 = 26
{ 17 } [
{
T{ gc-map
{ gc-roots V{ 1 3 } }
}
} gc-maps set
{ 123 } return-addresses set
serialize-gc-maps length
] unit-test
! gc-info + ret-addr + 3 base-pointers + 9bits = 20 + 4 + 12 + 2 = 38
{ 29 } [
{
T{ gc-map
{ gc-roots V{ 1 3 } }
{ derived-roots V{ { 2 4 } } }
}
} gc-maps set
{ 123 } return-addresses set
serialize-gc-maps length
] unit-test