Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ jobs:

- name: Run cargo clippy
uses: actions-rs/clippy-check@v1
env:
RUSTFLAGS: ""
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
38 changes: 21 additions & 17 deletions immix/src/allocator/big_obj_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,28 @@ impl BigObjAllocator {
for i in 0..self.unused_chunks.len() {
let unused_obj = self.unused_chunks[i];
let unused_size = unsafe { (*unused_obj).size };
if unused_size == size {
self.unused_chunks.remove(i);
// self.mmap.commit(unused_obj as *mut u8, size);
println!(
"get_chunk: {:p}[reused {}/{}]",
unused_obj, size, unused_size
);
return unused_obj;
} else if unused_size > size {
let ptr = unsafe { (unused_obj as *mut u8).add(unused_size - size) };
let new_obj = BigObj::new(ptr, size);
unsafe {
(*unused_obj).size -= size;
match unused_size.cmp(&size) {
std::cmp::Ordering::Less => {}
std::cmp::Ordering::Equal => {
self.unused_chunks.remove(i);
// self.mmap.commit(unused_obj as *mut u8, size);
println!(
"get_chunk: {:p}[reused {}/{}]",
unused_obj, size, unused_size
);
return unused_obj;
}
// self.mmap.commit(new_obj as *mut BigObj as *mut u8, size);
println!("get_chunk: {:p}[reused {}/{}]", new_obj, size, unused_size);
return new_obj;
}
std::cmp::Ordering::Greater => {
let ptr = unsafe { (unused_obj as *mut u8).add(unused_size - size) };
let new_obj = BigObj::new(ptr, size);
unsafe {
(*unused_obj).size -= size;
}
// self.mmap.commit(new_obj as *mut BigObj as *mut u8, size);
println!("get_chunk: {:p}[reused {}/{}]", new_obj, size, unused_size);
return new_obj;
}
};
}

let chunk = self.alloc_chunk(size).unwrap();
Expand Down
7 changes: 3 additions & 4 deletions immix/src/allocator/thread_local_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ impl ThreadLocalAllocator {
let uf = self.recyclable_blocks.pop_front().unwrap();
self.unavailable_blocks.push(uf);
let ff = self.recyclable_blocks.front();
if ff.is_none() {
// recycle blocks全用光了
return self.alloc(size, obj_type);
if let Some(ff) = ff {
f = ff;
} else {
f = ff.unwrap()
return self.alloc(size, obj_type);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion immix/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl Block {
// 未使用或者未标记
if !self.line_map[idx].get_used()
|| (self.line_map[idx] & 0b10 == 0 //即使标记位为0,也有可能是被标记的对象数据体
&& (!marked || (marked && self.line_map[idx] & 0b10000010 == 0b10000000)))
&& (!marked || self.line_map[idx] & 0b10000010 == 0b10000000))
{
len += 1;
self.line_map[idx] &= 0;
Expand Down
2 changes: 1 addition & 1 deletion immix/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Collector {
.as_mut()
.unwrap()
.alloc(size, obj_type);
debug_assert!(ptr.is_null() == false);
debug_assert!(!ptr.is_null());
ptr
}
}
Expand Down
77 changes: 35 additions & 42 deletions pl_linker/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,7 @@ impl Linker for Ld64Linker {
// use ld for default linker, as lld has a bug affcting backtrace on arm64 target
// https://github.com/rust-lang/backtrace-rs/issues/150
let re = Command::new("ld").args(&self.args).output();
if re.is_err() {
println!("ld not found, try to link with lld, this may break gc(https://github.com/rust-lang/backtrace-rs/issues/150)");
lld_rs::link(lld_rs::LldFlavor::MachO, &self.args)
.ok()
.map_err(LinkerError::LinkError)
} else {
let re = re.unwrap();
if let Ok(re) = re {
if !re.status.success() {
eprintln!(
"link failed\nargs: {:?}\nld stdout: {}, stderr: {}",
Expand All @@ -244,6 +238,11 @@ impl Linker for Ld64Linker {
} else {
Ok(())
}
} else {
println!("ld not found, try to link with lld, this may break gc(https://github.com/rust-lang/backtrace-rs/issues/150)");
lld_rs::link(lld_rs::LldFlavor::MachO, &self.args)
.ok()
.map_err(LinkerError::LinkError)
}
} else {
lld_rs::link(lld_rs::LldFlavor::MachO, &self.args)
Expand Down Expand Up @@ -319,14 +318,7 @@ impl Linker for MsvcLinker {
let re = Command::new(linker.expect("failed to find link.exe"))
.args(&self.args)
.output();

if re.is_err() {
return Err(LinkerError::LinkError(format!(
"link failed: {:?}",
re.err()
)));
} else {
let re = re.unwrap();
if let Ok(re) = re {
if !re.status.success() {
eprintln!(
"link failed\nargs: {:?}\nld stdout: {}, stderr: {}",
Expand All @@ -338,6 +330,11 @@ impl Linker for MsvcLinker {
} else {
Ok(())
}
} else {
Err(LinkerError::LinkError(format!(
"link failed: {:?}",
re.err()
)))
}
}

Expand Down Expand Up @@ -388,33 +385,29 @@ fn get_win_sdk_lib_paths() -> (Option<PathBuf>, Vec<PathBuf>) {
});
let sdkroot = PathBuf::from(r"C:\Program Files (x86)\Windows Kits\");
assert!(sdkroot.is_dir(), "Windows SDK not found");
for dir in sdkroot.read_dir().unwrap() {
if let Ok(dir) = dir {
if dir.path().is_symlink() || !dir.path().is_dir() {
continue;
}
let mut p = dir.path();
p.push("Lib");
if p.is_dir() {
for d in p.read_dir().unwrap() {
if let Ok(d) = d {
if d.path().is_dir() {
let mut p = d.path();
p.push("ucrt\\x64");
if p.exists() {
paths.push(p);
}
let mut p = d.path();
p.push("um\\x64");
if p.exists() {
paths.push(p);
}
if paths.len() == 4 {
return (linker_path, paths);
} else {
paths = paths[0..2].to_vec();
}
}
for dir in sdkroot.read_dir().unwrap().flatten() {
if dir.path().is_symlink() || !dir.path().is_dir() {
continue;
}
let mut p = dir.path();
p.push("Lib");
if p.is_dir() {
for d in p.read_dir().unwrap().flatten() {
if d.path().is_dir() {
let mut p = d.path();
p.push("ucrt\\x64");
if p.exists() {
paths.push(p);
}
let mut p = d.path();
p.push("um\\x64");
if p.exists() {
paths.push(p);
}
if paths.len() == 4 {
return (linker_path, paths);
} else {
paths = paths[0..2].to_vec();
}
}
}
Expand Down
Loading