aboutsummaryrefslogtreecommitdiffstats
path: root/src/thread.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd2022-03-13 17:26:05 +0100
committerMattias EngdegÄrd2022-03-13 17:51:49 +0100
commit3ed79cdbf21039fa209c421f746c0b49ec33f4da (patch)
treef6d3c5dbf4f1d5ea1a413c80293b1abc52571ff3 /src/thread.c
parent267f41c7ce1e02f392b57aa338d387e7627df184 (diff)
downloademacs-3ed79cdbf21039fa209c421f746c0b49ec33f4da.tar.gz
emacs-3ed79cdbf21039fa209c421f746c0b49ec33f4da.zip
Separate bytecode stack
Use a dedicated stack for bytecode, instead of using the C stack. Stack frames are managed explicitly and we stay in the same exec_byte_code activation throughout bytecode function calls and returns. In other words, exec_byte_code no longer uses recursion for calling bytecode functions. This results in better performance, and bytecode recursion is no longer limited by the size of the C stack. The bytecode stack is currently of fixed size but overflow is handled gracefully by signalling a Lisp error instead of the hard crash that we get now. In addition, GC marking of the stack is now faster and more precise. Full precision could be attained if desired. * src/alloc.c (ATTRIBUTE_NO_SANITIZE_ADDRESS): Make non-static. * src/bytecode.c (enum stack_frame_index, BC_STACK_SIZE) (sf_get_ptr, sf_set_ptr, sf_get_lisp_ptr, sf_set_lisp_ptr) (sf_get_saved_pc, sf_set_saved_pc, init_bc_thread, free_bc_thread) (mark_bytecode, Finternal_stack_stats, valid_sp): New. (exec_byte_code): Adapt to use the new bytecode stack. (syms_of_bytecode): Add defsubr. * src/eval.c (unwind_to_catch): Restore saved stack frame. (push_handler_nosignal): Save stack frame. * src/lisp.h (struct handler): Add act_rec member. (get_act_rec, set_act_rec): New. * src/thread.c (mark_one_thread): Call mark_bytecode. (finalize_one_thread): Free bytecode thread state. (Fmake_thread, init_threads): Set up bytecode thread state. * src/thread.h (struct bc_thread_state): New. (struct thread_state): Add bytecode thread state.
Diffstat (limited to 'src/thread.c')
-rw-r--r--src/thread.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/thread.c b/src/thread.c
index b5b7d7c0d71..c6742341fb8 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -671,6 +671,8 @@ mark_one_thread (struct thread_state *thread)
671 mark_object (tem); 671 mark_object (tem);
672 } 672 }
673 673
674 mark_bytecode (&thread->bc);
675
674 /* No need to mark Lisp_Object members like m_last_thing_searched, 676 /* No need to mark Lisp_Object members like m_last_thing_searched,
675 as mark_threads_callback does that by calling mark_object. */ 677 as mark_threads_callback does that by calling mark_object. */
676} 678}
@@ -839,6 +841,7 @@ finalize_one_thread (struct thread_state *state)
839 free_search_regs (&state->m_search_regs); 841 free_search_regs (&state->m_search_regs);
840 free_search_regs (&state->m_saved_search_regs); 842 free_search_regs (&state->m_saved_search_regs);
841 sys_cond_destroy (&state->thread_condvar); 843 sys_cond_destroy (&state->thread_condvar);
844 free_bc_thread (&state->bc);
842} 845}
843 846
844DEFUN ("make-thread", Fmake_thread, Smake_thread, 1, 2, 0, 847DEFUN ("make-thread", Fmake_thread, Smake_thread, 1, 2, 0,
@@ -868,6 +871,8 @@ If NAME is given, it must be a string; it names the new thread. */)
868 new_thread->m_specpdl_end = new_thread->m_specpdl + size; 871 new_thread->m_specpdl_end = new_thread->m_specpdl + size;
869 new_thread->m_specpdl_ptr = new_thread->m_specpdl; 872 new_thread->m_specpdl_ptr = new_thread->m_specpdl;
870 873
874 init_bc_thread (&new_thread->bc);
875
871 sys_cond_init (&new_thread->thread_condvar); 876 sys_cond_init (&new_thread->thread_condvar);
872 877
873 /* We'll need locking here eventually. */ 878 /* We'll need locking here eventually. */
@@ -1127,6 +1132,7 @@ init_threads (void)
1127 sys_mutex_lock (&global_lock); 1132 sys_mutex_lock (&global_lock);
1128 current_thread = &main_thread.s; 1133 current_thread = &main_thread.s;
1129 main_thread.s.thread_id = sys_thread_self (); 1134 main_thread.s.thread_id = sys_thread_self ();
1135 init_bc_thread (&main_thread.s.bc);
1130} 1136}
1131 1137
1132void 1138void