Skip to content

Commit

Permalink
Place jump0 in wctx
Browse files Browse the repository at this point in the history
We just want to initialize jump0 once per worker thread which we now
achieve by placing jump0 in our worker context wctx. Previous to this,
we would rerun the $PUSH every time we entered wt_work_cb, and thus
actually push a new exception jump point to the stack - effectively a
memory "leak" with run-away memory consumption as a consequence.
  • Loading branch information
plajjan committed Apr 5, 2024
1 parent c0044a4 commit 2ed7582
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions base/rts/rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,6 @@ void wt_wake_cb(uv_async_t *ev) {
void wt_work_cb(uv_check_t *ev) {
WorkerCtx wctx = (WorkerCtx)pthread_getspecific(pkey_wctx);
assert(wctx->id >= 0 && wctx->id < 256);
volatile JumpBuf jump0 = NULL;

struct timespec ts_start, ts1, ts2, ts3;
long long int runtime = 0;
Expand All @@ -1525,9 +1524,9 @@ void wt_work_cb(uv_check_t *ev) {
wt_stats[wctx->id].state = WT_Working;

$R r;
if (jump0 || $PUSH()) { // Normal path
if (!jump0) {
jump0 = wctx->jump_top;
if (wctx->jump0 || $PUSH()) { // Normal path
if (!wctx->jump0) {
wctx->jump0 = wctx->jump_top;
}
rtsd_printf("## Running actor %ld : %s", current->$globkey, current->$class->$GCINFO);
r = cont->$class->__call__(cont, val);
Expand All @@ -1550,9 +1549,9 @@ void wt_work_cb(uv_check_t *ev) {
else if (diff < (long long int)100 * 1000000000) { wt_stats[wctx->id].conts_100s++; }
else { wt_stats[wctx->id].conts_inf++; }
} else { // Exceptional path
assert(jump0 != NULL);
assert(jump0->xval != NULL);
B_BaseException ex = jump0->xval;
assert(wctx->jump0 != NULL);
assert(wctx->jump0->xval != NULL);
B_BaseException ex = wctx->jump0->xval;
rtsd_printf("## (%d) Actor %ld : %s longjmp exception: %s", wctx->id, current->$globkey, current->$class->$GCINFO, ex->$class->$GCINFO);
r = $R_FAIL(ex);
}
Expand Down Expand Up @@ -1704,6 +1703,7 @@ void *main_loop(void *idx) {
wctx->id = (long)idx;
wctx->uv_loop = uv_loops[wctx->id];
wctx->jump_top = NULL;
wctx->jump0 = NULL;
pthread_setspecific(pkey_wctx, (void *)wctx);

char tname[11]; // Enough for "Worker XXX\0"
Expand Down
1 change: 1 addition & 0 deletions base/rts/rts.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ struct WorkerCtx {
long id;
uv_loop_t *uv_loop;
volatile JumpBuf jump_top;
volatile JumpBuf jump0;
};

JumpBuf $PUSH_BUF();
Expand Down

0 comments on commit 2ed7582

Please sign in to comment.