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 [ -1 = ] reject-values
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 ! The difference is because Windows stack references are
76 ! longer because of the home space.
78 { 156 { ?{ f f f f f t t t t } { } } }
82 { 155 { ?{ f t t t t } { } } }
86 \ effects:<effect> word>gc-maps first
91 \ + word>gc-maps empty?
95 \ word>gc-maps word>gc-maps
100 all-words [ normal? ] filter 50 sample
101 [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? ] reject
104 ! Originally from llvm.types, but llvm moved to unmaintained
105 TYPEDEF: void* LLVMTypeRef
106 TYPEDEF: void* LLVMTypeHandleRef
107 FUNCTION: LLVMTypeRef LLVMResolveTypeHandle ( LLVMTypeHandleRef TypeHandle )
108 FUNCTION: LLVMTypeHandleRef LLVMCreateTypeHandle ( LLVMTypeRef PotentiallyAbstractTy )
109 FUNCTION: void LLVMRefineType ( LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy )
110 FUNCTION: void LLVMDisposeTypeHandle ( LLVMTypeHandleRef TypeHandle )
112 : resolve-types ( typeref typeref -- typeref )
113 over LLVMCreateTypeHandle [ LLVMRefineType ] dip
114 [ LLVMResolveTypeHandle ] keep LLVMDisposeTypeHandle ;
116 ! base-pointer-groups
119 [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
125 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
129 \ opencl:cl-queue-kernel
130 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
134 \ crypto.aes.utils:bytes>words
135 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
139 \ cpu.x86.features.private:(sse-version)
140 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
145 \ gtk-samples.opengl:opengl-main
146 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
149 ! Ensure deterministic gc map generation.
150 : recompile-word>gc-info ( word -- gc-info )
151 [ 1array compile ] keep word>gc-info ;
153 : deterministic-gc-info? ( word -- ? )
155 _ recompile-word>gc-info struct-slot-values
156 dup last 0 = [ drop f ] when
157 ] replicate all-equal? ;
160 \ opencl:cl-queue-kernel deterministic-gc-info?
165 ! TODO: try on 32 bit \ feedback-format: