aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorVibhav Pant2022-12-13 20:40:38 +0530
committerVibhav Pant2022-12-13 20:40:38 +0530
commit722b58bf9d83c2de2efbf18737fa97040bcf3094 (patch)
treee9e699fe661246f6dddf44bdb326703e00f8b567 /src/alloc.c
parent0f3bcbba835cc8dd91e0c0354075dd0996e0d3d0 (diff)
downloademacs-722b58bf9d83c2de2efbf18737fa97040bcf3094.tar.gz
emacs-722b58bf9d83c2de2efbf18737fa97040bcf3094.zip
Add static_comp_object_p for working with statically emmited objects
* src/alloc.c [HAVE_STATIC_LISP_GLOBALS] (static_comp_object_p): New function. When statically emitted lisp objects in native compilation are enabled, try to guess whether the provided object can be treated as a Lisp object allocated on the heap. (mark_object) [HAVE_STATIC_LISP_GLOBALS]: Skip marking the object if it has been emitted statically. (valid_lisp_object_p, survives_gc_p): Return true if the obj has been statically emitted. * src/puresize.h (puresize_h_CHECK_IMPURE): [HAVE_STATIC_LISP_GLOBALS]: Return true for statically emitted objects as well, since they are marked as constants during native compilation. * src/lisp.h (static_comp_object_p): Add declaration.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c
index b1fa50816e6..3a2ff64b193 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -2517,6 +2517,11 @@ make_formatted_string (char *buf, const char *format, ...)
2517void 2517void
2518pin_string (Lisp_Object string) 2518pin_string (Lisp_Object string)
2519{ 2519{
2520#ifdef HAVE_STATIC_LISP_GLOBALS
2521 if (static_comp_object_p (string))
2522 return;
2523#endif
2524
2520 eassert (STRINGP (string) && !STRING_MULTIBYTE (string)); 2525 eassert (STRINGP (string) && !STRING_MULTIBYTE (string));
2521 struct Lisp_String *s = XSTRING (string); 2526 struct Lisp_String *s = XSTRING (string);
2522 ptrdiff_t size = STRING_BYTES (s); 2527 ptrdiff_t size = STRING_BYTES (s);
@@ -4083,6 +4088,44 @@ set_interval_marked (INTERVAL i)
4083 i->gcmarkbit = true; 4088 i->gcmarkbit = true;
4084} 4089}
4085 4090
4091#ifdef HAVE_STATIC_LISP_GLOBALS
4092/* Certain self-evaluating Lisp objects in natively compiled code are
4093 * emitted as permanently marked. Note that this function does not
4094 * *truly* determine if an object was statically compiled, but instead
4095 * serves as a (hopefully) fool-proof heuristic to know if it
4096 * cannot be treated as an otherwise ordinary heap-allocated object
4097 * (whether it is mutable or not, can be freed, etc). */
4098bool
4099static_comp_object_p (Lisp_Object obj)
4100{
4101 if (pdumper_object_p (XPNTR (obj)))
4102 return false;
4103
4104 switch (XTYPE (obj))
4105 {
4106 case Lisp_String:
4107 /* see `emit_lisp_string_constructor_rval' in comp.c */
4108 return XSTRING (obj)->u.s.intervals == NULL
4109 && string_marked_p (XSTRING (obj))
4110 && (STRING_MULTIBYTE (obj)
4111 || XSTRING (obj)->u.s.size_byte == -3);
4112 case Lisp_Vectorlike:
4113 /* see `emit_comp_lisp_obj' in comp.c */
4114 return (VECTORP (obj) || RECORDP (obj) || COMPILEDP (obj))
4115 && vector_marked_p (XVECTOR (obj));
4116 case Lisp_Cons:
4117 return cons_marked_p (XCONS (obj));
4118 case Lisp_Float:
4119 return XFLOAT_MARKED_P (XFLOAT (obj));
4120 case Lisp_Symbol:
4121 case_Lisp_Int:
4122 return false;
4123 default:
4124 emacs_abort ();
4125 }
4126}
4127#endif
4128
4086 4129
4087/************************************************************************ 4130/************************************************************************
4088 Memory Full Handling 4131 Memory Full Handling
@@ -5299,7 +5342,7 @@ valid_lisp_object_p (Lisp_Object obj)
5299 return 1; 5342 return 1;
5300 5343
5301#ifdef HAVE_STATIC_LISP_GLOBALS 5344#ifdef HAVE_STATIC_LISP_GLOBALS
5302 return valid; 5345 return static_comp_object_p (obj);
5303#else 5346#else
5304 return 0; 5347 return 0;
5305#endif 5348#endif
@@ -6791,6 +6834,11 @@ process_mark_stack (ptrdiff_t base_sp)
6791 while (mark_stk.sp > base_sp) 6834 while (mark_stk.sp > base_sp)
6792 { 6835 {
6793 Lisp_Object obj = mark_stack_pop (); 6836 Lisp_Object obj = mark_stack_pop ();
6837#ifdef HAVE_STATIC_LISP_GLOBALS
6838 if (static_comp_object_p (obj))
6839 continue;
6840#endif
6841
6794 mark_obj: ; 6842 mark_obj: ;
6795 void *po = XPNTR (obj); 6843 void *po = XPNTR (obj);
6796 if (PURE_P (po)) 6844 if (PURE_P (po))
@@ -7115,6 +7163,10 @@ process_mark_stack (ptrdiff_t base_sp)
7115void 7163void
7116mark_object (Lisp_Object obj) 7164mark_object (Lisp_Object obj)
7117{ 7165{
7166#ifdef HAVE_STATIC_LISP_GLOBALS
7167 if (static_comp_object_p (obj))
7168 return;
7169#endif
7118 ptrdiff_t sp = mark_stk.sp; 7170 ptrdiff_t sp = mark_stk.sp;
7119 mark_stack_push_value (obj); 7171 mark_stack_push_value (obj);
7120 process_mark_stack (sp); 7172 process_mark_stack (sp);
@@ -7155,6 +7207,11 @@ mark_terminals (void)
7155bool 7207bool
7156survives_gc_p (Lisp_Object obj) 7208survives_gc_p (Lisp_Object obj)
7157{ 7209{
7210#ifdef HAVE_STATIC_LISP_GLOBALS
7211 if (static_comp_object_p (obj))
7212 return true;
7213#endif
7214
7158 bool survives_p; 7215 bool survives_p;
7159 7216
7160 switch (XTYPE (obj)) 7217 switch (XTYPE (obj))