diff options
-rw-r--r-- | src/library_gc.js | 9 | ||||
-rw-r--r-- | system/include/gc.h | 3 | ||||
-rwxr-xr-x | tests/runner.py | 6 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/library_gc.js b/src/library_gc.js index 0f110f36..3d1a0700 100644 --- a/src/library_gc.js +++ b/src/library_gc.js @@ -113,6 +113,10 @@ if (GC_SUPPORT) { GC.finalizerArgs[ptr] = arg; }, + getHeapSize: function() { + return GC.totalAllocations; + }, + maybeCollect: function() { if (GC.needCollect()) GC.collect(); }, @@ -207,6 +211,11 @@ if (GC_SUPPORT) { GC.registerFinalizer(ptr, func, arg, old_func, old_arg); }, + GC_get_heap_size__deps: ['$GC'], + GC_get_heap_size: function() { + return GC.getHeapSize(); + }, + GC_MAYBE_COLLECT__deps: ['$GC'], GC_MAYBE_COLLECT: function() { GC.maybeCollect(); diff --git a/system/include/gc.h b/system/include/gc.h index 1a236f3d..8c5a8989 100644 --- a/system/include/gc.h +++ b/system/include/gc.h @@ -42,6 +42,9 @@ void GC_FREE(void *ptr); void GC_REGISTER_FINALIZER_NO_ORDER(void *ptr, void (*func)(void *, void *), void *arg, void *(*old_func)(void *, void *), void *old_arg); +/* Gets the bytes allocated and managed by the GC */ +int GC_get_heap_size(); + /* Non-Boehm additions */ /* Call this once per frame or such, it will collect if necessary */ diff --git a/tests/runner.py b/tests/runner.py index 28675e9b..d0e641e6 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7942,8 +7942,12 @@ def process(filename): // This should never trigger since local5 is uncollectable GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void*)5, 0, 0); + printf("heap size = %d\n", GC_get_heap_size()); + local4 = GC_REALLOC(local4, 24); + printf("heap size = %d\n", GC_get_heap_size()); + local6 = GC_MALLOC(12); GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void*)6, 0, 0); // This should be the same as a free @@ -7984,6 +7988,8 @@ finalizing2 2 (global == 0) finalizing2 3 (global == 0) * finalizing 0 (global == 1) +heap size = 72 +heap size = 84 finalizing 6 (global == 0) object scan test test finalizing 4 (global == 0) |