diff --git a/pkg/noun/allocate.c b/pkg/noun/allocate.c index fd563efe12..b905ce5912 100644 --- a/pkg/noun/allocate.c +++ b/pkg/noun/allocate.c @@ -2159,6 +2159,7 @@ u3a_rewrite_compact(void) u3a_rewrite_noun(u3R->pro.day); u3a_rewrite_noun(u3R->pro.trace); u3h_rewrite(u3R->cax.har_p); + u3h_rewrite(u3R->cax.per_p); u3R->ski.gul = u3a_rewritten_noun(u3R->ski.gul); u3R->bug.tax = u3a_rewritten_noun(u3R->bug.tax); @@ -2167,6 +2168,7 @@ u3a_rewrite_compact(void) u3R->pro.day = u3a_rewritten_noun(u3R->pro.day); u3R->pro.trace = u3a_rewritten_noun(u3R->pro.trace); u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p); + u3R->cax.per_p = u3a_rewritten(u3R->cax.per_p); } /* _ca_print_box(): heuristically print the contents of an allocation box. diff --git a/pkg/noun/allocate.h b/pkg/noun/allocate.h index 9ddeb8e5bf..362cc6f579 100644 --- a/pkg/noun/allocate.h +++ b/pkg/noun/allocate.h @@ -175,9 +175,11 @@ u3_noun day; // doss, only in u3H (moveme) } pro; - struct { // transient/persistent memoization - u3p(u3h_root) har_p; // (map (pair term noun) noun) - u3p(u3h_root) per_p; // (map (pair term noun) noun) + struct { // memoization caches + u3p(u3h_root) har_p; // transient + u3p(u3h_root) per_p; // persistent + // u3p(u3h_root) fod_p; // ford + // u3p(u3h_root) sam_p; // ames } cax; } u3a_road; typedef u3a_road u3_road; diff --git a/pkg/noun/jets.c b/pkg/noun/jets.c index dcabcdb559..13e417dab6 100644 --- a/pkg/noun/jets.c +++ b/pkg/noun/jets.c @@ -18,15 +18,6 @@ #include "vortex.h" #include "xtract.h" -/** Data structures. -**/ - -/* _cj_hank: cached hook information. - */ -typedef struct { - u3_weak hax; // axis of hooked inner core - u3j_site sit_u; // call-site data -} _cj_hank; /** Functions. **/ @@ -1069,7 +1060,7 @@ _cj_prog(u3_weak loc, u3_noun fol) /* cj_hank_find(): find cached hook information, keyed by arbitrary * prefix and term cords. RETAIN. */ -static _cj_hank* +static u3j_hank* _cj_hank_find(u3_noun pre, u3_noun tam) { u3_noun key = u3nc(u3k(pre), u3k(tam)); @@ -1077,10 +1068,10 @@ _cj_hank_find(u3_noun pre, u3_noun tam) if ( u3_none != got ) { u3z(key); - return u3to(_cj_hank, got); + return u3to(u3j_hank, got); } else { - _cj_hank* new_u = u3a_walloc(c3_wiseof(_cj_hank)); + u3j_hank* new_u = u3a_walloc(c3_wiseof(u3j_hank)); u3a_road* rod_u = u3R; while ( rod_u->par_p && u3_none == got ) { @@ -1092,7 +1083,7 @@ _cj_hank_find(u3_noun pre, u3_noun tam) new_u->hax = u3_none; } else { - _cj_hank* old_u = u3to(_cj_hank, got); + u3j_hank* old_u = u3to(u3j_hank, got); if ( u3_none != (new_u->hax = old_u->hax) ) { // it's unusual but safe to "take" here, because // u3a_take will no-op on senior nouns (just as u3k would) @@ -1101,7 +1092,7 @@ _cj_hank_find(u3_noun pre, u3_noun tam) } } - u3h_put(u3R->jed.han_p, key, u3of(_cj_hank, new_u)); + u3h_put(u3R->jed.han_p, key, u3of(u3j_hank, new_u)); u3z(key); return new_u; } @@ -1112,7 +1103,7 @@ _cj_hank_find(u3_noun pre, u3_noun tam) * core on return if valid. RETAIN. */ static c3_o -_cj_hank_fine(_cj_hank* han_u, u3_noun cor, u3_noun *inn) +_cj_hank_fine(u3j_hank* han_u, u3_noun cor, u3_noun *inn) { u3_noun hax = han_u->hax; if ( u3_none == hax ) { @@ -1134,7 +1125,7 @@ _cj_hank_fine(_cj_hank* han_u, u3_noun cor, u3_noun *inn) /* _cj_hank_lose(): release memory maintained in a hook cache. */ static void -_cj_hank_lose(_cj_hank* han_u) +_cj_hank_lose(u3j_hank* han_u) { if ( u3_none != han_u->hax ) { u3z(han_u->hax); @@ -1145,7 +1136,7 @@ _cj_hank_lose(_cj_hank* han_u) /* _cj_hank_fill(): slow path, populate han_u. */ static u3_noun -_cj_hank_fill(_cj_hank* han_u, u3_noun tam, u3_noun cor) +_cj_hank_fill(u3j_hank* han_u, u3_noun tam, u3_noun cor) { u3_weak loc, col; u3_noun got, pat, nam, huc; @@ -1642,7 +1633,7 @@ u3j_cook(const c3_c* key_c, const c3_c* tam_c) { u3_noun pro, key, tam, inn; - _cj_hank* han_u; + u3j_hank* han_u; u3t_on(glu_o); key = u3i_string(key_c); @@ -1992,11 +1983,11 @@ u3j_rite_mine(u3j_rite* rit_u, u3_noun clu, u3_noun cor) /* _cj_take_hank_cb(): u3h_take_with cb for taking hanks */ -static u3p(_cj_hank) -_cj_take_hank_cb(u3p(_cj_hank) nah_p) +static u3p(u3j_hank) +_cj_take_hank_cb(u3p(u3j_hank) nah_p) { - _cj_hank* nah_u = u3to(_cj_hank, nah_p); - _cj_hank* han_u = u3a_walloc(c3_wiseof(_cj_hank)); + u3j_hank* nah_u = u3to(u3j_hank, nah_p); + u3j_hank* han_u = u3a_walloc(c3_wiseof(u3j_hank)); if ( u3_none == nah_u->hax ) { han_u->hax = u3_none; @@ -2007,7 +1998,7 @@ _cj_take_hank_cb(u3p(_cj_hank) nah_p) u3j_site_take(&(han_u->sit_u), &(nah_u->sit_u)); } - return u3of(_cj_hank, han_u); + return u3of(u3j_hank, han_u); } /* u3j_take(): copy junior jet state. @@ -2029,25 +2020,25 @@ static void _cj_merge_hank_cb(u3_noun kev, void* wit) { u3p(u3h_root) han_p = *(u3p(u3h_root)*)wit; - _cj_hank* nah_u; + u3j_hank* nah_u; u3_noun key; - u3p(_cj_hank) nah_p; + u3p(u3j_hank) nah_p; u3x_cell(kev, &key, &nah_p); - nah_u = u3to(_cj_hank, nah_p); + nah_u = u3to(u3j_hank, nah_p); if ( u3_none == nah_u->hax ) { u3a_wfree(nah_u); } else { - _cj_hank* han_u; + u3j_hank* han_u; u3_weak got = u3h_git(u3R->jed.han_p, key); if ( u3_none == got ) { han_u = nah_u; } else { - han_u = u3to(_cj_hank, got); + han_u = u3to(u3j_hank, got); if ( u3_none != han_u->hax ) { u3z(han_u->hax); @@ -2058,7 +2049,7 @@ _cj_merge_hank_cb(u3_noun kev, void* wit) u3a_wfree(nah_u); } - u3h_put(han_p, key, u3of(_cj_hank, han_u)); + u3h_put(han_p, key, u3of(u3j_hank, han_u)); } } @@ -2170,7 +2161,7 @@ _cj_warm_tap(u3_noun kev, void* wit) static void _cj_ream_hank(u3_noun kev) { - u3j_site_ream(&(u3to(_cj_hank, u3t(kev))->sit_u)); + u3j_site_ream(&(u3to(u3j_hank, u3t(kev))->sit_u)); } /* u3j_ream(): rebuild warm state @@ -2304,7 +2295,7 @@ static void _cj_mark_hank(u3_noun kev, void* dat) { c3_w* tot_w = (c3_w*) dat; - _cj_hank* han_u = u3to(_cj_hank, u3t(kev)); + u3j_hank* han_u = u3to(u3j_hank, u3t(kev)); *tot_w += u3a_mark_ptr(han_u); if ( u3_none != han_u->hax ) { *tot_w += u3a_mark_noun(han_u->hax); @@ -2337,12 +2328,12 @@ u3j_mark(FILE* fil_u) return u3a_maid(fil_u, "total jet stuff", tot_w); } -/* _cj_free_hank(): free an entry from the hank cache. +/* u3j_free_hank(): free an entry from the hank cache. */ -static void -_cj_free_hank(u3_noun kev) +void +u3j_free_hank(u3_noun kev) { - _cj_hank* han_u = u3to(_cj_hank, u3t(kev)); + u3j_hank* han_u = u3to(u3j_hank, u3t(kev)); if ( u3_none != han_u->hax ) { u3z(han_u->hax); u3j_site_lose(&(han_u->sit_u)); @@ -2355,7 +2346,7 @@ _cj_free_hank(u3_noun kev) void u3j_free(void) { - u3h_walk(u3R->jed.han_p, _cj_free_hank); + u3h_walk(u3R->jed.han_p, u3j_free_hank); u3h_free(u3R->jed.war_p); u3h_free(u3R->jed.cod_p); u3h_free(u3R->jed.han_p); @@ -2379,7 +2370,7 @@ u3j_reclaim(void) // } // clear the jet hank cache // - u3h_walk(u3R->jed.han_p, _cj_free_hank); + u3h_walk(u3R->jed.han_p, u3j_free_hank); u3h_free(u3R->jed.han_p); u3R->jed.han_p = u3h_new(); } diff --git a/pkg/noun/jets.h b/pkg/noun/jets.h index 9c5241c5db..1440f7558a 100644 --- a/pkg/noun/jets.h +++ b/pkg/noun/jets.h @@ -126,6 +126,13 @@ u3p(u3j_fink) fin_p; // fine check } u3j_site; + /* u3j_hank: cached hook information. + */ + typedef struct { + u3_weak hax; // axis of hooked inner core + u3j_site sit_u; // call-site data + } u3j_hank; + /** Globals. **/ /* u3_Dash: jet dashboard. @@ -297,6 +304,11 @@ void u3j_free(void); + /* u3j_free_hank(): free an entry from the hank cache. + */ + void + u3j_free_hank(u3_noun kev); + /* u3j_reclaim(): clear ad-hoc persistent caches to reclaim memory. */ void diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 1456b153ba..ec1f32524b 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -1,6 +1,8 @@ /// @file -#include "manage.h" +#include "pkg/noun/manage.h" +#include "pkg/noun/v2/manage.h" +#include "pkg/noun/v3/manage.h" #include #include @@ -23,7 +25,6 @@ #include "urcrypt/urcrypt.h" #include "vortex.h" #include "xtract.h" -#include "zave.h" // XX stack-overflow recovery should be gated by -a // @@ -597,7 +598,8 @@ _find_home(void) switch ( ver_w ) { case 1: u3m_v2_migrate(); - case 2: break; + case 2: u3m_v3_migrate(); + case 3: break; default: { fprintf(stderr, "loom: checkpoint version mismatch: " "have %u, need %u\r\n", @@ -2128,7 +2130,6 @@ u3m_boot(c3_c* dir_c, size_t len_i) if ( c3n == nuu_o ) { u3j_ream(); u3n_ream(); - // u3z_ream(); return u3A->eve_d; } else { diff --git a/pkg/noun/nock.c b/pkg/noun/nock.c index e495920e06..452b04c309 100644 --- a/pkg/noun/nock.c +++ b/pkg/noun/nock.c @@ -15,7 +15,6 @@ #include "vortex.h" #include "xtract.h" #include "zave.h" -#include "log.h" // define to have each opcode printed as it executes, // along with some other debugging info @@ -1128,9 +1127,11 @@ _n_bint(u3_noun* ops, u3_noun hif, u3_noun nef, c3_o los_o, c3_o tel_o) op_y = (c3y == los_o) ? SLIB : SKIB; // overflows to SLIS / SKIS u3z_cid cid = u3z_memo_toss; - hod = u3r_skip(hod); - if ( c3y == u3du(hod) ) { - cid = u3z_memo_keep; + { + u3_weak con = u3r_skip(hod); + if ( (u3_none != con) && (c3y == u3du(con)) ) { + cid = u3z_memo_keep; + } } ++tot_w; _n_emit(ops, u3nq(op_y, cid, mem_w, u3k(nef))); tot_w += mem_w; _n_apen(ops, mem); @@ -2634,13 +2635,11 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) o = *top; if ( ( u3z_memo_toss == u3h(o) ) ? ( &(u3H->rod_u) != u3R ) - // : ( 0 == u3R->ski.gul ) ) { // prevents userspace from persistence - : ( 1 ) ) { // prevents userspace from persistence + : ( 0 == u3R->ski.gul ) ) { // prevents userspace from persistence u3z_save_m(u3h(o), 144 + c3__nock, u3t(o), x); } - else if ( ( u3z_memo_keep == u3h(o) ) && - ( 0 != u3R->ski.gul ) ) { - u3l_log("nock: userspace can't save to persistent cache\r\n"); + else if ( u3z_memo_keep == u3h(o) ) { + fprintf(stderr, "\r\nnock: userspace can't save to persistent cache\r\n"); } *top = x; u3z(o); diff --git a/pkg/noun/retrieve.c b/pkg/noun/retrieve.c index fa25fb2e38..cc1add4c9c 100644 --- a/pkg/noun/retrieve.c +++ b/pkg/noun/retrieve.c @@ -1908,32 +1908,23 @@ u3r_mug(u3_noun veb) ** ** Extract a constant from a formula, ignoring ** safe/static hints, doing no computation. -** */ -u3_weak u3r_skip(u3_noun fol) { - while ( 1 ) { - if ( c3n == u3du(fol) ) { - return u3_none; - } - else switch ( u3h(fol) ) { - default: - return u3_none; - case 1: - return u3k(u3t(fol)); +u3_weak +u3r_skip(u3_noun fol) { + while ( c3y == u3du(fol) ) { + switch ( u3h(fol) ) { + default: return u3_none; + case 1: return u3t(fol); case 11: { u3_noun arg = u3t(fol), hod = u3h(arg); - if ( c3y == u3du(hod) ) { - u3_weak dug = u3r_skip(u3t(hod)); - if ( u3_none == dug ) { - return u3_none; - } - u3z(dug); + if ( (c3y == u3du(hod)) && (u3_none == u3r_skip(u3t(hod))) ) { + return u3_none; } fol = u3t(arg); - continue; } } } -} \ No newline at end of file + return u3_none; +} diff --git a/pkg/noun/v1/allocate.c b/pkg/noun/v1/allocate.c index 226aa33f00..29a1f5de77 100644 --- a/pkg/noun/v1/allocate.c +++ b/pkg/noun/v1/allocate.c @@ -210,10 +210,10 @@ u3a_v1_reclaim(void) u3h_v1_free_nodes(u3R_v1->cax.har_p); } -/* _me_lose_north(): lose on a north road. +/* _me_v1_lose_north(): lose on a north road. */ static void -_me_lose_north(u3_noun dog) +_me_v1_lose_north(u3_noun dog) { top: { @@ -234,7 +234,7 @@ _me_lose_north(u3_noun dog) u3_noun t_dog = dog_u->tel; if ( !_(u3a_v1_is_cat(h_dog)) ) { - _me_lose_north(h_dog); + _me_v1_lose_north(h_dog); } u3a_v1_wfree(dog_w); if ( !_(u3a_v1_is_cat(t_dog)) ) { @@ -256,6 +256,6 @@ void u3a_v1_lose(u3_noun som) { if ( !_(u3a_v1_is_cat(som)) ) { - _me_lose_north(som); + _me_v1_lose_north(som); } } diff --git a/pkg/noun/v1/jets.c b/pkg/noun/v1/jets.c index be13a63d49..272930e11d 100644 --- a/pkg/noun/v1/jets.c +++ b/pkg/noun/v1/jets.c @@ -9,19 +9,6 @@ #include "pkg/noun/v1/allocate.h" #include "pkg/noun/v1/hashtable.h" -/** Data structures. -**/ - -/* _cj_v1_hank: cached hook information. -** NB: copy of _cj_hank from pkg/noun/jets.c - */ -typedef struct { - u3_weak hax; // axis of hooked inner core - u3j_v1_site sit_u; // call-site data -} _cj_v1_hank; - -/** Functions. -**/ /* _cj_fink_free(): lose and free everything in a u3j_v1_fink. */ @@ -75,13 +62,12 @@ u3j_v1_site_lose(u3j_v1_site* sit_u) } /* _cj_v1_free_hank(): free an entry from the hank cache. -** NB: copy of _cj_v1_free_hank() from pkg/noun/jets.c */ static void _cj_v1_free_hank(u3_noun kev) { u3a_v1_cell* cel_u = (u3a_v1_cell*) u3a_v1_to_ptr(kev); - _cj_v1_hank* han_u = u3to(_cj_v1_hank, cel_u->tel); + u3j_v1_hank* han_u = u3to(u3j_v1_hank, cel_u->tel); if ( u3_none != han_u->hax ) { u3a_v1_lose(han_u->hax); u3j_v1_site_lose(&(han_u->sit_u)); diff --git a/pkg/noun/v1/jets.h b/pkg/noun/v1/jets.h index 1711a0e675..bf3dfe6afe 100644 --- a/pkg/noun/v1/jets.h +++ b/pkg/noun/v1/jets.h @@ -10,6 +10,7 @@ **/ # define u3j_v1_fink u3j_v2_fink # define u3j_v1_fist u3j_v2_fist +# define u3j_v1_hank u3j_v2_hank # define u3j_v1_rite u3j_v2_rite # define u3j_v1_site u3j_v2_site @@ -23,11 +24,11 @@ /* u3j_v1_rite_lose(): lose references of u3j_rite (but do not free). */ void - u3j_v1_rite_lose(u3j_rite* rit_u); + u3j_v1_rite_lose(u3j_v1_rite* rit_u); /* u3j_v1_site_lose(): lose references of u3j_site (but do not free). */ void - u3j_v1_site_lose(u3j_site* sit_u); + u3j_v1_site_lose(u3j_v1_site* sit_u); #endif /* ifndef U3_JETS_V1_H */ diff --git a/pkg/noun/v1/nock.c b/pkg/noun/v1/nock.c index 4e0de27dc2..cce00b28b6 100644 --- a/pkg/noun/v1/nock.c +++ b/pkg/noun/v1/nock.c @@ -22,17 +22,10 @@ u3n_v1_reclaim(void) } /* _cn_v1_prog_free(): free memory retained by program pog_u -** NB: copy of _cn_v1_prog_free in pkg/noun/nock.c */ static void _cn_v1_prog_free(u3n_v1_prog* pog_u) { - // fix up pointers for loom portability - // pog_u->byc_u.ops_y = (c3_y*) ((void*) pog_u) + sizeof(u3n_v1_prog); - // pog_u->lit_u.non = (u3_noun*) (pog_u->byc_u.ops_y + pog_u->byc_u.len_w); - // pog_u->mem_u.sot_u = (u3n_memo*) (pog_u->lit_u.non + pog_u->lit_u.len_w); - // pog_u->cal_u.sit_u = (u3j_site*) (pog_u->mem_u.sot_u + pog_u->mem_u.len_w); - // pog_u->reg_u.rit_u = (u3j_rite*) (pog_u->cal_u.sit_u + pog_u->cal_u.len_w); c3_w dex_w; for (dex_w = 0; dex_w < pog_u->lit_u.len_w; ++dex_w) { @@ -47,13 +40,21 @@ _cn_v1_prog_free(u3n_v1_prog* pog_u) for (dex_w = 0; dex_w < pog_u->reg_u.len_w; ++dex_w) { u3j_v1_rite_lose(&(pog_u->reg_u.rit_u[dex_w])); } + + // fix up pointers for loom portability + pog_u->byc_u.ops_y = (c3_y*) ((void*) pog_u) + sizeof(u3n_v1_prog); + pog_u->lit_u.non = (u3_noun*) (pog_u->byc_u.ops_y + pog_u->byc_u.len_w); + pog_u->mem_u.sot_u = (u3n_v1_memo*) (pog_u->lit_u.non + pog_u->lit_u.len_w); + pog_u->cal_u.sit_u = (u3j_v1_site*) (pog_u->mem_u.sot_u + pog_u->mem_u.len_w); + pog_u->reg_u.rit_u = (u3j_rite*) (pog_u->cal_u.sit_u + pog_u->cal_u.len_w); + u3a_v1_free(pog_u); } -/* _n_feb(): u3h_v1_walk helper for u3n_v1_free +/* _n_v1_feb(): u3h_v1_walk helper for u3n_v1_free */ static void -_n_feb(u3_noun kev) +_n_v1_feb(u3_noun kev) { u3a_v1_cell *cel_u = (u3a_v1_cell*) u3a_v1_to_ptr(kev); _cn_v1_prog_free(u3to(u3n_v1_prog, cel_u->tel)); @@ -65,6 +66,6 @@ void u3n_v1_free() { u3p(u3h_v1_root) har_p = u3R_v1->byc.har_p; - u3h_v1_walk(har_p, _n_feb); + u3h_v1_walk(har_p, _n_v1_feb); u3h_v1_free_nodes(har_p); } diff --git a/pkg/noun/v1/nock.h b/pkg/noun/v1/nock.h index 08a7a5959a..5320307b6b 100644 --- a/pkg/noun/v1/nock.h +++ b/pkg/noun/v1/nock.h @@ -7,6 +7,7 @@ /** Aliases. **/ +# define u3n_v1_memo u3n_v2_memo # define u3n_v1_prog u3n_v2_prog /** Functions. diff --git a/pkg/noun/v2/allocate.h b/pkg/noun/v2/allocate.h index 82b1826adb..b08ffd9c69 100644 --- a/pkg/noun/v2/allocate.h +++ b/pkg/noun/v2/allocate.h @@ -21,6 +21,7 @@ # define u3a_v2_is_north u3a_is_north # define u3a_v2_is_pom u3a_is_pom # define u3a_v2_is_pug u3a_is_pug +# define u3a_v2_lose u3a_lose # define u3a_v2_malloc u3a_malloc # define u3a_v2_minimum u3a_minimum # define u3a_v2_outa u3a_outa diff --git a/pkg/noun/v2/hashtable.h b/pkg/noun/v2/hashtable.h index be6ab9587c..09025fc19f 100644 --- a/pkg/noun/v2/hashtable.h +++ b/pkg/noun/v2/hashtable.h @@ -3,6 +3,7 @@ #define u3h_v2_buck u3h_buck #define u3h_v2_free u3h_free +#define u3h_v2_new u3h_new #define u3h_v2_node u3h_node #define u3h_v2_noun_to_slot u3h_noun_to_slot #define u3h_v2_root u3h_root diff --git a/pkg/noun/v2/jets.c b/pkg/noun/v2/jets.c index e70ef46abe..4b25c0e9d5 100644 --- a/pkg/noun/v2/jets.c +++ b/pkg/noun/v2/jets.c @@ -9,6 +9,18 @@ #include "pkg/noun/v2/hashtable.h" #include "pkg/noun/v2/vortex.h" +/* u3j_v2_reclaim(): clear ad-hoc persistent caches to reclaim memory. +*/ +void +u3j_v2_reclaim(void) +{ + // clear the jet hank cache + // + u3h_v2_walk(u3R_v2->jed.han_p, u3j_v2_free_hank); + u3h_v2_free(u3R_v2->jed.han_p); + u3R_v2->jed.han_p = u3h_v2_new(); +} + /* u3j_v2_rewrite_compact(): rewrite jet state for compaction. * * NB: u3R_v2->jed.han_p *must* be cleared (currently via u3j_v2_reclaim above) diff --git a/pkg/noun/v2/jets.h b/pkg/noun/v2/jets.h index a596170f60..281c5d62be 100644 --- a/pkg/noun/v2/jets.h +++ b/pkg/noun/v2/jets.h @@ -3,17 +3,30 @@ #ifndef U3_JETS_V2_H #define U3_JETS_V2_H +#include "pkg/noun/allocate.h" +#include "pkg/noun/jets.h" + + /** Aliases. **/ +# define u3j_v2_core u3j_core # define u3j_v2_fink u3j_fink # define u3j_v2_fist u3j_fist +# define u3j_v2_hank u3j_hank +# define u3j_v2_free_hank u3j_free_hank +# define u3j_v2_harm u3j_harm # define u3j_v2_rite u3j_rite -# define u3j_v2_rite_lose u3j_rite_lose # define u3j_v2_site u3j_site +# define u3j_v2_rite_lose u3j_rite_lose # define u3j_v2_site_lose u3j_site_lose /** Functions. **/ + /* u3j_v2_reclaim(): clear ad-hoc persistent caches to reclaim memory. + */ + void + u3j_v2_reclaim(void); + /* u3j_v2_rewrite_compact(): rewrite jet state for compaction. */ void diff --git a/pkg/noun/v2/manage.h b/pkg/noun/v2/manage.h index 998a37cc65..1d03b97809 100644 --- a/pkg/noun/v2/manage.h +++ b/pkg/noun/v2/manage.h @@ -3,10 +3,9 @@ #ifndef U3_MANAGE_V2_H #define U3_MANAGE_V2_H - /** System management. + /** System management. **/ /* u3m_v2_migrate: perform pointer compression loom migration if necessary. - ver_w - target version */ void u3m_v2_migrate(); diff --git a/pkg/noun/v2/nock.c b/pkg/noun/v2/nock.c index 95a011e005..d8e447a417 100644 --- a/pkg/noun/v2/nock.c +++ b/pkg/noun/v2/nock.c @@ -1,11 +1,9 @@ /// @file -#include "pkg/noun/nock.h" #include "pkg/noun/v2/nock.h" #include "pkg/noun/v2/allocate.h" #include "pkg/noun/v2/hashtable.h" -#include "pkg/noun/v2/vortex.h" /* u3n_v2_rewrite_compact(): rewrite the bytecode cache for compaction. * diff --git a/pkg/noun/v2/nock.h b/pkg/noun/v2/nock.h index eddc3d2074..13432f384b 100644 --- a/pkg/noun/v2/nock.h +++ b/pkg/noun/v2/nock.h @@ -3,13 +3,16 @@ #ifndef U3_NOCK_V2_H #define U3_NOCK_V2_H +#include "pkg/noun/nock.h" + +#include "types.h" + /** Aliases. **/ -#define u3n_v2_free u3n_free -#define u3n_v2_prog u3n_prog +# define u3n_v2_memo u3n_memo +# define u3n_v2_prog u3n_prog +# define u3n_v2_reclaim u3n_reclaim - /** Functions. - **/ /* u3n_v2_rewrite_compact(): rewrite bytecode cache for compaction. */ void diff --git a/pkg/noun/v3/allocate.h b/pkg/noun/v3/allocate.h new file mode 100644 index 0000000000..fb9fa73015 --- /dev/null +++ b/pkg/noun/v3/allocate.h @@ -0,0 +1,16 @@ +#ifndef U3_ALLOCATE_V3_H +#define U3_ALLOCATE_V3_H + +#include "pkg/noun/allocate.h" + +#include "pkg/noun/v3/manage.h" +#include "options.h" + + /** Aliases. + **/ +# define u3R_v3 u3a_Road +# define u3a_v3_balign u3a_balign +# define u3a_v3_road u3a_road +# define u3a_v3_walign u3a_walign + +#endif /* ifndef U3_ALLOCATE_V3_H */ diff --git a/pkg/noun/v3/hashtable.h b/pkg/noun/v3/hashtable.h new file mode 100644 index 0000000000..7ad854b91c --- /dev/null +++ b/pkg/noun/v3/hashtable.h @@ -0,0 +1,8 @@ +#ifndef U3_HASHTABLE_V3_H +#define U3_HASHTABLE_V3_H + +#define u3h_v3_new_cache u3h_new_cache + +#include "pkg/noun/hashtable.h" + +#endif /* U3_HASHTABLE_V3_H */ diff --git a/pkg/noun/v3/manage.c b/pkg/noun/v3/manage.c new file mode 100644 index 0000000000..a9236ffa80 --- /dev/null +++ b/pkg/noun/v3/manage.c @@ -0,0 +1,111 @@ +/// @file + +#include "pkg/noun/v3/manage.h" + +#include "pkg/noun/v2/jets.h" +#include "pkg/noun/v2/nock.h" +#include "pkg/noun/v2/vortex.h" + +#include "pkg/noun/v3/allocate.h" +#include "pkg/noun/v3/hashtable.h" +#include "pkg/noun/version.h" +#include "pkg/noun/v3/vortex.h" +#include + +/* u3m_v3_migrate: perform loom migration if necessary. +*/ +void +u3m_v3_migrate() +{ + fprintf(stderr, "loom: memoization migration running...\r\n"); + + + c3_w ver_w = *(u3_Loom + u3C.wor_i - 1); + c3_w *mem_w = u3_Loom + u3a_v3_walign; + c3_w len_w = u3C.wor_i - u3a_v3_walign; + c3_w suz_w = c3_wiseof(u3v_v2_home); + c3_w *mut_w = c3_align(mem_w + len_w - suz_w, u3a_v3_balign, C3_ALGLO); + + // old road + u3v_v2_home* hum_u = (u3v_v2_home*)mut_w; + u3a_v2_road* rud_u = &hum_u->rod_u; + size_t ruz_t = sizeof(u3a_v2_road); + + // set v2 globals + u3H_v2 = (void *)mut_w; + u3R_v2 = &u3H_v2->rod_u; + u3R_v2->cap_p = u3R_v2->mat_p = u3a_v2_outa(u3H_v2); + u3H = (u3v_home*)u3H_v2; + u3R = (u3a_road*)u3R_v2; + + // free bytecode caches in old road + u3j_v2_reclaim(); + u3n_v2_reclaim(); + + // new home, new road + u3v_v3_home hom_u = {0}; + u3a_v3_road rod_u = {0}; + + // copy members, one-by-one, from old road to new road + rod_u.par_p = rud_u->par_p; + rod_u.kid_p = rud_u->kid_p; + rod_u.nex_p = rud_u->nex_p; + + rod_u.cap_p = rud_u->cap_p; + rod_u.hat_p = rud_u->hat_p; + rod_u.mat_p = rud_u->mat_p; + rod_u.rut_p = rud_u->rut_p; + rod_u.ear_p = rud_u->ear_p; + + // no need to zero-out fut_w + // no need to do anything with esc + + rod_u.how.fag_w = rud_u->how.fag_w; + + memcpy(rod_u.all.fre_p, rud_u->all.fre_p, sizeof(rud_u->all.fre_p)); + rod_u.all.cel_p = rud_u->all.cel_p; + rod_u.all.fre_w = rud_u->all.fre_w; + rod_u.all.max_w = rud_u->all.max_w; + + rod_u.jed.hot_p = rud_u->jed.hot_p; + rod_u.jed.war_p = rud_u->jed.war_p; + rod_u.jed.cod_p = rud_u->jed.cod_p; + rod_u.jed.han_p = rud_u->jed.han_p; + rod_u.jed.bas_p = rud_u->jed.bas_p; + + rod_u.byc.har_p = rud_u->byc.har_p; + + rod_u.ski.gul = rud_u->ski.gul; + + rod_u.bug.tax = rud_u->bug.tax; + rod_u.bug.mer = rud_u->bug.mer; + + rod_u.pro.nox_d = rud_u->pro.nox_d; + rod_u.pro.cel_d = rud_u->pro.cel_d; + rod_u.pro.don = rud_u->pro.don; + rod_u.pro.trace = rud_u->pro.trace; + rod_u.pro.day = rud_u->pro.day; + + rod_u.cax.har_p = rud_u->cax.har_p; + + // prepare the new home, update the version + hom_u.arv_u = hum_u->arv_u; + hom_u.rod_u = rod_u; + hom_u.ver_w = U3V_VER3; + + // place the new home over the old one + c3_w siz_w = c3_wiseof(u3v_v3_home); + c3_w *mat_w = c3_align(mem_w + len_w - siz_w, u3a_v3_balign, C3_ALGLO); + memcpy(mat_w, &hom_u, sizeof(u3v_v3_home)); + + // set globals + u3H_v3 = (void*)mat_w; + u3R_v3 = &u3H_v3->rod_u; + u3H = (u3v_home*)u3H_v3; + u3R = (u3a_road*)u3R_v3; + + // initialize persistent cache + u3R_v3->cax.per_p = u3h_v3_new_cache(u3C.per_w); + + fprintf(stderr, "loom: memoization migration done\r\n"); +} diff --git a/pkg/noun/v3/manage.h b/pkg/noun/v3/manage.h new file mode 100644 index 0000000000..5745a6316b --- /dev/null +++ b/pkg/noun/v3/manage.h @@ -0,0 +1,13 @@ +/// @file + +#ifndef U3_MANAGE_V3_H +#define U3_MANAGE_V3_H + + /** System management. + **/ + /* u3m_v3_migrate: perform memoization loom migration if necessary. + */ + void + u3m_v3_migrate(); + +#endif /* ifndef U3_MANAGE_V3_H */ diff --git a/pkg/noun/v3/vortex.c b/pkg/noun/v3/vortex.c new file mode 100644 index 0000000000..7f2a9e6569 --- /dev/null +++ b/pkg/noun/v3/vortex.c @@ -0,0 +1,5 @@ +/// @file + +#include "pkg/noun/v3/vortex.h" + +u3v_v3_home* u3v_v3_Home; diff --git a/pkg/noun/v3/vortex.h b/pkg/noun/v3/vortex.h new file mode 100644 index 0000000000..58443a79a3 --- /dev/null +++ b/pkg/noun/v3/vortex.h @@ -0,0 +1,35 @@ +/// @file + +#ifndef U3_VORTEX_V3_H +#define U3_VORTEX_V3_H + +#include "pkg/noun/vortex.h" + +#include "pkg/noun/v3/allocate.h" +#include "pkg/noun/version.h" + + /** Aliases. + **/ +# define u3v_v3_arvo u3v_arvo +# define u3H_v3 u3v_Home +# define u3A_v3 (&(u3H_v3)->arv_u) + + /** Data structures. + **/ + /* u3v_v3_home: all internal (within image) state. + ** NB: version must be last for discriminability in north road + */ + typedef struct _u3v_v3_home { + u3a_v3_road rod_u; // storage state + u3v_v3_arvo arv_u; // arvo state + u3v_version ver_w; // version number + } u3v_v3_home; + + /** Functions. + **/ + /* u3v_v3_rewrite_compact(): rewrite arvo kernel for compaction. + */ + void + u3v_v3_rewrite_compact(); + +#endif /* ifndef U3_VORTEX_V3_H */ diff --git a/pkg/noun/version.h b/pkg/noun/version.h index f64d0a398e..bc81c83f5a 100644 --- a/pkg/noun/version.h +++ b/pkg/noun/version.h @@ -8,7 +8,8 @@ typedef c3_w u3v_version; #define U3V_VER1 1 #define U3V_VER2 2 -#define U3V_VERLAT U3V_VER2 +#define U3V_VER3 3 +#define U3V_VERLAT U3V_VER3 /* EVENTS */ diff --git a/pkg/noun/zave.c b/pkg/noun/zave.c index a3b2228c9f..596200f887 100644 --- a/pkg/noun/zave.c +++ b/pkg/noun/zave.c @@ -63,7 +63,6 @@ u3z_find(u3z_cid cid, u3_noun key) while ( 1 ) { u3_weak got = u3h_get(_har(rod_u, cid), key); if ( u3_none != got ) { - fprintf(stderr, "\r\nHIT MY BOY!\r\n"); return got; } if ( 0 == rod_u->kid_p ) { @@ -78,8 +77,10 @@ u3z_find_m(u3z_cid cid, c3_m fun, u3_noun one) { u3_noun key = u3nc(fun, u3k(one)); u3_weak val; + val = u3z_find(cid, key); + u3z(key); - return u3z_find(cid, key); + return val; } /* u3z_save(): save in memo cache. TRANSFER key; RETAIN val @@ -130,4 +131,4 @@ u3z_reap(u3z_cid cid, u3p(u3h_root) har_p) u3h_uni(_har(u3R, cid), har_p); u3h_free(har_p); -} \ No newline at end of file +} diff --git a/pkg/vere/lord.c b/pkg/vere/lord.c index 114fad8504..a63824ae9b 100644 --- a/pkg/vere/lord.c +++ b/pkg/vere/lord.c @@ -1178,7 +1178,6 @@ u3_lord_init(c3_c* pax_c, c3_w wag_w, c3_d key_d[4], u3_lord_cb cb_u) sprintf(wag_c, "%u", god_u->wag_w); - // XX hap_w sprintf(hap_c, "%u", u3_Host.ops_u.hap_w); sprintf(per_c, "%u", u3_Host.ops_u.per_w); @@ -1187,7 +1186,6 @@ u3_lord_init(c3_c* pax_c, c3_w wag_w, c3_d key_d[4], u3_lord_cb cb_u) sprintf(tos_c, "%u", u3C.tos_w); - // XX arg_c[0] = god_u->bin_c; // executable arg_c[1] = "serf"; // protocol arg_c[2] = god_u->pax_c; // path to checkpoint directory @@ -1216,7 +1214,6 @@ u3_lord_init(c3_c* pax_c, c3_w wag_w, c3_d key_d[4], u3_lord_cb cb_u) arg_c[10] = per_c; arg_c[11] = NULL; - uv_pipe_init(u3L, &god_u->inn_u.pyp_u, 0); uv_timer_init(u3L, &god_u->out_u.tim_u); uv_pipe_init(u3L, &god_u->out_u.pyp_u, 0);