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

Store all annotation information in the read only data buffer.

* include/lightning/jit_private.h, lib/jit_note.c, lib/lightning.c:
	  Store all annotation information in the mmap'ed area reserved for
	read only data. This adds code to not allocate memory for jit_note_t
	objects, and to	relocate jit_line_t objects and its contents after
	calculating annotation information. The jit_line_t objects are
	relocated because it is not possible to always calculate before
	hand data layout because note information may be extended or
	redundant entries removed, as well as allowed to be added in
	non sequential order.
	  A bug was also corrected in _jit_set_note, that was causing it
	to allocate new jit_line_t objects when not needed. It was still
	working correctly, but allocating way more memory than required.
This commit is contained in:
pcpa 2013-02-11 15:50:59 -02:00
parent 60c1c545fc
commit 6039794ec3
4 changed files with 117 additions and 36 deletions

View file

@ -531,6 +531,11 @@ jit_new_state(void)
sizeof(jit_data_info_t));
#endif
/* allocate at most one extra note in case jit_name() is
* never called, or called after adding at least one note */
_jit->note.length = 1;
_jit->note.size = sizeof(jit_note_t);
return (_jit);
}
@ -1045,6 +1050,7 @@ _jit_patch_at(jit_state_t *_jit, jit_node_t *instr, jit_node_t *label)
void
_jit_optimize(jit_state_t *_jit)
{
jit_uint8_t *ptr;
jit_bool_t jump;
jit_int32_t mask;
jit_node_t *node;
@ -1151,22 +1157,29 @@ _jit_optimize(jit_state_t *_jit)
}
}
/* create read only data buffer */
if ((_jit->data.length = (_jit->data.offset + 4095) & -4096)) {
jit_uint8_t *ptr;
/* ensure it is aligned */
_jit->data.offset = (_jit->data.offset + 7) & -8;
ptr = mmap(NULL, _jit->data.length,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
assert(ptr != MAP_FAILED);
memcpy(ptr, _jit->data.ptr, _jit->data.offset);
free(_jit->data.ptr);
_jit->data.ptr = ptr;
for (offset = 0; offset < _jit->data.size; offset++) {
for (node = _jit->data.table[offset]; node; node = node->next) {
node->flag |= jit_flag_patch;
node->u.w = (jit_word_t)(_jit->data.ptr + node->u.w);
}
/* create read only data buffer */
_jit->data.length = (_jit->data.offset +
/* reserve space for annotations */
_jit->note.size + 4095) & -4096;
ptr = mmap(NULL, _jit->data.length,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
assert(ptr != MAP_FAILED);
memcpy(ptr, _jit->data.ptr, _jit->data.offset);
free(_jit->data.ptr);
_jit->data.ptr = ptr;
/* to be filled with note contents once offsets are known */
_jit->note.base = ptr + _jit->data.offset;
memset(_jit->note.base, 0, _jit->data.length - _jit->data.offset);
for (offset = 0; offset < _jit->data.size; offset++) {
for (node = _jit->data.table[offset]; node; node = node->next) {
node->flag |= jit_flag_patch;
node->u.w = (jit_word_t)(_jit->data.ptr + node->u.w);
}
}
}