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.
This commit is contained in:
Paul Eggert 2020-08-30 23:40:11 -07:00
parent cf95bb0213
commit 7e2f6f8448
3 changed files with 21 additions and 95 deletions

View file

@ -4680,97 +4680,6 @@ 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. */
static void
mark_maybe_object (Lisp_Object obj)
{
#if USE_VALGRIND
VALGRIND_MAKE_MEM_DEFINED (&obj, sizeof (obj));
#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))
{
/* 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. */
@ -4783,14 +4692,21 @@ mark_maybe_pointer (void *p)
VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p));
#endif
/* 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 (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. */
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

View file

@ -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:

View file

@ -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)