From: "Nicolas Bértolo" <nicolasbertolo@gmail.com>
To: Andrea Corallo <akrl@sdf.org>
Cc: 41242-done@debbugs.gnu.org
Subject: bug#41242: Port feature/native-comp to Windows - Reduce the number of files probed when finding a lisp file.
Date: Tue, 9 Jun 2020 11:14:55 -0300 [thread overview]
Message-ID: <CAFnS-O=2CP+huxLBP3+W6T0NWY6NTTMMueN4=xEk5P5Fi1GOUg@mail.gmail.com> (raw)
In-Reply-To: <xjfy2ozye71.fsf@sdf.org>
[-- Attachment #1: Type: text/plain, Size: 328 bytes --]
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.
[-- Attachment #2: 0001-Use-a-C-array-to-keep-the-list-of-live-native-compil.patch --]
[-- Type: application/octet-stream, Size: 7537 bytes --]
From 717437852b7e91a5fb9cf87dab21b4661f3bb3b4 Mon Sep 17 00:00:00 2001
From: Nicolas Bertolo <nicolasbertolo@gmail.com>
Date: Sun, 7 Jun 2020 15:54:50 -0300
Subject: [PATCH] Use a C array to keep the list of live native compilation
units.
I was getting crashes related to the access to the hashtable when
Emacs was about to close. I couldn't debug them, so I replaced it with
a simple C array.
* src/lisp.h (allocate_native_comp_unit): register every native
compilation unit allocated.
* src/comp.h: Expose register_native_comp_unit () to lisp.h.
* src/comp.c: Remove all_loaded_comp_units_h. Replace it with a
dynamically sized array.
---
src/comp.c | 94 +++++++++++++++++++++++++++++++-----------------------
src/comp.h | 5 +++
src/lisp.h | 9 ++++--
3 files changed, 66 insertions(+), 42 deletions(-)
diff --git a/src/comp.c b/src/comp.c
index 521cadcb10c..1a7eafaaadf 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -4111,17 +4111,17 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (Lisp_Object a, enum pvec_type code)
There are two data structures used:
- - The `all_loaded_comp_units_h` hashtable.
+ - The `all_loaded_comp_units` list.
- This hashtable is used like an array of weak references to native
- compilation units. This hash table is filled by load_comp_unit ()
- and dispose_all_remaining_comp_units () iterates over all values
- that were not disposed by the GC and performs all disposal steps
- when Emacs is closing.
+ This list is filled by allocate_native_comp_unit () and
+ dispose_all_remaining_comp_units () iterates over all values that
+ remain and performs all disposal steps when Emacs is closing. The
+ dispose_comp_unit () function removes entries that were disposed by
+ the GC.
- The `delayed_comp_unit_disposal_list` list.
- This is were the dispose_comp_unit () function, when called by the
+ This is where the dispose_comp_unit () function, when called by the
GC sweep stage, stores the original filenames of the disposed native
compilation units. This is an ad-hoc C structure instead of a Lisp
cons because we need to allocate instances of this structure during
@@ -4136,7 +4136,35 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (Lisp_Object a, enum pvec_type code)
#ifdef WINDOWSNT
#define OLD_ELN_SUFFIX_REGEXP build_string ("\\.eln\\.old\\'")
-static Lisp_Object all_loaded_comp_units_h;
+struct all_loaded_comp_units_s {
+ struct Lisp_Native_Comp_Unit **mem;
+ size_t size;
+ size_t capacity;
+};
+
+static struct all_loaded_comp_units_s all_loaded_comp_units;
+
+static void
+loaded_comp_units_remove (struct Lisp_Native_Comp_Unit * comp_u)
+{
+ size_t i;
+ bool found = false;
+ for (i = 0 ; i < all_loaded_comp_units.size; ++i)
+ if (all_loaded_comp_units.mem[i] == comp_u)
+ {
+ found = true;
+ break;
+ }
+ if (!found)
+ emacs_abort ();
+
+ size_t elements_on_right = all_loaded_comp_units.size - i - 1;
+ memmove (&all_loaded_comp_units.mem[i],
+ &all_loaded_comp_units.mem[i + 1],
+ elements_on_right * sizeof (struct Lisp_Native_Comp_Unit *));
+
+ all_loaded_comp_units.mem[--all_loaded_comp_units.size] = NULL;
+}
/* We need to allocate instances of this struct during a GC sweep.
This is why it can't be transformed into a simple cons. */
@@ -4193,17 +4221,9 @@ clean_package_user_dir_of_old_comp_units (void)
void
dispose_all_remaining_comp_units (void)
{
- struct Lisp_Hash_Table *h = XHASH_TABLE (all_loaded_comp_units_h);
-
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
+ for (ptrdiff_t i = all_loaded_comp_units.size - 1; i >= 0; --i)
{
- Lisp_Object k = HASH_KEY (h, i);
- if (!EQ (k, Qunbound))
- {
- Lisp_Object val = HASH_VALUE (h, i);
- struct Lisp_Native_Comp_Unit *cu = XNATIVE_COMP_UNIT (val);
- dispose_comp_unit (cu, false);
- }
+ dispose_comp_unit (all_loaded_comp_units.mem[i], false);
}
}
@@ -4227,22 +4247,26 @@ finish_delayed_disposal_of_comp_units (void)
xfree (item);
}
}
-#endif
/* This function puts the compilation unit in the
- `all_loaded_comp_units_h` hashmap. */
-static void
-register_native_comp_unit (Lisp_Object comp_u)
+ `all_loaded_comp_units` list. */
+void
+register_native_comp_unit (struct Lisp_Native_Comp_Unit * comp_u)
{
-#ifdef WINDOWSNT
- /* We have to do this since we can't use `gensym'. This function is
- called early when loading a dump file and subr.el may not have
- been loaded yet. */
- static intmax_t count;
+ /* Grow the array if necessary. */
+ if (all_loaded_comp_units.size + 1 > all_loaded_comp_units.capacity)
+ {
+ all_loaded_comp_units.capacity = max (1,
+ 2 * all_loaded_comp_units.capacity);
+ all_loaded_comp_units.mem
+ = xrealloc (all_loaded_comp_units.mem,
+ all_loaded_comp_units.capacity
+ * sizeof (struct Lisp_Native_Comp_Unit *));
+ }
- Fputhash (make_int (count++), comp_u, all_loaded_comp_units_h);
-#endif
+ all_loaded_comp_units.mem[all_loaded_comp_units.size++] = comp_u;
}
+#endif
/* This function disposes compilation units. It is called during the GC sweep
stage and when Emacs is closing.
@@ -4257,6 +4281,7 @@ dispose_comp_unit (struct Lisp_Native_Comp_Unit *comp_handle, bool delay)
eassert (comp_handle->handle);
dynlib_close (comp_handle->handle);
#ifdef WINDOWSNT
+ loaded_comp_units_remove (comp_handle);
if (!delay)
{
Lisp_Object dirname = internal_condition_case_1 (
@@ -4501,12 +4526,6 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump,
d_vec_len = XFIXNUM (Flength (comp_u->data_impure_vec));
for (EMACS_INT i = 0; i < d_vec_len; i++)
data_imp_relocs[i] = AREF (comp_u->data_impure_vec, i);
-
- /* If we register them while dumping we will get some entries in
- the hash table that will be duplicated when pdumper calls
- load_comp_unit. */
- if (!will_dump_p ())
- register_native_comp_unit (comp_u_lisp_obj);
}
if (!loading_dump)
@@ -4818,11 +4837,6 @@ syms_of_comp (void)
staticpro (&delayed_sources);
delayed_sources = Qnil;
-#ifdef WINDOWSNT
- staticpro (&all_loaded_comp_units_h);
- all_loaded_comp_units_h = CALLN (Fmake_hash_table, QCweakness, Qvalue);
-#endif
-
DEFVAR_LISP ("comp-ctxt", Vcomp_ctxt,
doc: /* The compiler context. */);
Vcomp_ctxt = Qnil;
diff --git a/src/comp.h b/src/comp.h
index 507379bf5e6..e4196d4a5f9 100644
--- a/src/comp.h
+++ b/src/comp.h
@@ -101,6 +101,11 @@ XNATIVE_COMP_UNIT (Lisp_Object a)
extern void clean_package_user_dir_of_old_comp_units (void);
+#ifdef WINDOWSNT
+extern void
+register_native_comp_unit (struct Lisp_Native_Comp_Unit * comp_unit);
+#endif
+
#else /* #ifdef HAVE_NATIVE_COMP */
static inline void
diff --git a/src/lisp.h b/src/lisp.h
index 22cd166c954..f64463afeec 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4764,8 +4764,13 @@ SUBR_NATIVE_COMPILEDP (Lisp_Object a)
INLINE struct Lisp_Native_Comp_Unit *
allocate_native_comp_unit (void)
{
- return ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Native_Comp_Unit,
- data_impure_vec, PVEC_NATIVE_COMP_UNIT);
+ struct Lisp_Native_Comp_Unit * comp_u
+ = ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Native_Comp_Unit,
+ data_impure_vec, PVEC_NATIVE_COMP_UNIT);
+#ifdef WINDOWSNT
+ register_native_comp_unit (comp_u);
+#endif
+ return comp_u;
}
#else
INLINE bool
--
2.25.1.windows.1
next prev parent reply other threads:[~2020-06-09 14:14 UTC|newest]
Thread overview: 149+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 19:26 bug#41242: Port feature/native-comp to Windows Nicolas Bértolo
2020-05-13 19:36 ` Eli Zaretskii
2020-05-13 19:39 ` Eli Zaretskii
2020-05-13 20:01 ` Nicolas Bértolo
2020-05-13 22:25 ` Andrea Corallo
2020-05-14 13:42 ` Eli Zaretskii
2020-05-13 20:08 ` Andrea Corallo
2020-05-13 20:27 ` Andrea Corallo
2020-05-13 19:56 ` Andrea Corallo
2020-05-13 20:03 ` Nicolas Bértolo
2020-05-14 10:18 ` Andrea Corallo
2020-05-14 10:45 ` Eli Zaretskii
2020-05-14 11:17 ` Andrea Corallo
2020-05-14 14:32 ` Eli Zaretskii
2020-05-14 15:03 ` Andrea Corallo
2020-05-14 16:50 ` Nicolas Bértolo
2020-05-14 17:28 ` Eli Zaretskii
2020-05-14 17:35 ` Nicolas Bértolo
2020-05-14 17:56 ` Eli Zaretskii
2020-05-14 18:00 ` Nicolas Bértolo
2020-05-14 18:29 ` Eli Zaretskii
2020-05-14 18:35 ` Andrea Corallo
2020-05-14 18:29 ` Andrea Corallo
2020-05-14 18:59 ` Achim Gratz
2020-05-14 17:34 ` Andrea Corallo
2020-05-14 17:51 ` Nicolas Bértolo
2020-05-14 18:13 ` Andrea Corallo
2020-05-14 18:40 ` Nicolas Bértolo
2020-05-14 18:48 ` Andrea Corallo
2020-05-14 19:00 ` Nicolas Bértolo
2020-05-14 19:15 ` Andrea Corallo
2020-05-14 19:48 ` Nicolas Bértolo
2020-05-14 19:58 ` Andrea Corallo
2020-05-14 20:16 ` Nicolas Bértolo
2020-05-14 20:29 ` Andrea Corallo
2020-05-14 20:34 ` Nicolas Bértolo
2020-05-15 6:10 ` Eli Zaretskii
2020-05-14 19:16 ` Eli Zaretskii
2020-05-14 19:00 ` Eli Zaretskii
2020-05-14 19:36 ` Nicolas Bértolo
2020-05-15 6:08 ` Eli Zaretskii
2020-05-15 12:33 ` Nicolas Bértolo
2020-05-15 13:00 ` Eli Zaretskii
2020-05-15 19:44 ` Nicolas Bértolo
2020-05-16 6:22 ` Eli Zaretskii
2020-05-16 7:12 ` Andrea Corallo
2020-05-16 16:12 ` Nicolas Bértolo
2020-05-16 16:19 ` Eli Zaretskii
2020-05-16 16:31 ` Nicolas Bértolo
2020-05-16 16:42 ` Eli Zaretskii
2020-05-16 17:09 ` Nicolas Bértolo
2020-05-19 19:23 ` Nicolas Bértolo
2020-05-19 19:25 ` Nicolas Bértolo
2020-05-20 15:27 ` Eli Zaretskii
2020-05-20 15:46 ` Nicolas Bértolo
[not found] ` <83blmf13d1.fsf@gnu.org>
[not found] ` <xjfh7w7vyjk.fsf@sdf.org>
[not found] ` <83367r0zvb.fsf@gnu.org>
2020-05-23 10:37 ` Andrea Corallo
2020-05-23 11:03 ` Eli Zaretskii
2020-05-23 11:21 ` Andrea Corallo
2020-05-23 12:20 ` Eli Zaretskii
2020-05-23 12:54 ` Andrea Corallo
2020-05-23 14:41 ` Nicolas Bértolo
2020-05-23 15:11 ` Andrea Corallo
2020-05-23 15:26 ` Nicolas Bértolo
2020-05-23 16:00 ` Andrea Corallo
2020-05-23 16:04 ` Eli Zaretskii
2020-05-23 16:20 ` Nicolas Bértolo
2020-05-23 17:04 ` Eli Zaretskii
2020-05-23 17:20 ` Nicolas Bértolo
2020-05-23 17:35 ` Eli Zaretskii
2020-05-23 17:47 ` Nicolas Bértolo
2020-05-23 18:21 ` Eli Zaretskii
2020-05-23 18:29 ` Nicolas Bértolo
2020-05-23 18:37 ` Eli Zaretskii
2020-05-23 18:43 ` Nicolas Bértolo
2020-05-23 22:52 ` Nicolas Bértolo
2020-05-25 12:21 ` Andrea Corallo
2020-05-24 3:53 ` Richard Stallman
2020-05-23 17:56 ` Andrea Corallo
2020-05-23 15:52 ` Eli Zaretskii
2020-05-23 16:03 ` Nicolas Bértolo
2020-05-20 16:06 ` Andrea Corallo
2020-05-20 15:55 ` Eli Zaretskii
2020-05-20 16:12 ` Andrea Corallo
2020-05-20 16:17 ` Nicolas Bértolo
2020-05-20 17:24 ` Andrea Corallo
2020-05-20 17:29 ` Andrea Corallo
2020-05-20 17:59 ` Eli Zaretskii
2020-05-20 18:09 ` Andrea Corallo
2020-05-20 18:48 ` Nicolas Bértolo
2020-05-20 21:38 ` Andrea Corallo
2020-05-21 1:58 ` Nicolas Bértolo
2020-05-21 18:51 ` Andrea Corallo
2020-05-22 21:23 ` Andrea Corallo
2020-05-14 19:13 ` Eli Zaretskii
2020-05-14 17:14 ` Eli Zaretskii
2020-05-14 16:24 ` Nicolas Bértolo
2020-05-14 17:21 ` Eli Zaretskii
2020-05-20 16:44 ` Eli Zaretskii
2020-05-23 22:58 ` bug#41242: Port feature/native-comp to Windows - Improve handling of native compilation Andrea Corallo
2020-05-23 23:43 ` Nicolas Bértolo
2020-05-24 8:19 ` Andrea Corallo
2020-05-24 17:58 ` Nicolas Bértolo
2020-05-24 19:13 ` Andrea Corallo
2020-05-24 19:43 ` Nicolas Bértolo
2020-05-25 14:04 ` Andrea Corallo
2020-05-25 14:27 ` Nicolas Bértolo
2020-05-25 15:06 ` Andrea Corallo
2020-05-25 20:27 ` Andrea Corallo
2020-05-25 21:49 ` Nicolas Bértolo
2020-05-27 21:02 ` bug#41242: Port feature/native-comp to Windows - Determine the emacs root dir Andrea Corallo
2020-05-28 6:17 ` Eli Zaretskii
2020-05-29 0:39 ` Nicolas Bértolo
2020-05-29 12:12 ` Andrea Corallo
2020-05-29 13:54 ` Eli Zaretskii
2020-05-29 14:26 ` Andrea Corallo
2020-05-30 10:51 ` Andrea Corallo
2020-05-30 13:06 ` Nicolas Bértolo
2020-05-30 14:17 ` Andrea Corallo
2020-05-30 13:23 ` Nicolas Bértolo
2020-05-30 14:51 ` Andrea Corallo
2020-05-30 16:25 ` Nicolas Bértolo
2020-05-30 18:51 ` Andrea Corallo
2020-05-30 20:15 ` Nicolas Bértolo
2020-05-30 20:54 ` Nicolas Bértolo
2020-05-31 8:55 ` Andrea Corallo
2020-05-30 16:29 ` Eli Zaretskii
2020-05-30 14:15 ` bug#41242: Port feature/native-comp to Windows - Reduce the number of files probed when finding a lisp file Andrea Corallo
2020-05-31 15:34 ` Nicolas Bértolo
2020-05-31 22:41 ` Nicolas Bértolo
2020-06-01 7:21 ` Andrea Corallo
2020-06-01 13:56 ` Nicolas Bértolo
2020-06-01 19:24 ` Andrea Corallo
2020-06-02 0:42 ` Nicolas Bértolo
2020-06-02 14:43 ` Andrea Corallo
2020-06-02 15:02 ` Eli Zaretskii
2020-06-02 16:24 ` Andrea Corallo
2020-06-02 21:17 ` Nicolas Bértolo
2020-06-02 23:08 ` Andrea Corallo
2020-06-02 23:39 ` Nicolas Bértolo
2020-06-03 13:50 ` Andrea Corallo
2020-06-03 15:28 ` Nicolas Bértolo
2020-06-03 16:24 ` Andrea Corallo
2020-06-06 21:41 ` Andrea Corallo
2020-06-06 21:51 ` Nicolas Bértolo
2020-06-06 22:32 ` Andrea Corallo
2020-06-06 22:50 ` Nicolas Bértolo
2020-06-06 23:20 ` Andrea Corallo
2020-06-09 14:14 ` Nicolas Bértolo [this message]
2020-06-09 17:17 ` Andrea Corallo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFnS-O=2CP+huxLBP3+W6T0NWY6NTTMMueN4=xEk5P5Fi1GOUg@mail.gmail.com' \
--to=nicolasbertolo@gmail.com \
--cc=41242-done@debbugs.gnu.org \
--cc=akrl@sdf.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).