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 t f t t t t } ! 64-bit
31 ?{ t t t t f f f f f t t t t } ! 32-bit
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 [ [ check-d>> length ] map supremum ]
64 [ [ check-r>> length ] map supremum ]
65 [ [ gc-root-offsets ] map largest-spill-slot ]
66 [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
68 } cleave 7 narray ] if-empty ;
70 ! Like word>gc-info but uses the compiler
71 : word>gc-info-expected ( word -- seq/f )
72 test-regs first dup stack-frame>> stack-frame
73 [ cfg>gc-maps tally-gc-maps ] with-variable ;
75 : same-gc-info? ( compiler-gc-info gc-info -- ? )
76 [ struct-slot-values = ]
77 [ [ not ] dip return-address-count>> 0 = and ] 2bi or ;
79 ! Do it also for a bunch of random words
80 : normal? ( word -- ? )
81 { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
84 all-words [ normal? ] filter 50 sample
85 [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? not ] filter
88 : base-pointer-groups-expected ( word -- seq )
89 test-regs first dup stack-frame>> stack-frame [
90 cfg>gc-maps [ derived-root-offsets { } like ] { } map-as
93 : base-pointer-groups-decoded ( word -- seq )
94 word>gc-info base-pointer-groups [
95 [ swap 2array ] map-index [ nip -1 = not ] assoc-filter
100 \ llvm.types:resolve-types
101 [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
106 \ llvm.types:resolve-types
107 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
111 \ opencl:cl-queue-kernel
112 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
116 \ crypto.aes.utils:bytes>words
117 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
121 \ cpu.x86.features.private:(sse-version)
122 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
125 ! Ensure deterministic gc map generation.
126 : recompile-word>gc-info ( word -- gc-info )
127 [ 1array compile ] keep word>gc-info ;
129 : deterministic-gc-info? ( word -- ? )
131 _ recompile-word>gc-info struct-slot-values
132 dup last 0 = [ drop f ] when
133 ] replicate all-equal? ;
137 \ opencl:cl-queue-kernel deterministic-gc-info?