| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -946,7 +946,9 @@ static bool mi_arena_visit_abandoned_blocks(mi_subproc_t* subproc, int heap_tag, | |||
| 946 | 946 | _mi_arena_field_cursor_init(NULL, subproc, ¤t); | |
| 947 | 947 | mi_segment_t* segment; | |
| 948 | 948 | while ((segment = _mi_arena_segment_clear_abandoned_next(¤t, true /* visit all */)) != NULL) { | |
| 949 | - if (!_mi_segment_visit_blocks(segment, heap_tag, visit_blocks, visitor, arg)) return false; | ||
| 949 | + bool ok = _mi_segment_visit_blocks(segment, heap_tag, visit_blocks, visitor, arg); | ||
| 950 | + _mi_arena_segment_mark_abandoned(segment); | ||
| 951 | + if (!ok) return false; | ||
| 950 | 952 | } | |
| 951 | 953 | return true; | |
| 952 | 954 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,10 @@ static int ITER = 50; // N full iterations destructing and re-creating a | |||
| 39 | 39 | ||
| 40 | 40 | #define STRESS // undefine for leak test | |
| 41 | 41 | ||
| 42 | + #ifndef NDEBUG | ||
| 43 | + #define HEAP_WALK // walk the heap objects? | ||
| 44 | + #endif | ||
| 45 | + | ||
| 42 | 46 | static bool allow_large_objects = true; // allow very large objects? (set to `true` if SCALE>100) | |
| 43 | 47 | static size_t use_one_size = 0; // use single object size of `N * sizeof(uintptr_t)`? | |
| 44 | 48 | ||
@@ -129,7 +133,7 @@ static void free_items(void* p) { | |||
| 129 | 133 | custom_free(p); | |
| 130 | 134 | } | |
| 131 | 135 | ||
| 132 | - /* | ||
| 136 | + #ifdef HEAP_WALK | ||
| 133 | 137 | static bool visit_blocks(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg) { | |
| 134 | 138 | (void)(heap); (void)(area); | |
| 135 | 139 | size_t* total = (size_t*)arg; | |
@@ -138,7 +142,7 @@ static bool visit_blocks(const mi_heap_t* heap, const mi_heap_area_t* area, void | |||
| 138 | 142 | } | |
| 139 | 143 | return true; | |
| 140 | 144 | } | |
| 141 | - */ | ||
| 145 | + #endif | ||
| 142 | 146 | ||
| 143 | 147 | static void stress(intptr_t tid) { | |
| 144 | 148 | //bench_start_thread(); | |
@@ -183,9 +187,12 @@ static void stress(intptr_t tid) { | |||
| 183 | 187 | data[data_idx] = q; | |
| 184 | 188 | } | |
| 185 | 189 | } | |
| 190 | + | ||
| 191 | + #ifdef HEAP_WALK | ||
| 186 | 192 | // walk the heap | |
| 187 | - // size_t total = 0; | ||
| 188 | - // mi_heap_visit_blocks(mi_heap_get_default(), true, visit_blocks, &total); | ||
| 193 | + size_t total = 0; | ||
| 194 | + mi_heap_visit_blocks(mi_heap_get_default(), true, visit_blocks, &total); | ||
| 195 | + #endif | ||
| 189 | 196 | ||
| 190 | 197 | // free everything that is left | |
| 191 | 198 | for (size_t i = 0; i < retain_top; i++) { | |
@@ -205,6 +212,10 @@ static void test_stress(void) { | |||
| 205 | 212 | uintptr_t r = rand(); | |
| 206 | 213 | for (int n = 0; n < ITER; n++) { | |
| 207 | 214 | run_os_threads(THREADS, &stress); | |
| 215 | + #ifdef HEAP_WALK | ||
| 216 | + size_t total = 0; | ||
| 217 | + mi_abandoned_visit_blocks(mi_subproc_main(), -1, true, visit_blocks, &total); | ||
| 218 | + #endif | ||
| 208 | 219 | for (int i = 0; i < TRANSFERS; i++) { | |
| 209 | 220 | if (chance(50, &r) || n + 1 == ITER) { // free all on last run, otherwise free half of the transfers | |
| 210 | 221 | void* p = atomic_exchange_ptr(&transfer[i], NULL); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments