1 USING: accessors alien.c-types alien.syntax arrays assocs bit-arrays
2 classes.struct combinators.short-circuit compiler compiler.cfg
3 compiler.cfg.debugger compiler.cfg.instructions
4 compiler.cfg.linearization compiler.codegen.gc-maps compiler.units fry
5 generic grouping io io.encodings.binary io.streams.byte-array kernel
6 math namespaces random sequences system tools.image-analyzer.gc-info
7 tools.image-analyzer.utils tools.test vm vocabs words ;
8 IN: tools.image-analyzer.gc-info.tests
9 QUALIFIED: cpu.x86.features.private
10 QUALIFIED: crypto.aes.utils
12 QUALIFIED: gtk-samples.opengl
15 : normal? ( word -- ? )
16 { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
18 : word>gc-info ( word -- gc-info )
19 word>byte-array binary <byte-reader> <backwards-reader> [
20 gc-info read-struct-safe
23 : cfg>gc-maps ( cfg -- gc-maps )
24 cfg>insns [ gc-map-insn? ] filter [ gc-map>> ] map
25 [ gc-map-needed? ] filter ;
27 : tally-gc-maps ( gc-maps -- seq/f )
29 [ [ gc-root-offsets ] map largest-spill-slot ]
30 [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
34 ! Like word>gc-info but uses the compiler
35 : word>gc-info-expected ( word -- seq/f )
36 test-regs first [ cfg set ] [ cfg>gc-maps tally-gc-maps ] bi ;
38 ! Handle f f as input. Deferred words don't have any gc-info. See #1394.
39 : same-gc-info? ( compiler-gc-info/f gc-info/f -- ? )
43 [ struct-slot-values = ]
44 [ [ not ] dip return-address-count>> 0 = and ] 2bi or
47 : base-pointer-groups-expected ( word -- seq )
48 test-regs first cfg>gc-maps [ derived-root-offsets { } like ] { } map-as ;
50 : base-pointer-groups-decoded ( word -- seq )
52 second second [ swap 2array ] map-index
53 [ nip -1 = ] assoc-reject
56 ! byte-array>bit-array
63 B{ 239 1 } byte-array>bit-array
66 { ?{ t t t t t t t t } } [ B{ 255 } byte-array>bit-array ] unit-test
70 \ effects:<effect> word>gc-maps empty?
75 { { 155 { ?{ f t t t t } { } } } }
77 \ effects:<effect> word>gc-maps
82 \ + word>gc-maps empty?
86 \ word>gc-maps word>gc-maps
91 all-words [ normal? ] filter 50 sample
92 [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? ] reject
95 ! Originally from llvm.types, but llvm moved to unmaintained
96 TYPEDEF: void* LLVMTypeRef
97 TYPEDEF: void* LLVMTypeHandleRef
98 FUNCTION: LLVMTypeRef LLVMResolveTypeHandle ( LLVMTypeHandleRef TypeHandle )
99 FUNCTION: LLVMTypeHandleRef LLVMCreateTypeHandle ( LLVMTypeRef PotentiallyAbstractTy )
100 FUNCTION: void LLVMRefineType ( LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy )
101 FUNCTION: void LLVMDisposeTypeHandle ( LLVMTypeHandleRef TypeHandle )
103 : resolve-types ( typeref typeref -- typeref )
104 over LLVMCreateTypeHandle [ LLVMRefineType ] dip
105 [ LLVMResolveTypeHandle ] keep LLVMDisposeTypeHandle ;
107 ! base-pointer-groups
110 [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
116 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
120 \ opencl:cl-queue-kernel
121 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
125 \ crypto.aes.utils:bytes>words
126 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
130 \ cpu.x86.features.private:(sse-version)
131 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
136 \ gtk-samples.opengl:opengl-main
137 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
140 ! Ensure deterministic gc map generation.
141 : recompile-word>gc-info ( word -- gc-info )
142 [ 1array compile ] keep word>gc-info ;
144 : deterministic-gc-info? ( word -- ? )
146 _ recompile-word>gc-info struct-slot-values
147 dup last 0 = [ drop f ] when
148 ] replicate all-equal? ;
151 \ opencl:cl-queue-kernel deterministic-gc-info?
156 ! TODO: try on 32 bit \ feedback-format: