[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 185/437: Store all annotation information in the read on
From: |
Andy Wingo |
Subject: |
[Guile-commits] 185/437: Store all annotation information in the read only data buffer. |
Date: |
Mon, 2 Jul 2018 05:14:14 -0400 (EDT) |
wingo pushed a commit to branch lightning
in repository guile.
commit 6039794ec310e1072d57c6651083bd0972931228
Author: pcpa <address@hidden>
Date: Mon Feb 11 15:50:59 2013 -0200
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.
---
ChangeLog | 15 ++++++++
include/lightning/jit_private.h | 14 +++++--
lib/jit_note.c | 81 ++++++++++++++++++++++++++++++++---------
lib/lightning.c | 43 ++++++++++++++--------
4 files changed, 117 insertions(+), 36 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e91a7c6..c02440d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2013-02-11 Paulo Andrade <address@hidden>
+
+ * 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.
+
2013-02-05 Paulo Andrade <address@hidden>
*include/lightning.h, lib/lightning.c: Add the new jit_live code
diff --git a/include/lightning/jit_private.h b/include/lightning/jit_private.h
index 202fc67..a708a3d 100644
--- a/include/lightning/jit_private.h
+++ b/include/lightning/jit_private.h
@@ -319,10 +319,16 @@ struct jit_state {
} pool;
jit_node_t *list;
struct {
- jit_note_t *ptr;
- jit_node_t *head; /* first note node */
- jit_node_t *tail; /* linked list insertion */
- jit_word_t length;
+ jit_note_t *ptr;
+ jit_node_t *head; /* first note node */
+ jit_node_t *tail; /* linked list insertion */
+ jit_word_t length;
+
+ /* fields to store temporary state information */
+ jit_word_t size;
+ jit_node_t *name;
+ jit_node_t *note;
+ jit_uint8_t *base;
} note;
#if __arm__
# if DISASSEMBLER
diff --git a/lib/jit_note.c b/lib/jit_note.c
index 29bdc3f..13ead7f 100644
--- a/lib/jit_note.c
+++ b/lib/jit_note.c
@@ -60,8 +60,11 @@ _jit_name(jit_state_t *_jit, char *name)
_jit->note.tail->link = node;
_jit->note.tail = node;
}
-
- return (node);
+ ++_jit->note.length;
+ _jit->note.size += sizeof(jit_note_t);
+ /* remember previous note is invalid due to name change */
+ _jit->note.note = NULL;
+ return (_jit->note.name = node);
}
jit_node_t *
@@ -81,8 +84,14 @@ _jit_note(jit_state_t *_jit, char *name, int line)
_jit->note.tail->link = node;
_jit->note.tail = node;
}
-
- return (node);
+ if (_jit->note.note == NULL ||
+ (name == NULL && _jit->note.note != NULL) ||
+ (name != NULL && _jit->note.note == NULL) ||
+ (name != NULL && _jit->note.note != NULL &&
+ strcmp(name, (char *)_jit->data.ptr + _jit->note.note->v.n->u.w)))
+ _jit->note.size += sizeof(jit_line_t);
+ _jit->note.size += sizeof(jit_int32_t) * 2;
+ return (_jit->note.note = node);
}
void
@@ -90,6 +99,14 @@ _jit_annotate(jit_state_t *_jit)
{
jit_node_t *node;
jit_note_t *note;
+ jit_line_t *line;
+ jit_word_t length;
+ jit_word_t note_offset;
+ jit_word_t line_offset;
+
+ /* initialize pointers in mmaped data area */
+ _jit->note.ptr = (jit_note_t *)_jit->note.base;
+ _jit->note.length = 0;
note = NULL;
for (node = _jit->note.head; node; node = node->link) {
@@ -105,6 +122,43 @@ _jit_annotate(jit_state_t *_jit)
/* last note */
if (note)
note->size = _jit->pc.uc - note->code;
+
+ /* annotations may be very complex with conditions to extend
+ * or ignore redudant notes, as well as add entries to earlier
+ * notes, so, relocate the information to the data buffer,
+ * with likely over allocated reserved space */
+
+ /* relocate jit_line_t objects */
+ for (note_offset = 0; note_offset < _jit->note.length; note_offset++) {
+ note = _jit->note.ptr + note_offset;
+ length = sizeof(jit_line_t) * note->length;
+ assert(_jit->note.base + length < _jit->data.ptr + _jit->data.length);
+ memcpy(_jit->note.base, note->lines, length);
+ free(note->lines);
+ note->lines = (jit_line_t *)_jit->note.base;
+ _jit->note.base += length;
+ }
+
+ /* relocate offset and line number information */
+ for (note_offset = 0; note_offset < _jit->note.length; note_offset++) {
+ note = _jit->note.ptr + note_offset;
+ for (line_offset = 0; line_offset < note->length; line_offset++) {
+ line = note->lines + line_offset;
+ length = sizeof(jit_int32_t) * line->length;
+ assert(_jit->note.base + length <
+ _jit->data.ptr + _jit->data.length);
+ memcpy(_jit->note.base, line->linenos, length);
+ free(line->linenos);
+ line->linenos = (jit_int32_t *)_jit->note.base;
+ _jit->note.base += length;
+ assert(_jit->note.base + length <
+ _jit->data.ptr + _jit->data.length);
+ memcpy(_jit->note.base, line->offsets, length);
+ free(line->offsets);
+ line->offsets = (jit_int32_t *)_jit->note.base;
+ _jit->note.base += length;
+ }
+ }
}
void
@@ -115,6 +169,9 @@ _jit_set_note(jit_state_t *_jit, jit_note_t *note,
jit_int32_t index;
index = line_insert_index(note, offset);
+ if (note->length && index == note->length &&
+ note->lines[index - 1].file == file)
+ --index;
if (index >= note->length || note->lines[index].file != file)
new_line(index, note, file, lineno, offset);
else {
@@ -190,26 +247,16 @@ _new_note(jit_state_t *_jit, jit_uint8_t *code, char
*name)
jit_note_t *note;
jit_note_t *prev;
- if (_jit->note.ptr == NULL) {
- prev = NULL;
- _jit->note.ptr = malloc(sizeof(jit_note_t) * 8);
- }
- else {
- if ((_jit->note.length & 7) == 7)
- _jit->note.ptr = realloc(_jit->note.ptr, sizeof(jit_note_t) *
- (_jit->note.length + 9));
+ if (_jit->note.length) {
prev = _jit->note.ptr + _jit->note.length - 1;
- }
- if (prev) {
assert(code >= prev->code);
prev->size = code - prev->code;
}
- note = _jit->note.ptr + _jit->note.length;
+ note = (jit_note_t *)_jit->note.base;
+ _jit->note.base += sizeof(jit_note_t);
++_jit->note.length;
note->code = code;
note->name = name;
- note->lines = NULL;
- note->length = note->size = 0;
return (note);
}
diff --git a/lib/lightning.c b/lib/lightning.c
index 2486e51..a408cf9 100644
--- a/lib/lightning.c
+++ b/lib/lightning.c
@@ -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)
}
}
+ /* ensure it is aligned */
+ _jit->data.offset = (_jit->data.offset + 7) & -8;
+
/* create read only data buffer */
- if ((_jit->data.length = (_jit->data.offset + 4095) & -4096)) {
- jit_uint8_t *ptr;
-
- 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);
- }
+ _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);
}
}
}
- [Guile-commits] 311/437: Implement jit_frame and jit_tramp interfaces, (continued)
- [Guile-commits] 311/437: Implement jit_frame and jit_tramp interfaces, Andy Wingo, 2018/07/02
- [Guile-commits] 312/437: Use jit_code_last_code as symbolic name of last enum, Andy Wingo, 2018/07/02
- [Guile-commits] 293/437: Do not have assertions with a long type test, Andy Wingo, 2018/07/02
- [Guile-commits] 384/437: ia64: Do not use a dangling pointer for double to integer copy, Andy Wingo, 2018/07/02
- [Guile-commits] 203/437: Make it simpler to add support for more than 64 registers., Andy Wingo, 2018/07/02
- [Guile-commits] 415/437: Build and pass all test cases on Alpha Linux, Andy Wingo, 2018/07/02
- [Guile-commits] 142/437: Make current test cases pass in armv7l., Andy Wingo, 2018/07/02
- [Guile-commits] 188/437: Add framework for sparc port., Andy Wingo, 2018/07/02
- [Guile-commits] 227/437: Cosmetic removal of unused macros., Andy Wingo, 2018/07/02
- [Guile-commits] 330/437: Resync with new patch to make functions receive a const argument, Andy Wingo, 2018/07/02
- [Guile-commits] 185/437: Store all annotation information in the read only data buffer.,
Andy Wingo <=
- [Guile-commits] 170/437: Test and correct test cases in all current backends., Andy Wingo, 2018/07/02
- [Guile-commits] 368/437: Implement jit_allocar for dynamic stack allocation, Andy Wingo, 2018/07/02
- [Guile-commits] 355/437: Update documentation on jit_frame and jit_tramp, Andy Wingo, 2018/07/02
- [Guile-commits] 323/437: misc: Make jit_note and related functions take a const argument, Andy Wingo, 2018/07/02
- [Guile-commits] 429/437: Remove disassembler support from lightning, Andy Wingo, 2018/07/02
- [Guile-commits] 346/437: PPC: Build and pass all tests in powerpcle, Andy Wingo, 2018/07/02
- [Guile-commits] 180/437: Correct C sequence point problem., Andy Wingo, 2018/07/02
- [Guile-commits] 370/437: Add missing ellipsis in allocar.tst, Andy Wingo, 2018/07/02
- [Guile-commits] 337/437: Remove a wrong optimization of callee save registers, Andy Wingo, 2018/07/02
- [Guile-commits] 437/437: Wire up lightning into libguile build, Andy Wingo, 2018/07/02