summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Knegjens <rob@knegjens.net>2022-04-13 09:52:22 -0700
committerDamien George <damien@micropython.org>2022-07-23 00:43:08 +1000
commitd2e4cf00ccec432ccd38adea78099887ac578882 (patch)
tree6b8990c78be88c44da8dd2bd9808b01fd011af41
parent4a48531803843f53caf2b535da7ff3bb2a802106 (diff)
unix: Enable MICROPY_GC_SPLIT_HEAP on coverage build.
With a new option to evenly split the GC heap over multiple areas. This adds code coverage for gc_add() and code associated with MICROPY_GC_SPLIT_HEAP.
-rw-r--r--ports/unix/main.c20
-rw-r--r--ports/unix/mpconfigport.h4
-rw-r--r--ports/unix/variants/coverage/mpconfigvariant.h2
3 files changed, 26 insertions, 0 deletions
diff --git a/ports/unix/main.c b/ports/unix/main.c
index e7048dd71..0b27a1f5f 100644
--- a/ports/unix/main.c
+++ b/ports/unix/main.c
@@ -477,8 +477,22 @@ MP_NOINLINE int main_(int argc, char **argv) {
pre_process_options(argc, argv);
#if MICROPY_ENABLE_GC
+ #if !MICROPY_GC_SPLIT_HEAP
char *heap = malloc(heap_size);
gc_init(heap, heap + heap_size);
+ #else
+ assert(MICROPY_GC_SPLIT_HEAP_N_HEAPS > 0);
+ char *heaps[MICROPY_GC_SPLIT_HEAP_N_HEAPS];
+ long multi_heap_size = heap_size / MICROPY_GC_SPLIT_HEAP_N_HEAPS;
+ for (size_t i = 0; i < MICROPY_GC_SPLIT_HEAP_N_HEAPS; i++) {
+ heaps[i] = malloc(multi_heap_size);
+ if (i == 0) {
+ gc_init(heaps[i], heaps[i] + multi_heap_size);
+ } else {
+ gc_add(heaps[i], heaps[i] + multi_heap_size);
+ }
+ }
+ #endif
#endif
#if MICROPY_ENABLE_PYSTACK
@@ -729,7 +743,13 @@ MP_NOINLINE int main_(int argc, char **argv) {
#if MICROPY_ENABLE_GC && !defined(NDEBUG)
// We don't really need to free memory since we are about to exit the
// process, but doing so helps to find memory leaks.
+ #if !MICROPY_GC_SPLIT_HEAP
free(heap);
+ #else
+ for (size_t i = 0; i < MICROPY_GC_SPLIT_HEAP_N_HEAPS; i++) {
+ free(heaps[i]);
+ }
+ #endif
#endif
// printf("total bytes = %d\n", m_get_total_bytes_allocated());
diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h
index 312c0cce8..4252a406c 100644
--- a/ports/unix/mpconfigport.h
+++ b/ports/unix/mpconfigport.h
@@ -120,6 +120,10 @@
#define MICROPY_EMIT_ARM (1)
#endif
#define MICROPY_ENABLE_GC (1)
+// Number of heaps to assign if MICROPY_GC_SPLIT_HEAP=1
+#ifndef MICROPY_GC_SPLIT_HEAP_N_HEAPS
+#define MICROPY_GC_SPLIT_HEAP_N_HEAPS (1)
+#endif
#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1)
#define MICROPY_MEM_STATS (1)
#define MICROPY_DEBUG_PRINTERS (1)
diff --git a/ports/unix/variants/coverage/mpconfigvariant.h b/ports/unix/variants/coverage/mpconfigvariant.h
index 30e3a4e5d..fb70d791a 100644
--- a/ports/unix/variants/coverage/mpconfigvariant.h
+++ b/ports/unix/variants/coverage/mpconfigvariant.h
@@ -32,6 +32,8 @@
// Enable additional features.
#define MICROPY_DEBUG_PARSE_RULE_NAME (1)
+#define MICROPY_GC_SPLIT_HEAP (1)
+#define MICROPY_GC_SPLIT_HEAP_N_HEAPS (4)
#define MICROPY_TRACKED_ALLOC (1)
#define MICROPY_FLOAT_HIGH_QUALITY_HASH (1)
#define MICROPY_REPL_EMACS_WORDS_MOVE (1)