Skip to content

Commit c14e2af

Browse files
committed
sb-cover: Stop dumping +code-coverage-unmarked+.
There's no need to dump conses of the form (path . +code-coverage-unmarked+) into the fasl file itself. Just dump the paths and create the fresh conses in the loader. This avoids problems with list coalescing so that we can just use NIL as the unmarked marker now, allowing us to remove a lot of pointless abstractions. It also shrinks the fasl size. We can also now move a bunch of sb-cover stuff out of the compiler and the compiler package into the contrib proper.
1 parent 94816a4 commit c14e2af

File tree

8 files changed

+35
-58
lines changed

8 files changed

+35
-58
lines changed

contrib/sb-cover/cover.lisp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818
(eval-when (:compile-toplevel :load-toplevel :execute)
1919
(setf (sb-int:system-package-p *package*) t))
2020

21-
(defmacro code-coverage-hashtable () `(car sb-c:*code-coverage-info*))
21+
(defmacro code-coverage-hashtable () `(car sb-int:*code-coverage-info*))
22+
23+
(defun reset-code-coverage ()
24+
(maphash (lambda (info cc)
25+
(declare (ignore info))
26+
(dolist (cc-entry cc)
27+
(setf (cdr cc-entry) nil)))
28+
(car sb-int:*code-coverage-info*)))
2229

2330
;;;; New coverage representation.
2431
;;;; One byte per coverage mark is stored in the unboxed constants of the code.
@@ -77,13 +84,14 @@
7784
into the database when the FASL files (produced by compiling
7885
STORE-COVERAGE-DATA optimization policy set to 3) are loaded again into the
7986
image."
80-
(sb-c:clear-code-coverage))
87+
(clrhash (car sb-int:*code-coverage-info*))
88+
(setf (cdr sb-int:*code-coverage-info*) nil))
8189

