Skip to content

Commit dbf5687

Browse files
Merge #36
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 <[email protected]>
2 parents f356a0d + e73691c commit dbf5687

File tree

10 files changed

+59
-236
lines changed

10 files changed

+59
-236
lines changed

.buildbot.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sh rustup.sh --default-host x86_64-unknown-linux-gnu \
1212
--profile minimal \
1313
-y
1414
export PATH=`pwd`/.cargo/bin/:$PATH
15-
cargo check --features use_boehm
15+
cargo check
1616

1717
rustup toolchain install nightly --allow-downgrade --component rustfmt
1818
cargo +nightly fmt --all -- --check

Cargo.toml

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
[package]
2-
name = "rboehm"
2+
name = "libgc"
33
version = "0.1.0"
44
authors = ["Jacob Hughes <[email protected]>"]
55
edition = "2018"
66

7-
[workspace]
8-
members = ["boehm"]
9-
107
[features]
118
# Enable this feature to turn on additional GC optimizations that are only
12-
# possible with the rustc_boehm fork of the compiler.
13-
rustc_boehm = []
9+
# possible with the rustgc fork of the compiler.
10+
rustgc = []
1411

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

19-
# Use boehm as a backend
20-
use_boehm = ["boehm"]
21-
2216
[dependencies]
2317
libc = "*"
24-
boehm = { path = "boehm", optional = true }
18+
libgc_internal = { git = "https://github.com/softdevteam/libgc_internal" }
2519

2620
[build-dependencies]
2721
rerun_except = "0.1"

README.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
1-
# rboehm
2-
A Rust API for the Boehm-Demers-Weiser garbage collector
1+
# libgc
2+
3+
libgc is a garbage collector for Rust. It works by providing a garbage-collected
4+
`Gc<T>` smart pointer in the style of `Rc<T>`.
5+
6+
# Structure
7+
8+
There are three repositories which make up the gc infrastructure:
9+
- **libgc** the main library which provides the `Gc<T>` smart pointer and its
10+
API.
11+
- **libgc_internal** contains the gc allocation and collector logic. This is
12+
collector specific, and can be conditionally compiled to support different
13+
implementations. At the moment, it only supports a single collector
14+
implementation: the Boehm-Demers-Weiser GC. Users should never interact
15+
directly with this crate. Instead, any relevant APIs are re-exported
16+
through libgc.
17+
- **rustgc** a fork of rustc with GC-aware optimisations. This can be used to
18+
compile user programs which use `libgc`, giving them better GC
19+
performance. Use of rustgc is not mandated, but it enables further
20+
optimisations for programs which use `libgc`.
21+
22+
This seperation between libgc and rustgc exists so that a stripped-down form of
23+
garbage collection can be used without compiler support. The further split
24+
between libgc and libgc_core exists to make linkage easier when the rustgc
25+
compiler is used.
26+
27+
rustgc needs access to the GC's `Allocator` implementation. This exists in the
28+
libgc_internal crate so that it can be linked to the target binary either as
29+
part of libgc, or as part of the rust standard library (if compiled with
30+
rustgc). libgc contains code which would not compile if it was packaged as part
31+
of rustgc. To prevent duplication, the libgc_interal crate will link correctly
32+
as either a standard cargo crate, or as part of the rust core library.

boehm/Cargo.toml

-9
This file was deleted.

boehm/src/allocator.rs

-34
This file was deleted.

boehm/src/ffi.rs

-67
This file was deleted.

boehm/src/lib.rs

-76
This file was deleted.

src/gc.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,27 @@ impl<T> GcBox<T> {
205205
#[cfg(feature = "gc_stats")]
206206
crate::stats::NUM_REGISTERED_FINALIZERS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
207207

208-
#[cfg(feature = "boehm")]
209-
boehm::register_finalizer(self as *mut _ as *mut T);
208+
if !needs_finalizer::<T>() {
209+
return;
210+
}
211+
212+
unsafe extern "C" fn fshim<T>(obj: *mut u8, _meta: *mut u8) {
213+
ManuallyDrop::drop(&mut *(obj as *mut ManuallyDrop<T>));
214+
}
215+
216+
unsafe {
217+
GC_ALLOCATOR.register_finalizer(
218+
self as *mut _ as *mut u8,
219+
Some(fshim::<T>),
220+
::std::ptr::null_mut(),
221+
::std::ptr::null_mut(),
222+
::std::ptr::null_mut(),
223+
)
224+
}
210225
}
211226

212227
fn unregister_finalizer(&mut self) {
213-
#[cfg(feature = "boehm")]
214-
boehm::unregister_finalizer(self as *mut _ as *mut u8);
228+
unsafe { GC_ALLOCATOR.unregister_finalizer(self as *mut _ as *mut u8) };
215229
}
216230
}
217231

src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ pub mod stats;
1919

2020
pub use gc::Gc;
2121

22-
#[cfg(feature = "use_boehm")]
23-
pub use boehm::force_gc;
22+
use libgc_internal::GcAllocator;
23+
pub use libgc_internal::GlobalAllocator;
2424

25-
pub use boehm::allocator::BoehmAllocator;
26-
use boehm::allocator::BoehmGcAllocator;
27-
28-
static mut GC_ALLOCATOR: BoehmGcAllocator = BoehmGcAllocator;
25+
static GC_ALLOCATOR: GcAllocator = GcAllocator;
26+
pub static GLOBAL_ALLOCATOR: GlobalAllocator = GlobalAllocator;

src/stats.rs

-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
11
use std::sync::atomic::{AtomicUsize, Ordering};
22

33
pub static NUM_REGISTERED_FINALIZERS: AtomicUsize = AtomicUsize::new(0);
4-
5-
#[derive(Debug)]
6-
pub struct GcStats {
7-
total_gc_time: usize, // In milliseconds.
8-
num_collections: usize,
9-
finalizers_registered: usize,
10-
total_freed: usize, // In bytes
11-
total_alloced: usize, // In bytes
12-
}
13-
14-
#[cfg(feature = "gc_stats")]
15-
impl From<boehm::BoehmStats> for GcStats {
16-
fn from(item: boehm::BoehmStats) -> Self {
17-
GcStats {
18-
total_gc_time: item.total_gc_time,
19-
num_collections: item.num_collections,
20-
finalizers_registered: NUM_REGISTERED_FINALIZERS.load(Ordering::Relaxed),
21-
total_freed: item.total_freed,
22-
total_alloced: item.total_alloced,
23-
}
24-
}
25-
}
26-
27-
#[cfg(feature = "gc_stats")]
28-
pub fn get_stats() -> GcStats {
29-
GcStats::from(boehm::BoehmStats::gen())
30-
}

0 commit comments

Comments
 (0)