From 5a8e6c4183a30f3b10de22fa5ba80950dfb2adea Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Mon, 7 Dec 2009 15:25:32 +0100 Subject: Fit all heap data into the 32-bit address range This is the first step in the implementation of the half-word emulator, a 64-bit emulator where all pointers to heap data will be stored in 32-bit words. Code specific for this emulator variant is conditionally compiled when the HALFWORD_HEAP define has a non-zero value. First force all pointers to heap data to fall into a single 32-bit range, but still store them in 64-bit words. Temporary term data stored on C stack is moved into scheduler specific storage (allocated as heaps) and macros are added to make this happen only in emulators where this is needed. For a vanilla VM the temporary terms are still stored on the C stack. --- erts/emulator/beam/erl_node_tables.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'erts/emulator/beam/erl_node_tables.c') diff --git a/erts/emulator/beam/erl_node_tables.c b/erts/emulator/beam/erl_node_tables.c index 42b28d987c..f3f10201b5 100644 --- a/erts/emulator/beam/erl_node_tables.c +++ b/erts/emulator/beam/erl_node_tables.c @@ -1109,9 +1109,10 @@ insert_offheap(ErlOffHeap *oh, int type, Eterm id) break; } if (insert_bin) { - Uint id_heap[BIG_UINT_HEAP_SIZE]; + DeclareTmpHeapNoproc(id_heap,BIG_UINT_HEAP_SIZE); Uint *hp = &id_heap[0]; InsertedBin *nib; + UseTmpHeapNoproc(BIG_UINT_HEAP_SIZE); a.id = erts_bld_uint(&hp, NULL, (Uint) pb->val); erts_match_prog_foreach_offheap(pb->val, insert_offheap2, @@ -1120,6 +1121,7 @@ insert_offheap(ErlOffHeap *oh, int type, Eterm id) nib->bin_val = pb->val; nib->next = inserted_bins; inserted_bins = nib; + UnUseTmpHeapNoproc(BIG_UINT_HEAP_SIZE); } } } @@ -1190,12 +1192,15 @@ static void insert_bif_timer(Eterm receiver, Eterm msg, ErlHeapFragment *bp, void *arg) { if (bp) { - Eterm heap[3]; + DeclareTmpHeapNoproc(heap,3); + + UseTmpHeapNoproc(3); insert_offheap(&bp->off_heap, TIMER_REF, (is_internal_pid(receiver) ? receiver : TUPLE2(&heap[0], AM_process, receiver))); + UnUseTmpHeapNoproc(3); } } @@ -1230,7 +1235,7 @@ setup_reference_table(void) DistEntry *dep; HashInfo hi; int i; - Eterm heap[3]; + DeclareTmpHeapNoproc(heap,3); inserted_bins = NULL; @@ -1251,6 +1256,7 @@ setup_reference_table(void) /* Go through the hole system, and build a table of all references to ErlNode and DistEntry structures */ + UseTmpHeapNoproc(3); insert_node(erts_this_node, SYSTEM_REF, TUPLE2(&heap[0], AM_system, am_undefined)); @@ -1261,6 +1267,7 @@ setup_reference_table(void) HEAP_REF, TUPLE2(&heap[0], AM_processes, am_undefined)); #endif + UnUseTmpHeapNoproc(3); /* Insert all processes */ for (i = 0; i < erts_max_processes; i++) -- cgit v1.2.3 From fb94cd974dc03baf149264ca4f4d50c6d1f80f21 Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Wed, 20 Jan 2010 16:26:14 +0100 Subject: Store pointers to heap data in 32-bit words Store Erlang terms in 32-bit entities on the heap, expanding the pointers to 64-bit when needed. This works because all terms are stored on addresses in the 32-bit address range (the 32 most significant bits of pointers to term data are always 0). Introduce a new datatype called UWord (along with its companion SWord), which is an integer having the exact same size as the machine word (a void *), but might be larger than Eterm/Uint. Store code as machine words, as the instructions are pointers to executable code which might reside outside the 32-bit address range. Continuation pointers are stored on the 32-bit stack and hence must point to addresses in the low range, which means that loaded beam code much be placed in the low 32-bit address range (but, as said earlier, the instructions themselves are full words). No Erlang term data can be stored on C stacks (enforced by an earlier commit). This version gives a prompt, but test cases still fail (and dump core). The loader (and emulator loop) has instruction packing disabled. The main issues has been in rewriting loader and actual virtual machine. Subsystems (like distribution) does not work yet. --- erts/emulator/beam/erl_node_tables.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'erts/emulator/beam/erl_node_tables.c') diff --git a/erts/emulator/beam/erl_node_tables.c b/erts/emulator/beam/erl_node_tables.c index f3f10201b5..6960844e99 100644 --- a/erts/emulator/beam/erl_node_tables.c +++ b/erts/emulator/beam/erl_node_tables.c @@ -1109,11 +1109,21 @@ insert_offheap(ErlOffHeap *oh, int type, Eterm id) break; } if (insert_bin) { +#if HALFWORD_HEAP + UWord val = (UWord) pb->val; + DeclareTmpHeapNoproc(id_heap,BIG_UINT_HEAP_SIZE*2); /* extra place allocated */ +#else DeclareTmpHeapNoproc(id_heap,BIG_UINT_HEAP_SIZE); +#endif Uint *hp = &id_heap[0]; InsertedBin *nib; +#if HALFWORD_HEAP + UseTmpHeapNoproc(BIG_UWORD_HEAP_SIZE(val)); + a.id = erts_bld_uword(&hp, NULL, (UWord) val); +#else UseTmpHeapNoproc(BIG_UINT_HEAP_SIZE); a.id = erts_bld_uint(&hp, NULL, (Uint) pb->val); +#endif erts_match_prog_foreach_offheap(pb->val, insert_offheap2, (void *) &a); @@ -1121,7 +1131,11 @@ insert_offheap(ErlOffHeap *oh, int type, Eterm id) nib->bin_val = pb->val; nib->next = inserted_bins; inserted_bins = nib; +#if HALFWORD_HEAP + UnUseTmpHeapNoproc(BIG_UINT_HEAP_SIZE*2); +#else UnUseTmpHeapNoproc(BIG_UINT_HEAP_SIZE); +#endif } } } -- cgit v1.2.3 From ac0b3f0a64705717d21e4a3d84d91d9c44f3baf7 Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Thu, 11 Feb 2010 11:00:47 +0100 Subject: Correct the VM to work for more test suites The following test suites now work: send_term_SUITE trace_nif_SUITE binary_SUITE match_spec_SUITE node_container_SUITE beam_literals_SUITE Also add a testcases for system_info({wordsize,internal|external}). --- erts/emulator/beam/erl_node_tables.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'erts/emulator/beam/erl_node_tables.c') diff --git a/erts/emulator/beam/erl_node_tables.c b/erts/emulator/beam/erl_node_tables.c index 6960844e99..de4c4e353e 100644 --- a/erts/emulator/beam/erl_node_tables.c +++ b/erts/emulator/beam/erl_node_tables.c @@ -1118,7 +1118,9 @@ insert_offheap(ErlOffHeap *oh, int type, Eterm id) Uint *hp = &id_heap[0]; InsertedBin *nib; #if HALFWORD_HEAP - UseTmpHeapNoproc(BIG_UWORD_HEAP_SIZE(val)); + int actual_need = BIG_UWORD_HEAP_SIZE(val); + ASSERT(actual_need <= (BIG_UINT_HEAP_SIZE*2)); + UseTmpHeapNoproc(actual_need); a.id = erts_bld_uword(&hp, NULL, (UWord) val); #else UseTmpHeapNoproc(BIG_UINT_HEAP_SIZE); @@ -1132,7 +1134,7 @@ insert_offheap(ErlOffHeap *oh, int type, Eterm id) nib->next = inserted_bins; inserted_bins = nib; #if HALFWORD_HEAP - UnUseTmpHeapNoproc(BIG_UINT_HEAP_SIZE*2); + UnUseTmpHeapNoproc(actual_need); #else UnUseTmpHeapNoproc(BIG_UINT_HEAP_SIZE); #endif -- cgit v1.2.3