cs: check memory limit in make-phantom-bytes

This commit is contained in:
Matthew Flatt 2020-06-29 13:44:07 -06:00
parent 9e74f2d6c8
commit b00e8415b7
2 changed files with 8 additions and 1 deletions

View File

@ -247,6 +247,10 @@
(unless (eq? 'cgc (system-type 'gc))
(define s (make-semaphore))
(define c (make-custodian))
(define bits (let loop ([bits 29])
(if (fixnum? (expt 2 bits))
bits
(loop (sub1 bits)))))
(define t (parameterize ([current-custodian c])
(thread (lambda ()
(semaphore-wait s)

View File

@ -123,7 +123,7 @@
;; `post-allocated+overhead` seems to be too long a wait, because
;; that value may include underused pages that have locked objects.
;; Using just `post-allocated` is too small, because it may force an
;; immediate major GC too soon. Split the difference.
;; immediate major GC too soon. Split the difference.
(set! trigger-major-gc-allocated (* GC-TRIGGER-FACTOR (- post-allocated (bytes-finalized))))
(set! trigger-major-gc-allocated+overhead (* GC-TRIGGER-FACTOR post-allocated+overhead)))
(update-eq-hash-code-table-size!)
@ -490,6 +490,7 @@
(define/who (make-phantom-bytes k)
(check who exact-nonnegative-integer? k)
(guard-large-allocation who "byte string" k 1)
(let ([ph (create-phantom-bytes (make-phantom-bytevector k))])
(when (or (>= (bytes-allocated) trigger-major-gc-allocated)
(>= (current-memory-bytes) trigger-major-gc-allocated+overhead))
@ -499,6 +500,8 @@
(define/who (set-phantom-bytes! phantom-bstr k)
(check who phantom-bytes? phantom-bstr)
(check who exact-nonnegative-integer? k)
(when (> k (phantom-bytevector-length (phantom-bytes-pbv phantom-bstr)))
(guard-large-allocation who "byte string" k 1))
(set-phantom-bytevector-length! (phantom-bytes-pbv phantom-bstr) k))
;; ----------------------------------------