[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/comp-static-data 5eda8d1abbe: Rename HAVE_STATIC_LISP_OBJECTS, a
From: |
Vibhav Pant |
Subject: |
scratch/comp-static-data 5eda8d1abbe: Rename HAVE_STATIC_LISP_OBJECTS, add documentation for it. |
Date: |
Tue, 31 Jan 2023 10:39:17 -0500 (EST) |
branch: scratch/comp-static-data
commit 5eda8d1abbed40e808264496658ced4f003834eb
Author: Vibhav Pant <vibhavp@gmail.com>
Commit: Vibhav Pant <vibhavp@gmail.com>
Rename HAVE_STATIC_LISP_OBJECTS, add documentation for it.
* src/comp.h: Rename HAVE_STATIC_LISP_OBJECTS to
USE_COMP_STATIC_LISP_OBJECTS. Add comments explaining the macro's
use.
* src/comp.c (comp_lisp_const_get_lisp_obj_rval, emit_comp_lisp_obj,
emit_data_container_vector, define_init_objs): Add documentation
comments.
---
src/alloc.c | 10 ++--
src/comp.c | 152 +++++++++++++++++++++++++++++++++++++++++-------------------
src/comp.h | 37 +++++++++++----
src/lisp.h | 12 ++---
4 files changed, 144 insertions(+), 67 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index f342f10992d..f238177cace 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3790,7 +3790,7 @@ usage: (make-closure PROTOTYPE &rest CLOSURE-VARS) */)
ptrdiff_t protosize = PVSIZE (protofun);
struct Lisp_Vector *v = allocate_vectorlike (protosize, false);
v->header = XVECTOR (protofun)->header;
-#if HAVE_STATIC_LISP_GLOBALS
+#if USE_COMP_STATIC_LISP_OBJECTS
/* We might be copying from a vector statically allocated during
native compilation, be sure to unset the mark flag. */
v->header.size &= ~ARRAY_MARK_FLAG;
@@ -4295,7 +4295,7 @@ set_interval_marked (INTERVAL i)
i->gcmarkbit = true;
}
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
/* Certain self-evaluating Lisp objects in natively compiled code are
emitted as permanently marked. When called **outside of GC**,
static_comp_object_p returns whether the passed argument is one
@@ -5608,7 +5608,7 @@ valid_lisp_object_p (Lisp_Object obj)
if (SUBRP (obj) || STRINGP (obj) || CONSP (obj))
return 1;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
return static_comp_object_p (obj);
#else
return 0;
@@ -6286,7 +6286,7 @@ visit_vectorlike_root (struct gc_root_visitor visitor,
if (size & PSEUDOVECTOR_FLAG)
size &= PSEUDOVECTOR_SIZE_MASK;
-#if HAVE_STATIC_LISP_GLOBALS
+#if USE_COMP_STATIC_LISP_OBJECTS
size &= ~ARRAY_MARK_FLAG;
#endif
for (i = 0; i < size; i++)
@@ -6866,7 +6866,7 @@ mark_native_comp_unit (struct Lisp_Vector *ptr)
set_vector_marked (ptr);
mark_stack_push_values (ptr->contents, size);
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp_u->have_static_lisp_data)
{
eassert (NILP (comp_u->lambda_gc_guard_h));
diff --git a/src/comp.c b/src/comp.c
index 24e760032af..f539a7c368d 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -563,7 +563,7 @@ load_gccjit_if_necessary (bool mandatory)
#define LINK_TABLE_HASH_SYM "freloc_hash"
#define COMP_UNIT_SYM "comp_unit"
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
# define DATA_STATICPRO_SYM "d_staticpro"
# define DATA_EPHEMERAL_SYM "d_ephemeral"
# define HAVE_STATIC_LISP_DATA_SYM "comp_have_static_lisp_data"
@@ -664,7 +664,7 @@ typedef struct {
gcc_jit_type *lisp_word_type;
gcc_jit_type *lisp_word_tag_type;
gcc_jit_type *untagged_ptr_type;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
gcc_jit_type *bits_word_type;
#endif
#ifdef LISP_OBJECT_IS_STRUCT
@@ -685,7 +685,7 @@ typedef struct {
gcc_jit_type *lisp_cons_u_type;
gcc_jit_type *lisp_cons_u_s_type;
gcc_jit_type *lisp_cons_u_s_u_type;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
/* struct cons_block */
gcc_jit_struct *cons_block_s;
gcc_jit_field *cons_block_conses;
@@ -745,7 +745,7 @@ typedef struct {
gcc_jit_type *lisp_float_type;
gcc_jit_type *lisp_float_ptr_type;
gcc_jit_type *lisp_float_u_type;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
/* struct Lisp_Subr */
gcc_jit_struct *lisp_subr_s;
gcc_jit_field *lisp_subr_header;
@@ -844,7 +844,7 @@ typedef struct {
Lisp_Object d_impure_idx;
Lisp_Object d_ephemeral_idx;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
/* If true, compile lisp constants statically into the eln file. */
bool compile_static_data;
/* A list of
@@ -889,8 +889,8 @@ typedef struct {
gcc_jit_rvalue *idx;
} imm_reloc_t;
-#ifdef HAVE_STATIC_LISP_GLOBALS
-/* Represents a JIT compiled Lisp_Object value. */
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
+/* Represents a JIT compiled const static Lisp object. */
typedef struct
{
union
@@ -916,17 +916,14 @@ typedef struct
COMP_LISP_CONST_SELF_REPR = 1,
COMP_LISP_CONST_VAR = 2
} expr_type;
- /* True if is this is a constant expression. */
+ /* True if is this can be emitted with a constant expression
+ initializer. This is usually the case with self representing
+ objects, and forms consisting of self representing objects. To
+ see the criteria for an object to be emitted statically, see
+ emit_comp_lisp_obj. */
bool const_expr_p;
} comp_lisp_const_t;
-/* Get the actual Lisp_Object rvalue for a given compiled constant.
- For types COMP_LISP_CONST_VAR and COMP_LISP_CONST_SELF_REPR, this
- does nothing but return the lisp_obj field.
- For COMP_LISP_CONST_INIT_WITH_TYPE values, create a global constant
- static to store the underlying data and return a pointer to it,
- tagged with the corresponding Lisp_Type value.
-*/
static gcc_jit_rvalue *
comp_lisp_const_get_lisp_obj_rval (Lisp_Object obj,
comp_lisp_const_t expr);
@@ -944,7 +941,7 @@ static void helper_save_restriction (void);
static bool helper_PSEUDOVECTOR_TYPEP_XUNTAG (Lisp_Object, enum pvec_type);
static struct Lisp_Symbol_With_Pos *
helper_GET_SYMBOL_WITH_POSITION (Lisp_Object);
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
static bool helper_static_comp_object_p (Lisp_Object);
#endif
@@ -965,7 +962,7 @@ static void *helper_link_table[] = {
specbind,
maybe_gc,
maybe_quit,
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
helper_static_comp_object_p,
#endif
};
@@ -1053,7 +1050,7 @@ hash_native_abi (void)
/* Check runs once. */
eassert (NILP (Vcomp_abi_hash));
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
Lisp_Object builtin_syms = Qnil;
AUTO_STRING (sep, " ");
@@ -1072,7 +1069,7 @@ hash_native_abi (void)
Vsystem_configuration_options),
Fmapconcat (intern_c_string ("comp--subr-signature"),
Vcomp_subr_list, build_string (""))
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
,builtin_syms
#endif
));
@@ -2054,7 +2051,7 @@ emit_make_fixnum (gcc_jit_rvalue *obj)
: emit_make_fixnum_MSB_TAG (obj);
}
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
/* Emits a Lisp_Cons struct with the given car and cdr values. */
static gcc_jit_rvalue *
@@ -2879,6 +2876,13 @@ emit_lisp_data_var (gcc_jit_type *type, enum
gcc_jit_global_kind kind)
SSDATA (final_name));
}
+/* Get the actual Lisp_Object rvalue for a given compiled constant.
+ For types COMP_LISP_CONST_VAR and COMP_LISP_CONST_SELF_REPR, this
+ does nothing but return the lisp_obj field.
+ For COMP_LISP_CONST_INIT_WITH_TYPE values, create a global constant
+ static to store the underlying data and return a pointer to it,
+ tagged with the corresponding Lisp_Type value.
+*/
static gcc_jit_rvalue *
comp_lisp_const_get_lisp_obj_rval (Lisp_Object lobj,
comp_lisp_const_t expr)
@@ -3023,6 +3027,41 @@ lisp_object_constructed_p (Lisp_Object obj)
|| CONSP (obj);
}
+/* Recursively create a comp_lisp_const_t for the given Lisp_Object
+ obj, with the given allocation class. We are able to statically
+ construct constant rvalues for the following objects:
+
+ * Fixnums (they're self-evaluating, so its trivial)
+ * Builtin bare symbols in lispsym (also self-evaluting)
+ * Strings without any intervals
+ * Floats
+ * Vectors, records and bytecode vectors
+ * Conses
+
+ For other kinds of object, emit_comp_lisp_obj will simply create a
+ static Lisp_Object global, and set it up to be initialized in
+ `comp_init_objs`. Conses and (pseudo)vectors containing them are
+ still statically initialized, but with space left for them for
+ `comp_init_objs` to fill. For instance, a form like
+ '#[1 non-c-symbol "foo"]' is compiled as:
+
+ static struct Lisp_String lisp_data_0 = {.u=
+ {.s = {.size = (3 & ARRAY_MARK_BIT), size_byte = -3, intervals = NULL,
+ data = "foo"}}};
+ static struct Lisp_Vector lisp_data_2 =
+ {.header = (3 & ARRAY_MARK_BIT),
+ .contents =
+ {make_fixnum (1), Qnil, make_lisp_ptr (&lisp_data_0, Lisp_String)}};
+ ...
+ void comp_init_objs(...) {
+ ...
+ lisp_data_2.contents[1] = Fintern ("non-c-symbol", Qnil);
+ ...
+ }
+
+ Note that this function does not compile lambda forms, because only
+ objects that need to be fixed up can be validly compiled. This
+ special case is handled by 'emit_static_data_container'. */
static comp_lisp_const_t
emit_comp_lisp_obj (Lisp_Object obj, Lisp_Object alloc_class)
{
@@ -3259,6 +3298,9 @@ emit_comp_lisp_obj (Lisp_Object obj, Lisp_Object
alloc_class)
return expr;
}
+/* Create a static Lisp_Vector variable for storing a data container,
+ with the given name and type. Returns a Lisp_Object reference to
+ the newly created vector. */
static gcc_jit_rvalue *
emit_data_container_vector (const char *name, jit_vector_type_t type)
{
@@ -3316,6 +3358,13 @@ emit_float_blocks (void)
}
}
+/* Define comp_init_objs, an exported function that takes the comp
+ unit being initialized as an argument, and initializes objects that
+ cannot be statically emitted, storing them in either d_staticpro or
+ d_ephemeral, depending on their allocation class. It also
+ initializes Lisp_Subr objects for anonymous lambda functions, by
+ setting their comp_u field to the unit passed to it from
+ load_comp_unit. */
static void
define_init_objs (void)
{
@@ -3431,6 +3480,8 @@ define_init_objs (void)
alloc_class_check (alloc_class);
+ /* If value is a mint pointer, it just references an rvalue,
+ so just set 'accessor' to that. */
if (mint_ptrp (value))
{
gcc_jit_rvalue *init = xmint_pointer (value);
@@ -3441,6 +3492,13 @@ define_init_objs (void)
}
else
{
+ /* Functions used for initializing/creating objects:
+ * Bare symbols - intern
+ * Uninterned bare symbols - make-symbol
+ * Everything else - read
+ TODO: Using read is a fairly inefficient way to create
+ new objects, we should use the appropriate functions for
+ the remaining object types here (make-hash-table, etc). */
next_block = gcc_jit_function_new_block (
comp.func, gcc_jit_object_get_debug_string (
gcc_jit_lvalue_as_object (accessor)));
@@ -3641,7 +3699,7 @@ emit_lisp_obj_rval (Lisp_Object obj)
return emit_coerce (comp.lisp_obj_type, n);
}
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp.compile_static_data)
return emit_lisp_obj_static_rval (obj);
#endif
@@ -3967,7 +4025,7 @@ emit_PURE_P (gcc_jit_rvalue *ptr)
PURESIZE));
}
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
static gcc_jit_rvalue *
emit_static_comp_object_p (gcc_jit_rvalue *obj)
{
@@ -4541,7 +4599,7 @@ emit_limple_insn (Lisp_Object insn)
emit_comment (SSDATA (Fprin1_to_string (arg[1], Qnil, Qnil)));
gcc_jit_rvalue *val;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp.compile_static_data)
val = emit_lisp_obj_static_rval (arg[1]);
else
@@ -4552,7 +4610,7 @@ emit_limple_insn (Lisp_Object insn)
gcc_jit_context_new_array_access (comp.ctxt, NULL,
reloc.array.r_val,
reloc.idx));
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
}
#endif
emit_frame_assignment (arg[0], val);
@@ -4707,7 +4765,7 @@ emit_maybe_gc_or_quit (Lisp_Object insn)
static void
emit_static_object (const char *name, Lisp_Object obj)
{
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp.compile_static_data)
{
comp_lisp_const_t expr = emit_comp_lisp_obj (obj, Qd_default);
@@ -4901,7 +4959,7 @@ emit_maybe_gc_or_quit (Lisp_Object insn)
}
#pragma GCC diagnostic pop
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
static Lisp_Object
emit_static_data_container (Lisp_Object container,
Lisp_Object alloc_class)
@@ -5081,7 +5139,7 @@ declare_runtime_imported_funcs (void)
ADD_IMPORTED (maybe_quit, comp.void_type, 0, NULL);
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
args[0] = comp.lisp_obj_type;
ADD_IMPORTED (helper_static_comp_object_p, comp.bool_type, 1, args);
#endif
@@ -5140,7 +5198,7 @@ emit_ctxt_code (void)
comp.lisp_obj_type,
COMP_UNIT_SYM);
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp.compile_static_data)
emit_lisp_data ();
else
@@ -5326,7 +5384,7 @@ define_lisp_cons (void)
NULL, 1, &comp.lisp_cons_u);
}
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
static void
define_cons_block (void)
{
@@ -6504,7 +6562,7 @@ define_CHECK_IMPURE (void)
gcc_jit_rvalue *pure_p
= emit_PURE_P (gcc_jit_param_as_rvalue (param[0]));
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
gcc_jit_rvalue *static_const_p
= emit_static_comp_object_p (gcc_jit_param_as_rvalue (param[0]));
pure_write_p
@@ -7207,18 +7265,18 @@ Return t on success. */)
/* Define data structures. */
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
comp.lisp_vector_structs_h = CALLN (Fmake_hash_table);
#endif
define_lisp_cons ();
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
define_cons_block ();
#endif
define_lisp_symbol_with_position ();
define_lisp_string ();
define_lisp_float ();
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
define_float_block ();
#endif
define_lisp_vector ();
@@ -7406,7 +7464,7 @@ DEFUN ("comp--compile-ctxt-to-file",
Fcomp__compile_ctxt_to_file,
comp.driver_options = CALL1I (comp-ctxt-driver-options, Vcomp_ctxt);
comp.compiler_options = CALL1I (comp-ctxt-compiler-options, Vcomp_ctxt);
- #ifdef HAVE_STATIC_LISP_GLOBALS
+ #ifdef USE_COMP_STATIC_LISP_OBJECTS
comp.compile_static_data = !NILP (CALL1I (comp-ctxt-with-static-data,
Vcomp_ctxt));
#endif
@@ -7442,7 +7500,7 @@ DEFUN ("comp--compile-ctxt-to-file",
Fcomp__compile_ctxt_to_file,
comp.ctxt, SSDATA (Ffile_name_nondirectory (filename)));
#endif
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp.compile_static_data)
{
comp.static_lisp_data_count = 0;
@@ -7468,7 +7526,7 @@ DEFUN ("comp--compile-ctxt-to-file",
Fcomp__compile_ctxt_to_file,
CALL1I (comp-data-container-idx,
CALL1I (comp-ctxt-d-ephemeral, Vcomp_ctxt));
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
}
#endif
@@ -7499,7 +7557,7 @@ DEFUN ("comp--compile-ctxt-to-file",
Fcomp__compile_ctxt_to_file,
if (!BASE_EQ (HASH_VALUE (func_h, i), Qunbound))
compile_function (HASH_VALUE (func_h, i));
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp.compile_static_data)
define_init_objs ();
#endif
@@ -7617,7 +7675,7 @@ helper_GET_SYMBOL_WITH_POSITION (Lisp_Object a)
return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Symbol_With_Pos);
}
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
static bool
helper_static_comp_object_p (Lisp_Object o)
{
@@ -7793,7 +7851,7 @@ typedef char *(*comp_lit_str_func) (void);
static Lisp_Object
load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name)
{
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp_u->have_static_lisp_data)
{
Lisp_Object *obj = dynlib_sym (comp_u->handle, name);
@@ -7926,7 +7984,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
bool loading_dump,
void **pure_reloc = dynlib_sym (handle, PURE_RELOC_SYM);
bool data_valid = false;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
Lisp_Object *data_staticpro;
Lisp_Object (*comp_init_objs) (Lisp_Object);
if (comp_u->have_static_lisp_data)
@@ -7966,7 +8024,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
bool loading_dump,
/* Imported functions. */
*freloc_link_table = freloc.link_table;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp_u->have_static_lisp_data)
{
comp_u->staticpro = *data_staticpro;
@@ -8052,7 +8110,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
bool loading_dump,
register_native_comp_unit (comp_u_lisp_obj);
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
if (comp_u->have_static_lisp_data)
comp_u->ephemeral = Qnil;
#endif
@@ -8148,7 +8206,7 @@ This gets called by top_level_run during the load phase.
*/)
Lisp_Object maxarg, Lisp_Object type, Lisp_Object rest,
Lisp_Object comp_u)
{
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
eassert (!XNATIVE_COMP_UNIT (comp_u)->have_static_lisp_data);
#endif
Lisp_Object doc_idx = FIRST (rest);
@@ -8266,13 +8324,13 @@ LATE-LOAD has to be non-nil when loading for deferred
compilation. */)
comp_u->file = filename;
comp_u->have_static_lisp_data =
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
dynlib_sym (comp_u->handle, HAVE_STATIC_LISP_DATA_SYM) != NULL;
#else
false;
#endif
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
comp_u->staticpro = Qnil;
comp_u->ephemeral = Qnil;
#endif
@@ -8441,7 +8499,7 @@ compiled one. */);
build_pure_c_string ("eln file inconsistent with current runtime "
"configuration, please recompile"));
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
DEFSYM (Qinit_expr_type_val, "init-expr-type-val");
DEFSYM (Qinit_expr_type_self_repr, "init-expr-type-self-repr");
DEFSYM (Qinit_expr_type_var, "init-expr-type-var");
@@ -8472,7 +8530,7 @@ compiled one. */);
staticpro (&loadsearch_re_list);
loadsearch_re_list = Qnil;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
staticpro (&comp.d_default_rvals);
comp.d_default_rvals = Qnil;
staticpro (&comp.d_impure_rvals);
diff --git a/src/comp.h b/src/comp.h
index ffa292ae115..e27f6c459c1 100644
--- a/src/comp.h
+++ b/src/comp.h
@@ -23,14 +23,33 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. */
#include <dynlib.h>
#ifdef HAVE_NATIVE_COMP
-#include <libgccjit.h>
-#if defined (LIBGCCJIT_HAVE_REFLECTION) \
- && defined (LIBGCCJIT_HAVE_CTORS) \
- && defined (LIBGCCJIT_HAVE_gcc_jit_type_get_aligned) \
- && defined (LIBGCCJIT_HAVE_ALIGNMENT) && USE_STACK_LISP_OBJECTS \
- && !GC_CHECK_MARKED_OBJECTS
-#define HAVE_STATIC_LISP_GLOBALS 1
-#endif
+# include <libgccjit.h>
+/* If USE_COMP_STATIC_LISP_OBJECTS, allow the AOT native compiler to
+ compile self evaluating Lisp forms as static consts in the
+ generated eln. Just like USE_STACK_LISP_OBJECTS, these objects
+ have better performance, and can significantly reduce heap usage.
+ Such objects are perma-marked, which means that data structures
+ that store the mark bit as a bitfield need to unset it in functions
+ that make use of the field in which it's stored (ASIZE for
+ Lisp_Vectors, SCHARS for Lisp_Strings, etc). A good way to think
+ about them is as every eln file having its own purespace for
+ storing self-evaluating forms.
+
+ Just like objects in purespace, these objects are emitted as
+ consts, so modifying them is illegal. To enforce that, we add an
+ additional check to CHECK_IMPURE that checks if the object being
+ modified is emitted statically by comp, exploiting their
+ "perma-marked" nature (see static_comp_object_p in alloc.c).
+
+ To make debugging a little easier, this is only enabled alongside
+ USE_STACK_LISP_OBJECTS, and when GC runtime checks are disabled. */
+# if defined(LIBGCCJIT_HAVE_REFLECTION) \
+ && defined(LIBGCCJIT_HAVE_CTORS) \
+ && defined(LIBGCCJIT_HAVE_gcc_jit_type_get_aligned) \
+ && defined(LIBGCCJIT_HAVE_ALIGNMENT) && USE_STACK_LISP_OBJECTS \
+ && !GC_CHECK_MARKED_OBJECTS
+# define USE_COMP_STATIC_LISP_OBJECTS 1
+# endif
#endif
struct Lisp_Native_Comp_Unit
@@ -62,7 +81,7 @@ struct Lisp_Native_Comp_Unit
dynlib_handle_ptr handle;
bool have_static_lisp_data;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
/* vector of dynamically allocated lisp objects, marked manually on GC. */
Lisp_Object staticpro;
/* vector of ephemeral objects that need to be marked only during
diff --git a/src/lisp.h b/src/lisp.h
index dc042e67ff6..e860bf4594f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1713,7 +1713,7 @@ INLINE ptrdiff_t
SCHARS (Lisp_Object string)
{
ptrdiff_t nchars = XSTRING (string)->u.s.size;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
nchars &= ~ARRAY_MARK_FLAG;
#endif
eassume (0 <= nchars);
@@ -1728,7 +1728,7 @@ STRING_BYTES (struct Lisp_String *s)
{
#ifdef GC_CHECK_STRING_BYTES
ptrdiff_t nbytes = string_bytes (s);
-#elif defined (HAVE_STATIC_LISP_GLOBALS)
+#elif defined (USE_COMP_STATIC_LISP_OBJECTS)
ptrdiff_t nbytes
= (s->u.s.size_byte < 0 ? s->u.s.size & ~ARRAY_MARK_FLAG
: s->u.s.size_byte);
@@ -1743,7 +1743,7 @@ INLINE ptrdiff_t
STRING_CHARS (struct Lisp_String *s)
{
ptrdiff_t nchars = s->u.s.size;
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
nchars &= ~ARRAY_MARK_FLAG;
#endif
eassume (0 <= nchars);
@@ -1811,7 +1811,7 @@ gc_asize (Lisp_Object array)
INLINE ptrdiff_t
ASIZE (Lisp_Object array)
{
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
ptrdiff_t size = gc_asize (array);
#else
ptrdiff_t size = XVECTOR (array)->header.size;
@@ -1823,7 +1823,7 @@ ASIZE (Lisp_Object array)
INLINE ptrdiff_t
VECTOR_ASIZE (struct Lisp_Vector *v)
{
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
return v->header.size & ~ARRAY_MARK_FLAG;
#else
return v->header.size;
@@ -4258,7 +4258,7 @@ extern void mark_c_stack (char const *, char const *);
extern void flush_stack_call_func1 (void (*func) (void *arg), void *arg);
extern void mark_memory (void const *start, void const *end);
extern void pin_object (Lisp_Object obj);
-#ifdef HAVE_STATIC_LISP_GLOBALS
+#ifdef USE_COMP_STATIC_LISP_OBJECTS
extern bool static_comp_object_p (Lisp_Object obj);
#else
INLINE bool
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- scratch/comp-static-data 5eda8d1abbe: Rename HAVE_STATIC_LISP_OBJECTS, add documentation for it.,
Vibhav Pant <=