[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/comp-static-data 485f868bbfe 14/16: src/alloc.c: Improve checks
From: |
Vibhav Pant |
Subject: |
scratch/comp-static-data 485f868bbfe 14/16: src/alloc.c: Improve checks in static_comp_object_p. |
Date: |
Thu, 19 Jan 2023 12:44:47 -0500 (EST) |
branch: scratch/comp-static-data
commit 485f868bbfe9f1ab2378f522db52050b92c1677d
Author: Vibhav Pant <vibhavp@gmail.com>
Commit: Vibhav Pant <vibhavp@gmail.com>
src/alloc.c: Improve checks in static_comp_object_p.
src/alloc.c (static_comp_object_p): Improve documentation, return true
if the object lies outside the heap, make checks for static objects
more efficient.
---
src/alloc.c | 54 +++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 15 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index e5ea28c921d..b05eb347c22 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -4298,33 +4298,57 @@ set_interval_marked (INTERVAL i)
#ifdef HAVE_STATIC_LISP_GLOBALS
/* Certain self-evaluating Lisp objects in natively compiled code are
- * emitted as permanently marked. Note that this function does not
- * *truly* determine if an object was statically compiled, but instead
- * serves as a (hopefully) fool-proof heuristic to know if it
- * cannot be treated as an otherwise ordinary heap-allocated object
- * (whether it is mutable or not, can be freed, etc). */
+ emitted as permanently marked. When called **outside of GC**,
+ static_comp_object_p returns whether the passed argument is one
+ such object. Note that this function does not *truly* determine if
+ an object was statically compiled (i.e, it lies inside the address
+ space of a dlopen'ed eln object), but instead checks for certain
+ properties that these objects are compiled with. The purpose of
+ this function is to decide if an object cannot be treated as an
+ otherwise ordinary heap-allocated object (whether it is mutable or
+ not, can be freed, etc). */
bool
static_comp_object_p (Lisp_Object obj)
{
- if (pdumper_object_p (XPNTR (obj)))
+ void *ptr = XPNTR (obj);
+ if (pdumper_object_p (ptr))
return false;
+ /* If the object points to Lisp data allocated outside the heap,
+ it likely exists in a native compiled eln file. Either way, we
+ should not be mutating it, so it's good enough for this function. */
+ if (ptr < min_heap_address || ptr > max_heap_address)
+ return true;
+
switch (XTYPE (obj))
{
case Lisp_String:
- /* see `emit_lisp_string_constructor_rval' in comp.c */
- return XSTRING (obj)->u.s.intervals == NULL
- && string_marked_p (XSTRING (obj))
- && (STRING_MULTIBYTE (obj)
- || XSTRING (obj)->u.s.size_byte == -3);
+ /* See `emit_lisp_string_constructor_rval' in comp.c. Statically
+ compiled strings also have no intervals, and have u.s.size_byte
+ == -3 if they're unibyte. */
+ return string_marked_p (XSTRING (obj));
case Lisp_Vectorlike:
/* see `emit_comp_lisp_obj' in comp.c */
- return (VECTORP (obj) || RECORDP (obj) || COMPILEDP (obj))
- && vector_marked_p (XVECTOR (obj));
+ return vector_marked_p (XVECTOR (obj));
case Lisp_Cons:
- return cons_marked_p (XCONS (obj));
+ {
+ /* The cons_block for static comp cons objects have all bits for
+ its conses marked. */
+ struct cons_block *blk = CONS_BLOCK (XCONS (obj));
+ for (ptrdiff_t i = 0; i < cons_block_gcmarkbits_length; i++)
+ if (blk->gcmarkbits[i] != BITS_WORD_MAX)
+ return false;
+ return true;
+ }
case Lisp_Float:
- return XFLOAT_MARKED_P (XFLOAT (obj));
+ {
+ /* Ditto, for floats as well. */
+ struct float_block *blk = FLOAT_BLOCK (XFLOAT (obj));
+ for (ptrdiff_t i = 0; i < float_block_gcmarkbits_length; i++)
+ if (blk->gcmarkbits[i] != BITS_WORD_MAX)
+ return false;
+ return true;
+ }
case Lisp_Symbol:
case_Lisp_Int:
return false;
- scratch/comp-static-data 80ea23618da 06/16: Avoid directly accessing the size field in a Lisp String., (continued)
- scratch/comp-static-data 80ea23618da 06/16: Avoid directly accessing the size field in a Lisp String., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 7727f85b869 07/16: src/.gdbinit: Add pretty-printing support for native comp units., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 83c49e2f376 01/16: Avoid additional recursion while marking natively compiled unit., Vibhav Pant, 2023/01/19
- scratch/comp-static-data ab886f48966 05/16: comp.c: Only call comp_init_objs when not recursively loading., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 4a0854c9e32 03/16: src/alloc.c: Unmark Lisp Vectors when accessing the size field., Vibhav Pant, 2023/01/19
- scratch/comp-static-data a0bd3b7d32a 02/16: src/alloc.c: Remove unnecessary calls to static_comp_object_p., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 6bf897449b6 09/16: src/comp.c: Disable native compiling certain bytecode forms for now., Vibhav Pant, 2023/01/19
- scratch/comp-static-data fb3a68c171e 12/16: ; src/comp.c: Fix typo in call to comp-func-byte-func., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 99896f21267 10/16: Merge branch 'master' into scratch/comp-static-data, Vibhav Pant, 2023/01/19
- scratch/comp-static-data 87909765da7 13/16: comp.el: Avoid unnecessary allocation of byte-code forms., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 485f868bbfe 14/16: src/alloc.c: Improve checks in static_comp_object_p.,
Vibhav Pant <=
- scratch/comp-static-data b67b328d6ab 16/16: Pin native comp units with static objects for now., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 2cc0d51f29d 11/16: src/comp.c: Address several GC-related issues with static literals., Vibhav Pant, 2023/01/19
- scratch/comp-static-data 94120d328e8 08/16: Merge branch 'master' into scratch/comp-static-data, Vibhav Pant, 2023/01/19
- scratch/comp-static-data 9c6acb9681e 15/16: pdumper.c (dump_object): Assert the object is not statically emitted, Vibhav Pant, 2023/01/19