Subject: bug#41242: Port feature/native-comp to Windows - Reduce the number of files probed when finding a lisp file.

From: Andrea Corallo <[email-masked]>
Date: Tue, 09 Jun 2020 17:17:19 +0000

Nicolas Bértolo <[email-masked]> writes:

> Hi,
>
> I have attached a bugfix for the issue that causes crashes when closing Emacs.
>
> Ideally I would figure out why iterating over  a weak hash-table does not skip
> elements that were already GC'd, but I could not do it. I feel fixing
> this bug is
> very important, so I used a C array to keep the list of native
> compilation units.

Hi Nico,

at a quick look your code to itereate looks correct and very similar to
other we have in the codebase so this is important to understand what is
going on.  Have you tried to run a reproducer like the following?

======
;;; -*- lexical-binding: t; -*-

(setq gc-cons-threshold most-positive-fixnum)
(defun foo ())
(load (native-compile #'foo))

(setq xxx (make-hash-table :weakness 'value))
(puthash 1 (subr-native-comp-unit (symbol-function #'foo)) xxx)

(defun foo ())
(maphash (lambda (k v)
	   (message "%s %s" k v))
	 xxx)

(garbage-collect)
(maphash (lambda (k v)
	   (message "%s %s" k v))
	 xxx)
======

The thing is that 'mark_and_sweep_weak_table_contents' is called after
convetional mark and before conventional sweep.  This will eventually
call 'sweep_weak_table' that sets the Qunbound as key.

Should be relativelly easy to see that the CU is sweeped there, and in
case is not see the reason.

A possibility where I bet is that something goes wrong dumping and
reviving a weak hashtable (like this is not in 'weak_hash_tables').

You can quickly check against that moving the creation of your hash such
that is created at each startup.

Hope it helps

  Andrea

-- 
[email-masked]