8290
(macrolet
8391
((do-instrumented-code ((var &optional result) &body body)
8492
;; Scan list of weak-pointers to all coverage-instrumented code,
8593
;; binding VAR to each object, and removing broken weak-pointers.
86-
`(let ((predecessor sb-c:*code-coverage-info*))
94+
`(let ((predecessor sb-int:*code-coverage-info*))
8795
(loop
8896
(let ((cell (cdr predecessor)))
8997
(unless cell (return ,result))
@@ -141,7 +149,7 @@ image."
141149
(t ; reset everything
142150
(do-instrumented-code (code)
143151
(reset-coverage code))
144-
(sb-c:reset-code-coverage))))
152+
(reset-code-coverage))))
145153

146154
;;; Transfer data from new-style coverage marks into old-style.
147155
;;; Update only data for FILENAME if supplied, or all files if NIL.
@@ -151,7 +159,7 @@ image."
151159
(declare (ignorable filename))
152160
;; NAMESTRING->PATH-TABLES maps a namestring to a hashtable which maps
153161
;; source paths to the legacy coverage record for that path in that file,
154-
;; e.g. (1 4 1) -> ((1 4 1) . SB-C::%CODE-COVERAGE-UNMARKED%)
162+
;; e.g. (1 4 1) -> ((1 4 1) . NIL)
155163
(let ((namestring->path-tables (make-hash-table :test 'equal))
156164
(coverage-records (code-coverage-hashtable))
157165
(n-marks 0))
@@ -594,7 +602,7 @@ table.summary tr.subheading td { text-align: left; font-weight: bold; padding-le
594602
unless (member (caar record) '(:then :else))
595603
collect (list mode
596604
(car record)
597-
(if (sb-c:code-coverage-record-marked record)
605+
(if (cdr record)
598606
1
599607
2))))
600608
(:branch
@@ -604,7 +612,7 @@ table.summary tr.subheading td { text-align: left; font-weight: bold; padding-le
604612
(when (member (car path) '(:then :else))
605613
(setf (gethash (cdr path) hash)
606614
(logior (gethash (cdr path) hash 0)
607-
(ash (if (sb-c:code-coverage-record-marked record)
615+
(ash (if (cdr record)
608616
1
609617
2)
610618
(if (eql (car path) :then)

src/code/early-impl.lisp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@
5959
(declaim (type cons sb-kernel::*gc-epoch*))
6060
(define-load-time-global sb-kernel::*gc-epoch* '(nil . nil))
6161

62+
;;; Stores the code coverage instrumentation results. The CAR is a
63+
;;; hashtable. The CDR is a list of weak pointers to code objects
64+
;;; having coverage marks embedded in the unboxed constants. Keys in
65+
;;; the hashtable are namestrings, the value is a list of (CONS PATH
66+
;;; VISITED).
67+
(define-load-time-global *code-coverage-info*
68+
(list (make-hash-table :test 'equal :synchronized t)))
69+
(declaim (type (cons hash-table) *code-coverage-info*))
70+
6271
;;; Default evaluator mode (interpreter / compiler)
6372

6473
(declaim (type (member :compile #+(or sb-eval sb-fasteval) :interpret)

src/code/load.lisp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@
12301230
(when (typep (code-header-ref code (1- n-boxed-words))
12311231
'(cons (eql sb-c::coverage-map)))
12321232
;; Record this in the global list of coverage-instrumented code.
1233-
(atomic-push (make-weak-pointer code) (cdr sb-c:*code-coverage-info*)))
1233+
(atomic-push (make-weak-pointer code) (cdr *code-coverage-info*)))
12341234
(possibly-log-new-code code "load")))))
12351235

12361236
;; this gets you an #<fdefn> object, not the result of (FDEFINITION x)
@@ -1310,8 +1310,9 @@
13101310

13111311
;;;; fops for code coverage
13121312

1313-
(define-fop 120 :not-host (fop-record-code-coverage (namestring cc) nil)
1314-
(setf (gethash namestring (car sb-c:*code-coverage-info*)) cc)
1313+
(define-fop 120 :not-host (fop-record-code-coverage (namestring paths) nil)
1314+
(setf (gethash namestring (car *code-coverage-info*))
1315+
(mapcar #'list paths))
13151316
(values))
13161317

13171318
;;; Primordial layouts.

src/code/save.lisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ sufficiently motivated to do lengthy fixes."
338338
;; recreate it so that we don't preserve an empty vector taking up 16KB
339339
(setq sb-kernel::*forward-referenced-layouts* (make-hash-table :test 'equal)))
340340
;; Clean up the simulated weak list of covered code components.
341-
(rplacd sb-c:*code-coverage-info*
342-
(delete-if-not #'weak-pointer-value (cdr sb-c:*code-coverage-info*)))
341+
(rplacd *code-coverage-info*
342+
(delete-if-not #'weak-pointer-value (cdr *code-coverage-info*)))
343343
(sb-kernel::rebuild-ctype-hashsets)
344344
(drop-all-hash-caches)
345345
(os-deinit)

src/cold/exports.lisp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,10 @@ possibly temporarily, because it might be used internally.")
960960
"*REPL-PROMPT-FUN*"
961961
"*REPL-READ-FORM-FUN*"
962962

963+
;; for SB-COVER
964+
965+
"*CODE-COVERAGE-INFO*"
966+
963967
;; Character database access
964968

965969
"MISC-INDEX"
@@ -2770,11 +2774,6 @@ be submitted as a CDR")
27702774

27712775
"BRANCH-IF" "MULTIWAY-BRANCH-IF-EQ"
27722776
"JUMP-TABLE" "CASE-TO-JUMP-TABLE"
2773-
;; for SB-COVER
2774-
2775-
"*CODE-COVERAGE-INFO*" "CODE-COVERAGE-RECORD-MARKED"
2776-
"CLEAR-CODE-COVERAGE" "RESET-CODE-COVERAGE"
2777-
"+CODE-COVERAGE-UNMARKED+"
27782777
;; for SB-INTROSPECT
27792778

27802779
"MAP-PACKED-XREF-DATA" "MAP-SIMPLE-FUNS"))

src/compiler/early-c.lisp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,6 @@
185185
;;; 2 implies an even length boxed header; 1 implies no restriction.
186186
(defconstant code-boxed-words-align (+ 2 #+(or x86 x86-64) -1))
187187

188-
;;; Used as the CDR of the code coverage instrumentation records
189-
;;; (instead of NIL) to ensure that any well-behaving user code will
190-
;;; not have constants EQUAL to that record. This avoids problems with
191-
;;; the records getting coalesced with non-record conses, which then
192-
;;; get mutated when the instrumentation runs. Note that it's
193-
;;; important for multiple records for the same location to be
194-
;;; coalesced. -- JES, 2008-01-02
195-
(defconstant +code-coverage-unmarked+ '%code-coverage-unmarked%)
196-
197-
;;; Stores the code coverage instrumentation results.
198-
;;; The CAR is a hashtable. The CDR is a list of weak pointers to code objects
199-
;;; having coverage marks embedded in the unboxed constants.
200-
;;; Keys in the hashtable are namestrings, the
201-
;;; value is a list of (CONS PATH STATE), where STATE is +CODE-COVERAGE-UNMARKED+
202-
;;; for a path that has not been visited, and T for one that has.
203-
#-sb-xc-host
204-
(progn
205-
(define-load-time-global *code-coverage-info*
206-
(list (make-hash-table :test 'equal :synchronized t)))
207-
(declaim (type (cons hash-table) *code-coverage-info*)))
208-
209188
;;; Unique number assigned into high 4 bytes of 64-bit code size slot
210189
;;; so that we can sort the contents of text space in a more-or-less
211190
;;; predictable manner based on the order in which code was loaded.

src/compiler/main.lisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ necessary, since type inference may take arbitrarily long to converge.")
16851685
(dump-code-coverage-records
16861686
(namestring *compile-file-pathname*)
16871687
(loop for k being each hash-key of code-coverage-records
1688-
collect (cons k +code-coverage-unmarked+))
1688+
collect k)
16891689
*compile-object*)))
16901690
nil)))
16911691
;; Some errors are sufficiently bewildering that we just fail

src/compiler/target-main.lisp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -426,22 +426,3 @@ not STYLE-WARNINGs occur during compilation, and NIL otherwise.
426426
#'< :key 'caar))))
427427
(recurse path-to-find (cdaar list) (cdr list))))
428428
start-char))
429-
430-
;;;; Coverage helpers
431-
432-
(defun clear-code-coverage ()
433-
(clrhash (car *code-coverage-info*))
434-
(setf (cdr *code-coverage-info*) nil))
435-
436-
(defun reset-code-coverage ()
437-
(maphash (lambda (info cc)
438-
(declare (ignore info))
439-
(dolist (cc-entry cc)
440-
(setf (cdr cc-entry) +code-coverage-unmarked+)))
441-
(car *code-coverage-info*)))
442-
443-
(defun code-coverage-record-marked (record)
444-
(aver (consp record))
445-
(ecase (cdr record)
446-
((#.+code-coverage-unmarked+) nil)
447-
((t) t)))

0 commit comments

Comments
 (0)