summaryrefslogtreecommitdiff
path: root/src/lisp.h
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2021-12-31 17:24:31 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2022-01-24 11:41:46 +0100
commit65caf5b205d22f76bb4ec85cfe597b621a83afb3 (patch)
tree8a4b71295d56f76ad0fee6c4471aa036c6e7e226 /src/lisp.h
parentce1de3a8d9723305f48fd4527fbceaff3cec50ba (diff)
downloademacs-65caf5b205d22f76bb4ec85cfe597b621a83afb3.tar.gz
emacs-65caf5b205d22f76bb4ec85cfe597b621a83afb3.tar.bz2
emacs-65caf5b205d22f76bb4ec85cfe597b621a83afb3.zip
Pin bytecode strings to avoid copy at call time
Avoid making a copy (in the interpreter C stack frame) of the bytecode string by making sure it won't be moved by the GC. This is done by reallocating it to the heap normally only used for large strings, which isn't compacted. This requires that we retain an explicit reference to the bytecode string object (`bytestr`) lest it be GCed away should all other references vanish during execution. We allocate an extra stack slot for that, as we already do for the constant vector object. * src/alloc.c (allocate_string_data): Add `immovable` argument. (resize_string_data, make_clear_multibyte_string): Use it. (pin_string): New. * src/pdumper.c (dump_string): Fix incorrect comment. Update hash for Lisp_String (only comments changed, not contents). * src/lread.c (read1): * src/alloc.c (Fmake_byte_code, purecopy): * src/bytecode.c (Fbyte_code): Pin bytecode on object creation. (exec_byte_code): Don't copy bytecode. Retain `bytestr` explicitly. * src/lisp.h (Lisp_String): Explain special size_byte values. (string_immovable_p): New.
Diffstat (limited to 'src/lisp.h')
-rw-r--r--src/lisp.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lisp.h b/src/lisp.h
index 020fe6e0943..fdcb7f39d59 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1554,7 +1554,9 @@ struct Lisp_String
struct
{
ptrdiff_t size; /* MSB is used as the markbit. */
- ptrdiff_t size_byte; /* Set to -1 for unibyte strings. */
+ ptrdiff_t size_byte; /* Set to -1 for unibyte strings,
+ -2 for data in rodata,
+ -3 for immovable unibyte strings. */
INTERVAL intervals; /* Text properties in this string. */
unsigned char *data;
} s;
@@ -1702,6 +1704,13 @@ CHECK_STRING_NULL_BYTES (Lisp_Object string)
Qfilenamep, string);
}
+/* True if STR is immovable (whose data won't move during GC). */
+INLINE bool
+string_immovable_p (Lisp_Object str)
+{
+ return XSTRING (str)->u.s.size_byte == -3;
+}
+
/* A regular vector is just a header plus an array of Lisp_Objects. */
struct Lisp_Vector
@@ -4048,6 +4057,7 @@ extern Lisp_Object make_specified_string (const char *,
ptrdiff_t, ptrdiff_t, bool);
extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, bool);
extern Lisp_Object make_pure_c_string (const char *, ptrdiff_t);
+extern void pin_string (Lisp_Object string);
/* Make a string allocated in pure space, use STR as string data. */