[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 7e2f6f8 4/6: Remove mark_maybe_object
From: |
Paul Eggert |
Subject: |
master 7e2f6f8 4/6: Remove mark_maybe_object |
Date: |
Mon, 31 Aug 2020 03:06:04 -0400 (EDT) |
branch: master
commit 7e2f6f8448f9d98e90e0343e2aeba22a7985480f
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
Remove mark_maybe_object
* src/alloc.c (mark_maybe_object, mark_maybe_objects): Remove.
(mark_objects): New function.
* src/eval.c (mark_specpdl): Use mark_objects instead of
mark_maybe_objects, since the array now has only valid Lisp objects.
* src/lisp.h (SAFE_ALLOCA_LISP_EXTRA): When allocating a large
array, clear it so that it contains only valid Lisp objects. This
is simpler and safer, and does not hurt performance significantly
on my usual benchmark as the code is executed so rarely.
---
src/alloc.c | 105 ++++++++----------------------------------------------------
src/eval.c | 2 +-
src/lisp.h | 7 ++--
3 files changed, 20 insertions(+), 94 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index 5453c54..2f66b5e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -4680,117 +4680,33 @@ live_small_vector_p (struct mem_node *m, void *p)
return live_small_vector_holding (m, p) == p;
}
-/* Mark OBJ if we can prove it's a Lisp_Object. */
+/* If P points to Lisp data, mark that as live if it isn't already
+ marked. */
static void
-mark_maybe_object (Lisp_Object obj)
+mark_maybe_pointer (void *p)
{
+ struct mem_node *m;
+
#if USE_VALGRIND
- VALGRIND_MAKE_MEM_DEFINED (&obj, sizeof (obj));
+ VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p));
#endif
- int type_tag = XTYPE (obj);
- intptr_t pointer_word_tag = LISP_WORD_TAG (type_tag), offset, ipo;
-
- switch (type_tag)
- {
- case_Lisp_Int: case Lisp_Type_Unused0:
- return;
-
- case Lisp_Symbol:
- offset = (intptr_t) lispsym;
- break;
-
- default:
- offset = 0;
- break;
- }
-
- INT_ADD_WRAPV ((intptr_t) XLP (obj), offset - pointer_word_tag, &ipo);
- void *po = (void *) ipo;
-
/* If the pointer is in the dump image and the dump has a record
of the object starting at the place where the pointer points, we
definitely have an object. If the pointer is in the dump image
and the dump has no idea what the pointer is pointing at, we
definitely _don't_ have an object. */
- if (pdumper_object_p (po))
+ if (pdumper_object_p (p))
{
/* Don't use pdumper_object_p_precise here! It doesn't check the
tag bits. OBJ here might be complete garbage, so we need to
verify both the pointer and the tag. */
- if (pdumper_find_object_type (po) == type_tag)
- mark_object (obj);
- return;
- }
-
- struct mem_node *m = mem_find (po);
-
- if (m != MEM_NIL)
- {
- bool mark_p = false;
-
- switch (type_tag)
- {
- case Lisp_String:
- mark_p = m->type == MEM_TYPE_STRING && live_string_p (m, po);
- break;
-
- case Lisp_Cons:
- mark_p = m->type == MEM_TYPE_CONS && live_cons_p (m, po);
- break;
-
- case Lisp_Symbol:
- mark_p = m->type == MEM_TYPE_SYMBOL && live_symbol_p (m, po);
- break;
-
- case Lisp_Float:
- mark_p = m->type == MEM_TYPE_FLOAT && live_float_p (m, po);
- break;
-
- case Lisp_Vectorlike:
- mark_p = (m->type == MEM_TYPE_VECTOR_BLOCK
- ? live_small_vector_p (m, po)
- : (m->type == MEM_TYPE_VECTORLIKE
- && live_large_vector_p (m, po)));
- break;
-
- default:
- eassume (false);
- }
-
- if (mark_p)
- mark_object (obj);
- }
-}
-
-void
-mark_maybe_objects (Lisp_Object const *array, ptrdiff_t nelts)
-{
- for (Lisp_Object const *lim = array + nelts; array < lim; array++)
- mark_maybe_object (*array);
-}
-
-/* If P points to Lisp data, mark that as live if it isn't already
- marked. */
-
-static void
-mark_maybe_pointer (void *p)
-{
- struct mem_node *m;
-
-#if USE_VALGRIND
- VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p));
-#endif
-
- if (pdumper_object_p (p))
- {
int type = pdumper_find_object_type (p);
if (pdumper_valid_object_type_p (type))
mark_object (type == Lisp_Symbol
? make_lisp_symbol (p)
: make_lisp_ptr (p, type));
- /* See mark_maybe_object for why we can confidently return. */
return;
}
@@ -6570,6 +6486,13 @@ mark_hash_table (struct Lisp_Vector *ptr)
}
}
+void
+mark_objects (Lisp_Object *obj, ptrdiff_t n)
+{
+ for (ptrdiff_t i = 0; i < n; i++)
+ mark_object (obj[i]);
+}
+
/* Determine type of generic Lisp_Object and mark it accordingly.
This function implements a straightforward depth-first marking
diff --git a/src/eval.c b/src/eval.c
index 9daae92..a9bce55 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3960,7 +3960,7 @@ mark_specpdl (union specbinding *first, union specbinding
*ptr)
break;
case SPECPDL_UNWIND_ARRAY:
- mark_maybe_objects (pdl->unwind_array.array, pdl->unwind_array.nelts);
+ mark_objects (pdl->unwind_array.array, pdl->unwind_array.nelts);
break;
case SPECPDL_UNWIND_EXCURSION:
diff --git a/src/lisp.h b/src/lisp.h
index 7983339..745c056 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3767,12 +3767,12 @@ extern AVOID memory_full (size_t);
extern AVOID buffer_memory_full (ptrdiff_t);
extern bool survives_gc_p (Lisp_Object);
extern void mark_object (Lisp_Object);
+extern void mark_objects (Lisp_Object *, ptrdiff_t);
#if defined REL_ALLOC && !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
extern void refill_memory_reserve (void);
#endif
extern void alloc_unexec_pre (void);
extern void alloc_unexec_post (void);
-extern void mark_maybe_objects (Lisp_Object const *, ptrdiff_t);
extern void mark_stack (char const *, char const *);
extern void flush_stack_call_func1 (void (*func) (void *arg), void *arg);
@@ -4884,7 +4884,10 @@ safe_free_unbind_to (ptrdiff_t count, ptrdiff_t
sa_count, Lisp_Object val)
(buf) = AVAIL_ALLOCA (alloca_nbytes); \
else \
{ \
- (buf) = xmalloc (alloca_nbytes); \
+ /* Although only the first nelt words need clearing, \
+ typically EXTRA is 0 or small so just use xzalloc; \
+ this is simpler and often faster. */ \
+ (buf) = xzalloc (alloca_nbytes); \
record_unwind_protect_array (buf, nelt); \
} \
} while (false)
- master updated (886ba06 -> 416195f), Paul Eggert, 2020/08/31
- master 2ff930d 1/6: Fix GC bug with Lisp floats and --with-wide-int, Paul Eggert, 2020/08/31
- master 7e2f6f8 4/6: Remove mark_maybe_object,
Paul Eggert <=
- master cf95bb0 3/6: Avoid some false matches in mark_maybe_pointer, Paul Eggert, 2020/08/31
- master aa1b586 2/6: Omit no-longer-needed stack mark_maybe_object, Paul Eggert, 2020/08/31
- master 89350d4 5/6: Use mark_objects elsewhere too, Paul Eggert, 2020/08/31
- master 416195f 6/6: * src/lisp.h (lisp_h_XPL, XPL): Remove; unused., Paul Eggert, 2020/08/31