From cb5362334134f1d0d8b2c5557c49ee6534526474 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Thu, 6 Sep 2012 21:22:50 -0700 Subject: [PATCH] gc: Add early abort when GC is disabled. --- src/libcore/gc.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 2c68607c6d488..d99fc631bef60 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -65,6 +65,11 @@ unsafe fn align_to_pointer(ptr: *T) -> *T { return unsafe::reinterpret_cast(&ptr); } +unsafe fn get_safe_point_count() -> uint { + let module_meta = rustrt::rust_gc_metadata(); + return *module_meta; +} + type SafePoint = { sp_meta: *Word, fn_meta: *Word }; // Returns the safe point metadata for the given program counter, if @@ -260,6 +265,11 @@ unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) { fn gc() { unsafe { + // Abort when GC is disabled. + if get_safe_point_count() == 0 { + return; + } + for walk_gc_roots(task_local_heap, ptr::null()) |_root, _tydesc| { // FIXME(#2997): Walk roots and mark them. io::stdout().write([46]); // . @@ -288,6 +298,11 @@ fn expect_sentinel() -> bool { false } // dead. fn cleanup_stack_for_failure() { unsafe { + // Abort when GC is disabled. + if get_safe_point_count() == 0 { + return; + } + // Leave a sentinel on the stack to mark the current frame. The // stack walker will ignore any frames above the sentinel, thus // avoiding collecting any memory being used by the stack walker