Finalizing initial pass on GC2

It was not a problem with the particular collector. All allocation
sites need to update the gc-roots-key with their static information.
This commit is contained in:
Jay McCarthy 2012-01-04 19:37:49 -07:00
parent 55e1df1445
commit c2355caef6
6 changed files with 45 additions and 17 deletions

View File

@ -225,10 +225,11 @@
[(_ fe ae ...) [(_ fe ae ...)
(with-syntax ([(env-id ...) (syntax-parameter-value #'mutator-env-roots)]) (with-syntax ([(env-id ...) (syntax-parameter-value #'mutator-env-roots)])
(if (syntax-parameter-value #'mutator-tail-call?) (if (syntax-parameter-value #'mutator-tail-call?)
; If this call is in tail position, we will not need access to its environment when it returns. ; If this call is in tail position, we will not need access
; to its environment when it returns.
(syntax/loc stx ((deref-proc fe) ae ...)) (syntax/loc stx ((deref-proc fe) ae ...))
; If this call is not in tail position, we make the environment at the call site ; If this call is not in tail position, we make the
; reachable. ; environment at the call site reachable.
#`(with-continuation-mark gc-roots-key #`(with-continuation-mark gc-roots-key
(list (make-env-root env-id) ...) (list (make-env-root env-id) ...)
#,(syntax/loc stx ((deref-proc fe) ae ...)))))])) #,(syntax/loc stx ((deref-proc fe) ae ...)))))]))
@ -363,6 +364,7 @@
(syntax-local-introduce #'scheme))]) (syntax-local-introduce #'scheme))])
#`(begin #`(begin
(require (only-in source [id renamed-id] ...)) (require (only-in source [id renamed-id] ...))
;; XXX make a macro to unify this and provide/lift
(define id (define id
(lambda args (lambda args
(unless (andmap (lambda (v) (and (location? v) (collector:flat? v))) args) (unless (andmap (lambda (v) (and (location? v) (collector:flat? v))) args)
@ -409,7 +411,21 @@
[(x (... ...)) [(x (... ...))
#'(mutator-app x (... ...))] #'(mutator-app x (... ...))]
[x (identifier? #'x) [x (identifier? #'x)
#'(collector:closure (closure-code 0 (mutator-lift id)) (vector))])))) ;; XXX Make a macro to unify this and mutator-lambda
(with-syntax
([(env-id (... ...)) (syntax-parameter-value #'mutator-env-roots)])
(if (syntax-parameter-value #'mutator-tail-call?)
(syntax/loc stx
(#%app collector:closure
(closure-code 0 (mutator-lift id))
(vector)))
(syntax/loc stx
(with-continuation-mark
gc-roots-key
(list (make-env-root env-id) (... ...))
(#%app collector:closure
(closure-code 0 (mutator-lift id))
(vector))))))]))))
... ...
(provide (rename-out [lifted-id id] (provide (rename-out [lifted-id id]
...))))])) ...))))]))

View File

@ -31,6 +31,9 @@ A collector for use in testing the random mutator generator.
(test (with-heap #(free free free) (test (with-heap #(free free free)
(n-free-blocks? 0 3)) (n-free-blocks? 0 3))
#t) #t)
(test (with-heap #(free free free free)
(n-free-blocks? 0 4))
#t)
(test (with-heap #(free free free) (test (with-heap #(free free free)
(n-free-blocks? 0 4)) (n-free-blocks? 0 4))
#f) #f)
@ -101,9 +104,13 @@ A collector for use in testing the random mutator generator.
(define (gc:closure-env-ref a i) (define (gc:closure-env-ref a i)
(if (gc:closure? a) (if (gc:closure? a)
(heap-ref (+ a 3 i)) (if (< i (heap-ref (+ a 2)))
(heap-ref (+ a 3 i))
(error 'closure-env-ref "closure-env-ref out of bounds"))
(error 'closure-env-ref "non closure"))) (error 'closure-env-ref "non closure")))
;; XXX test
(define (gc:flat? loc) (equal? (heap-ref loc) 'flat)) (define (gc:flat? loc) (equal? (heap-ref loc) 'flat))
(test (with-heap (vector 'free 'free 'pair 0 1 'flat 14) (test (with-heap (vector 'free 'free 'pair 0 1 'flat 14)
@ -230,9 +237,10 @@ A collector for use in testing the random mutator generator.
[(closure) [(closure)
(heap-set! white 'free) (heap-set! white 'free)
(heap-set! (+ white 1) 'free) (heap-set! (+ white 1) 'free)
(for ([i (in-range (heap-ref (+ white 2)))]) (define env-len (heap-ref (+ white 2)))
(heap-set! (+ white 3 i) 'free)) (heap-set! (+ white 2) 'free)
(heap-set! (+ white 2) 'free)] (for ([i (in-range env-len)])
(heap-set! (+ white 3 i) 'free))]
[else [else
(error 'free! "unknown tag ~s\n" (heap-ref white))]) (error 'free! "unknown tag ~s\n" (heap-ref white))])
(free! (cdr whites)))])) (free! (cdr whites)))]))
@ -264,10 +272,10 @@ A collector for use in testing the random mutator generator.
(cond (cond
[(< i (heap-size)) [(< i (heap-size))
(case (heap-ref i) (case (heap-ref i)
[(closure) (cons i (get-all-records (+ i 3 (heap-ref (+ i 2)))))] [(closure) (cons i (get-all-records (+ i 2 (heap-ref (+ i 2)) 1)))]
[(pair) (cons i (get-all-records (+ i 3)))] [(pair) (cons i (get-all-records (+ i 2 1)))]
[(flat) (cons i (get-all-records (+ i 2)))] [(flat) (cons i (get-all-records (+ i 1 1)))]
[(free) (get-all-records (+ i 1))] [(free) (get-all-records (+ i 0 1))]
[else (error 'get-all-records "Unknown tag ~e in cell ~e" (heap-ref i) i)])] [else (error 'get-all-records "Unknown tag ~e in cell ~e" (heap-ref i) i)])]
[else null])) [else null]))

View File

@ -15,7 +15,7 @@
; Finally it runs the sample tests distributed with the assignment ; Finally it runs the sample tests distributed with the assignment
(allocator-setup "../good-collectors/good-collector.rkt" 80) (allocator-setup "../good-collectors/good-collector.rkt" 110)
; Helper to generate long lists ; Helper to generate long lists
(define (gen-list x) (define (gen-list x)

View File

@ -1,5 +1,5 @@
#lang plai/gc2/mutator #lang plai/gc2/mutator
(allocator-setup "../good-collectors/good-collector.rkt" 84) (allocator-setup "../good-collectors/good-collector.rkt" 104)
(halt-on-errors) (halt-on-errors)
;(check-temps1 temps) -> boolean? ;(check-temps1 temps) -> boolean?

View File

@ -1,9 +1,13 @@
#lang plai/gc2/mutator #lang plai/gc2/mutator
(allocator-setup "../good-collectors/good-collector.rkt" 7) (allocator-setup "../good-collectors/good-collector.rkt" 10)
; 3
(define (go) (define (go)
; 2
(let ([obj 'z]) (let ([obj 'z])
2 3 9 10
; 3
(symbol? obj))) (symbol? obj)))
; 2
(go) (go)

View File

@ -56,7 +56,7 @@ END
(capture-output (test-mutator (build-path here "other-mutators" "begin.rkt"))) (capture-output (test-mutator (build-path here "other-mutators" "begin.rkt")))
=> =>
#<<END #<<END
Value at location 2: Value at location 8:
#t #t
END END