diff --git a/pkg/noun/hashtable.c b/pkg/noun/hashtable.c index 5915de5944..f4b1201db4 100644 --- a/pkg/noun/hashtable.c +++ b/pkg/noun/hashtable.c @@ -898,6 +898,31 @@ u3h_take(u3p(u3h_root) har_p) return u3h_take_with(har_p, u3a_take); } +/* _ch_take_uni_cb(): take a key/value pair, put into [dst_p]. +*/ +static void +_ch_take_uni_cb(u3_cell kev, void* wit) +{ + u3a_cell* kev_u = u3a_to_ptr(kev); + u3_noun key = u3a_take(kev_u->hed); + u3_noun val = u3a_take(kev_u->tel); + + { + u3p(u3h_root) dst_p = *(u3p(u3h_root)*)wit; + u3h_put(dst_p, key, val); + } + + u3z(key); +} + +/* u3h_take_uni(): take entries from [src_p], put into [dst_p]. +*/ +void +u3h_take_uni(u3p(u3h_root) dst_p, u3p(u3h_root) src_p) +{ + u3h_walk_with(src_p, _ch_take_uni_cb, &dst_p); +} + /* _ch_mark_buck(): mark bucket for gc. */ c3_w diff --git a/pkg/noun/hashtable.h b/pkg/noun/hashtable.h index be1d3f93be..2558516dca 100644 --- a/pkg/noun/hashtable.h +++ b/pkg/noun/hashtable.h @@ -180,6 +180,11 @@ u3p(u3h_root) u3h_take(u3p(u3h_root) har_p); + /* u3h_take_uni(): take entries from [src_p], put into [dst_p]. + */ + void + u3h_take_uni(u3p(u3h_root) dst_p, u3p(u3h_root) src_p); + /* u3h_wyt(): number of entries */ c3_w diff --git a/pkg/noun/jets.c b/pkg/noun/jets.c index 00edefec40..e27b92e208 100644 --- a/pkg/noun/jets.c +++ b/pkg/noun/jets.c @@ -1990,94 +1990,58 @@ u3j_rite_mine(u3j_rite* rit_u, u3_noun clu, u3_noun cor) u3t_off(glu_o); } -/* _cj_take_hank_cb(): u3h_take_with cb for taking hanks -*/ -static u3p(_cj_hank) -_cj_take_hank_cb(u3p(_cj_hank) nah_p) -{ - _cj_hank* nah_u = u3to(_cj_hank, nah_p); - _cj_hank* han_u = u3a_walloc(c3_wiseof(_cj_hank)); - - if ( u3_none == nah_u->hax ) { - han_u->hax = u3_none; - // han_u->sit_u left uninitialized, will be ignored - } - else { - han_u->hax = u3a_take(nah_u->hax); - u3j_site_take(&(han_u->sit_u), &(nah_u->sit_u)); - } - - return u3of(_cj_hank, han_u); -} - -/* u3j_take(): copy junior jet state. -*/ -u3a_jets -u3j_take(u3a_jets jed_u) -{ - jed_u.war_p = u3h_take(jed_u.war_p); - jed_u.cod_p = u3h_take(jed_u.cod_p); - jed_u.han_p = u3h_take_with(jed_u.han_p, _cj_take_hank_cb); - jed_u.bas_p = u3h_take(jed_u.bas_p); - return jed_u; -} - -/* _cj_merge_hank_cb(): u3h_uni_with cb for integrating taken hanks -** NB "transfers" or frees hanks in jed_u.han_p +/* _cj_reap_hank(): promote call site. */ static void -_cj_merge_hank_cb(u3_noun kev, void* wit) +_cj_reap_hank(u3_cell kev) { - u3p(u3h_root) han_p = *(u3p(u3h_root)*)wit; - _cj_hank* nah_u; - u3_noun key; - u3p(_cj_hank) nah_p; - u3x_cell(kev, &key, &nah_p); - - nah_u = u3to(_cj_hank, nah_p); - - if ( u3_none == nah_u->hax ) { - u3a_wfree(nah_u); - } - else { - _cj_hank* han_u; - u3_weak got = u3h_git(u3R->jed.han_p, key); + u3a_cell* kev_u = u3a_to_ptr(kev); + u3_noun key = u3a_take(kev_u->hed); + u3_weak got = u3h_git(u3R->jed.han_p, key); + _cj_hank* nah_u = u3to(_cj_hank, kev_u->tel); + _cj_hank* han_u; - if ( u3_none == got ) { - han_u = nah_u; - } - else { + if ( u3_none != got ) { + if ( u3_none != nah_u->hax ) { + u3_weak old; han_u = u3to(_cj_hank, got); + old = han_u->hax; + han_u->hax = u3a_take(nah_u->hax); - if ( u3_none != han_u->hax ) { - u3z(han_u->hax); + u3j_site_take(&(nah_u->sit_u), &(nah_u->sit_u)); + u3j_site_merge(&(han_u->sit_u), &(nah_u->sit_u)); + + if ( u3_none != old ) { + u3z(old); } - han_u->hax = nah_u->hax; - u3j_site_merge(&(han_u->sit_u), &(nah_u->sit_u)); - u3a_wfree(nah_u); + // XX double check, see _cn_reap_prog_cb() + // + u3h_put(u3R->jed.han_p, key, u3of(_cj_hank, han_u)); } - - u3h_put(han_p, key, u3of(_cj_hank, han_u)); } + else if ( u3_none != nah_u->hax ) { + han_u = u3a_walloc(c3_wiseof(_cj_hank)); + han_u->hax = u3a_take(nah_u->hax); + u3j_site_take(&(han_u->sit_u), &(nah_u->sit_u)); + u3h_put(u3R->jed.han_p, key, u3of(_cj_hank, han_u)); + } + + u3z(key); } /* u3j_reap(): promote jet state. */ void -u3j_reap(u3a_jets jed_u) +u3j_reap(u3a_jets* jed_u) { - u3h_uni(u3R->jed.war_p, jed_u.war_p); - u3h_free(jed_u.war_p); - - u3h_uni(u3R->jed.cod_p, jed_u.cod_p); - u3h_free(jed_u.cod_p); - - u3h_walk_with(jed_u.han_p, _cj_merge_hank_cb, &u3R->jed.han_p); - u3h_free(jed_u.han_p); - - u3h_uni(u3R->jed.bas_p, jed_u.bas_p); - u3h_free(jed_u.bas_p); + u3h_take_uni(u3R->jed.cod_p, jed_u->cod_p); + // call sites must be reaped before the warm dashboard; + // they may contain references to labels on this road + // + u3h_walk(jed_u->han_p, _cj_reap_hank); + u3h_take_uni(u3R->jed.war_p, jed_u->war_p); + u3h_take_uni(u3R->jed.bas_p, jed_u->bas_p); } /* _cj_ream(): ream list of battery [bash registry] pairs. RETAIN. diff --git a/pkg/noun/jets.h b/pkg/noun/jets.h index 9c5241c5db..6db106918c 100644 --- a/pkg/noun/jets.h +++ b/pkg/noun/jets.h @@ -208,12 +208,7 @@ /* u3j_reap(): promote jet state. */ void - u3j_reap(u3a_jets jed_u); - - /* u3j_take(): copy junior jet state. - */ - u3a_jets - u3j_take(u3a_jets jed_u); + u3j_reap(u3a_jets* jed_u); /* u3j_rite_mine(): mine cor with clu, using u3j_rite for caching */ diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 5ff7d7b129..00b76d2cc3 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -995,28 +995,26 @@ u3m_love(u3_noun pro) // save cache pointers from current road // u3p(u3h_root) byc_p = u3R->byc.har_p; - u3a_jets jed_u = u3R->jed; + u3a_jets* jed_u = &(u3R->jed); // fallback to parent road (child heap on parent's stack) // u3m_fall(); - // copy product and caches off our stack + // copy product off our stack // - pro = u3a_take(pro); - jed_u = u3j_take(jed_u); - byc_p = u3n_take(byc_p); - - // pop the stack - // - u3R->cap_p = u3R->ear_p; - u3R->ear_p = 0; + pro = u3a_take(pro); // integrate junior caches // u3j_reap(jed_u); u3n_reap(byc_p); + // pop the stack + // + u3R->cap_p = u3R->ear_p; + u3R->ear_p = 0; + return pro; } diff --git a/pkg/noun/nock.c b/pkg/noun/nock.c index 6ac08779ef..b3fab4e6cb 100644 --- a/pkg/noun/nock.c +++ b/pkg/noun/nock.c @@ -2866,12 +2866,11 @@ _cn_take_prog_dat(u3n_prog* dst_u, u3n_prog* src_u) } } -/* _cn_take_prog_cb(): u3h_take_with cb for taking junior u3n_prog's. +/* _cn_take_prog(): take junior u3n_prog. */ -static u3p(u3n_prog) -_cn_take_prog_cb(u3p(u3n_prog) pog_p) +static u3n_prog* +_cn_take_prog(u3n_prog* pog_u) { - u3n_prog* pog_u = u3to(u3n_prog, pog_p); u3n_prog* gop_u; if ( c3y == pog_u->byc_u.own_o ) { @@ -2887,17 +2886,8 @@ _cn_take_prog_cb(u3p(u3n_prog) pog_p) } _cn_take_prog_dat(gop_u, pog_u); - // _n_prog_take_dat(gop_u, pog_u, c3n); - return u3of(u3n_prog, gop_u); -} - -/* u3n_take(): copy junior bytecode state. -*/ -u3p(u3h_root) -u3n_take(u3p(u3h_root) har_p) -{ - return u3h_take_with(har_p, _cn_take_prog_cb); + return gop_u; } /* _cn_merge_prog_dat(): copy references from src_u u3n_prog to dst_u. @@ -2931,29 +2921,38 @@ _cn_merge_prog_dat(u3n_prog* dst_u, u3n_prog* src_u) } } -/* _cn_merge_prog_cb(): u3h_walk_with cb for integrating taken u3n_prog's. +/* _cn_reap_prog_cb(): promote junior bytecode entry. */ static void -_cn_merge_prog_cb(u3_noun kev, void* wit) +_cn_reap_prog_cb(u3_cell kev) { - u3p(u3h_root) har_p = *(u3p(u3h_root)*)wit; - u3n_prog* pog_u; - u3_weak got; - u3_noun key; - u3p(u3n_prog) pog_p; - u3x_cell(kev, &key, &pog_p); - - pog_u = u3to(u3n_prog, pog_p); - got = u3h_git(har_p, key); + u3a_cell* kev_u = u3a_to_ptr(kev); + u3_noun key = u3a_take(kev_u->hed); + u3n_prog* pog_u = u3to(u3n_prog, kev_u->tel); + u3_weak got = u3h_git(u3R->byc.har_p, key); - if ( u3_none != got ) { + // promote + // + if ( u3_none == got ) { + pog_u = _cn_take_prog(pog_u); + } + // integrate + // + else { u3n_prog* sep_u = u3to(u3n_prog, got); + _cn_take_prog_dat(pog_u, pog_u); _cn_merge_prog_dat(sep_u, pog_u); - u3a_free(pog_u); pog_u = sep_u; } - u3h_put(har_p, key, u3of(u3n_prog, pog_u)); + // we must always put, because we have taken. + // we must always keep what we have taken, + // or we can break relocation pointers. + // + // XX double check + // + u3h_put(u3R->byc.har_p, key, u3of(u3n_prog, pog_u)); + u3z(key); } /* u3n_reap(): promote bytecode state. @@ -2961,9 +2960,7 @@ _cn_merge_prog_cb(u3_noun kev, void* wit) void u3n_reap(u3p(u3h_root) har_p) { - u3h_walk_with(har_p, _cn_merge_prog_cb, &u3R->byc.har_p); - // NB *not* u3n_free, _cn_merge_prog_cb() transfers u3n_prog's - u3h_free(har_p); + u3h_walk(har_p, _cn_reap_prog_cb); } /* _n_ream(): ream program call sites diff --git a/pkg/noun/nock.h b/pkg/noun/nock.h index 7dded22058..a60b0ece58 100644 --- a/pkg/noun/nock.h +++ b/pkg/noun/nock.h @@ -114,11 +114,6 @@ void u3n_reap(u3p(u3h_root) har_p); - /* u3n_take(): copy junior bytecode state. - */ - u3p(u3h_root) - u3n_take(u3p(u3h_root) har_p); - /* u3n_mark(): mark bytecode cache. */ c3_w