From 4496a3f5ba899c89e45cd478a22b25ddf77869ec Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Fri, 20 Dec 2019 05:22:09 +0100 Subject: initial compilation unit as object add --- src/print.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/print.c') diff --git a/src/print.c b/src/print.c index 425b0dc4ee3..2e2c863ece8 100644 --- a/src/print.c +++ b/src/print.c @@ -1825,7 +1825,16 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, } break; #endif - +#ifdef HAVE_NATIVE_COMP + case PVEC_NATIVE_COMP_UNIT: + { + print_c_string ("#", printcharfun); + int len = sprintf (buf, "%d", XCOMPILATION_UNIT (obj)->fd); + strout (buf, len, len, printcharfun); + printchar ('>', printcharfun); + } + break; +#endif default: emacs_abort (); } -- cgit v1.2.3 From c5bb62f99db4b1c70e68e7c7a30ede8227f199a3 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sat, 21 Dec 2019 18:57:56 +0100 Subject: initial gc support --- src/alloc.c | 12 ++++++++++-- src/comp.c | 27 +++++++++++++++------------ src/comp.h | 1 + src/lisp.h | 34 +++++++++++++++++++++++++--------- src/print.c | 2 +- 5 files changed, 52 insertions(+), 24 deletions(-) (limited to 'src/print.c') diff --git a/src/alloc.c b/src/alloc.c index dba2c2df881..547990c7a9e 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6567,10 +6567,18 @@ mark_object (Lisp_Object arg) case PVEC_SUBR: #ifdef HAVE_NATIVE_COMP if (SUBRP_NATIVE_COMPILEDP (obj)) - set_vector_marked (ptr); + { + set_vector_marked (ptr); + struct Lisp_Subr *subr = XSUBR (obj); + mark_object (subr->native_comp_u); + } + break; + case PVEC_NATIVE_COMP_UNIT: + set_vector_marked (ptr); + /* FIXME see comp.h. */ + mark_object (XCOMPILATION_UNIT (obj)->data_vec); #endif break; - case PVEC_FREE: emacs_abort (); diff --git a/src/comp.c b/src/comp.c index ea5d3238d2c..71d4d79f9e7 100644 --- a/src/comp.c +++ b/src/comp.c @@ -3225,8 +3225,10 @@ load_static_obj (dynlib_handle_ptr handle, const char *name) } static void -load_comp_unit (dynlib_handle_ptr handle, Lisp_Object file) +load_comp_unit (Lisp_Object comp_u_obj, Lisp_Object file) { + struct Lisp_Native_Compilation_Unit *comp_u = XCOMPILATION_UNIT (comp_u_obj); + dynlib_handle_ptr handle = comp_u->handle; struct thread_state ***current_thread_reloc = dynlib_sym (handle, CURRENT_THREAD_RELOC_SYM); EMACS_INT ***pure_reloc = dynlib_sym (handle, PURE_RELOC_SYM); @@ -3249,11 +3251,9 @@ load_comp_unit (dynlib_handle_ptr handle, Lisp_Object file) EMACS_INT d_vec_len = XFIXNUM (Flength (d_vec)); for (EMACS_INT i = 0; i < d_vec_len; i++) - { data_relocs[i] = AREF (d_vec, i); - prevent_gc (data_relocs[i]); - } + comp_u->data_vec = d_vec; /* Imported functions. */ *freloc_link_table = freloc.link_table; @@ -3270,24 +3270,26 @@ DEFUN ("comp--register-subr", Fcomp__register_subr, Scomp__register_subr, (Lisp_Object name, Lisp_Object minarg, Lisp_Object maxarg, Lisp_Object c_name, Lisp_Object doc, Lisp_Object intspec) { - dynlib_handle_ptr handle = xmint_pointer (XCAR (load_handle_stack)); + Lisp_Object comp_u = XCAR (load_handle_stack); + dynlib_handle_ptr handle = XCOMPILATION_UNIT (comp_u)->handle; if (!handle) xsignal0 (Qwrong_register_subr_call); void *func = dynlib_sym (handle, SSDATA (c_name)); eassert (func); - /* FIXME add gc support, now just leaking. */ - union Aligned_Lisp_Subr *x = xmalloc (sizeof (*x)); - - x->s.header.size = PVEC_SUBR << PSEUDOVECTOR_AREA_BITS; + union Aligned_Lisp_Subr *x = + (union Aligned_Lisp_Subr *) allocate_pseudovector ( + VECSIZE (union Aligned_Lisp_Subr), + 0, VECSIZE (union Aligned_Lisp_Subr), + PVEC_SUBR); x->s.function.a0 = func; x->s.min_args = XFIXNUM (minarg); x->s.max_args = FIXNUMP (maxarg) ? XFIXNUM (maxarg) : MANY; x->s.symbol_name = xstrdup (SSDATA (Fsymbol_name (name))); x->s.native_intspec = intspec; x->s.native_doc = doc; - XSETPVECTYPE (&x->s, PVEC_SUBR); + x->s.native_comp_u = comp_u; Lisp_Object tem; XSETSUBR (tem, &x->s); set_symbol_function (name, tem); @@ -3324,11 +3326,12 @@ DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 1, 0, copy_file_fd (fd_out, fd_in, &st, Qnil, file); dynlib_handle_ptr handle = dynlib_open (format_string ("/proc/%d/fd/%d", getpid (), fd_out)); - load_handle_stack = Fcons (make_mint_ptr (handle), load_handle_stack); + Lisp_Object comp_u = make_native_comp_u (fd_in, handle); + load_handle_stack = Fcons (comp_u, load_handle_stack); if (!handle) xsignal2 (Qnative_lisp_load_failed, file, build_string (dynlib_error ())); - load_comp_unit (handle, file); + load_comp_unit (comp_u, file); load_handle_stack = XCDR (load_handle_stack); diff --git a/src/comp.h b/src/comp.h index 457b678699c..876615e8dd4 100644 --- a/src/comp.h +++ b/src/comp.h @@ -29,6 +29,7 @@ struct Lisp_Native_Compilation_Unit /* Compilation unit file descriptor and handle. */ int fd; dynlib_handle_ptr handle; + Lisp_Object data_vec; /* FIXME this should be in the normal lisp slot. */ }; INLINE bool diff --git a/src/lisp.h b/src/lisp.h index 7a4b3517574..3d467a84d18 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1342,6 +1342,7 @@ dead_object (void) #define XSETTHREAD(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_THREAD)) #define XSETMUTEX(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_MUTEX)) #define XSETCONDVAR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CONDVAR)) +#define XSETNATIVE_COMP_UNIT(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_NATIVE_COMP_UNIT)) /* Efficiently convert a pointer to a Lisp object and back. The pointer is represented as a fixnum, so the garbage collector @@ -2100,7 +2101,7 @@ struct Lisp_Subr Lisp_Object native_doc; }; #ifdef HAVE_NATIVE_COMP - Lisp_Object native_comp_u;; + Lisp_Object native_comp_u; #endif } GCALIGNED_STRUCT; union Aligned_Lisp_Subr @@ -2138,14 +2139,6 @@ enum char_table_specials = PSEUDOVECSIZE (struct Lisp_Sub_Char_Table, contents) - 1 }; -#ifdef HAVE_NATIVE_COMP -INLINE bool -SUBRP_NATIVE_COMPILEDP (Lisp_Object a) -{ - return SUBRP (a) && XSUBR (a)->native_comp_u; -} -#endif - /* Sanity-check pseudovector layout. */ verify (offsetof (struct Lisp_Char_Table, defalt) == header_size); verify (offsetof (struct Lisp_Char_Table, extras) @@ -4769,6 +4762,29 @@ extern void syms_of_profiler (void); extern char *emacs_root_dir (void); #endif /* DOS_NT */ +#ifdef HAVE_NATIVE_COMP +INLINE bool +SUBRP_NATIVE_COMPILEDP (Lisp_Object a) +{ + return SUBRP (a) && XSUBR (a)->native_comp_u; +} + +INLINE Lisp_Object +make_native_comp_u (int fd, dynlib_handle_ptr handle) +{ + struct Lisp_Native_Compilation_Unit *x = + (struct Lisp_Native_Compilation_Unit *) allocate_pseudovector ( + VECSIZE (struct Lisp_Native_Compilation_Unit), + 0, VECSIZE (struct Lisp_Native_Compilation_Unit), + PVEC_NATIVE_COMP_UNIT); + x->fd = fd; + x->handle = handle; + Lisp_Object cu; + XSETNATIVE_COMP_UNIT (cu, x); + return cu; +} +#endif + /* Defined in lastfile.c. */ extern char my_edata[]; extern char my_endbss[]; diff --git a/src/print.c b/src/print.c index 2e2c863ece8..e7ddafbbbbd 100644 --- a/src/print.c +++ b/src/print.c @@ -1828,7 +1828,7 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, #ifdef HAVE_NATIVE_COMP case PVEC_NATIVE_COMP_UNIT: { - print_c_string ("#", printcharfun); + print_c_string ("#fd); strout (buf, len, len, printcharfun); printchar ('>', printcharfun); -- cgit v1.2.3 From 4c8b46514d87856e5e2044bce804ad0156097d04 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sun, 22 Dec 2019 08:12:27 +0100 Subject: some rename on compilation unit struct --- src/alloc.c | 6 +++--- src/comp.c | 6 +++--- src/comp.h | 12 ++++++------ src/lisp.h | 10 +++++----- src/print.c | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/print.c') diff --git a/src/alloc.c b/src/alloc.c index 547990c7a9e..d47f9c8a574 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3026,8 +3026,8 @@ cleanup_vector (struct Lisp_Vector *vector) #ifdef HAVE_NATIVE_COMP else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_NATIVE_COMP_UNIT)) { - struct Lisp_Native_Compilation_Unit *cu = - PSEUDOVEC_STRUCT (vector, Lisp_Native_Compilation_Unit); + struct Lisp_Native_Comp_Unit *cu = + PSEUDOVEC_STRUCT (vector, Lisp_Native_Comp_Unit); eassert (cu->handle); dynlib_close (cu->handle); } @@ -6576,7 +6576,7 @@ mark_object (Lisp_Object arg) case PVEC_NATIVE_COMP_UNIT: set_vector_marked (ptr); /* FIXME see comp.h. */ - mark_object (XCOMPILATION_UNIT (obj)->data_vec); + mark_object (XNATIVE_COMP_UNIT (obj)->data_vec); #endif break; case PVEC_FREE: diff --git a/src/comp.c b/src/comp.c index 71d4d79f9e7..c74e5cf2e6c 100644 --- a/src/comp.c +++ b/src/comp.c @@ -3227,7 +3227,7 @@ load_static_obj (dynlib_handle_ptr handle, const char *name) static void load_comp_unit (Lisp_Object comp_u_obj, Lisp_Object file) { - struct Lisp_Native_Compilation_Unit *comp_u = XCOMPILATION_UNIT (comp_u_obj); + struct Lisp_Native_Comp_Unit *comp_u = XNATIVE_COMP_UNIT (comp_u_obj); dynlib_handle_ptr handle = comp_u->handle; struct thread_state ***current_thread_reloc = dynlib_sym (handle, CURRENT_THREAD_RELOC_SYM); @@ -3271,7 +3271,7 @@ DEFUN ("comp--register-subr", Fcomp__register_subr, Scomp__register_subr, Lisp_Object c_name, Lisp_Object doc, Lisp_Object intspec) { Lisp_Object comp_u = XCAR (load_handle_stack); - dynlib_handle_ptr handle = XCOMPILATION_UNIT (comp_u)->handle; + dynlib_handle_ptr handle = XNATIVE_COMP_UNIT (comp_u)->handle; if (!handle) xsignal0 (Qwrong_register_subr_call); @@ -3313,7 +3313,7 @@ DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 1, 0, /* FIXME non portable. */ /* We copy the content of the file to be loaded in a memory mapped file. We then keep track of this in the struct - Lisp_Native_Compilation_Unit. In case this will be overwritten + Lisp_Native_Comp_Unit. In case this will be overwritten or delete we'll dump the right data. */ int fd_in = emacs_open (SSDATA (file), O_RDONLY, 0); int fd_out = memfd_create (SSDATA (file), 0); diff --git a/src/comp.h b/src/comp.h index 876615e8dd4..04c57278667 100644 --- a/src/comp.h +++ b/src/comp.h @@ -23,7 +23,7 @@ along with GNU Emacs. If not, see . */ #include -struct Lisp_Native_Compilation_Unit +struct Lisp_Native_Comp_Unit { union vectorlike_header header; /* Compilation unit file descriptor and handle. */ @@ -33,16 +33,16 @@ struct Lisp_Native_Compilation_Unit }; INLINE bool -COMPILATIONP_UNITP (Lisp_Object a) +NATIVE_COMP_UNITP (Lisp_Object a) { return PSEUDOVECTORP (a, PVEC_NATIVE_COMP_UNIT); } -INLINE struct Lisp_Native_Compilation_Unit * -XCOMPILATION_UNIT (Lisp_Object a) +INLINE struct Lisp_Native_Comp_Unit * +XNATIVE_COMP_UNIT (Lisp_Object a) { - eassert (COMPILATIONP_UNITP (a)); - return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Native_Compilation_Unit); + eassert (NATIVE_COMP_UNITP (a)); + return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Native_Comp_Unit); } /* Defined in comp.c. */ diff --git a/src/lisp.h b/src/lisp.h index 3d467a84d18..2e4a6c89846 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4772,11 +4772,11 @@ SUBRP_NATIVE_COMPILEDP (Lisp_Object a) INLINE Lisp_Object make_native_comp_u (int fd, dynlib_handle_ptr handle) { - struct Lisp_Native_Compilation_Unit *x = - (struct Lisp_Native_Compilation_Unit *) allocate_pseudovector ( - VECSIZE (struct Lisp_Native_Compilation_Unit), - 0, VECSIZE (struct Lisp_Native_Compilation_Unit), - PVEC_NATIVE_COMP_UNIT); + struct Lisp_Native_Comp_Unit *x = + (struct Lisp_Native_Comp_Unit *) allocate_pseudovector ( + VECSIZE (struct Lisp_Native_Comp_Unit), + 0, VECSIZE (struct Lisp_Native_Comp_Unit), + PVEC_NATIVE_COMP_UNIT); x->fd = fd; x->handle = handle; Lisp_Object cu; diff --git a/src/print.c b/src/print.c index e7ddafbbbbd..4d7932a81d7 100644 --- a/src/print.c +++ b/src/print.c @@ -1829,7 +1829,7 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, case PVEC_NATIVE_COMP_UNIT: { print_c_string ("#fd); + int len = sprintf (buf, "%d", XNATIVE_COMP_UNIT (obj)->fd); strout (buf, len, len, printcharfun); printchar ('>', printcharfun); } -- cgit v1.2.3 From 12639610f78f9006b70933bfc6898c1312f95290 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 23 Dec 2019 09:24:51 +0100 Subject: better printing for native compilation unit --- src/comp.h | 2 +- src/print.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/print.c') diff --git a/src/comp.h b/src/comp.h index 677ffdc4d7f..36ee5d10e45 100644 --- a/src/comp.h +++ b/src/comp.h @@ -26,7 +26,7 @@ along with GNU Emacs. If not, see . */ struct Lisp_Native_Comp_Unit { union vectorlike_header header; - /* Original eln file loaded (just for debug purpose). */ + /* Original eln file loaded. */ Lisp_Object file; /* Analogous to the constant vector but per compilation unit. */ Lisp_Object data_vec; diff --git a/src/print.c b/src/print.c index 4d7932a81d7..9013ccc8ccd 100644 --- a/src/print.c +++ b/src/print.c @@ -1829,8 +1829,7 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, case PVEC_NATIVE_COMP_UNIT: { print_c_string ("#fd); - strout (buf, len, len, printcharfun); + print_string (XNATIVE_COMP_UNIT (obj)->file, printcharfun); printchar ('>', printcharfun); } break; -- cgit v1.2.3 From 511415f6f656a5bf4da4f5f49d58de9dc7d5d64d Mon Sep 17 00:00:00 2001 From: AndreaCorallo Date: Tue, 25 Feb 2020 22:37:20 +0000 Subject: Store optimize qualities into .eln files For now just comp-speed and comp-debug are stored. --- src/comp.c | 10 ++++++++++ src/comp.h | 1 + src/print.c | 7 +++++-- 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/print.c') diff --git a/src/comp.c b/src/comp.c index 9855e352785..0fc6e412924 100644 --- a/src/comp.c +++ b/src/comp.c @@ -47,6 +47,7 @@ along with GNU Emacs. If not, see . */ #define TEXT_DATA_RELOC_SYM "text_data_reloc" #define TEXT_DATA_RELOC_IMPURE_SYM "text_data_reloc_imp" #define TEXT_DATA_RELOC_EPHEMERAL_SYM "text_data_reloc_eph" +#define TEXT_OPTIM_QLY "text_optim_qly" #define SPEED XFIXNUM (Fsymbol_value (Qcomp_speed)) #define COMP_DEBUG XFIXNUM (Fsymbol_value (Qcomp_debug)) @@ -1915,6 +1916,14 @@ declare_runtime_imported_funcs (void) static void emit_ctxt_code (void) { + /* Emit optimize qualities. */ + Lisp_Object opt_qly[] = + { Fcons (Qcomp_speed, + Fsymbol_value (Qcomp_speed)), + Fcons (Qcomp_debug, + Fsymbol_value (Qcomp_debug)) }; + emit_static_object (TEXT_OPTIM_QLY, Flist (2, opt_qly)); + comp.current_thread_ref = gcc_jit_lvalue_as_rvalue ( gcc_jit_context_new_global ( @@ -3414,6 +3423,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump) /* Imported data. */ if (!loading_dump) { + comp_u->optimize_qualities = load_static_obj (comp_u, TEXT_OPTIM_QLY); comp_u->data_vec = load_static_obj (comp_u, TEXT_DATA_RELOC_SYM); comp_u->data_impure_vec = load_static_obj (comp_u, TEXT_DATA_RELOC_IMPURE_SYM); diff --git a/src/comp.h b/src/comp.h index 6019831bc30..3aff440ecb7 100644 --- a/src/comp.h +++ b/src/comp.h @@ -36,6 +36,7 @@ struct Lisp_Native_Comp_Unit union vectorlike_header header; /* Original eln file loaded. */ Lisp_Object file; + Lisp_Object optimize_qualities; /* Analogous to the constant vector but per compilation unit. */ Lisp_Object data_vec; /* Same but for data that cannot be moved to pure space. diff --git a/src/print.c b/src/print.c index ce8dd625b68..9b8308a6758 100644 --- a/src/print.c +++ b/src/print.c @@ -1840,8 +1840,11 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, #ifdef HAVE_NATIVE_COMP case PVEC_NATIVE_COMP_UNIT: { - print_c_string ("#file, printcharfun); + struct Lisp_Native_Comp_Unit *cu = XNATIVE_COMP_UNIT (obj); + print_c_string ("#file, printcharfun); + printchar (' ', printcharfun); + print_object (cu->optimize_qualities, printcharfun, escapeflag); printchar ('>', printcharfun); } break; -- cgit v1.2.3