summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c53
1 files changed, 34 insertions, 19 deletions
diff --git a/src/alloc.c b/src/alloc.c
index e909d312c4e..a2302a6f462 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -30,6 +30,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <pthread.h>
#endif
+#ifdef HAVE_LIBJIT
+#include <jit.h>
+#endif
+
#include "lisp.h"
#include "dispextern.h"
#include "intervals.h"
@@ -3184,6 +3188,16 @@ cleanup_vector (struct Lisp_Vector *vector)
finalize_one_mutex ((struct Lisp_Mutex *) vector);
else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_CONDVAR))
finalize_one_condvar ((struct Lisp_CondVar *) vector);
+ else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_COMPILED)
+ && vector->contents[COMPILED_JIT_CTXT] != (Lisp_Object )NULL)
+ {
+#ifdef HAVE_LIBJIT
+ jit_context_t ctxt = (jit_context_t )vector->contents[COMPILED_JIT_CTXT];
+ jit_context_destroy (ctxt);
+#endif
+ vector->contents[COMPILED_JIT_CTXT] = (Lisp_Object )NULL;
+ vector->contents[COMPILED_JIT_CLOSURE] = (Lisp_Object )NULL;
+ }
}
/* Reclaim space used by unmarked vectors. */
@@ -3422,23 +3436,6 @@ usage: (vector &rest OBJECTS) */)
return val;
}
-void
-make_byte_code (struct Lisp_Vector *v)
-{
- /* Don't allow the global zero_vector to become a byte code object. */
- eassert (0 < v->header.size);
-
- if (v->header.size > 1 && STRINGP (v->contents[1])
- && STRING_MULTIBYTE (v->contents[1]))
- /* BYTECODE-STRING must have been produced by Emacs 20.2 or the
- earlier because they produced a raw 8-bit string for byte-code
- and now such a byte-code string is loaded as multibyte while
- raw 8-bit characters converted to multibyte form. Thus, now we
- must convert them back to the original unibyte form. */
- v->contents[1] = Fstring_as_unibyte (v->contents[1]);
- XSETPVECTYPE (v, PVEC_COMPILED);
-}
-
DEFUN ("make-byte-code", Fmake_byte_code, Smake_byte_code, 4, MANY, 0,
doc: /* Create a byte-code object with specified arguments as elements.
The arguments should be the ARGLIST, bytecode-string BYTE-CODE, constant
@@ -3457,8 +3454,12 @@ 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 (nargs);
+ 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_CLOSURE);
+
+ /* Don't allow the global zero_vector to become a byte code object. */
+ eassert (0 < nargs);
/* We used to purecopy everything here, if purify-flag was set. This worked
OK for Emacs-23, but with Emacs-24's lexical binding code, it can be
@@ -3469,7 +3470,21 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
to be setcar'd). */
memcpy (p->contents, args, nargs * sizeof *args);
- make_byte_code (p);
+
+ if (STRINGP (p->contents[COMPILED_BYTECODE])
+ && STRING_MULTIBYTE (p->contents[COMPILED_BYTECODE]))
+ /* BYTECODE-STRING must have been produced by Emacs 20.2 or the
+ earlier because they produced a raw 8-bit string for byte-code
+ and now such a byte-code string is loaded as multibyte while
+ raw 8-bit characters converted to multibyte form. Thus, now we
+ 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_CLOSURE + 1 */
+ XSETPVECTYPESIZE (p, PVEC_COMPILED, size, COMPILED_JIT_CLOSURE + 1 - size);
+ p->contents[COMPILED_INTERPRETER] = (Lisp_Object )exec_byte_code;
+ p->contents[COMPILED_JIT_CTXT] = (Lisp_Object )NULL;
+ p->contents[COMPILED_JIT_CLOSURE] = (Lisp_Object )NULL;
XSETCOMPILED (val, p);
return val;
}