Skip to content

Commit cb53623

Browse files
author
Elliott Slaughter
committed
gc: Add early abort when GC is disabled.
1 parent 244b954 commit cb53623

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libcore/gc.rs

+15
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
6565
return unsafe::reinterpret_cast(&ptr);
6666
}
6767

68+
unsafe fn get_safe_point_count() -> uint {
69+
let module_meta = rustrt::rust_gc_metadata();
70+
return *module_meta;
71+
}
72+
6873
type SafePoint = { sp_meta: *Word, fn_meta: *Word };
6974

7075
// 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) {
260265

261266
fn gc() {
262267
unsafe {
268+
// Abort when GC is disabled.
269+
if get_safe_point_count() == 0 {
270+
return;
271+
}
272+
263273
for walk_gc_roots(task_local_heap, ptr::null()) |_root, _tydesc| {
264274
// FIXME(#2997): Walk roots and mark them.
265275
io::stdout().write([46]); // .
@@ -288,6 +298,11 @@ fn expect_sentinel() -> bool { false }
288298
// dead.
289299
fn cleanup_stack_for_failure() {
290300
unsafe {
301+
// Abort when GC is disabled.
302+
if get_safe_point_count() == 0 {
303+
return;
304+
}
305+
291306
// Leave a sentinel on the stack to mark the current frame. The
292307
// stack walker will ignore any frames above the sentinel, thus
293308
// avoiding collecting any memory being used by the stack walker

0 commit comments

Comments
 (0)