Skip to content

Commit 0ccf7dc

Browse files
author
Elliott Slaughter
committed
---
yaml --- r: 32440 b: refs/heads/dist-snap c: 7823ad8 h: refs/heads/master v: v3
1 parent 2ae91fc commit 0ccf7dc

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 88f5ab31635855595e4053cb64153e6bb7ec622b
10+
refs/heads/dist-snap: 7823ad8586f52bcd6277965277bd15ff15674219
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/libcore/gc.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import stackwalk::Word;
22
import libc::size_t;
33
import send_map::linear::LinearMap;
44

5+
export Word;
6+
export gc;
7+
export cleanup_stack_for_failure;
8+
59
extern mod rustrt {
610
fn rust_annihilate_box(ptr: *Word);
711

@@ -93,15 +97,29 @@ const stack: Memory = 4;
9397

9498
const need_cleanup: Memory = exchange_heap | stack;
9599

96-
unsafe fn walk_gc_roots(mem: Memory, visitor: Visitor) {
100+
unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
97101
let mut last_ret: *Word = ptr::null();
102+
// To avoid collecting memory used by the GC itself, skip stack
103+
// frames until past the root GC stack frame. The root GC stack
104+
// frame is marked by a sentinel, which is a box pointer stored on
105+
// the stack.
106+
let mut reached_sentinel = ptr::is_null(sentinel);
98107
for stackwalk::walk_stack |frame| {
99108
unsafe {
109+
let mut delay_reached_sentinel = reached_sentinel;
100110
if ptr::is_not_null(last_ret) {
101111
let sp = is_safe_point(last_ret);
102112
match sp {
103113
Some(sp_info) => {
104114
for walk_safe_point(frame.fp, sp_info) |root, tydesc| {
115+
// Skip roots until we see the sentinel.
116+
if !reached_sentinel {
117+
if root == sentinel {
118+
delay_reached_sentinel = true;
119+
}
120+
again;
121+
}
122+
105123
// Skip null pointers, which can occur when a
106124
// unique pointer has already been freed.
107125
if ptr::is_null(*root) {
@@ -128,14 +146,15 @@ unsafe fn walk_gc_roots(mem: Memory, visitor: Visitor) {
128146
None => ()
129147
}
130148
}
149+
reached_sentinel = delay_reached_sentinel;
131150
last_ret = *ptr::offset(frame.fp, 1) as *Word;
132151
}
133152
}
134153
}
135154

136155
fn gc() {
137156
unsafe {
138-
for walk_gc_roots(task_local_heap) |_root, _tydesc| {
157+
for walk_gc_roots(task_local_heap, ptr::null()) |_root, _tydesc| {
139158
// FIXME(#2997): Walk roots and mark them.
140159
io::stdout().write([46]); // .
141160
}
@@ -153,8 +172,16 @@ fn RootSet() -> RootSet {
153172
// dead.
154173
fn cleanup_stack_for_failure() {
155174
unsafe {
175+
// Leave a sentinel on the stack to mark the current
176+
// frame. The stack walker will ignore any frames above the
177+
// sentinel, thus avoiding collecting any memory being used by
178+
// the stack walker itself.
179+
let sentinel_box = ~0;
180+
let sentinel: **Word =
181+
unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box));
182+
156183
let mut roots = ~RootSet();
157-
for walk_gc_roots(need_cleanup) |root, tydesc| {
184+
for walk_gc_roots(need_cleanup, sentinel) |root, tydesc| {
158185
// Track roots to avoid double frees.
159186
if option::is_some(roots.find(&*root)) {
160187
again;

branches/dist-snap/src/libcore/rt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use libc::c_void;
88
use libc::size_t;
99
use libc::uintptr_t;
1010

11-
import gc::gc;
12-
import gc::cleanup_stack_for_failure;
11+
import gc::{cleanup_stack_for_failure, gc, Word};
1312

1413
#[allow(non_camel_case_types)]
1514
type rust_task = c_void;

0 commit comments

Comments
 (0)