diff --git a/pkg/noun/v1/allocate.c b/pkg/noun/v1/allocate.c index 4192fedd20..b8da1684e6 100644 --- a/pkg/noun/v1/allocate.c +++ b/pkg/noun/v1/allocate.c @@ -28,7 +28,7 @@ u3a_v1_rewritten_noun(u3_noun som) if ( c3y == u3a_is_cat(som) ) { return som; } - u3_post som_p = u3a_v1_rewritten(u3a_v1_to_off(som)); + u3_post som_p = u3a_rewritten(u3a_v1_to_off(som)); if ( c3y == u3a_is_pug(som) ) { som_p = u3a_v1_to_pug(som_p); // XX alias? @@ -60,8 +60,8 @@ u3a_v1_rewrite_compact(void) u3R->bug.mer = u3a_v1_rewritten_noun(u3R->bug.mer); u3R->pro.don = u3a_v1_rewritten_noun(u3R->pro.don); u3R->pro.day = u3a_v1_rewritten_noun(u3R->pro.day); - u3R->pro.trace = u3a_v1_rewritten_noun(u3R->pro.trace); - u3R->cax.har_p = u3a_v1_rewritten(u3R->cax.har_p); + u3R->pro.trace = u3a_rewritten_noun(u3R->pro.trace); + u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p); } void u3a_v1_rewrite_noun(u3_noun som) diff --git a/pkg/noun/v1/hashtable.c b/pkg/noun/v1/hashtable.c index 1a2cb6b6c9..1018201abb 100644 --- a/pkg/noun/v1/hashtable.c +++ b/pkg/noun/v1/hashtable.c @@ -10,20 +10,20 @@ #include "xtract.h" -/* _ch_popcount(): number of bits set in word. A standard intrinsic. -** NB: copy of _ch_popcount in pkg/noun/hashtable.c +/* _ch_v1_popcount(): number of bits set in word. A standard intrinsic. +** NB: copy of _ch_v1_popcount in pkg/noun/hashtable.c */ static c3_w -_ch_popcount(c3_w num_w) +_ch_v1_popcount(c3_w num_w) { return __builtin_popcount(num_w); } -/* _ch_free_buck(): free bucket -** NB: copy of _ch_free_buck in pkg/noun/hashtable.c +/* _ch_v1_free_buck(): free bucket +** NB: copy of _ch_v1_free_buck in pkg/noun/hashtable.c */ static void -_ch_free_buck(u3h_buck* hab_u) +_ch_v1_free_buck(u3h_buck* hab_u) { c3_w i_w; @@ -33,12 +33,12 @@ _ch_free_buck(u3h_buck* hab_u) u3a_wfree(hab_u); } -/* _ch_free_node(): free node. +/* _ch_v1_free_node(): free node. */ static void -_ch_free_node(u3h_node* han_u, c3_w lef_w) +_ch_v1_free_node(u3h_node* han_u, c3_w lef_w) { - c3_w len_w = _ch_popcount(han_u->map_w); + c3_w len_w = _ch_v1_popcount(han_u->map_w); c3_w i_w; lef_w -= 5; @@ -53,9 +53,9 @@ _ch_free_node(u3h_node* han_u, c3_w lef_w) void* hav_v = u3h_v1_slot_to_node(sot_w); if ( 0 == lef_w ) { - _ch_free_buck(hav_v); + _ch_v1_free_buck(hav_v); } else { - _ch_free_node(hav_v, lef_w); + _ch_v1_free_node(hav_v, lef_w); } } } @@ -79,17 +79,17 @@ u3h_v1_free(u3p(u3h_root) har_p) else if ( _(u3h_slot_is_node(sot_w)) ) { u3h_node* han_u = u3h_slot_to_node(sot_w); - _ch_free_node(han_u, 25); + _ch_v1_free_node(han_u, 25); } } u3a_free(har_u); } -/* _ch_walk_buck(): walk bucket for gc. -** NB: copy of _ch_walk_buck in pkg/noun/hashtable.c +/* _ch_v1_walk_buck(): walk bucket for gc. +** NB: copy of _ch_v1_walk_buck in pkg/noun/hashtable.c */ static void -_ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v1_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) { c3_w i_w; @@ -98,12 +98,12 @@ _ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) } } -/* _ch_walk_node(): walk node for gc. +/* _ch_v1_walk_node(): walk node for gc. */ static void -_ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) { - c3_w len_w = _ch_popcount(han_u->map_w); + c3_w len_w = _ch_v1_popcount(han_u->map_w); c3_w i_w; lef_w -= 5; @@ -120,9 +120,9 @@ _ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* void* hav_v = u3h_slot_to_node(sot_w); if ( 0 == lef_w ) { - _ch_walk_buck(hav_v, fun_f, wit); + _ch_v1_walk_buck(hav_v, fun_f, wit); } else { - _ch_walk_node(hav_v, lef_w, fun_f, wit); + _ch_v1_walk_node(hav_v, lef_w, fun_f, wit); } } } @@ -150,15 +150,15 @@ u3h_v1_walk_with(u3p(u3h_root) har_p, else if ( _(u3h_slot_is_node(sot_w)) ) { u3h_node* han_u = u3h_slot_to_node(sot_w); - _ch_walk_node(han_u, 25, fun_f, wit); + _ch_v1_walk_node(han_u, 25, fun_f, wit); } } } -/* _ch_v1_walk_plain(): use plain u3_noun fun_f for each node +/* _ch_v1_v1_walk_plain(): use plain u3_noun fun_f for each node */ static void -_ch_v1_walk_plain(u3_noun kev, void* wit) +_ch_v1_v1_walk_plain(u3_noun kev, void* wit) { void (*fun_f)(u3_noun) = wit; fun_f(kev); @@ -169,13 +169,13 @@ _ch_v1_walk_plain(u3_noun kev, void* wit) void u3h_v1_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun)) { - u3h_v1_walk_with(har_p, _ch_v1_walk_plain, fun_f); + u3h_v1_walk_with(har_p, _ch_v1_v1_walk_plain, fun_f); } -/* _ch_rewrite_buck(): rewrite buck for compaction. +/* _ch_v1_rewrite_buck(): rewrite buck for compaction. */ void -_ch_rewrite_buck(u3h_buck* hab_u) +_ch_v1_rewrite_buck(u3h_buck* hab_u) { if ( c3n == u3a_rewrite_ptr(hab_u) ) return; c3_w i_w; @@ -187,14 +187,14 @@ _ch_rewrite_buck(u3h_buck* hab_u) } } -/* _ch_rewrite_node(): rewrite node for compaction. +/* _ch_v1_rewrite_node(): rewrite node for compaction. */ void -_ch_rewrite_node(u3h_node* han_u, c3_w lef_w) +_ch_v1_rewrite_node(u3h_node* han_u, c3_w lef_w) { if ( c3n == u3a_rewrite_ptr(han_u) ) return; - c3_w len_w = _ch_popcount(han_u->map_w); + c3_w len_w = _ch_v1_popcount(han_u->map_w); c3_w i_w; lef_w -= 5; @@ -210,14 +210,14 @@ _ch_rewrite_node(u3h_node* han_u, c3_w lef_w) } else { void* hav_v = u3h_v1_slot_to_node(sot_w); - u3h_node* nod_u = u3to(u3h_node, u3a_v1_rewritten(u3of(u3h_node,hav_v))); + u3h_node* nod_u = u3to(u3h_node, u3a_rewritten(u3of(u3h_node,hav_v))); han_u->sot_w[i_w] = u3h_v1_node_to_slot(nod_u); if ( 0 == lef_w ) { - _ch_rewrite_buck(hav_v); + _ch_v1_rewrite_buck(hav_v); } else { - _ch_rewrite_node(hav_v, lef_w); + _ch_v1_rewrite_node(hav_v, lef_w); } } } @@ -244,11 +244,11 @@ u3h_v1_rewrite(u3p(u3h_root) har_p) } else if ( _(u3h_slot_is_node(sot_w)) ) { u3h_node* han_u = u3h_v1_slot_to_node(sot_w); - u3h_node* nod_u = u3to(u3h_node, u3a_v1_rewritten(u3of(u3h_node,han_u))); + u3h_node* nod_u = u3to(u3h_node, u3a_rewritten(u3of(u3h_node,han_u))); har_u->sot_w[i_w] = u3h_v1_node_to_slot(nod_u); - _ch_rewrite_node(han_u, 25); + _ch_v1_rewrite_node(han_u, 25); } } } diff --git a/pkg/noun/v1/jets.c b/pkg/noun/v1/jets.c index da57d7a4f9..f84c856fb1 100644 --- a/pkg/noun/v1/jets.c +++ b/pkg/noun/v1/jets.c @@ -11,24 +11,24 @@ /** Data structures. **/ -/* _cj_hank: cached hook information. -** NB: copy of _cj_hank from pkg/noun/jets.c +/* _cj_v1_hank: cached hook information. +** NB: copy of _cj_v1_hank from pkg/noun/jets.c */ typedef struct { u3_weak hax; // axis of hooked inner core u3j_site sit_u; // call-site data -} _cj_hank; +} _cj_v1_hank; /** Functions. **/ -/* _cj_free_hank(): free an entry from the hank cache. -** NB: copy of _cj_free_hank() from pkg/noun/jets.c +/* _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_free_hank(u3_noun kev) +_cj_v1_free_hank(u3_noun kev) { - _cj_hank* han_u = u3to(_cj_hank, u3t(kev)); + _cj_v1_hank* han_u = u3to(_cj_v1_hank, u3t(kev)); if ( u3_none != han_u->hax ) { u3z(han_u->hax); u3j_site_lose(&(han_u->sit_u)); @@ -51,7 +51,7 @@ u3j_v1_reclaim(void) // clear the jet hank cache // - u3h_v1_walk(u3R->jed.han_p, _cj_free_hank); + u3h_v1_walk(u3R->jed.han_p, _cj_v1_free_hank); u3h_v1_free(u3R->jed.han_p); u3R->jed.han_p = u3h_new(); } diff --git a/pkg/noun/v1/nock.c b/pkg/noun/v1/nock.c index ffd390d969..f701e05b22 100644 --- a/pkg/noun/v1/nock.c +++ b/pkg/noun/v1/nock.c @@ -59,3 +59,23 @@ u3n_v1_free() u3h_v1_walk(har_p, _n_feb); u3h_v1_free(har_p); } + +/* u3n_v1_rewrite_compact(): rewrite the bytecode cache for compaction. + * + * NB: u3R->byc.har_p *must* be cleared (currently via u3n_v1_reclaim above), + * since it contains things that look like nouns but aren't. + * Specifically, it contains "cells" where the tail is a + * pointer to a u3a_malloc'ed block that contains loom pointers. + * + * You should be able to walk this with u3h_walk and rewrite the + * pointers, but you need to be careful to handle that u3a_malloc + * pointers can't be turned into a box by stepping back two words. You + * must step back one word to get the padding, step then step back that + * many more words (plus one?). + */ +void +u3n_v1_rewrite_compact() +{ + u3h_v1_rewrite(u3R->byc.har_p); + u3R->byc.har_p = u3a_rewritten(u3R->byc.har_p); +} diff --git a/pkg/noun/v2/allocate.c b/pkg/noun/v2/allocate.c index d30629487a..a6ac5f3604 100644 --- a/pkg/noun/v2/allocate.c +++ b/pkg/noun/v2/allocate.c @@ -67,8 +67,8 @@ u3a_v2_rewrite_compact(void) u3R->bug.mer = u3a_v2_rewritten_noun(u3R->bug.mer); u3R->pro.don = u3a_v2_rewritten_noun(u3R->pro.don); u3R->pro.day = u3a_v2_rewritten_noun(u3R->pro.day); - u3R->pro.trace = u3a_v2_rewritten_noun(u3R->pro.trace); - u3R->cax.har_p = u3a_v2_rewritten(u3R->cax.har_p); + u3R->pro.trace = u3a_rewritten_noun(u3R->pro.trace); + u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p); } void diff --git a/pkg/noun/v2/hashtable.c b/pkg/noun/v2/hashtable.c index 47dadc5311..6593d9a299 100644 --- a/pkg/noun/v2/hashtable.c +++ b/pkg/noun/v2/hashtable.c @@ -11,20 +11,20 @@ #include "retrieve.h" #include "xtract.h" -/* _ch_popcount(): number of bits set in word. A standard intrinsic. -** NB: copy of _ch_popcount in pkg/noun/hashtable.c +/* _ch_v2_popcount(): number of bits set in word. A standard intrinsic. +** NB: copy of _ch_v2_popcount in pkg/noun/hashtable.c */ static c3_w -_ch_popcount(c3_w num_w) +_ch_v2_popcount(c3_w num_w) { return __builtin_popcount(num_w); } -/* _ch_free_buck(): free bucket -** NB: copy of _ch_free_buck in pkg/noun/hashtable.c +/* _ch_v2_free_buck(): free bucket +** NB: copy of _ch_v2_free_buck in pkg/noun/hashtable.c */ static void -_ch_free_buck(u3h_buck* hab_u) +_ch_v2_free_buck(u3h_buck* hab_u) { c3_w i_w; @@ -34,12 +34,12 @@ _ch_free_buck(u3h_buck* hab_u) u3a_wfree(hab_u); } -/* _ch_free_node(): free node. +/* _ch_v2_free_node(): free node. */ static void -_ch_free_node(u3h_node* han_u, c3_w lef_w) +_ch_v2_free_node(u3h_node* han_u, c3_w lef_w) { - c3_w len_w = _ch_popcount(han_u->map_w); + c3_w len_w = _ch_v2_popcount(han_u->map_w); c3_w i_w; lef_w -= 5; @@ -55,9 +55,9 @@ _ch_free_node(u3h_node* han_u, c3_w lef_w) void* hav_v = u3h_v2_slot_to_node(sot_w); if ( 0 == lef_w ) { - _ch_free_buck(hav_v); + _ch_v2_free_buck(hav_v); } else { - _ch_free_node(hav_v, lef_w); + _ch_v2_free_node(hav_v, lef_w); } } } @@ -81,17 +81,17 @@ u3h_v2_free(u3p(u3h_root) har_p) else if ( _(u3h_slot_is_node(sot_w)) ) { u3h_node* han_u = u3h_v2_slot_to_node(sot_w); - _ch_free_node(han_u, 25); + _ch_v2_free_node(han_u, 25); } } u3a_wfree(har_u); } -/* _ch_walk_buck(): walk bucket for gc. -** NB: copy of _ch_walk_buck in pkg/noun/hashtable.c +/* _ch_v2_walk_buck(): walk bucket for gc. +** NB: copy of _ch_v2_walk_buck in pkg/noun/hashtable.c */ static void -_ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v2_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) { c3_w i_w; @@ -100,12 +100,12 @@ _ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) } } -/* _ch_walk_node(): walk node for gc. +/* _ch_v2_walk_node(): walk node for gc. */ static void -_ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v2_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) { - c3_w len_w = _ch_popcount(han_u->map_w); + c3_w len_w = _ch_v2_popcount(han_u->map_w); c3_w i_w; lef_w -= 5; @@ -122,9 +122,9 @@ _ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* void* hav_v = u3h_v2_slot_to_node(sot_w); if ( 0 == lef_w ) { - _ch_walk_buck(hav_v, fun_f, wit); + _ch_v2_walk_buck(hav_v, fun_f, wit); } else { - _ch_walk_node(hav_v, lef_w, fun_f, wit); + _ch_v2_walk_node(hav_v, lef_w, fun_f, wit); } } } @@ -152,15 +152,15 @@ u3h_v2_walk_with(u3p(u3h_root) har_p, else if ( _(u3h_slot_is_node(sot_w)) ) { u3h_node* han_u = u3h_v2_slot_to_node(sot_w); - _ch_walk_node(han_u, 25, fun_f, wit); + _ch_v2_walk_node(han_u, 25, fun_f, wit); } } } -/* _ch_walk_plain(): use plain u3_noun fun_f for each node +/* _ch_v2_walk_plain(): use plain u3_noun fun_f for each node */ static void -_ch_walk_plain(u3_noun kev, void* wit) +_ch_v2_walk_plain(u3_noun kev, void* wit) { void (*fun_f)(u3_noun) = wit; fun_f(kev); @@ -171,13 +171,13 @@ _ch_walk_plain(u3_noun kev, void* wit) void u3h_v2_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun)) { - u3h_v2_walk_with(har_p, _ch_walk_plain, fun_f); + u3h_v2_walk_with(har_p, _ch_v2_walk_plain, fun_f); } -/* _ch_rewrite_buck(): rewrite buck for compaction. +/* _ch_v2_rewrite_buck(): rewrite buck for compaction. */ void -_ch_rewrite_buck(u3h_buck* hab_u) +_ch_v2_rewrite_buck(u3h_buck* hab_u) { if ( c3n == u3a_rewrite_ptr(hab_u) ) return; c3_w i_w; @@ -189,14 +189,14 @@ _ch_rewrite_buck(u3h_buck* hab_u) } } -/* _ch_rewrite_node(): rewrite node for compaction. +/* _ch_v2_rewrite_node(): rewrite node for compaction. */ void -_ch_rewrite_node(u3h_node* han_u, c3_w lef_w) +_ch_v2_rewrite_node(u3h_node* han_u, c3_w lef_w) { if ( c3n == u3a_rewrite_ptr(han_u) ) return; - c3_w len_w = _ch_popcount(han_u->map_w); + c3_w len_w = _ch_v2_popcount(han_u->map_w); c3_w i_w; lef_w -= 5; @@ -212,7 +212,7 @@ _ch_rewrite_node(u3h_node* han_u, c3_w lef_w) } else { void* hav_v = u3h_v1_slot_to_node(sot_w); - u3h_node* nod_u = u3to(u3h_node, u3a_v1_rewritten(u3of(u3h_node,hav_v))); + u3h_node* nod_u = u3to(u3h_node, u3a_rewritten(u3of(u3h_node,hav_v))); if (u3C.migration_state == MIG_REWRITE_COMPRESSED) u3C.vits_w = 1; @@ -223,9 +223,9 @@ _ch_rewrite_node(u3h_node* han_u, c3_w lef_w) u3C.vits_w = 0; if ( 0 == lef_w ) { - _ch_rewrite_buck(hav_v); + _ch_v2_rewrite_buck(hav_v); } else { - _ch_rewrite_node(hav_v, lef_w); + _ch_v2_rewrite_node(hav_v, lef_w); } } } @@ -263,7 +263,7 @@ u3h_v2_rewrite(u3p(u3h_root) har_p) if (u3C.migration_state == MIG_REWRITE_COMPRESSED) u3C.vits_w = 0; - _ch_rewrite_node(han_u, 25); + _ch_v2_rewrite_node(han_u, 25); } } } diff --git a/pkg/noun/v2/jets.c b/pkg/noun/v2/jets.c index 840a8cbfe2..080f6e9660 100644 --- a/pkg/noun/v2/jets.c +++ b/pkg/noun/v2/jets.c @@ -11,24 +11,24 @@ /** Data structures. **/ -/* _cj_hank: cached hook information. -** NB: copy of _cj_hank from pkg/noun/jets.c +/* _cj_v2_hank: cached hook information. +** NB: copy of _cj_v2_hank from pkg/noun/jets.c */ typedef struct { u3_weak hax; // axis of hooked inner core u3j_site sit_u; // call-site data -} _cj_hank; +} _cj_v2_hank; /** Functions. **/ -/* _cj_free_hank(): free an entry from the hank cache. -** NB: copy of _cj_free_hank() from pkg/noun/jets.c +/* _cj_v2_free_hank(): free an entry from the hank cache. +** NB: copy of _cj_v2_free_hank() from pkg/noun/jets.c */ static void -_cj_free_hank(u3_noun kev) +_cj_v2_free_hank(u3_noun kev) { - _cj_hank* han_u = u3to(_cj_hank, u3t(kev)); + _cj_v2_hank* han_u = u3to(_cj_v2_hank, u3t(kev)); if ( u3_none != han_u->hax ) { u3z(han_u->hax); u3j_site_lose(&(han_u->sit_u)); @@ -51,7 +51,7 @@ u3j_v2_reclaim(void) // clear the jet hank cache // - u3h_v2_walk(u3R->jed.han_p, _cj_free_hank); + u3h_v2_walk(u3R->jed.han_p, _cj_v2_free_hank); u3h_v2_free(u3R->jed.han_p); u3R->jed.han_p = u3h_new(); } diff --git a/pkg/noun/v2/manage.c b/pkg/noun/v2/manage.c index 79a694c851..a01a29b46f 100644 --- a/pkg/noun/v2/manage.c +++ b/pkg/noun/v2/manage.c @@ -190,7 +190,7 @@ u3m_v2_migrate() /* only home road migration is supported */ c3_dessert((uintptr_t)u3H == (uintptr_t)u3R); - fprintf(stderr, "loom: pointer compression migration running..."); + fprintf(stderr, "loom: pointer compression migration running...\r\n"); /* packing first simplifies migration logic and minimizes required buffer space */ // XX determine if we need to version this for the v2 migration diff --git a/pkg/noun/v2/nock.c b/pkg/noun/v2/nock.c index e2e2a36651..d476a394ce 100644 --- a/pkg/noun/v2/nock.c +++ b/pkg/noun/v2/nock.c @@ -59,3 +59,23 @@ u3n_v2_free() u3h_v2_walk(har_p, _n_feb); u3h_v2_free(har_p); } + +/* u3n_v2_rewrite_compact(): rewrite the bytecode cache for compaction. + * + * NB: u3R->byc.har_p *must* be cleared (currently via u3n_v2_reclaim above), + * since it contains things that look like nouns but aren't. + * Specifically, it contains "cells" where the tail is a + * pointer to a u3a_malloc'ed block that contains loom pointers. + * + * You should be able to walk this with u3h_walk and rewrite the + * pointers, but you need to be careful to handle that u3a_malloc + * pointers can't be turned into a box by stepping back two words. You + * must step back one word to get the padding, step then step back that + * many more words (plus one?). + */ +void +u3n_v2_rewrite_compact() +{ + u3h_v2_rewrite(u3R->byc.har_p); + u3R->byc.har_p = u3a_rewritten(u3R->byc.har_p); +}