Skip to content

Commit

Permalink
branchable frame to prevent traces from escaping the function they st…
Browse files Browse the repository at this point in the history
…arted in

appears that somehow yield with python was creating a frame that was not getting popped correctly, can not locate where that frame was getting popped so now have it such that exiting a branchable frame will end all traces that are still alive
  • Loading branch information
matthewfl committed Aug 1, 2016
1 parent aebfaf6 commit 0efe508
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 144 deletions.
15 changes: 15 additions & 0 deletions src/code_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ CodeBuffer::CodeBuffer(CodeBuffer &&x) {
external_trampolines_size = x.external_trampolines_size;
}

CodeBuffer& CodeBuffer::operator=(CodeBuffer &&x) {
buffer = x.buffer;
trampolines_size = x.trampolines_size;
size = x.size;
buffer_consumed = x.buffer_consumed;
assert(!owns_buffer);
assert(!x.owns_buffer); /////// TODO: move an owning buffer?
owns_buffer = x.owns_buffer;
x.owns_buffer = false;
can_write_buffer = x.can_write_buffer;
external_trampolines = x.external_trampolines;
external_trampolines_size = x.external_trampolines_size;
return *this;
}

CodeBuffer CodeBuffer::writeToEnd(const CodeBuffer &other, long start, long end) {
assert(other.external_trampolines == nullptr); // we can't relocate this without understanding the code
mem_loc_t position = 0;
Expand Down
8 changes: 7 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
// redmagic will attempt inline forward jumps which is useful in cases like: `if(a || b || c...)` where many conditional jumps
// will merge to the same point, but it may require back tracking in a lot of cases which may be slower
//#define CONF_ATTEMPT_FORWARD_JUMP_INLINE
// ^^^ There is some issue with this, it causes ipython to crash....have already spent a lot of time trying to trace down the issue

// backward jumps that are inside the same generated block will be inlined, does _not_ require back tracking as the size of the block
// is know at the time the instruction is emitted, this is useful for sort loops eg: `while (a != NULL) a = a->next;`
#define CONF_ATTEMPT_BACKWARDS_JUMP_INLINE

// makes it print all the instructions processed an extra info
// makes it print all the instructions processed and extra info
#define CONF_VERBOSE

// support aborting the system after some fixed number of instruction have been processed, see tools/bisect for debugging with this
#define CONF_GLOBAL_ABORT

// somehow python is not hitting the fellthrough trace for some traces that it starts
// unable to determine where it should actually be performing this, so we are just makeing the end of the branchable frame
// close out any traces that were created in this frame
#define CONF_ALLOW_UNCLOSED_TRACES

#endif // REDMAGIC_CONFIG_H_
8 changes: 7 additions & 1 deletion src/jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace redmagic {
void* backwards_branch(void *id, void *ret_addr);
void* fellthrough_branch(void *id, void *ret_addr);

void ensure_not_traced();
// void ensure_not_traced();

void *temp_disable(void *ret_addr);
void *temp_enable(void *ret_addr);
Expand All @@ -72,7 +72,9 @@ namespace redmagic {

void do_not_trace_method(void *addr);

void* ensure_not_traced();

void* end_branchable_frame(void *ret_addr);

uint32_t get_thread_id();

Expand Down Expand Up @@ -121,6 +123,7 @@ namespace redmagic {
bool is_temp_disabled = false;
bool is_traced = false;
bool is_compiled = false;
int32_t frame_id = -1;
//bool did_abort = false;
};

Expand All @@ -131,6 +134,7 @@ namespace redmagic {
extern Manager *manager;
extern thread_local bool protected_malloc;
extern std::atomic<Tracer*> free_tracer_list;
extern thread_local int32_t branchable_frame_id;


class CodeBuffer final {
Expand All @@ -150,6 +154,8 @@ namespace redmagic {

~CodeBuffer();

CodeBuffer& operator=(CodeBuffer &&x);

//void *getBuffer() { return buffer; }
const inline size_t getSize() { return size - trampolines_size + external_trampolines_size; }
const inline size_t getFree() { return size - trampolines_size - buffer_consumed; }
Expand Down
Loading

0 comments on commit 0efe508

Please sign in to comment.