Skip to content

Commit c32d8f1

Browse files
committed
---
yaml --- r: 44685 b: refs/heads/master c: 0309af4 h: refs/heads/master i: 44683: 05515a8 v: v3
1 parent 0ed00fd commit c32d8f1

34 files changed

+756
-687
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4a853894fab6b9a4b60c1b3260b446a3473577fa
2+
refs/heads/master: 0309af458cc0a911adfa974c3800feac6b3ed858
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/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

trunk/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 {

trunk/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
}

trunk/src/librustc/driver/session.rs

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -165,49 +165,49 @@ pub struct Session_ {
165165
pub type Session = @Session_;
166166

167167
pub impl Session {
168-
fn span_fatal(&self, sp: span, msg: ~str) -> ! {
168+
fn span_fatal(sp: span, msg: ~str) -> ! {
169169
self.span_diagnostic.span_fatal(sp, msg)
170170
}
171-
fn fatal(&self, msg: ~str) -> ! {
171+
fn fatal(msg: ~str) -> ! {
172172
self.span_diagnostic.handler().fatal(msg)
173173
}
174-
fn span_err(&self, sp: span, msg: ~str) {
174+
fn span_err(sp: span, msg: ~str) {
175175
self.span_diagnostic.span_err(sp, msg)
176176
}
177-
fn err(&self, msg: ~str) {
177+
fn err(msg: ~str) {
178178
self.span_diagnostic.handler().err(msg)
179179
}
180-
fn has_errors(&self) -> bool {
180+
fn has_errors() -> bool {
181181
self.span_diagnostic.handler().has_errors()
182182
}
183-
fn abort_if_errors(&self) {
183+
fn abort_if_errors() {
184184
self.span_diagnostic.handler().abort_if_errors()
185185
}
186-
fn span_warn(&self, sp: span, msg: ~str) {
186+
fn span_warn(sp: span, msg: ~str) {
187187
self.span_diagnostic.span_warn(sp, msg)
188188
}
189-
fn warn(&self, msg: ~str) {
189+
fn warn(msg: ~str) {
190190
self.span_diagnostic.handler().warn(msg)
191191
}
192-
fn span_note(&self, sp: span, msg: ~str) {
192+
fn span_note(sp: span, msg: ~str) {
193193
self.span_diagnostic.span_note(sp, msg)
194194
}
195-
fn note(&self, msg: ~str) {
195+
fn note(msg: ~str) {
196196
self.span_diagnostic.handler().note(msg)
197197
}
198-
fn span_bug(&self, sp: span, msg: ~str) -> ! {
198+
fn span_bug(sp: span, msg: ~str) -> ! {
199199
self.span_diagnostic.span_bug(sp, msg)
200200
}
201-
fn bug(&self, msg: ~str) -> ! {
201+
fn bug(msg: ~str) -> ! {
202202
self.span_diagnostic.handler().bug(msg)
203203
}
204-
fn span_unimpl(&self, sp: span, msg: ~str) -> ! {
204+
fn span_unimpl(sp: span, msg: ~str) -> ! {
205205
self.span_diagnostic.span_unimpl(sp, msg)
206206
}
207-
fn unimpl(&self, msg: ~str) -> ! {
207+
fn unimpl(msg: ~str) -> ! {
208208
self.span_diagnostic.handler().unimpl(msg)
209209
}
210-
fn span_lint_level(&self, level: lint::level, sp: span, +msg: ~str) {
210+
fn span_lint_level(level: lint::level, sp: span, +msg: ~str) {
211211
match level {
212212
lint::allow => { },
213213
lint::warn => self.span_warn(sp, msg),
@@ -216,7 +216,7 @@ pub impl Session {
216216
}
217217
}
218218
}
219-
fn span_lint(&self, lint_mode: lint::lint,
219+
fn span_lint(lint_mode: lint::lint,
220220
expr_id: ast::node_id,
221221
item_id: ast::node_id,
222222
span: span,
@@ -225,55 +225,45 @@ pub impl Session {
225225
self.lint_settings, lint_mode, expr_id, item_id);
226226
self.span_lint_level(level, span, msg);
227227
}
228-
fn next_node_id(&self) -> ast::node_id {
228+
fn next_node_id() -> ast::node_id {
229229
return syntax::parse::next_node_id(self.parse_sess);
230230
}
231-
fn diagnostic(&self) -> diagnostic::span_handler {
231+
fn diagnostic() -> diagnostic::span_handler {
232232
self.span_diagnostic
233233
}
234-
fn debugging_opt(&self, opt: uint) -> bool {
234+
fn debugging_opt(opt: uint) -> bool {
235235
(self.opts.debugging_opts & opt) != 0u
236236
}
237237
// This exists to help with refactoring to eliminate impossible
238238
// cases later on
239-
fn impossible_case(&self, sp: span, msg: &str) -> ! {
239+
fn impossible_case(sp: span, msg: &str) -> ! {
240240
self.span_bug(sp, fmt!("Impossible case reached: %s", msg));
241241
}
242-
fn verbose(&self) -> bool { self.debugging_opt(verbose) }
243-
fn time_passes(&self) -> bool { self.debugging_opt(time_passes) }
244-
fn count_llvm_insns(&self) -> bool {
245-
self.debugging_opt(count_llvm_insns)
246-
}
247-
fn count_type_sizes(&self) -> bool {
248-
self.debugging_opt(count_type_sizes)
249-
}
250-
fn time_llvm_passes(&self) -> bool {
251-
self.debugging_opt(time_llvm_passes)
252-
}
253-
fn trans_stats(&self) -> bool { self.debugging_opt(trans_stats) }
254-
fn meta_stats(&self) -> bool { self.debugging_opt(meta_stats) }
255-
fn no_asm_comments(&self) -> bool { self.debugging_opt(no_asm_comments) }
256-
fn no_verify(&self) -> bool { self.debugging_opt(no_verify) }
257-
fn trace(&self) -> bool { self.debugging_opt(trace) }
258-
fn coherence(&self) -> bool { self.debugging_opt(coherence) }
259-
fn borrowck_stats(&self) -> bool { self.debugging_opt(borrowck_stats) }
260-
fn borrowck_note_pure(&self) -> bool {
261-
self.debugging_opt(borrowck_note_pure)
262-
}
263-
fn borrowck_note_loan(&self) -> bool {
264-
self.debugging_opt(borrowck_note_loan)
265-
}
266-
fn no_monomorphic_collapse(&self) -> bool {
242+
fn verbose() -> bool { self.debugging_opt(verbose) }
243+
fn time_passes() -> bool { self.debugging_opt(time_passes) }
244+
fn count_llvm_insns() -> bool { self.debugging_opt(count_llvm_insns) }
245+
fn count_type_sizes() -> bool { self.debugging_opt(count_type_sizes) }
246+
fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) }
247+
fn trans_stats() -> bool { self.debugging_opt(trans_stats) }
248+
fn meta_stats() -> bool { self.debugging_opt(meta_stats) }
249+
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }
250+
fn no_verify() -> bool { self.debugging_opt(no_verify) }
251+
fn trace() -> bool { self.debugging_opt(trace) }
252+
fn coherence() -> bool { self.debugging_opt(coherence) }
253+
fn borrowck_stats() -> bool { self.debugging_opt(borrowck_stats) }
254+
fn borrowck_note_pure() -> bool { self.debugging_opt(borrowck_note_pure) }
255+
fn borrowck_note_loan() -> bool { self.debugging_opt(borrowck_note_loan) }
256+
fn no_monomorphic_collapse() -> bool {
267257
self.debugging_opt(no_monomorphic_collapse)
268258
}
269259

270-
fn str_of(&self, id: ast::ident) -> @~str {
260+
fn str_of(id: ast::ident) -> @~str {
271261
self.parse_sess.interner.get(id)
272262
}
273-
fn ident_of(&self, +st: ~str) -> ast::ident {
263+
fn ident_of(+st: ~str) -> ast::ident {
274264
self.parse_sess.interner.intern(@st)
275265
}
276-
fn intr(&self) -> @syntax::parse::token::ident_interner {
266+
fn intr() -> @syntax::parse::token::ident_interner {
277267
self.parse_sess.interner
278268
}
279269
}

trunk/src/librustc/metadata/filesearch.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
2929
}
3030

3131
pub trait FileSearch {
32-
fn sysroot(&self) -> Path;
33-
fn lib_search_paths(&self) -> ~[Path];
34-
fn get_target_lib_path(&self) -> Path;
35-
fn get_target_lib_file_path(&self, file: &Path) -> Path;
32+
fn sysroot() -> Path;
33+
fn lib_search_paths() -> ~[Path];
34+
fn get_target_lib_path() -> Path;
35+
fn get_target_lib_file_path(file: &Path) -> Path;
3636
}
3737

3838
pub fn mk_filesearch(maybe_sysroot: Option<Path>,
@@ -44,8 +44,8 @@ pub fn mk_filesearch(maybe_sysroot: Option<Path>,
4444
target_triple: ~str
4545
}
4646
impl FileSearch for FileSearchImpl {
47-
fn sysroot(&self) -> Path { /*bad*/copy self.sysroot }
48-
fn lib_search_paths(&self) -> ~[Path] {
47+
fn sysroot() -> Path { /*bad*/copy self.sysroot }
48+
fn lib_search_paths() -> ~[Path] {
4949
let mut paths = /*bad*/copy self.addl_lib_search_paths;
5050

5151
paths.push(
@@ -61,10 +61,10 @@ pub fn mk_filesearch(maybe_sysroot: Option<Path>,
6161
}
6262
paths
6363
}
64-
fn get_target_lib_path(&self) -> Path {
64+
fn get_target_lib_path() -> Path {
6565
make_target_lib_path(&self.sysroot, self.target_triple)
6666
}
67-
fn get_target_lib_file_path(&self, file: &Path) -> Path {
67+
fn get_target_lib_file_path(file: &Path) -> Path {
6868
self.get_target_lib_path().push_rel(file)
6969
}
7070
}

0 commit comments

Comments
 (0)