1 USING: accessors arrays assocs bit-arrays classes.struct combinators
2 combinators.short-circuit compiler compiler.cfg.debugger
3 compiler.cfg.instructions compiler.cfg.stack-frame compiler.cfg.utilities
4 compiler.codegen.gc-maps compiler.units fry generic grouping kernel math
5 namespaces random sequences sequences.generalizations slots.syntax
6 tools.gc-decode tools.test vm vocabs words compiler.cfg.linearization ;
7 QUALIFIED: cpu.x86.features.private
8 QUALIFIED: crypto.aes.utils
12 IN: tools.gc-decode.tests
14 ! byte-array>bit-array
21 B{ 239 1 } byte-array>bit-array
24 { ?{ t t t t t t t t } } [ B{ 255 } byte-array>bit-array ] unit-test
28 \ effects:<effect> word>gc-info scrub-bits
30 ?{ t t t f t t t t } ! 64-bit
31 ?{ t t t t f f f f f t t t t } ! 32-bit TODO
38 \ decode-gc-maps word>gc-info scrub-bits
43 \ effects:<effect> decode-gc-maps empty?
47 \ + decode-gc-maps empty?
52 \ decode-gc-maps decode-gc-maps
55 : cfg>gc-maps ( cfg -- gc-maps )
56 cfg>insns [ gc-map-insn? ] filter [ gc-map>> ] map
57 [ gc-map-needed? ] filter ;
59 : tally-gc-maps ( gc-maps -- seq/f )
61 [ [ scrub-d>> length ] map supremum ]
62 [ [ scrub-r>> length ] map supremum ]
63 [ [ gc-root-offsets ] map largest-spill-slot ]
64 [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
66 } cleave 5 narray ] if-empty ;
68 ! Like word>gc-info but uses the compiler
69 : word>gc-info-expected ( word -- seq/f )
70 test-regs first dup stack-frame>> stack-frame
71 [ cfg>gc-maps tally-gc-maps ] with-variable ;
73 : same-gc-info? ( compiler-gc-info gc-info -- ? )
74 [ struct-slot-values = ]
75 [ [ not ] dip return-address-count>> 0 = and ] 2bi or ;
77 ! Do it also for a bunch of random words
78 : normal? ( word -- ? )
79 { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
82 all-words [ normal? ] filter 50 sample
83 [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? not ] filter
86 : base-pointer-groups-expected ( word -- seq )
87 test-regs first dup stack-frame>> stack-frame [
88 cfg>gc-maps [ derived-root-offsets { } like ] { } map-as
91 : base-pointer-groups-decoded ( word -- seq )
92 word>gc-info base-pointer-groups [
93 [ swap 2array ] map-index [ nip -1 = not ] assoc-filter
98 \ llvm.types:resolve-types
99 [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
104 \ llvm.types:resolve-types
105 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
109 \ opencl:cl-queue-kernel
110 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
114 \ crypto.aes.utils:bytes>words
115 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
119 \ cpu.x86.features.private:(sse-version)
120 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
123 ! Ensure deterministic gc map generation.
124 : recompile-word>gc-info ( word -- gc-info )
125 [ 1array compile ] keep word>gc-info ;
127 : deterministic-gc-info? ( word -- ? )
129 _ recompile-word>gc-info struct-slot-values
130 dup last 0 = [ drop f ] when
131 ] replicate all-equal? ;
135 \ opencl:cl-queue-kernel deterministic-gc-info?