diff options
| author | Christian Walther <cwalther@gmx.ch> | 2020-10-11 14:59:33 +0200 |
|---|---|---|
| committer | Christian Walther <cwalther@gmx.ch> | 2020-11-28 17:50:23 +0100 |
| commit | c7404a3ff89c738c002ec63448a58d56330dfcc3 (patch) | |
| tree | b7eabbfe9dd8cdd9f6029252dc9c341e1b3d1ac1 /supervisor/shared/display.c | |
| parent | bd87201c4f5a326e0328648700e1929d876b8c36 (diff) | |
Add movable allocation system.
This allows calls to `allocate_memory()` while the VM is running, it will then allocate from the GC heap (unless there is a suitable hole among the supervisor allocations), and when the VM exits and the GC heap is freed, the allocation will be moved to the bottom of the former GC heap and transformed into a proper supervisor allocation. Existing movable allocations will also be moved to defragment the supervisor heap and ensure that the next VM run gets as much memory as possible for the GC heap.
By itself this breaks terminalio because it violates the assumption that supervisor_display_move_memory() still has access to an undisturbed heap to copy the tilegrid from. It will work in many cases, but if you're unlucky you will get garbled terminal contents after exiting from the vm run that created the display. This will be fixed in the following commit, which is separate to simplify review.
Diffstat (limited to 'supervisor/shared/display.c')
| -rw-r--r-- | supervisor/shared/display.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index a9ae25884..de45e2672 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -82,7 +82,7 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { uint16_t total_tiles = width_in_tiles * height_in_tiles; // First try to allocate outside the heap. This will fail when the VM is running. - tilegrid_tiles = allocate_memory(align32_size(total_tiles), false); + tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, false); uint8_t* tiles; if (tilegrid_tiles == NULL) { tiles = m_malloc(total_tiles, true); @@ -133,7 +133,7 @@ void supervisor_display_move_memory(void) { grid->tiles == MP_STATE_VM(terminal_tilegrid_tiles)) { uint16_t total_tiles = grid->width_in_tiles * grid->height_in_tiles; - tilegrid_tiles = allocate_memory(align32_size(total_tiles), false); + tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, false); if (tilegrid_tiles != NULL) { memcpy(tilegrid_tiles->ptr, grid->tiles, total_tiles); grid->tiles = (uint8_t*) tilegrid_tiles->ptr; |
