trace-continuation.scm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, David Frese, Mike Sperber
  3. ; Code shared by both GCs for the GC package.
  4. ; We can't put it in a separate package because of circular
  5. ; dependencies.
  6. ; Tracing continuations
  7. (define (trace-continuation contents-pointer size)
  8. (let* ((code (continuation-code contents-pointer))
  9. (pc (continuation-pc contents-pointer))
  10. (code-pointer (address+ (address-after-header code)
  11. (extract-fixnum pc)))
  12. (mask-size (fetch-byte (address+ code-pointer gc-mask-size-offset))))
  13. (if (= mask-size 0)
  14. (s48-trace-locations! contents-pointer
  15. (address+ contents-pointer size))
  16. (let ((data-pointer (address+ contents-pointer
  17. continuation-registers-size)))
  18. (s48-trace-locations! contents-pointer data-pointer)
  19. (s48-trace-continuation-contents! data-pointer
  20. code-pointer
  21. mask-size))))
  22. (unspecific))
  23. ; The extra values added when a continuation is moved to the heap are not
  24. ; included in the continuation's mask.
  25. (define continuation-registers-size
  26. (cells->a-units continuation-cells))
  27. ; Exported for use by the stack code.
  28. (define (s48-trace-continuation-contents! contents-pointer
  29. code-pointer
  30. mask-size)
  31. (let ((mask-pointer (address+ code-pointer (+ gc-mask-offset 1))))
  32. (let byte-loop ((mask-ptr (address- mask-pointer mask-size))
  33. (trace-ptr contents-pointer))
  34. (if (not (address= mask-ptr mask-pointer))
  35. (let bit-loop ((mask (fetch-byte mask-ptr)) (ptr trace-ptr))
  36. (if (= mask 0)
  37. (byte-loop (address+ mask-ptr 1)
  38. (address+ trace-ptr (cells->a-units 8)))
  39. (begin
  40. (if (odd? mask)
  41. ;; can't use s48-trace-value here:
  42. ;; `s48-trace-locations!' triggers the write barrier
  43. (s48-trace-locations! ptr (address1+ ptr)))
  44. (bit-loop (arithmetic-shift-right mask 1)
  45. (address1+ ptr)))))
  46. (unspecific)))))
  47. (define (odd? x)
  48. (= (bitwise-and x 1)
  49. 1))
  50. (define (continuation-code contents-pointer)
  51. (fetch (address+ contents-pointer
  52. (cells->a-units continuation-code-index))))
  53. (define (continuation-pc contents-pointer)
  54. (fetch (address+ contents-pointer
  55. (cells->a-units continuation-pc-index))))
  56. (define (continuation-header? x)
  57. (= (header-type x)
  58. (enum stob continuation)))