esp32/main: Store native code as linked list instead of list on GC heap. #15589
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Finalisers that run during
gc_sweep_all()
may run native code, for example if an open file is closed and the underlying block device is implemented in native code, then the filesystem driver (eg FAT) may call into the native code.Therefore, native code must be freed after the call to
gc_sweep_all()
. That can only be achieved if the GC heap is not used to store the list of allocated native code blocks. Instead, this commit makes the native code blocks a linked list.Testing
Tested on an ESP32C3, running the native tests as per #15551:
All the tests pass.
Note: requires #15573, #15575.
Trade-offs and Alternatives
This approach uses 4 bytes extra iRAM per native function, but keeps the code simple and understandable. An alternative would be to still use the GC heap to store the list of native memory blocks, and make
gc_sweep_all()
only call the finalisers, not actually reclaim/clear memory. That's a complex change to make though.