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 literals 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 ! The difference is because Windows stack references are
76 ! longer because of the home space.
77 { ${ os windows? 156 155 ? { ?{ f t t t t } { } } } }
79 \ effects:<effect> word>gc-maps
84 \ + word>gc-maps empty?
88 \ word>gc-maps word>gc-maps
93 all-words [ normal? ] filter 50 sample
94 [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? ] reject
97 ! Originally from llvm.types, but llvm moved to unmaintained
98 TYPEDEF: void* LLVMTypeRef
99 TYPEDEF: void* LLVMTypeHandleRef
100 FUNCTION: LLVMTypeRef LLVMResolveTypeHandle ( LLVMTypeHandleRef TypeHandle )
101 FUNCTION: LLVMTypeHandleRef LLVMCreateTypeHandle ( LLVMTypeRef PotentiallyAbstractTy )
102 FUNCTION: void LLVMRefineType ( LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy )
103 FUNCTION: void LLVMDisposeTypeHandle ( LLVMTypeHandleRef TypeHandle )
105 : resolve-types ( typeref typeref -- typeref )
106 over LLVMCreateTypeHandle [ LLVMRefineType ] dip
107 [ LLVMResolveTypeHandle ] keep LLVMDisposeTypeHandle ;
109 ! base-pointer-groups
112 [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
118 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
122 \ opencl:cl-queue-kernel
123 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
127 \ crypto.aes.utils:bytes>words
128 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
132 \ cpu.x86.features.private:(sse-version)
133 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
138 \ gtk-samples.opengl:opengl-main
139 [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
142 ! Ensure deterministic gc map generation.
143 : recompile-word>gc-info ( word -- gc-info )
144 [ 1array compile ] keep word>gc-info ;
146 : deterministic-gc-info? ( word -- ? )
148 _ recompile-word>gc-info struct-slot-values
149 dup last 0 = [ drop f ] when
150 ] replicate all-equal? ;
153 \ opencl:cl-queue-kernel deterministic-gc-info?
158 ! TODO: try on 32 bit \ feedback-format: