|
33 | 33 | #include "supervisor/shared/display.h" |
34 | 34 |
|
35 | 35 | enum { |
36 | | - CIRCUITPY_SUPERVISOR_ALLOC_COUNT = |
| 36 | + CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT = |
37 | 37 | // stack + heap |
38 | 38 | 2 |
39 | 39 | #ifdef EXTERNAL_FLASH_DEVICES |
|
42 | 42 | #if CIRCUITPY_USB_MIDI |
43 | 43 | + 1 |
44 | 44 | #endif |
| 45 | + , |
| 46 | + CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT = |
| 47 | + 0 |
45 | 48 | #if CIRCUITPY_DISPLAYIO |
46 | 49 | #if CIRCUITPY_TERMINALIO |
47 | 50 | + 1 |
|
57 | 60 | #endif |
58 | 61 | ) |
59 | 62 | #endif |
| 63 | + , |
| 64 | + CIRCUITPY_SUPERVISOR_ALLOC_COUNT = CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT + CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT |
60 | 65 | }; |
61 | 66 |
|
62 | 67 | // The lowest two bits of a valid length are always zero, so we can use them to mark an allocation |
@@ -147,6 +152,9 @@ static supervisor_allocation_node* find_hole(supervisor_allocation_node* node, s |
147 | 152 | } |
148 | 153 |
|
149 | 154 | static supervisor_allocation_node* allocate_memory_node(uint32_t length, bool high, bool movable) { |
| 155 | + if (CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT == 0) { |
| 156 | + assert(!movable); |
| 157 | + } |
150 | 158 | // supervisor_move_memory() currently does not support movable allocations on the high side, it |
151 | 159 | // must be extended first if this is ever needed. |
152 | 160 | assert(!(high && movable)); |
@@ -223,6 +231,11 @@ size_t get_allocation_length(supervisor_allocation* allocation) { |
223 | 231 | } |
224 | 232 |
|
225 | 233 | void supervisor_move_memory(void) { |
| 234 | + // This whole function is not needed when there are no movable allocations, let it be optimized |
| 235 | + // out. |
| 236 | + if (CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT == 0) { |
| 237 | + return; |
| 238 | + } |
226 | 239 | // This must be called exactly after freeing the heap, so that the embedded allocations, if any, |
227 | 240 | // are now in the free region. |
228 | 241 | assert(MP_STATE_VM(first_embedded_allocation) == NULL || (low_head < MP_STATE_VM(first_embedded_allocation) && MP_STATE_VM(first_embedded_allocation) < high_head)); |
|
0 commit comments