allocation.scm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, David Frese, Marcus Crestani,
  3. ; Mike Sperber
  4. ; Interface to the VM for allocation
  5. ; (pre)allocates space for a small, fixed-sized objects
  6. (define (s48-make-available+gc len)
  7. (if (not (bytes-available? len))
  8. (s48-collect #f))
  9. (if (not (bytes-available? len))
  10. (error "Scheme 48 heap overflow")))
  11. ; actually allocate a small, fixed-sized object, with no heap check and no GC
  12. (define s48-allocate-small allocate)
  13. ; allocate a weak-pointer object, GCing to get room if necessary
  14. (define (s48-allocate-weak+gc len)
  15. (s48-allocate-traced+gc len))
  16. ; tell the GC not to collect in any case
  17. ; mainly used on startup during reading the image
  18. (define (s48-forbid-gc!)
  19. (unspecific))
  20. ; the GC may collect again
  21. (define (s48-allow-gc!)
  22. (unspecific))
  23. ; allocate a potentially large object containing pointers,
  24. ; GCing to get room if necessary
  25. (define (s48-allocate-traced+gc len)
  26. (if (not (bytes-available? len))
  27. (s48-collect #f))
  28. (if (not (bytes-available? len))
  29. null-address
  30. (allocate len)))
  31. ; allocate a potentially large object not containing pointers,
  32. ; GCing to get room if necessary
  33. ;; Same again. Just doing (define x y) for exported procedures X and Y
  34. ;; causes the Pre-Scheme compiler to emit bad code.
  35. (define (s48-allocate-untraced+gc len)
  36. (s48-allocate-traced+gc len))
  37. ; unmovable objects are not supported.
  38. (define (s48-gc-can-allocate-unmovable?) #f)
  39. (define (s48-allocate-traced-unmovable+gc len)
  40. (= len 0) ;; for the type-checker
  41. (error "twospace gc does not support unmovable objects")
  42. null-address ;; for the correct signature
  43. )
  44. (define (s48-allocate-untraced-unmovable+gc len)
  45. (= len 0) ;; for the type-checker
  46. (error "twospace gc does not support unmovable objects")
  47. null-address ;; for the correct signature
  48. )
  49. (define (s48-unmovable? stob)
  50. (= stob 0) ;; for the type-checker
  51. #f)
  52. ;; For allocation done outside the VM.
  53. (define (s48-allocate-stob type size)
  54. (let* ((traced? (< type least-b-vector-type))
  55. (length-in-bytes (if traced?
  56. (cells->bytes size)
  57. size))
  58. (needed (+ length-in-bytes (cells->bytes stob-overhead)))
  59. (thing (if traced?
  60. (s48-allocate-traced+gc needed)
  61. (s48-allocate-untraced+gc needed))))
  62. (if (null-address? thing)
  63. (error "insufficient heap space for external allocation"))
  64. (store! thing (make-header type length-in-bytes))
  65. (address->stob-descriptor (address+ thing
  66. (cells->bytes stob-overhead)))))
  67. (define (s48-allocate-weak-stob type size)
  68. (s48-allocate-stob type size))
  69. (define (s48-allocate-unmovable-stob type size)
  70. (= type 0) ;; for the type-checker
  71. (= size 0) ;; for the type-checker
  72. (error "twospace gc does not support unmovable objects")
  73. 0 ;; for the correct signature
  74. )