generated from oovm/RustTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
152 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[package] | ||
name = "zgc" | ||
version = "0.0.0" | ||
version = "0.0.1" | ||
authors = ["Aster <[email protected]>"] | ||
description = "Concurrent GC in Rust" | ||
description = "Pauseless GC in Rust" | ||
repository = "https://github.com/nyar-vm/zero-gc" | ||
documentation = "https://docs.rs/zgc" | ||
readme = "Readme.md" | ||
|
@@ -11,7 +11,7 @@ edition = "2021" | |
exclude = ["package.json", "tests/**"] | ||
|
||
[dependencies] | ||
bitflags = "2.3.1" | ||
#bitflags = "2.3.1" | ||
|
||
[dev-dependencies] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// Result type of gc | ||
pub type GcResult<T> = std::result::Result<T, GcError>; | ||
|
||
/// Error type for the GC | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum GcError { | ||
/// The object is not a valid gc object. | ||
UnknownError | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,38 @@ | ||
use std::alloc::{Allocator, AllocError, Layout}; | ||
use std::marker::PhantomData; | ||
use std::ptr::NonNull; | ||
|
||
/// Gc pointer | ||
|
||
use crate::GcPointer; | ||
|
||
/// A typed gc object. | ||
#[repr(C)] | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct Gc<T> { | ||
/// Pointer to the head | ||
ptr: *mut u64, | ||
head: GcPointer, | ||
/// Pointer to the data | ||
bytes: *mut u8, | ||
size: usize, | ||
/// Phantom data | ||
typing: PhantomData<T>, | ||
} | ||
|
||
|
||
pub trait Region { | ||
fn allocate(&mut self, size: usize) -> *mut u8; | ||
fn free(&mut self, ptr: *mut u8); | ||
} | ||
|
||
impl Region for SmallRegion { | ||
fn allocate(&mut self, size: usize) -> *mut u8 { | ||
todo!() | ||
} | ||
|
||
fn free(&mut self, ptr: *mut u8) { | ||
todo!() | ||
impl<T> Gc<T> { | ||
/// Create a new gc object from the data | ||
pub fn new(value: T) -> Self { | ||
Self { | ||
head: GcPointer::make(&value), | ||
size: std::mem::size_of::<T>(), | ||
typing: PhantomData::default(), | ||
} | ||
} | ||
} | ||
|
||
/// The world. | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct TheWorld {} | ||
|
||
#[derive(Copy, Clone)] | ||
pub union TheRegion { | ||
small: SmallRegion, | ||
medium: MediumRegion, | ||
} | ||
|
||
unsafe impl Allocator for TheWorld { | ||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { | ||
todo!() | ||
} | ||
|
||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | ||
todo!() | ||
} | ||
} | ||
// 小型Region(Small Region):容量固定为2MB,用于放置小于256KB的小对象。 | ||
// 中型Region(Medium Region):容量固定为32MB,用于放置大于等于256KB但小于4MB的对象。 | ||
// 大型Region(Large Region):容量不固定,可以动态变化,但必须为2MB的整数倍,用于放置4MB或以上的大对象。每个大型Region中只会存放一个大对象,这也预示着虽然名字叫作“大型Region”,但它的实际容量完全有可能小于中型Region,最小容量可低至4MB。大型Region在ZGC的实现中是不会被重分配的,因为复制一个大对象的代价非常高昂。 | ||
|
||
/// 容量固定为1MB,用于放置小于128KB的小对象。 | ||
#[derive(Copy, Clone)] | ||
pub struct SmallRegion { | ||
bytes: [u8; 1 * 1024 * 1024], | ||
} | ||
|
||
/// 容量固定为 32MB,用于放置小于4MB的中等对象。 | ||
#[derive(Copy, Clone)] | ||
pub struct MediumRegion { | ||
bytes: [u8; 32 * 1024 * 1024], | ||
} | ||
|
||
pub struct OwnedRegion { | ||
bytes: Vec<u8>, | ||
} | ||
|
||
pub struct WorldControl { | ||
initiating_heap_occupancy_percent: u8, | ||
/// The world control. | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct TheWorldControl { | ||
/// The world | ||
pub initiating_heap_occupancy_percent: u8, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,35 @@ | ||
#[allow(unused, dead_code)] | ||
use zgc::{GcObject, GcPointer}; | ||
|
||
#[test] | ||
fn ready() { | ||
println!("it works!") | ||
} | ||
|
||
|
||
// #[test] | ||
// pub fn test() { | ||
// let a: i32 = -2333; | ||
// println!("{} at {:p}", a, &a); | ||
// let mut ptr = GcPointer::make(&a); | ||
// ptr.set_marked0(true); | ||
// ptr.set_marked1(false); | ||
// ptr.set_remapped(true); | ||
// ptr.set_finalize(false); | ||
// println!("{:#?}", ptr); | ||
// // println!("{:p}", ptr.as_pointer()); | ||
// let d = *unsafe { ptr.cast::<i32>() }; | ||
// println!("value: {}", d); | ||
// } | ||
|
||
|
||
// #[test] | ||
// pub fn test2() { | ||
// let a: [i32; 4] = [2, -3, -5, -7]; | ||
// println!("{:?} at {:p}", a, &a); | ||
// let obj = GcObject::make(a); | ||
// println!("{:#?}", obj); | ||
// println!("{:?}", obj.as_bytes()); | ||
// let d = unsafe { obj.cast::<[u32; 4]>() }; | ||
// println!("value: {:?}", d); | ||
// } |