Skip to content

Commit

Permalink
Merge #36
Browse files Browse the repository at this point in the history
36: Delete boehm specific code r=ltratt a=jacob-hughes

This is now being served from the softdev/boehm_allocator crate, which
contains code needed for both rboehm and rustc_boehm.

Co-authored-by: Jacob Hughes <jh@jakehughes.uk>
  • Loading branch information
bors[bot] and jacob-hughes authored Dec 23, 2020
2 parents f356a0d + e73691c commit dbf5687
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 236 deletions.
2 changes: 1 addition & 1 deletion .buildbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sh rustup.sh --default-host x86_64-unknown-linux-gnu \
--profile minimal \
-y
export PATH=`pwd`/.cargo/bin/:$PATH
cargo check --features use_boehm
cargo check

rustup toolchain install nightly --allow-downgrade --component rustfmt
cargo +nightly fmt --all -- --check
14 changes: 4 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
[package]
name = "rboehm"
name = "libgc"
version = "0.1.0"
authors = ["Jacob Hughes <jh@jakehughes.uk>"]
edition = "2018"

[workspace]
members = ["boehm"]

[features]
# Enable this feature to turn on additional GC optimizations that are only
# possible with the rustc_boehm fork of the compiler.
rustc_boehm = []
# possible with the rustgc fork of the compiler.
rustgc = []

# Enable various GC based statistics. Stats are disabled by default as they have
# a run-time cost and are expected to only be used for profiling purposes.
gc_stats = []

# Use boehm as a backend
use_boehm = ["boehm"]

[dependencies]
libc = "*"
boehm = { path = "boehm", optional = true }
libgc_internal = { git = "https://github.com/softdevteam/libgc_internal" }

[build-dependencies]
rerun_except = "0.1"
Expand Down
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# rboehm
A Rust API for the Boehm-Demers-Weiser garbage collector
# libgc

libgc is a garbage collector for Rust. It works by providing a garbage-collected
`Gc<T>` smart pointer in the style of `Rc<T>`.

# Structure

There are three repositories which make up the gc infrastructure:
- **libgc** the main library which provides the `Gc<T>` smart pointer and its
API.
- **libgc_internal** contains the gc allocation and collector logic. This is
collector specific, and can be conditionally compiled to support different
implementations. At the moment, it only supports a single collector
implementation: the Boehm-Demers-Weiser GC. Users should never interact
directly with this crate. Instead, any relevant APIs are re-exported
through libgc.
- **rustgc** a fork of rustc with GC-aware optimisations. This can be used to
compile user programs which use `libgc`, giving them better GC
performance. Use of rustgc is not mandated, but it enables further
optimisations for programs which use `libgc`.

This seperation between libgc and rustgc exists so that a stripped-down form of
garbage collection can be used without compiler support. The further split
between libgc and libgc_core exists to make linkage easier when the rustgc
compiler is used.

rustgc needs access to the GC's `Allocator` implementation. This exists in the
libgc_internal crate so that it can be linked to the target binary either as
part of libgc, or as part of the rust standard library (if compiled with
rustgc). libgc contains code which would not compile if it was packaged as part
of rustgc. To prevent duplication, the libgc_interal crate will link correctly
as either a standard cargo crate, or as part of the rust core library.
9 changes: 0 additions & 9 deletions boehm/Cargo.toml

This file was deleted.

34 changes: 0 additions & 34 deletions boehm/src/allocator.rs

This file was deleted.

67 changes: 0 additions & 67 deletions boehm/src/ffi.rs

This file was deleted.

76 changes: 0 additions & 76 deletions boehm/src/lib.rs

This file was deleted.

22 changes: 18 additions & 4 deletions src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,27 @@ impl<T> GcBox<T> {
#[cfg(feature = "gc_stats")]
crate::stats::NUM_REGISTERED_FINALIZERS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);

#[cfg(feature = "boehm")]
boehm::register_finalizer(self as *mut _ as *mut T);
if !needs_finalizer::<T>() {
return;
}

unsafe extern "C" fn fshim<T>(obj: *mut u8, _meta: *mut u8) {
ManuallyDrop::drop(&mut *(obj as *mut ManuallyDrop<T>));
}

unsafe {
GC_ALLOCATOR.register_finalizer(
self as *mut _ as *mut u8,
Some(fshim::<T>),
::std::ptr::null_mut(),
::std::ptr::null_mut(),
::std::ptr::null_mut(),
)
}
}

fn unregister_finalizer(&mut self) {
#[cfg(feature = "boehm")]
boehm::unregister_finalizer(self as *mut _ as *mut u8);
unsafe { GC_ALLOCATOR.unregister_finalizer(self as *mut _ as *mut u8) };
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ pub mod stats;

pub use gc::Gc;

#[cfg(feature = "use_boehm")]
pub use boehm::force_gc;
use libgc_internal::GcAllocator;
pub use libgc_internal::GlobalAllocator;

pub use boehm::allocator::BoehmAllocator;
use boehm::allocator::BoehmGcAllocator;

static mut GC_ALLOCATOR: BoehmGcAllocator = BoehmGcAllocator;
static GC_ALLOCATOR: GcAllocator = GcAllocator;
pub static GLOBAL_ALLOCATOR: GlobalAllocator = GlobalAllocator;
27 changes: 0 additions & 27 deletions src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
use std::sync::atomic::{AtomicUsize, Ordering};

pub static NUM_REGISTERED_FINALIZERS: AtomicUsize = AtomicUsize::new(0);

#[derive(Debug)]
pub struct GcStats {
total_gc_time: usize, // In milliseconds.
num_collections: usize,
finalizers_registered: usize,
total_freed: usize, // In bytes
total_alloced: usize, // In bytes
}

#[cfg(feature = "gc_stats")]
impl From<boehm::BoehmStats> for GcStats {
fn from(item: boehm::BoehmStats) -> Self {
GcStats {
total_gc_time: item.total_gc_time,
num_collections: item.num_collections,
finalizers_registered: NUM_REGISTERED_FINALIZERS.load(Ordering::Relaxed),
total_freed: item.total_freed,
total_alloced: item.total_alloced,
}
}
}

#[cfg(feature = "gc_stats")]
pub fn get_stats() -> GcStats {
GcStats::from(boehm::BoehmStats::gen())
}

0 comments on commit dbf5687

Please sign in to comment.