]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid extra calls to `jit_function_to_closure'
authorNickolas Lloyd <ultrageek.lloyd@gmail.com>
Sun, 1 Jan 2017 21:32:32 +0000 (16:32 -0500)
committerNickolas Lloyd <ultrageek.lloyd@gmail.com>
Mon, 23 Jan 2017 23:34:16 +0000 (18:34 -0500)
* 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.

src/alloc.c
src/bytecode-jit.c
src/bytecode.c
src/lisp.h

index 585be227941054ee2d2448f6633df7ca8cfcb4ad..1a3f747ec5c0ede6c957801ebda3cabae70a2567 100644 (file)
@@ -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;
 }
index 6ab73492195c741daedf26cc577069c3f81ab252..0d058c95b071eb9b51b06cdfc3ea9f5b3a3daaa7 100644 (file)
@@ -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));
   }
 }
 
index 0e95c3ea559155ada58cb529ae890aab4cf1d935..8b132caac0a5bc0044f99e22abf11e81154ce1ec 100644 (file)
@@ -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)
     {
index 63b336a106d906eea15d463d23eb259b3034234f..931dcef7712e6bc33d23f04f65b7039a0771f20e 100644 (file)
@@ -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.