| 1 |
/* |
| 2 |
* Test at the boundary between small and large objects. |
| 3 |
* Inspired by a test case from Zoltan Varga. |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
#include "gc.h" |
| 10 |
|
| 11 |
#define CHECK_OUT_OF_MEMORY(p) \ |
| 12 |
do { \ |
| 13 |
if (NULL == (p)) { \ |
| 14 |
fprintf(stderr, "Out of memory\n"); \ |
| 15 |
exit(69); \ |
| 16 |
} \ |
| 17 |
} while (0) |
| 18 |
|
| 19 |
int main (void) |
| 20 |
{ |
| 21 |
int i; |
| 22 |
|
| 23 |
GC_set_all_interior_pointers(0); |
| 24 |
GC_INIT(); |
| 25 |
if (GC_get_find_leak()) |
| 26 |
printf("This test program is not designed for leak detection mode\n"); |
| 27 |
|
| 28 |
for (i = 0; i < 20000; ++i) { |
| 29 |
CHECK_OUT_OF_MEMORY(GC_malloc_atomic(4096)); |
| 30 |
CHECK_OUT_OF_MEMORY(GC_malloc(4096)); |
| 31 |
} |
| 32 |
|
| 33 |
/* Test delayed start of marker threads, if they are enabled. */ |
| 34 |
GC_start_mark_threads(); |
| 35 |
|
| 36 |
for (i = 0; i < 20000; ++i) { |
| 37 |
CHECK_OUT_OF_MEMORY(GC_malloc_atomic(2048)); |
| 38 |
CHECK_OUT_OF_MEMORY(GC_malloc(2048)); |
| 39 |
} |
| 40 |
|
| 41 |
printf("Final heap size is %lu\n", (unsigned long)GC_get_heap_size()); |
| 42 |
return 0; |
| 43 |
} |