1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-05 06:50:21 +02:00

Do not start over jit generation if can safely grow buffer size.

* include/lightning/jit_private.h, lib/jit_arm.c, lib/jit_memory.c,
	lib/jit_mips.c, lib/jit_ppc.c, lib/jit_sparc.c, lib/jit_x86.c,
	lib/lightning.c: Do not start over jit generation if can grow
	the code buffer with mremap without moving the base pointer.
This commit is contained in:
pcpa 2013-03-29 12:53:40 -03:00
parent c39def9dce
commit 51c96f9e19
9 changed files with 49 additions and 10 deletions

View file

@ -1,3 +1,10 @@
2013-03-29 Paulo Andrade <pcpa@gnu.org>
* include/lightning/jit_private.h, lib/jit_arm.c, lib/jit_memory.c,
lib/jit_mips.c, lib/jit_ppc.c, lib/jit_sparc.c, lib/jit_x86.c,
lib/lightning.c: Do not start over jit generation if can grow
the code buffer with mremap without moving the base pointer.
2013-03-29 Paulo Andrade <pcpa@gnu.org> 2013-03-29 Paulo Andrade <pcpa@gnu.org>
* lib/jit_memory.c: Implement a simple memory allocation wrapper * lib/jit_memory.c: Implement a simple memory allocation wrapper

View file

@ -360,6 +360,8 @@ struct jit_compiler {
} prolog; } prolog;
jit_bool_t jump; jit_bool_t jump;
#endif #endif
/* global flag for code buffer heuristic size computation */
jit_word_t mult;
}; };
#define _jitc _jit->comp #define _jitc _jit->comp
@ -485,6 +487,13 @@ extern void jit_alloc(jit_pointer_t*, jit_word_t);
extern void jit_realloc(jit_pointer_t*, jit_word_t, jit_word_t); extern void jit_realloc(jit_pointer_t*, jit_word_t, jit_word_t);
void jit_free(jit_pointer_t*); void jit_free(jit_pointer_t*);
#if HAVE_MREMAP
# define jit_remap() _jit_remap(_jit)
extern jit_bool_t _jit_remap(jit_state_t*);
#else
# define jit_remap() 0
#endif
/* /*
* Externs * Externs
*/ */

View file

@ -1034,7 +1034,7 @@ _emit_code(jit_state_t *_jit)
} \ } \
break break
for (node = _jitc->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end) if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);

View file

@ -17,6 +17,7 @@
#include <lightning.h> #include <lightning.h>
#include <lightning/jit_private.h> #include <lightning/jit_private.h>
#include <sys/mman.h>
/* /*
* Prototypes * Prototypes
@ -83,6 +84,29 @@ jit_free(jit_pointer_t *ptr)
*ptr = NULL; *ptr = NULL;
} }
#if HAVE_MREMAP
jit_bool_t
_jit_remap(jit_state_t *_jit)
{
jit_uint8_t *code;
jit_word_t length;
length = _jitc->pool.length * 1024 * (_jitc->mult + 1);
code = mremap(_jit->code.ptr, _jit->code.length, length, 0, NULL);
if (code != MAP_FAILED) {
assert(code == _jit->code.ptr);
++_jitc->mult;
_jit->code.length = length;
_jitc->code.end = _jit->code.ptr + _jit->code.length - 64;
return (1);
}
return (0);
}
#endif
static void * static void *
jit_default_alloc_func(size_t size) jit_default_alloc_func(size_t size)
{ {

View file

@ -775,7 +775,7 @@ _emit_code(jit_state_t *_jit)
} \ } \
break break
for (node = _jitc->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end) if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);

View file

@ -866,7 +866,7 @@ _emit_code(jit_state_t *_jit)
} \ } \
break break
for (node = _jitc->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end) if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);

View file

@ -692,7 +692,7 @@ _emit_code(jit_state_t *_jit)
} \ } \
break break
for (node = _jitc->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end) if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);

View file

@ -1125,7 +1125,7 @@ _emit_code(jit_state_t *_jit)
} \ } \
break break
for (node = _jitc->head; node; node = node->next) { for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end) if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
return (NULL); return (NULL);
value = jit_classify(node->code); value = jit_classify(node->code);

View file

@ -1455,7 +1455,6 @@ _jit_emit(jit_state_t *_jit)
{ {
jit_pointer_t code; jit_pointer_t code;
jit_node_t *node; jit_node_t *node;
jit_int32_t mult;
size_t length; size_t length;
int result; int result;
@ -1464,11 +1463,11 @@ _jit_emit(jit_state_t *_jit)
jit_optimize(); jit_optimize();
/* Heuristic to guess code buffer size */ /* Heuristic to guess code buffer size */
mult = 4; _jitc->mult = 4;
_jitc->emit = 1; _jitc->emit = 1;
_jit->code.length = _jitc->pool.length * 1024 * mult; _jit->code.length = _jitc->pool.length * 1024 * _jitc->mult;
_jit->code.ptr = mmap(NULL, _jit->code.length, _jit->code.ptr = mmap(NULL, _jit->code.length,
PROT_EXEC | PROT_READ | PROT_WRITE, PROT_EXEC | PROT_READ | PROT_WRITE,
@ -1485,8 +1484,8 @@ _jit_emit(jit_state_t *_jit)
node->code == jit_code_epilog)) node->code == jit_code_epilog))
node->flag &= ~jit_flag_patch; node->flag &= ~jit_flag_patch;
} }
++mult; ++_jitc->mult;
length = _jitc->pool.length * 1024 * mult; length = _jitc->pool.length * 1024 * _jitc->mult;
#if !HAVE_MREMAP #if !HAVE_MREMAP
munmap(_jit->code.ptr, _jit->code.length); munmap(_jit->code.ptr, _jit->code.length);