lightning.git - Portable just-in-time compiler library

index : lightning.git
Portable just-in-time compiler library
summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorpcpa <paulo.cesar.pereira.de.andrade@gmail.com>2013年02月11日 15:51:55 -0200
committerpcpa <paulo.cesar.pereira.de.andrade@gmail.com>2013年02月11日 15:51:55 -0200
commit8f020fe0442a92a92119fdce6b15f7ba20008434 (patch)
treeaab99409bce7cff0e1c1d64d1fa0a61fd64a36e7 /lib
parent6039794ec310e1072d57c6651083bd0972931228 (diff)
downloadlightning-8f020fe0442a92a92119fdce6b15f7ba20008434.tar.gz
Add code to release all memory used by the jit state.
* include/lightning.h, lib/lightning.c: Implement the new jit_clear_state and jit_destroy_state calls. jit_clear_state releases all memory not required during jit_execution; that is, leaves only the mmap'ed data and code buffers allocated. jit_destroy_state releases the mmap'ed buffers as well as the jit_state_t object itself, that holds pointers to the code and data buffers, as well as annotation pointers (for disassembly or backtrace) in the data buffer. * lib/jit_note.c: Correct invalid vector offset access. * check/ccall.c, check/lightning.c, doc/ifib.c, doc/incr.c, doc/printf.c, doc/rfib.c, doc/rpn.c: Use the new jit_clear_state and jit_destroy_state calls, to demonstrate the new code to release all jit memory. * doc/body.texi: Add basic documentation and usage description of jit_clear_state and jit_destroy_state.
Diffstat (limited to 'lib')
-rw-r--r--lib/jit_note.c 4
-rw-r--r--lib/lightning.c 64
2 files changed, 66 insertions, 2 deletions
diff --git a/lib/jit_note.c b/lib/jit_note.c
index 13ead7f..284f02d 100644
--- a/lib/jit_note.c
+++ b/lib/jit_note.c
@@ -177,12 +177,12 @@ _jit_set_note(jit_state_t *_jit, jit_note_t *note,
else {
line = note->lines + index;
index = offset_insert_index(line, offset);
- if (line->offsets[index] == offset) {
+ if (index < line->length && line->offsets[index] == offset) {
/* common case if no code was generated for several source lines */
if (line->linenos[index] < lineno)
line->linenos[index] = lineno;
}
- else if (line->linenos[index] == lineno) {
+ else if (index < line->length && line->linenos[index] == lineno) {
/* common case of extending entry */
if (line->offsets[index] > offset)
line->offsets[index] = offset;
diff --git a/lib/lightning.c b/lib/lightning.c
index a408cf9..59ab8a7 100644
--- a/lib/lightning.c
+++ b/lib/lightning.c
@@ -539,6 +539,70 @@ jit_new_state(void)
return (_jit);
}
+void
+_jit_clear_state(jit_state_t *_jit)
+{
+ jit_word_t offset;
+ jit_function_t *function;
+
+ /* release memory not required at jit execution time and set
+ * pointers to NULL to explicitly know they are released */
+ _jit->head = _jit->tail = NULL;
+
+ mpz_clear(_jit->blockmask);
+
+ free(_jit->data.table);
+ _jit->data.table = NULL;
+ _jit->data.size = _jit->data.count = 0;
+
+ free(_jit->spill);
+ _jit->spill = NULL;
+ free(_jit->gen);
+ _jit->gen = NULL;
+ free(_jit->values);
+ _jit->values = NULL;
+
+ free(_jit->blocks.ptr);
+ _jit->blocks.ptr = NULL;
+
+ free(_jit->patches.ptr);
+ _jit->patches.ptr = NULL;
+ _jit->patches.offset = _jit->patches.length = 0;
+
+ for (offset = 0; offset < _jit->functions.offset; offset++) {
+ function = _jit->functions.ptr + offset;
+ free(function->regoff);
+ function->regoff = NULL;
+ }
+ free(_jit->functions.ptr);
+ _jit->functions.offset = _jit->functions.length = 0;
+ _jit->function = NULL;
+
+ for (offset = 0; offset < _jit->pool.length; offset++)
+ free(_jit->pool.ptr[offset]);
+ free(_jit->pool.ptr);
+ _jit->pool.ptr = NULL;
+ _jit->pool.offset = _jit->pool.length = 0;
+ _jit->list = NULL;
+
+ _jit->note.head = _jit->note.tail =
+ _jit->note.name = _jit->note.note = NULL;
+ _jit->note.base = NULL;
+
+#if __arm__ && DISASSEMBLER
+ free(_jit->data_info.ptr);
+ _jit->data_info.ptr = NULL;
+#endif
+}
+
+void
+_jit_destroy_state(jit_state_t *_jit)
+{
+ munmap(_jit->code.ptr, _jit->code.length);
+ munmap(_jit->data.ptr, _jit->data.length);
+ free(_jit);
+}
+
jit_node_t *
_jit_new_node(jit_state_t *_jit, jit_code_t code)
{
generated by cgit v1.2.3 (git 2.25.1) at 2025年10月02日 14:36:12 +0000

AltStyle によって変換されたページ (->オリジナル) /