diff --git a/mps/code/airtest.c b/mps/code/airtest.c index eea742def46..9399f643269 100644 --- a/mps/code/airtest.c +++ b/mps/code/airtest.c @@ -127,7 +127,7 @@ static void test_main(void *marker, int interior, int stack) error("Couldn't register thread"); if (stack) { - res = mps_root_create_stack(®_root, scheme_arena, mps_rank_ambig(), + res = mps_root_create_thread_tagged(®_root, scheme_arena, mps_rank_ambig(), 0, thread, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, marker); if (res != MPS_RES_OK) diff --git a/mps/code/amcssth.c b/mps/code/amcssth.c index 80320261aec..cf9c6cbf0a4 100644 --- a/mps/code/amcssth.c +++ b/mps/code/amcssth.c @@ -139,7 +139,7 @@ static void *kid_thread(void *arg) closure_t cl = arg; die(mps_thread_reg(&thread, (mps_arena_t)arena), "thread_reg"); - die(mps_root_create_stack(®_root, arena, mps_rank_ambig(), + die(mps_root_create_thread_tagged(®_root, arena, mps_rank_ambig(), 0, thread, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, marker), "root_create"); @@ -318,7 +318,7 @@ static void test_arena(int mode) &ambigRoots[0], ambigRootsCOUNT), "root_create_table(ambig)"); die(mps_thread_reg(&thread, arena), "thread_reg"); - die(mps_root_create_stack(®_root, arena, mps_rank_ambig(), + die(mps_root_create_thread_tagged(®_root, arena, mps_rank_ambig(), 0, thread, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, marker), "root_create"); diff --git a/mps/code/awlut.c b/mps/code/awlut.c index 1b2a430af47..61b3636d80a 100644 --- a/mps/code/awlut.c +++ b/mps/code/awlut.c @@ -267,7 +267,7 @@ static void *setup(void *v, size_t s) arena = guff->arena; thr = guff->thr; - die(mps_root_create_stack(&stack, arena, mps_rank_ambig(), + die(mps_root_create_thread_tagged(&stack, arena, mps_rank_ambig(), 0, thr, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, v), "Root Create\n"); diff --git a/mps/code/awluthe.c b/mps/code/awluthe.c index b5b4f4db07f..331128d54c0 100644 --- a/mps/code/awluthe.c +++ b/mps/code/awluthe.c @@ -271,7 +271,7 @@ static void *setup(void *v, size_t s) arena = guff->arena; thr = guff->thr; - die(mps_root_create_stack(&stack, arena, mps_rank_ambig(), + die(mps_root_create_thread_tagged(&stack, arena, mps_rank_ambig(), 0, thr, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, v), "Root Create\n"); diff --git a/mps/code/awlutth.c b/mps/code/awlutth.c index fad46a29844..8944df9b8bc 100644 --- a/mps/code/awlutth.c +++ b/mps/code/awlutth.c @@ -254,7 +254,7 @@ static void *setup(void *v, size_t s) arena = guff->arena; thr = guff->thr; - die(mps_root_create_stack(&stack, arena, mps_rank_ambig(), + die(mps_root_create_thread_tagged(&stack, arena, mps_rank_ambig(), 0, thr, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, v), "Root Create\n"); diff --git a/mps/code/gcbench.c b/mps/code/gcbench.c index 0451cd9fbc0..920c55d07da 100644 --- a/mps/code/gcbench.c +++ b/mps/code/gcbench.c @@ -176,7 +176,7 @@ static void *start(void *p) { gcthread_t thread = p; void *marker; RESMUST(mps_thread_reg(&thread->mps_thread, arena)); - RESMUST(mps_root_create_stack(&thread->reg_root, arena, mps_rank_ambig(), + RESMUST(mps_root_create_thread_tagged(&thread->reg_root, arena, mps_rank_ambig(), (mps_rm_t)0, thread->mps_thread, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, &marker)); diff --git a/mps/code/mpm.h b/mps/code/mpm.h index 1f652a566eb..8c9ab7a40a2 100644 --- a/mps/code/mpm.h +++ b/mps/code/mpm.h @@ -957,6 +957,11 @@ extern Res RootCreateAreaTagged(Root *rootReturn, Arena arena, Word *base, Word *limit, mps_area_scan_t scan_area, Word mask, Word pattern); +extern Res RootCreateThread(Root *rootReturn, Arena arena, + Rank rank, Thread thread, + mps_area_scan_t scan_area, + void *closure, size_t closure_size, + Word *stackBot); extern Res RootCreateThreadTagged(Root *rootReturn, Arena arena, Rank rank, Thread thread, mps_area_scan_t scan_area, diff --git a/mps/code/mpmtypes.h b/mps/code/mpmtypes.h index 5f31501938e..2571106984a 100644 --- a/mps/code/mpmtypes.h +++ b/mps/code/mpmtypes.h @@ -361,6 +361,7 @@ enum { RootFUN, RootAREA, RootAREA_TAGGED, + RootTHREAD, RootTHREAD_TAGGED, RootFMT, RootLIMIT diff --git a/mps/code/mps.h b/mps/code/mps.h index c1fd1e5f0eb..bc04426524b 100644 --- a/mps/code/mps.h +++ b/mps/code/mps.h @@ -691,11 +691,16 @@ extern mps_res_t mps_root_create_fmt(mps_root_t *, mps_arena_t, extern mps_res_t mps_root_create_reg(mps_root_t *, mps_arena_t, mps_rank_t, mps_rm_t, mps_thr_t, mps_reg_scan_t, void *, size_t); -extern mps_res_t mps_root_create_stack(mps_root_t *, mps_arena_t, - mps_rank_t, mps_rm_t, mps_thr_t, - mps_area_scan_t, - mps_word_t, mps_word_t, - void *); +extern mps_res_t mps_root_create_thread(mps_root_t *, mps_arena_t, + mps_rank_t, mps_rm_t, mps_thr_t, + mps_area_scan_t, + void *, size_t, + void *); +extern mps_res_t mps_root_create_thread_tagged(mps_root_t *, mps_arena_t, + mps_rank_t, mps_rm_t, mps_thr_t, + mps_area_scan_t, + mps_word_t, mps_word_t, + void *); extern void mps_root_destroy(mps_root_t); extern mps_res_t mps_stack_scan_ambig(mps_ss_t, mps_thr_t, diff --git a/mps/code/mpsi.c b/mps/code/mpsi.c index 4b1fb20b574..db941471cd7 100644 --- a/mps/code/mpsi.c +++ b/mps/code/mpsi.c @@ -1450,13 +1450,16 @@ mps_res_t mps_root_create_reg(mps_root_t *mps_root_o, mps_arena_t arena, } -/* FIXME: re-document */ -mps_res_t mps_root_create_stack(mps_root_t *mps_root_o, mps_arena_t arena, - mps_rank_t mps_rank, mps_rm_t mps_rm, - mps_thr_t thread, - mps_area_scan_t scan_area, - mps_word_t mask, mps_word_t pattern, - void *stack) +/* FIXME: document */ +mps_res_t mps_root_create_thread(mps_root_t *mps_root_o, + mps_arena_t arena, + mps_rank_t mps_rank, + mps_rm_t mps_rm, + mps_thr_t thread, + mps_area_scan_t scan_area, + void *closure, + size_t closure_size, + void *stack) { Rank rank = (Rank)mps_rank; Root root; @@ -1469,6 +1472,46 @@ mps_res_t mps_root_create_stack(mps_root_t *mps_root_o, mps_arena_t arena, AVER(AddrIsAligned(stack, sizeof(Word))); AVER(rank == mps_rank_ambig()); AVER(mps_rm == (mps_rm_t)0); + AVER(FUNCHECK(scan_area)); + /* Can't check anything about closure. */ + + /* See .root-mode. */ + res = RootCreateThread(&root, arena, rank, thread, + scan_area, closure, closure_size, + (Word *)stack); + + ArenaLeave(arena); + + if (res != ResOK) + return (mps_res_t)res; + *mps_root_o = (mps_root_t)root; + return MPS_RES_OK; +} + + +/* FIXME: re-document */ +mps_res_t mps_root_create_thread_tagged(mps_root_t *mps_root_o, + mps_arena_t arena, + mps_rank_t mps_rank, + mps_rm_t mps_rm, + mps_thr_t thread, + mps_area_scan_t scan_area, + mps_word_t mask, + mps_word_t pattern, + void *stack) +{ + Rank rank = (Rank)mps_rank; + Root root; + Res res; + + ArenaEnter(arena); + + AVER(mps_root_o != NULL); + AVER(stack != NULL); /* stackBot */ + AVER(AddrIsAligned(stack, sizeof(Word))); + AVER(rank == mps_rank_ambig()); + AVER(mps_rm == (mps_rm_t)0); + AVER(FUNCHECK(scan_area)); AVER((~mask & pattern) == 0); /* See .root-mode. */ diff --git a/mps/code/mpsicv.c b/mps/code/mpsicv.c index 10b98060ce5..55e499f55da 100644 --- a/mps/code/mpsicv.c +++ b/mps/code/mpsicv.c @@ -602,7 +602,7 @@ int main(int argc, char *argv[]) marker, (size_t)0), "root_create_reg"); } else { - die(mps_root_create_stack(®_root, arena, + die(mps_root_create_thread_tagged(®_root, arena, mps_rank_ambig(), (mps_rm_t)0, thread, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, marker), diff --git a/mps/code/root.c b/mps/code/root.c index 42c7510b5d1..bfcfb09d74c 100644 --- a/mps/code/root.c +++ b/mps/code/root.c @@ -53,9 +53,15 @@ typedef struct RootStruct { struct { Thread thread; /* passed to scan */ mps_area_scan_t scan_area;/* area scanner for stack and registers */ - mps_scan_tag_s tag; /* tag for scanning */ + union { + struct { + void *p; + size_t s; + } closure; + mps_scan_tag_s tag; /* tag for scanning */ + } the; Word *stackBot; /* bottom of stack */ - } threadTagged; + } thread; struct { mps_fmt_scan_t scan; /* format-like scanner */ Addr base, limit; /* passed to scan */ @@ -72,6 +78,7 @@ Bool RootVarCheck(RootVar rootVar) { CHECKL(rootVar == RootAREA || rootVar == RootAREA_TAGGED || rootVar == RootFUN || rootVar == RootFMT + || rootVar == RootTHREAD || rootVar == RootTHREAD_TAGGED); UNUSED(rootVar); return TRUE; @@ -128,9 +135,9 @@ Bool RootCheck(Root root) break; case RootTHREAD_TAGGED: - CHECKD_NOSIG(Thread, root->the.threadTagged.thread); /* */ - CHECKL(FUNCHECK(root->the.threadTagged.scan_area)); - CHECKL((~root->the.threadTagged.tag.mask & root->the.threadTagged.tag.pattern) == 0); + CHECKD_NOSIG(Thread, root->the.thread.thread); /* */ + CHECKL(FUNCHECK(root->the.thread.scan_area)); + CHECKL((~root->the.thread.the.tag.mask & root->the.thread.the.tag.pattern) == 0); /* Can't check anything about stackBot. */ break; @@ -317,6 +324,32 @@ Res RootCreateAreaTagged(Root *rootReturn, Arena arena, (Addr)base, (Addr)limit, &theUnion); } +Res RootCreateThread(Root *rootReturn, Arena arena, + Rank rank, Thread thread, + mps_area_scan_t scan_area, + void *closure, size_t closure_size, + Word *stackBot) +{ + union RootUnion theUnion; + + AVER(rootReturn != NULL); + AVERT(Arena, arena); + AVERT(Rank, rank); + AVERT(Thread, thread); + AVER(ThreadArena(thread) == arena); + AVER(FUNCHECK(scan_area)); + /* Can't check anything about closure. */ + + theUnion.thread.thread = thread; + theUnion.thread.scan_area = scan_area; + theUnion.thread.the.closure.p = closure; + theUnion.thread.the.closure.s = closure_size; + theUnion.thread.stackBot = stackBot; + + return rootCreate(rootReturn, arena, rank, (RootMode)0, RootTHREAD, + &theUnion); +} + Res RootCreateThreadTagged(Root *rootReturn, Arena arena, Rank rank, Thread thread, mps_area_scan_t scan_area, @@ -330,13 +363,14 @@ Res RootCreateThreadTagged(Root *rootReturn, Arena arena, AVERT(Rank, rank); AVERT(Thread, thread); AVER(ThreadArena(thread) == arena); + AVER(FUNCHECK(scan_area)); AVER((~mask & pattern) == 0); - theUnion.threadTagged.thread = thread; - theUnion.threadTagged.scan_area = scan_area; - theUnion.threadTagged.tag.mask = mask; - theUnion.threadTagged.tag.pattern = pattern; - theUnion.threadTagged.stackBot = stackBot; + theUnion.thread.thread = thread; + theUnion.thread.scan_area = scan_area; + theUnion.thread.the.tag.mask = mask; + theUnion.thread.the.tag.pattern = pattern; + theUnion.thread.stackBot = stackBot; return rootCreate(rootReturn, arena, rank, (RootMode)0, RootTHREAD_TAGGED, &theUnion); @@ -525,12 +559,22 @@ Res RootScan(ScanState ss, Root root) goto failScan; break; + case RootTHREAD: + res = ThreadScan(ss, root->the.thread.thread, + root->the.thread.stackBot, + root->the.thread.scan_area, + root->the.thread.the.closure.p, + root->the.thread.the.closure.s); + if (res != ResOK) + goto failScan; + break; + case RootTHREAD_TAGGED: - res = ThreadScan(ss, root->the.threadTagged.thread, - root->the.threadTagged.stackBot, - root->the.threadTagged.scan_area, - &root->the.threadTagged.tag, - sizeof(root->the.threadTagged.tag)); + res = ThreadScan(ss, root->the.thread.thread, + root->the.thread.stackBot, + root->the.thread.scan_area, + &root->the.thread.the.tag, + sizeof(root->the.thread.the.tag)); if (res != ResOK) goto failScan; break; @@ -695,13 +739,26 @@ Res RootDescribe(Root root, mps_lib_FILE *stream, Count depth) return res; break; + case RootTHREAD: + res = WriteF(stream, depth + 2, + "thread $P\n", (WriteFP)root->the.thread.thread, + "scan_area $P\n", (WriteFP)root->the.thread.scan_area, + "closure $P size $U\n", + (WriteFP)root->the.thread.the.closure.p, + (WriteFU)root->the.thread.the.closure.s, + "stackBot $P\n", (WriteFP)root->the.thread.stackBot, + NULL); + if (res != ResOK) + return res; + break; + case RootTHREAD_TAGGED: res = WriteF(stream, depth + 2, - "thread $P\n", (WriteFP)root->the.threadTagged.thread, - "scan_area $P\n", (WriteFP)root->the.threadTagged.scan_area, - "mask $B\n", (WriteFB)root->the.threadTagged.tag.mask, - "pattern $B\n", (WriteFB)root->the.threadTagged.tag.pattern, - "stackBot $P\n", (WriteFP)root->the.threadTagged.stackBot, + "thread $P\n", (WriteFP)root->the.thread.thread, + "scan_area $P\n", (WriteFP)root->the.thread.scan_area, + "mask $B\n", (WriteFB)root->the.thread.the.tag.mask, + "pattern $B\n", (WriteFB)root->the.thread.the.tag.pattern, + "stackBot $P\n", (WriteFP)root->the.thread.stackBot, NULL); if (res != ResOK) return res; diff --git a/mps/code/tagtest.c b/mps/code/tagtest.c index 7f27d45fc09..fa751b82537 100644 --- a/mps/code/tagtest.c +++ b/mps/code/tagtest.c @@ -208,16 +208,16 @@ static void test(int mode, void *marker) break; case MODE_CONS: /* Scan words tagged "cons" -- everything will live. */ - die(mps_root_create_stack(&root, arena, mps_rank_ambig(), 0, thread, - mps_scan_area_tagged, TAG_MASK, tag_cons, - marker), "root"); + die(mps_root_create_thread_tagged(&root, arena, mps_rank_ambig(), 0, thread, + mps_scan_area_tagged, TAG_MASK, tag_cons, + marker), "root"); expected = 0; break; case MODE_INVALID: /* Scan words tagged "invalid" -- everything will die. */ - die(mps_root_create_stack(&root, arena, mps_rank_ambig(), 0, thread, - mps_scan_area_tagged, TAG_MASK, tag_invalid, - marker), "root"); + die(mps_root_create_thread_tagged(&root, arena, mps_rank_ambig(), 0, thread, + mps_scan_area_tagged, TAG_MASK, tag_invalid, + marker), "root"); expected = OBJCOUNT; break; } diff --git a/mps/code/zcoll.c b/mps/code/zcoll.c index 16b403be2f4..96dfdbf7f46 100644 --- a/mps/code/zcoll.c +++ b/mps/code/zcoll.c @@ -574,7 +574,7 @@ static void StackScan(mps_arena_t arena, int on) { if(on) { Insist(root_stackreg == NULL); - die(mps_root_create_stack(&root_stackreg, arena, + die(mps_root_create_thread_tagged(&root_stackreg, arena, mps_rank_ambig(), (mps_rm_t)0, stack_thr, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, stack_start), @@ -763,7 +763,7 @@ static void *testscriptB(void *arg, size_t s) /* root_stackreg: stack & registers are ambiguous roots = mutator's workspace */ stack_start = &stack_starts_here; stack_thr = thr; - die(mps_root_create_stack(&root_stackreg, arena, + die(mps_root_create_thread_tagged(&root_stackreg, arena, mps_rank_ambig(), (mps_rm_t)0, stack_thr, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, stack_start), diff --git a/mps/code/zmess.c b/mps/code/zmess.c index 60a9c4a1e99..b1294dd4324 100644 --- a/mps/code/zmess.c +++ b/mps/code/zmess.c @@ -330,7 +330,7 @@ static void *testscriptB(void *arg, size_t s) die(mps_ap_create(&ap, amc, mps_rank_exact()), "ap_create"); /* root_stackreg: stack & registers are ambiguous roots = mutator's workspace */ - die(mps_root_create_stack(&root_stackreg, arena, + die(mps_root_create_thread_tagged(&root_stackreg, arena, mps_rank_ambig(), (mps_rm_t)0, thr, mps_scan_area_tagged, sizeof(mps_word_t) - 1, 0, &stack_starts_here),