From: Nickolas Lloyd Date: Sun, 1 Jan 2017 21:32:32 +0000 (-0500) Subject: Avoid extra calls to `jit_function_to_closure' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=932eacc3df12fea80aa4c17cc8413d7a7355f512;p=emacs.git Avoid extra calls to `jit_function_to_closure' * src/bytecode-jit.c (jit_byte_code__, jit_exec): * src/alloc.c (cleanup_vector, mark_compiled): Add vector slot for holding the generated closure so that it only has to be generated once. --- diff --git a/src/alloc.c b/src/alloc.c index 585be227941..1a3f747ec5c 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3219,11 +3219,12 @@ cleanup_vector (struct Lisp_Vector *vector) else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_CONDVAR)) finalize_one_condvar ((struct Lisp_CondVar *) vector); else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_COMPILED) - && (void *)vector->contents[COMPILED_JIT_ID] != NULL) + && vector->contents[COMPILED_JIT_CTXT] != (Lisp_Object )NULL) { - jit_function_t func = - (jit_function_t )vector->contents[COMPILED_JIT_ID]; - jit_context_destroy (jit_function_get_context (func)); + jit_context_t ctxt = (jit_context_t )vector->contents[COMPILED_JIT_CTXT]; + jit_context_destroy (ctxt); + vector->contents[COMPILED_JIT_CTXT] = (Lisp_Object )NULL; + vector->contents[COMPILED_JIT_CLOSURE] = (Lisp_Object )NULL; } } @@ -3481,9 +3482,9 @@ stack before executing the byte-code. usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) (ptrdiff_t nargs, Lisp_Object *args) { - Lisp_Object val = make_uninit_vector (max(nargs, COMPILED_JIT_ID + 1)); + Lisp_Object val = make_uninit_vector (max(nargs, COMPILED_JIT_CLOSURE + 1)); struct Lisp_Vector *p = XVECTOR (val); - size_t size = min(nargs, COMPILED_JIT_ID); + size_t size = min(nargs, COMPILED_JIT_CLOSURE); /* Don't allow the global zero_vector to become a byte code object. */ eassert (0 < nargs); @@ -3507,9 +3508,10 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT must convert them back to the original unibyte form. */ p->contents[COMPILED_BYTECODE] = Fstring_as_unibyte (p->contents[COMPILED_BYTECODE]); - /* set rest size so that total footprint = COMPILED_JIT_ID + 1 */ - XSETPVECTYPESIZE (p, PVEC_COMPILED, size, COMPILED_JIT_ID + 1 - size); - p->contents[COMPILED_JIT_ID] = 0; + /* set rest size so that total footprint = COMPILED_JIT_CLOSURE + 1 */ + XSETPVECTYPESIZE (p, PVEC_COMPILED, size, COMPILED_JIT_CLOSURE + 1 - size); + p->contents[COMPILED_JIT_CTXT] = (Lisp_Object )NULL; + p->contents[COMPILED_JIT_CLOSURE] = (Lisp_Object )NULL; XSETCOMPILED (val, p); return val; } diff --git a/src/bytecode-jit.c b/src/bytecode-jit.c index 6ab73492195..0d058c95b07 100644 --- a/src/bytecode-jit.c +++ b/src/bytecode-jit.c @@ -675,7 +675,7 @@ jit_exec (Lisp_Object byte_code, Lisp_Object args_template, ptrdiff_t nargs, Lis stack.next = byte_stack_list; byte_stack_list = &stack; Lisp_Object (*func)(Lisp_Object *) = - (Lisp_Object (*)(Lisp_Object *))jit_function_to_closure ((void *)AREF (byte_code, COMPILED_JIT_ID)); + (void *)AREF (byte_code, COMPILED_JIT_CLOSURE); Lisp_Object ret = func (top); byte_stack_list = byte_stack_list->next; return ret; @@ -820,7 +820,7 @@ jit_byte_code__ (Lisp_Object byte_code) CHECK_COMPILED (byte_code); /* check if function has already been compiled */ - if (XVECTOR (byte_code)->contents[COMPILED_JIT_ID]) + if (XVECTOR (byte_code)->contents[COMPILED_JIT_CTXT] != (Lisp_Object )NULL) return; if (!jit_initialized) emacs_jit_init (); @@ -1588,7 +1588,9 @@ jit_byte_code__ (Lisp_Object byte_code) jit_context_build_end (ctxt.libjit_ctxt); if (err) emacs_abort (); - ASET (byte_code, COMPILED_JIT_ID, (Lisp_Object )ctxt.func); + ASET (byte_code, COMPILED_JIT_CTXT, (Lisp_Object )ctxt.libjit_ctxt); + ASET (byte_code, COMPILED_JIT_CLOSURE, + (Lisp_Object )jit_function_to_closure (ctxt.func)); } } diff --git a/src/bytecode.c b/src/bytecode.c index 0e95c3ea559..8b132caac0a 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -1291,7 +1291,7 @@ exec_byte_code (Lisp_Object byte_code, Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args) { #ifdef HAVE_LIBJIT - if (AREF (byte_code, COMPILED_JIT_ID)) + if (AREF (byte_code, COMPILED_JIT_CTXT) != (Lisp_Object )NULL) return jit_exec (byte_code, args_template, nargs, args); else if (byte_code_jit_on) { diff --git a/src/lisp.h b/src/lisp.h index 63b336a106d..931dcef7712 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2592,7 +2592,8 @@ enum Lisp_Compiled COMPILED_STACK_DEPTH = 3, COMPILED_DOC_STRING = 4, COMPILED_INTERACTIVE = 5, - COMPILED_JIT_ID = 6 + COMPILED_JIT_CTXT = 6, + COMPILED_JIT_CLOSURE = 7 }; /* Flag bits in a character. These also get used in termhooks.h.