X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fgeneric%2Fgenesis.lisp;h=95be9b3c88b11e9b3914d05cbcb6c55583692875;hb=cd12bb346dbbd1e077ed3e14a9db4e1cc227c244;hp=d6e91ad90df9686330332e7323301b8b94617435;hpb=9603675940cce3bcac93b354dca62d20c991cbce;p=sbcl.git diff --git a/src/compiler/generic/genesis.lisp b/src/compiler/generic/genesis.lisp index d6e91ad..95be9b3 100644 --- a/src/compiler/generic/genesis.lisp +++ b/src/compiler/generic/genesis.lisp @@ -280,7 +280,7 @@ (high low &optional gspace word-offset)) (:copier nil)) ;; the GSPACE that this descriptor is allocated in, or NIL if not set yet. - (gspace nil :type (or gspace null)) + (gspace nil :type (or gspace (eql :load-time-value) null)) ;; the offset in words from the start of GSPACE, or NIL if not set yet (word-offset nil :type (or sb!vm:word null)) ;; the high and low halves of the descriptor @@ -400,21 +400,31 @@ ;;; (DESCRIPTOR-WORD-OFFSET DES), and return the GSPACE. (declaim (ftype (function (descriptor) gspace) descriptor-intuit-gspace)) (defun descriptor-intuit-gspace (des) - (if (descriptor-gspace des) - (descriptor-gspace des) - ;; KLUDGE: It's not completely clear to me what's going on here; - ;; this is a literal translation from of some rather mysterious - ;; code from CMU CL's DESCRIPTOR-SAP function. Some explanation - ;; would be nice. -- WHN 19990817 - (let ((lowtag (descriptor-lowtag des)) - (high (descriptor-high des)) - (low (descriptor-low des))) - (if (or (eql lowtag sb!vm:fun-pointer-lowtag) - (eql lowtag sb!vm:instance-pointer-lowtag) - (eql lowtag sb!vm:list-pointer-lowtag) - (eql lowtag sb!vm:other-pointer-lowtag)) + (or (descriptor-gspace des) + + ;; gspace wasn't set, now we have to search for it. + (let ((lowtag (descriptor-lowtag des)) + (high (descriptor-high des)) + (low (descriptor-low des))) + + ;; Non-pointer objects don't have a gspace. + (unless (or (eql lowtag sb!vm:fun-pointer-lowtag) + (eql lowtag sb!vm:instance-pointer-lowtag) + (eql lowtag sb!vm:list-pointer-lowtag) + (eql lowtag sb!vm:other-pointer-lowtag)) + (error "don't even know how to look for a GSPACE for ~S" des)) + (dolist (gspace (list *dynamic* *static* *read-only*) - (error "couldn't find a GSPACE for ~S" des)) + (error "couldn't find a GSPACE for ~S" des)) + ;; Bounds-check the descriptor against the allocated area + ;; within each gspace. + ;; + ;; Most of the faffing around in here involving ash and + ;; various computed shift counts is due to the high/low + ;; split representation of the descriptor bits and an + ;; apparent disinclination to create intermediate values + ;; larger than a target fixnum. + ;; ;; This code relies on the fact that GSPACEs are aligned ;; such that the descriptor-low-bits low bits are zero. (when (and (>= high (ash (gspace-word-address gspace) @@ -422,6 +432,8 @@ (<= high (ash (+ (gspace-word-address gspace) (gspace-free-word-index gspace)) (- sb!vm:word-shift descriptor-low-bits)))) + ;; Update the descriptor with the correct gspace and the + ;; offset within the gspace and return the gspace. (setf (descriptor-gspace des) gspace) (setf (descriptor-word-offset des) (+ (ash (- high (ash (gspace-word-address gspace) @@ -430,8 +442,7 @@ (- descriptor-low-bits sb!vm:word-shift)) (ash (logandc2 low sb!vm:lowtag-mask) (- sb!vm:word-shift)))) - (return gspace))) - (error "don't even know how to look for a GSPACE for ~S" des))))) + (return gspace)))))) (defun make-random-descriptor (value) (make-descriptor (logand (ash value (- descriptor-low-bits)) @@ -529,7 +540,7 @@ (read-wordindexed address 0)) ;;; (Note: In CMU CL, this function expected a SAP-typed ADDRESS -;;; value, instead of the SAP-INT we use here.) +;;; value, instead of the object-and-offset we use here.) (declaim (ftype (function (descriptor sb!vm:word descriptor) (values)) note-load-time-value-reference)) (defun note-load-time-value-reference (address offset marker) @@ -547,15 +558,7 @@ (defun write-wordindexed (address index value) #!+sb-doc "Write VALUE displaced INDEX words from ADDRESS." - ;; KLUDGE: There is an algorithm (used in DESCRIPTOR-INTUIT-GSPACE) - ;; for calculating the value of the GSPACE slot from scratch. It - ;; doesn't work for all values, only some of them, but mightn't it - ;; be reasonable to see whether it works on VALUE before we give up - ;; because (DESCRIPTOR-GSPACE VALUE) isn't set? (Or failing that, - ;; perhaps write a comment somewhere explaining why it's not a good - ;; idea?) -- WHN 19990817 - (if (and (null (descriptor-gspace value)) - (not (null (descriptor-word-offset value)))) + (if (eql (descriptor-gspace value) :load-time-value) (note-load-time-value-reference address (- (ash index sb!vm:word-shift) (logand (descriptor-bits address) @@ -1638,33 +1641,34 @@ core and return a descriptor to it." (defvar *load-time-code-fixups*) #!+x86 -(defun note-load-time-code-fixup (code-object offset value kind) +(defun note-load-time-code-fixup (code-object offset) ;; If CODE-OBJECT might be moved (when (= (gspace-identifier (descriptor-intuit-gspace code-object)) dynamic-core-space-id) - ;; FIXME: pushed thing should be a structure, not just a list - (push (list code-object offset value kind) *load-time-code-fixups*)) + (push offset (gethash (descriptor-bits code-object) + *load-time-code-fixups* + nil))) (values)) #!+x86 (defun output-load-time-code-fixups () - (dolist (fixups *load-time-code-fixups*) - (let ((code-object (first fixups)) - (offset (second fixups)) - (value (third fixups)) - (kind (fourth fixups))) - (cold-push (cold-cons - (cold-intern :load-time-code-fixup) - (cold-cons - code-object - (cold-cons - (number-to-core offset) - (cold-cons - (number-to-core value) - (cold-cons - (cold-intern kind) - *nil-descriptor*))))) - *current-reversed-cold-toplevels*)))) + (maphash + (lambda (code-object-address fixup-offsets) + (let ((fixup-vector + (allocate-vector-object + *dynamic* sb-vm:n-word-bits (length fixup-offsets) + sb!vm:simple-array-unsigned-byte-32-widetag))) + (do ((index sb!vm:vector-data-offset (1+ index)) + (fixups fixup-offsets (cdr fixups))) + ((null fixups)) + (write-wordindexed fixup-vector index + (make-random-descriptor (car fixups)))) + ;; KLUDGE: The fixup vector is stored as the first constant, + ;; not as a separately-named slot. + (write-wordindexed (make-random-descriptor code-object-address) + sb!vm:code-constants-offset + fixup-vector))) + *load-time-code-fixups*)) ;;; Given a pointer to a code object and an offset relative to the ;;; tail of the code object's header, return an offset relative to the @@ -1859,9 +1863,7 @@ core and return a descriptor to it." #!+x86 (unless (< fixed-up code-object-start-addr) (note-load-time-code-fixup code-object - after-header - value - kind)))) + after-header)))) (:relative ; (used for arguments to X86 relative CALL instruction) (let ((fixed-up (- (+ value un-fixed-up) gspace-byte-address @@ -1875,9 +1877,7 @@ core and return a descriptor to it." ;; a fixup. #!+x86 (note-load-time-code-fixup code-object - after-header - value - kind)))))))) + after-header)))))))) (values)) (defun resolve-assembler-fixups () @@ -2332,7 +2332,7 @@ core and return a descriptor to it." *nil-descriptor*))) *current-reversed-cold-toplevels*) (setf *load-time-value-counter* (1+ counter)) - (make-descriptor 0 0 nil counter))) + (make-descriptor 0 0 :load-time-value counter))) (defun finalize-load-time-value-noise () (cold-set (cold-intern '*!load-time-values*) @@ -3221,7 +3221,7 @@ initially undefined function references:~2%") sb!vm:unbound-marker-widetag)) *cold-assembler-fixups* *cold-assembler-routines* - #!+x86 *load-time-code-fixups*) + #!+x86 (*load-time-code-fixups* (make-hash-table))) ;; Prepare for cold load. (initialize-non-nil-symbols)