allocation.scm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; Interface to the VM for allocation
  3. ; (pre)allocates space for a small, fixed-sized objects
  4. (define (s48-make-available+gc len)
  5. (if (not (bytes-available? len))
  6. (s48-collect #f))
  7. (if (not (bytes-available? len))
  8. (error "Scheme 48 heap overflow")))
  9. ; actually allocate a small, fixed-sized object, with no heap check and no GC
  10. (define s48-allocate-small allocate)
  11. ; allocate a weak-pointer object, GCing to get room if necessary
  12. (define (s48-allocate-weak+gc len)
  13. (s48-allocate-traced+gc len))
  14. ; tell the GC not to collect in any case
  15. ; mainly used on startup during reading the image
  16. (define (s48-forbid-gc!)
  17. (unspecific))
  18. ; the GC may collect again
  19. (define (s48-allow-gc!)
  20. (unspecific))
  21. ; allocate a potentially large object containing pointers,
  22. ; GCing to get room if necessary
  23. (define (s48-allocate-traced+gc len)
  24. (if (not (bytes-available? len))
  25. (s48-collect #f))
  26. (if (not (bytes-available? len))
  27. null-address
  28. (allocate len)))
  29. ; allocate a potentially large object not containing pointers,
  30. ; GCing to get room if necessary
  31. ;; Same again. Just doing (define x y) for exported procedures X and Y
  32. ;; causes the Pre-Scheme compiler to emit bad code.
  33. (define (s48-allocate-untraced+gc len)
  34. (s48-allocate-traced+gc len))
  35. ; allocate an unmovable object (allocation uses the large area
  36. ; discarding the size of the object. The large area is collected with
  37. ; the non-copy algorithmus). GCing to get room if necessary
  38. (define (s48-allocate-untraced-unmovable+gc len)
  39. (s48-allocate-traced+gc len))
  40. ;; For allocation done outside the VM.
  41. (define (s48-allocate-stob type size)
  42. (let* ((traced? (< type least-b-vector-type))
  43. (length-in-bytes (if traced?
  44. (cells->bytes size)
  45. size))
  46. (needed (+ length-in-bytes (cells->bytes stob-overhead)))
  47. (thing (if traced?
  48. (s48-allocate-traced+gc needed)
  49. (s48-allocate-untraced+gc needed))))
  50. (if (null-address? thing)
  51. (error "insufficient heap space for external allocation"))
  52. (store! thing (make-header type length-in-bytes))
  53. (address->stob-descriptor (address+ thing
  54. (cells->bytes stob-overhead)))))