- (dconsing 0)
- (inner-enclosed-profiles 0))
- (declare (type unsigned-byte dticks dconsing))
- (declare (type unsigned-byte inner-enclosed-profiles))
- (aver (typep dticks 'unsigned-byte))
- (aver (typep dconsing 'unsigned-byte))
- (aver (typep inner-enclosed-profiles 'unsigned-byte))
- (multiple-value-prog1
- (let* ((start-ticks (get-internal-ticks))
- (*enclosed-ticks* 0)
- (*enclosed-consing* 0)
- (*enclosed-profiles* 0)
- (nbf-pcounter *n-bytes-freed-or-purified-pcounter*)
- ;; Typically NBF-PCOUNTER will represent a bignum.
- ;; In general we don't want to cons up a new
- ;; bignum for every encapsulated call, so instead
- ;; we keep track of the PCOUNTER internals, so
- ;; that as long as we only cons small amounts,
- ;; we'll almost always just do fixnum arithmetic.
- ;; (And for encapsulated functions which cons
- ;; large amounts, then we don't much care about a
- ;; single extra consed bignum.)
- (start-consing-integer (pcounter-integer nbf-pcounter))
- (start-consing-fixnum (pcounter-fixnum nbf-pcounter)))
- (declare (inline pcounter-or-fixnum->integer))
- (multiple-value-prog1
- (multiple-value-call encapsulated-fun
- (sb-c:%more-arg-values arg-context
- 0
- arg-count))
- (let ((*computing-profiling-data-for* encapsulated-fun))
- (setf dticks (fastbig- (get-internal-ticks) start-ticks))
- (setf dconsing
- (if (eq (pcounter-integer nbf-pcounter)
- start-consing-integer)
- (- (pcounter-fixnum nbf-pcounter)
- start-consing-fixnum)
- (- (get-bytes-consed)
- (+ (pcounter-integer nbf-pcounter)
- (pcounter-fixnum nbf-pcounter)))))
- (setf inner-enclosed-profiles
- (pcounter-or-fixnum->integer *enclosed-profiles*))
- (let ((net-dticks (fastbig- dticks *enclosed-ticks*)))
- (fastbig-incf-pcounter-or-fixnum ticks net-dticks))
- (let ((net-dconsing (fastbig- dconsing *enclosed-consing*)))
- (fastbig-incf-pcounter-or-fixnum consing net-dconsing))
- (fastbig-incf-pcounter-or-fixnum profiles
- inner-enclosed-profiles))))
- (fastbig-incf-pcounter-or-fixnum *enclosed-ticks* dticks)
- (fastbig-incf-pcounter-or-fixnum *enclosed-consing* dconsing)
- (fastbig-incf-pcounter-or-fixnum *enclosed-profiles*
- (fastbig-1+
- inner-enclosed-profiles)))))
+ (dconsing 0)
+ (inner-enclosed-profiles 0))
+ (declare (truly-dynamic-extent dticks dconsing inner-enclosed-profiles))
+ (unwind-protect
+ (let* ((start-ticks (get-internal-ticks))
+ (*enclosed-ticks* (make-counter))
+ (*enclosed-consing* (make-counter))
+ (*enclosed-profiles* (make-counter))
+ (nbf0 *n-bytes-freed-or-purified*)
+ (dynamic-usage-0 (sb-kernel:dynamic-usage)))
+ (declare (dynamic-extent *enclosed-ticks* *enclosed-consing* *enclosed-profiles*))
+ (unwind-protect
+ (multiple-value-call encapsulated-fun
+ (sb-c:%more-arg-values arg-context
+ 0
+ arg-count))
+ (let ((*computing-profiling-data-for* encapsulated-fun)
+ (dynamic-usage-1 (sb-kernel:dynamic-usage)))
+ (setf dticks (- (get-internal-ticks) start-ticks)
+ dconsing (if (eql *n-bytes-freed-or-purified* nbf0)
+ ;; common special case where we can avoid
+ ;; bignum arithmetic
+ (- dynamic-usage-1 dynamic-usage-0)
+ ;; general case
+ (- (get-bytes-consed) nbf0 dynamic-usage-0))
+ inner-enclosed-profiles (counter->integer *enclosed-profiles*))
+ (incf-counter ticks (- dticks (counter->integer *enclosed-ticks*)))
+ (incf-counter consing (- dconsing (counter->integer *enclosed-consing*)))
+ (incf-counter profiles inner-enclosed-profiles))))
+ (when (boundp '*enclosed-ticks*)
+ (incf-counter *enclosed-ticks* dticks)
+ (incf-counter *enclosed-consing* dconsing)
+ (incf-counter *enclosed-profiles* (1+ inner-enclosed-profiles))))))