Skip to content

Commit 2df6d4c

Browse files
committed
---
yaml --- r: 138458 b: refs/heads/try2 c: c316189 h: refs/heads/master v: v3
1 parent 8abab51 commit 2df6d4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1374
-1140
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: dab6a852303f68c2ed6c17abaca1d0728d9cf618
8+
refs/heads/try2: c316189d155e233ea04241116b11956626c8e7a3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/compiletest/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum mode {
2121
mode_debug_info,
2222
}
2323

24-
pub type config = {
24+
pub struct config {
2525
// The library paths required for running the compiler
2626
compile_lib_path: ~str,
2727

@@ -68,4 +68,4 @@ pub type config = {
6868
// Explain what's going on
6969
verbose: bool
7070

71-
};
71+
}

branches/try2/src/compiletest/compiletest.rc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#[crate_type = "bin"];
1212

1313
#[no_core];
14-
#[legacy_records];
1514

1615
#[allow(vecs_implicitly_copyable)];
1716
#[allow(non_camel_case_types)];
@@ -77,26 +76,28 @@ pub fn parse_config(args: ~[~str]) -> config {
7776
Path(getopts::opt_str(m, nm))
7877
}
7978

80-
return {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
81-
run_lib_path: getopts::opt_str(matches, ~"run-lib-path"),
82-
rustc_path: opt_path(matches, ~"rustc-path"),
83-
src_base: opt_path(matches, ~"src-base"),
84-
build_base: opt_path(matches, ~"build-base"),
85-
aux_base: opt_path(matches, ~"aux-base"),
86-
stage_id: getopts::opt_str(matches, ~"stage-id"),
87-
mode: str_mode(getopts::opt_str(matches, ~"mode")),
88-
run_ignored: getopts::opt_present(matches, ~"ignored"),
89-
filter:
79+
config {
80+
compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
81+
run_lib_path: getopts::opt_str(matches, ~"run-lib-path"),
82+
rustc_path: opt_path(matches, ~"rustc-path"),
83+
src_base: opt_path(matches, ~"src-base"),
84+
build_base: opt_path(matches, ~"build-base"),
85+
aux_base: opt_path(matches, ~"aux-base"),
86+
stage_id: getopts::opt_str(matches, ~"stage-id"),
87+
mode: str_mode(getopts::opt_str(matches, ~"mode")),
88+
run_ignored: getopts::opt_present(matches, ~"ignored"),
89+
filter:
9090
if vec::len(matches.free) > 0u {
9191
option::Some(matches.free[0])
9292
} else { option::None },
93-
logfile: option::map(&getopts::opt_maybe_str(matches,
93+
logfile: option::map(&getopts::opt_maybe_str(matches,
9494
~"logfile"),
95-
|s| Path(*s)),
96-
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
97-
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
98-
jit: getopts::opt_present(matches, ~"jit"),
99-
verbose: getopts::opt_present(matches, ~"verbose")};
95+
|s| Path(*s)),
96+
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
97+
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
98+
jit: getopts::opt_present(matches, ~"jit"),
99+
verbose: getopts::opt_present(matches, ~"verbose")
100+
}
100101
}
101102

102103
pub fn log_config(config: config) {

branches/try2/src/libcore/cleanup.rs

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,45 +111,102 @@ struct Task {
111111
* This runs at task death to free all boxes.
112112
*/
113113

114+
struct AnnihilateStats {
115+
n_total_boxes: uint,
116+
n_unique_boxes: uint,
117+
n_bytes_freed: uint
118+
}
119+
120+
unsafe fn each_live_alloc(f: fn(box: *mut BoxRepr, uniq: bool) -> bool) {
121+
use managed;
122+
123+
let task: *Task = transmute(rustrt::rust_get_task());
124+
let box = (*task).boxed_region.live_allocs;
125+
let mut box: *mut BoxRepr = transmute(copy box);
126+
while box != mut_null() {
127+
let next = transmute(copy (*box).header.next);
128+
let uniq =
129+
(*box).header.ref_count == managed::raw::RC_MANAGED_UNIQUE;
130+
131+
if ! f(box, uniq) {
132+
break
133+
}
134+
135+
box = next
136+
}
137+
}
138+
139+
#[cfg(unix)]
140+
fn debug_mem() -> bool {
141+
use os;
142+
use libc;
143+
do os::as_c_charp("RUST_DEBUG_MEM") |p| {
144+
unsafe { libc::getenv(p) != null() }
145+
}
146+
}
147+
148+
#[cfg(windows)]
149+
fn debug_mem() -> bool {
150+
false
151+
}
152+
114153
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
115154
#[cfg(notest)]
116155
#[lang="annihilate"]
117156
pub unsafe fn annihilate() {
118157
use rt::rt_free;
119158
use io::WriterUtil;
159+
use io;
160+
use libc;
161+
use sys;
162+
use managed;
120163

121-
let task: *Task = transmute(rustrt::rust_get_task());
164+
let mut stats = AnnihilateStats {
165+
n_total_boxes: 0,
166+
n_unique_boxes: 0,
167+
n_bytes_freed: 0
168+
};
122169

123170
// Pass 1: Make all boxes immortal.
124-
let box = (*task).boxed_region.live_allocs;
125-
let mut box: *mut BoxRepr = transmute(copy box);
126-
while box != mut_null() {
127-
debug!("making box immortal: %x", box as uint);
128-
(*box).header.ref_count = 0x77777777;
129-
box = transmute(copy (*box).header.next);
171+
for each_live_alloc |box, uniq| {
172+
stats.n_total_boxes += 1;
173+
if uniq {
174+
stats.n_unique_boxes += 1;
175+
} else {
176+
(*box).header.ref_count = managed::raw::RC_IMMORTAL;
177+
}
130178
}
131179

132180
// Pass 2: Drop all boxes.
133-
let box = (*task).boxed_region.live_allocs;
134-
let mut box: *mut BoxRepr = transmute(copy box);
135-
while box != mut_null() {
136-
debug!("calling drop glue for box: %x", box as uint);
137-
let tydesc: *TypeDesc = transmute(copy (*box).header.type_desc);
138-
let drop_glue: DropGlue = transmute(((*tydesc).drop_glue, 0));
139-
drop_glue(to_unsafe_ptr(&tydesc), transmute(&(*box).data));
140-
141-
box = transmute(copy (*box).header.next);
181+
for each_live_alloc |box, uniq| {
182+
if !uniq {
183+
let tydesc: *TypeDesc = transmute(copy (*box).header.type_desc);
184+
let drop_glue: DropGlue = transmute(((*tydesc).drop_glue, 0));
185+
drop_glue(to_unsafe_ptr(&tydesc), transmute(&(*box).data));
186+
}
142187
}
143188

144189
// Pass 3: Free all boxes.
145-
loop {
146-
let box = (*task).boxed_region.live_allocs;
147-
if box == null() { break; }
148-
let mut box: *mut BoxRepr = transmute(copy box);
149-
assert (*box).header.prev == null();
150-
151-
debug!("freeing box: %x", box as uint);
152-
rt_free(transmute(box));
190+
for each_live_alloc |box, uniq| {
191+
if !uniq {
192+
stats.n_bytes_freed +=
193+
(*((*box).header.type_desc)).size
194+
+ sys::size_of::<BoxRepr>();
195+
rt_free(transmute(box));
196+
}
197+
}
198+
199+
if debug_mem() {
200+
// We do logging here w/o allocation.
201+
let dbg = libc::STDERR_FILENO as io::fd_t;
202+
dbg.write_str("annihilator stats:");
203+
dbg.write_str("\n total_boxes: ");
204+
dbg.write_uint(stats.n_total_boxes);
205+
dbg.write_str("\n unique_boxes: ");
206+
dbg.write_uint(stats.n_unique_boxes);
207+
dbg.write_str("\n bytes_freed: ");
208+
dbg.write_uint(stats.n_bytes_freed);
209+
dbg.write_str("\n");
153210
}
154211
}
155212

branches/try2/src/libcore/managed.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ use managed::raw::BoxRepr;
1616
use prelude::*;
1717
use ptr;
1818

19+
1920
pub mod raw {
21+
22+
pub const RC_EXCHANGE_UNIQUE : uint = (-1) as uint;
23+
pub const RC_MANAGED_UNIQUE : uint = (-2) as uint;
24+
pub const RC_IMMORTAL : uint = 0x77777777;
25+
2026
use intrinsic::TyDesc;
2127

2228
pub struct BoxHeaderRepr {

branches/try2/src/libcore/vec.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -31,9 +31,14 @@ use vec;
3131

3232
#[abi = "cdecl"]
3333
pub extern mod rustrt {
34+
// These names are terrible. reserve_shared applies
35+
// to ~[] and reserve_shared_actual applies to @[].
3436
unsafe fn vec_reserve_shared(++t: *sys::TypeDesc,
3537
++v: **raw::VecRepr,
3638
++n: libc::size_t);
39+
unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
40+
++v: **raw::VecRepr,
41+
++n: libc::size_t);
3742
}
3843

3944
/// Returns true if a vector contains no elements
@@ -59,11 +64,17 @@ pub pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool {
5964
*/
6065
pub fn reserve<T>(v: &mut ~[T], n: uint) {
6166
// Only make the (slow) call into the runtime if we have to
67+
use managed;
6268
if capacity(v) < n {
6369
unsafe {
6470
let ptr: **raw::VecRepr = cast::transmute(v);
65-
rustrt::vec_reserve_shared(sys::get_type_desc::<T>(),
66-
ptr, n as size_t);
71+
let td = sys::get_type_desc::<T>();
72+
if ((**ptr).box_header.ref_count ==
73+
managed::raw::RC_MANAGED_UNIQUE) {
74+
rustrt::vec_reserve_shared_actual(td, ptr, n as size_t);
75+
} else {
76+
rustrt::vec_reserve_shared(td, ptr, n as size_t);
77+
}
6778
}
6879
}
6980
}

0 commit comments

Comments
 (0)