Skip to content

Commit

Permalink
remove the concept of managed-unique from libstd
Browse files Browse the repository at this point in the history
Closes #11545
  • Loading branch information
thestinger committed Jan 15, 2014
1 parent 197fe67 commit 29840ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
44 changes: 16 additions & 28 deletions src/libstd/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use unstable::raw;

type DropGlue<'a> = 'a |**TyDesc, *c_void|;

static RC_IMMORTAL : uint = 0x77777777;

/*
* Box annihilation
*
Expand All @@ -25,24 +27,21 @@ type DropGlue<'a> = 'a |**TyDesc, *c_void|;

struct AnnihilateStats {
n_total_boxes: uint,
n_unique_boxes: uint,
n_bytes_freed: uint
}

unsafe fn each_live_alloc(read_next_before: bool,
f: |alloc: *mut raw::Box<()>, uniq: bool| -> bool)
f: |alloc: *mut raw::Box<()>| -> bool)
-> bool {
//! Walks the internal list of allocations

use managed;
use rt::local_heap;

let mut alloc = local_heap::live_allocs();
while alloc != ptr::mut_null() {
let next_before = (*alloc).next;
let uniq = (*alloc).ref_count == managed::RC_MANAGED_UNIQUE;

if !f(alloc, uniq) {
if !f(alloc) {
return false;
}

Expand Down Expand Up @@ -70,25 +69,19 @@ fn debug_mem() -> bool {
pub unsafe fn annihilate() {
use rt::local_heap::local_free;
use mem;
use managed;

let mut stats = AnnihilateStats {
n_total_boxes: 0,
n_unique_boxes: 0,
n_bytes_freed: 0
};

// Pass 1: Make all boxes immortal.
//
// In this pass, nothing gets freed, so it does not matter whether
// we read the next field before or after the callback.
each_live_alloc(true, |alloc, uniq| {
each_live_alloc(true, |alloc| {
stats.n_total_boxes += 1;
if uniq {
stats.n_unique_boxes += 1;
} else {
(*alloc).ref_count = managed::RC_IMMORTAL;
}
(*alloc).ref_count = RC_IMMORTAL;
true
});

Expand All @@ -97,12 +90,10 @@ pub unsafe fn annihilate() {
// In this pass, unique-managed boxes may get freed, but not
// managed boxes, so we must read the `next` field *after* the
// callback, as the original value may have been freed.
each_live_alloc(false, |alloc, uniq| {
if !uniq {
let tydesc = (*alloc).type_desc;
let data = &(*alloc).data as *();
((*tydesc).drop_glue)(data as *i8);
}
each_live_alloc(false, |alloc| {
let tydesc = (*alloc).type_desc;
let data = &(*alloc).data as *();
((*tydesc).drop_glue)(data as *i8);
true
});

Expand All @@ -112,22 +103,19 @@ pub unsafe fn annihilate() {
// unique-managed boxes, though I think that none of those are
// left), so we must read the `next` field before, since it will
// not be valid after.
each_live_alloc(true, |alloc, uniq| {
if !uniq {
stats.n_bytes_freed +=
(*((*alloc).type_desc)).size
+ mem::size_of::<raw::Box<()>>();
local_free(alloc as *i8);
}
each_live_alloc(true, |alloc| {
stats.n_bytes_freed +=
(*((*alloc).type_desc)).size
+ mem::size_of::<raw::Box<()>>();
local_free(alloc as *i8);
true
});

if debug_mem() {
// We do logging here w/o allocation.
debug!("annihilator stats:\n \
total boxes: {}\n \
unique boxes: {}\n \
bytes freed: {}",
stats.n_total_boxes, stats.n_unique_boxes, stats.n_bytes_freed);
stats.n_total_boxes, stats.n_bytes_freed);
}
}
3 changes: 0 additions & 3 deletions src/libstd/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use ptr::to_unsafe_ptr;

#[cfg(not(test))] use cmp::*;

pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
pub static RC_IMMORTAL : uint = 0x77777777;

/// Returns the refcount of a shared box (as just before calling this)
#[inline]
pub fn refcount<T>(t: @T) -> uint {
Expand Down

11 comments on commit 29840ad

@huonw
Copy link
Member

@huonw huonw commented on 29840ad Jan 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at 29840ad

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging mozilla/rust/snapshot = 29840ad into auto

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mozilla/rust/snapshot = 29840ad merged ok, testing candidate = 0c5dd9ed

@huonw
Copy link
Member

@huonw huonw commented on 29840ad Jan 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors: retry

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at 29840ad

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging mozilla/rust/snapshot = 29840ad into auto

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mozilla/rust/snapshot = 29840ad merged ok, testing candidate = a5ed0c5

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 29840ad Jan 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = a5ed0c5

Please sign in to comment.