Skip to content

Commit 19325df

Browse files
author
Elliott Slaughter
committed
---
yaml --- r: 32446 b: refs/heads/dist-snap c: 244b954 h: refs/heads/master v: v3
1 parent 55cb551 commit 19325df

File tree

3 files changed

+40
-47
lines changed

3 files changed

+40
-47
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: d22b7ca39a4c9561e366faebf36c48daeb5576dc
10+
refs/heads/dist-snap: 244b95490b9f0ca5c7ab38455153b421b0b51818
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ extern mod rustrt {
5454
fn rust_get_stack_segment() -> *StackSegment;
5555
}
5656

57-
// Is fp contained in segment?
58-
unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
59-
let begin: Word = unsafe::reinterpret_cast(&segment);
60-
let end: Word = unsafe::reinterpret_cast(&(*segment).end);
61-
let frame: Word = unsafe::reinterpret_cast(&fp);
57+
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
58+
return unsafe::reinterpret_cast(&ptr::offset(ptr, count));
59+
}
6260

63-
return begin <= frame && frame <= end;
61+
unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
62+
let align = sys::min_align_of::<*T>();
63+
let ptr: uint = unsafe::reinterpret_cast(&ptr);
64+
let ptr = (ptr + (align - 1)) & -align;
65+
return unsafe::reinterpret_cast(&ptr);
6466
}
6567

6668
type SafePoint = { sp_meta: *Word, fn_meta: *Word };
@@ -69,59 +71,41 @@ type SafePoint = { sp_meta: *Word, fn_meta: *Word };
6971
// any.
7072
unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
7173
let module_meta = rustrt::rust_gc_metadata();
72-
let num_safe_points_ptr: *u32 = unsafe::reinterpret_cast(&module_meta);
73-
let num_safe_points = *num_safe_points_ptr as Word;
74-
let safe_points: *Word =
75-
ptr::offset(unsafe::reinterpret_cast(&module_meta), 1);
74+
let num_safe_points = *module_meta;
75+
let safe_points: *Word = bump(module_meta, 1);
7676

7777
if ptr::is_null(pc) {
7878
return None;
7979
}
8080

8181
// FIXME (#2997): Use binary rather than linear search.
82-
let mut sp = 0 as Word;
83-
while sp < num_safe_points {
84-
let sp_loc = *ptr::offset(safe_points, sp*3) as *Word;
82+
let mut spi = 0;
83+
while spi < num_safe_points {
84+
let sp: **Word = bump(safe_points, spi*3);
85+
let sp_loc = *sp;
8586
if sp_loc == pc {
86-
return Some(
87-
{sp_meta: *ptr::offset(safe_points, sp*3 + 1) as *Word,
88-
fn_meta: *ptr::offset(safe_points, sp*3 + 2) as *Word});
87+
return Some({sp_meta: *bump(sp, 1), fn_meta: *bump(sp, 2)});
8988
}
90-
sp += 1;
89+
spi += 1;
9190
}
9291
return None;
9392
}
9493

9594
type Visitor = fn(root: **Word, tydesc: *Word) -> bool;
9695

97-
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
98-
return unsafe::reinterpret_cast(&ptr::offset(ptr, count));
99-
}
100-
101-
unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
102-
let align = sys::min_align_of::<*T>();
103-
let ptr: uint = unsafe::reinterpret_cast(&ptr);
104-
let ptr = (ptr + (align - 1)) & -align;
105-
return unsafe::reinterpret_cast(&ptr);
106-
}
107-
10896
// Walks the list of roots for the given safe point, and calls visitor
10997
// on each root.
11098
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
11199
let fp_bytes: *u8 = unsafe::reinterpret_cast(&fp);
112-
let sp_meta_u32s: *u32 = unsafe::reinterpret_cast(&sp.sp_meta);
100+
let sp_meta: *u32 = unsafe::reinterpret_cast(&sp.sp_meta);
113101

114-
let num_stack_roots = *sp_meta_u32s as uint;
115-
let num_reg_roots = *ptr::offset(sp_meta_u32s, 1) as uint;
102+
let num_stack_roots = *sp_meta as uint;
103+
let num_reg_roots = *ptr::offset(sp_meta, 1) as uint;
116104

117-
let stack_roots: *u32 =
118-
unsafe::reinterpret_cast(&ptr::offset(sp_meta_u32s, 2));
119-
let reg_roots: *u8 =
120-
unsafe::reinterpret_cast(&ptr::offset(stack_roots, num_stack_roots));
121-
let addrspaces: *Word =
122-
unsafe::reinterpret_cast(&ptr::offset(reg_roots, num_reg_roots));
123-
let tydescs: ***Word =
124-
unsafe::reinterpret_cast(&ptr::offset(addrspaces, num_stack_roots));
105+
let stack_roots: *u32 = bump(sp_meta, 2);
106+
let reg_roots: *u8 = bump(stack_roots, num_stack_roots);
107+
let addrspaces: *Word = align_to_pointer(bump(reg_roots, num_reg_roots));
108+
let tydescs: ***Word = bump(addrspaces, num_stack_roots);
125109

126110
// Stack roots
127111
let mut sri = 0;
@@ -152,13 +136,14 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
152136
}
153137
}
154138

155-
type Memory = uint;
156-
157-
const task_local_heap: Memory = 1;
158-
const exchange_heap: Memory = 2;
159-
const stack: Memory = 4;
139+
// Is fp contained in segment?
140+
unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
141+
let begin: Word = unsafe::reinterpret_cast(&segment);
142+
let end: Word = unsafe::reinterpret_cast(&(*segment).end);
143+
let frame: Word = unsafe::reinterpret_cast(&fp);
160144

161-
const need_cleanup: Memory = exchange_heap | stack;
145+
return begin <= frame && frame <= end;
146+
}
162147

163148
// Find and return the segment containing the given frame pointer. At
164149
// stack segment boundaries, returns true for boundary, so that the
@@ -191,6 +176,14 @@ unsafe fn find_segment_for_frame(fp: *Word, segment: *StackSegment)
191176
return {segment: segment, boundary: false};
192177
}
193178

179+
type Memory = uint;
180+
181+
const task_local_heap: Memory = 1;
182+
const exchange_heap: Memory = 2;
183+
const stack: Memory = 4;
184+
185+
const need_cleanup: Memory = exchange_heap | stack;
186+
194187
// Walks stack, searching for roots of the requested type, and passes
195188
// each root to the visitor.
196189
unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {

branches/dist-snap/src/rt/rust_gc_metadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ update_gc_metadata(const void* map) {
5454
if (!global_safe_points) return;
5555

5656
uintptr_t *next = global_safe_points;
57-
*(uint32_t *)next = safe_points.size();
57+
*next = safe_points.size();
5858
next++;
5959
for (uint32_t i = 0; i < safe_points.size(); i++) {
6060
next[0] = safe_points[i].safe_point_loc;

0 commit comments

Comments
 (0)