Skip to content

Commit c86fd1b

Browse files
authored
Merge pull request #326 from Pivot-Studio/fix/bugs0814
Fix/bugs0814
2 parents b29ea25 + f01331e commit c86fd1b

39 files changed

+826
-386
lines changed

.github/workflows/bench.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: 1
12+
RUST_TEST_NOCAPTURE: 1
13+
PL_IMMIX_HEAP_SIZE: 1073741824
1114

1215
concurrency:
1316
group: ${{ github.workflow }}-${{ github.ref }}

Cargo.lock

Lines changed: 44 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ parking_lot = "0.12"
4444
derivative = "2.2"
4545
console = "0.15"
4646
anstyle = "1.0"
47+
regex = "1.9"
4748

4849
[target.'cfg(target_arch = "wasm32")'.dependencies]
4950
wasm-bindgen = "0.2"

immix/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ lazy_static = "1.4"
1414
vector-map = "1.0"
1515
backtrace = "0.3"
1616
log = "0.4"
17+
memory-stats = "1.1"
18+
1719
[target.'cfg(windows)'.dependencies]
1820
winapi = { version = "0.3", features = ["winuser","memoryapi"] }
1921

22+
2023
[dev-dependencies]
2124
rand = "0.8"
2225
criterion = "0.4"

immix/benches/immix_bench.rs

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ fn bench_n_threads(n: usize) -> impl Fn(&mut Criterion) {
1919
n, OBJ_NUM
2020
),
2121
|b| {
22-
b.iter_custom(|t| {
23-
let total = test_complecated_multiple_thread_gc(t as usize, n);
24-
total.0 + total.1
25-
});
22+
b.iter_custom(|t| test_complecated_multiple_thread_gc(t as usize, n));
2623
},
2724
);
2825
}
@@ -34,40 +31,37 @@ fn immix_benchmark_single_thread(c: &mut Criterion) {
3431
c.bench_function(
3532
&format!("singlethread gc benchmark--{} small objects", OBJ_NUM),
3633
|b| {
37-
b.iter_custom(|t| {
38-
let total = test_complecated_single_thread_gc(t as usize);
39-
total.0 + total.1
40-
});
34+
b.iter_custom(|t| test_complecated_single_thread_gc(t as usize));
4135
},
4236
);
4337
}
4438

45-
fn immix_benchmark_single_thread_mark(c: &mut Criterion) {
46-
gc_disable_auto_collect();
47-
set_evacuation(false);
48-
c.bench_function(
49-
&format!("singlethread gc mark benchmark--{} small objects", OBJ_NUM),
50-
|b| {
51-
b.iter_custom(|t| {
52-
let total = test_complecated_single_thread_gc(t as usize);
53-
total.0
54-
});
55-
},
56-
);
57-
}
58-
fn immix_benchmark_single_thread_sweep(c: &mut Criterion) {
59-
gc_disable_auto_collect();
60-
set_evacuation(false);
61-
c.bench_function(
62-
&format!("singlethread gc sweep benchmark--{} small objects", OBJ_NUM),
63-
|b| {
64-
b.iter_custom(|t| {
65-
let total = test_complecated_single_thread_gc(t as usize);
66-
total.1
67-
});
68-
},
69-
);
70-
}
39+
// fn immix_benchmark_single_thread_mark(c: &mut Criterion) {
40+
// gc_disable_auto_collect();
41+
// set_evacuation(false);
42+
// c.bench_function(
43+
// &format!("singlethread gc mark benchmark--{} small objects", OBJ_NUM),
44+
// |b| {
45+
// b.iter_custom(|t| {
46+
// let total = test_complecated_single_thread_gc(t as usize);
47+
// total.0
48+
// });
49+
// },
50+
// );
51+
// }
52+
// fn immix_benchmark_single_thread_sweep(c: &mut Criterion) {
53+
// gc_disable_auto_collect();
54+
// set_evacuation(false);
55+
// c.bench_function(
56+
// &format!("singlethread gc sweep benchmark--{} small objects", OBJ_NUM),
57+
// |b| {
58+
// b.iter_custom(|t| {
59+
// let total = test_complecated_single_thread_gc(t as usize);
60+
// total.1
61+
// });
62+
// },
63+
// );
64+
// }
7165

7266
fn immix_benchmark_single_thread_alloc(c: &mut Criterion) {
7367
gc_disable_auto_collect();
@@ -124,13 +118,12 @@ unsafe fn alloc_test_obj(gc: &mut Collector) -> *mut GCTestObj {
124118
a
125119
}
126120

127-
fn test_complecated_single_thread_gc(num_iter: usize) -> (Duration, Duration) {
121+
fn test_complecated_single_thread_gc(num_iter: usize) -> Duration {
128122
#[cfg(feature = "shadow_stack")]
129123
return {
130124
SPACE.with(|gc| unsafe {
131125
let mut gc = gc.borrow_mut();
132-
let mut total_mark = Duration::new(0, 0);
133-
let mut total_sweep = Duration::new(0, 0);
126+
let mut total = Duration::new(0, 0);
134127
for _ in 0..num_iter {
135128
let mut first_obj = alloc_test_obj(&mut gc);
136129
let rustptr = (&mut first_obj) as *mut *mut GCTestObj as *mut u8;
@@ -149,7 +142,9 @@ fn test_complecated_single_thread_gc(num_iter: usize) -> (Duration, Duration) {
149142
gc.add_root(rustptr, ObjectType::Pointer);
150143
let size1 = gc.get_size();
151144
assert_eq!(size1, OBJ_NUM + 1);
152-
let ctime = gc.collect();
145+
let now = std::time::Instant::now();
146+
gc.collect();
147+
total += now.elapsed();
153148
// println!("gc{} gc time = {:?}", gc.get_id(), ctime);
154149
let size2 = gc.get_size();
155150
assert_eq!(live_obj, size2);
@@ -158,10 +153,8 @@ fn test_complecated_single_thread_gc(num_iter: usize) -> (Duration, Duration) {
158153
gc.collect();
159154
let size3 = gc.get_size();
160155
assert_eq!(size3, 0);
161-
total_mark += ctime.0;
162-
total_sweep += ctime.1;
163156
}
164-
(total_mark, total_sweep)
157+
total
165158
})
166159
};
167160
#[cfg(not(feature = "shadow_stack"))]
@@ -170,7 +163,7 @@ fn test_complecated_single_thread_gc(num_iter: usize) -> (Duration, Duration) {
170163
(Duration::new(0, 100), Duration::new(0, 100))
171164
}
172165

173-
fn test_complecated_multiple_thread_gc(num_iter: usize, threads: usize) -> (Duration, Duration) {
166+
fn test_complecated_multiple_thread_gc(num_iter: usize, threads: usize) -> Duration {
174167
let mut handles = vec![];
175168
for _ in 0..threads {
176169
let t = std::thread::spawn(move || test_complecated_single_thread_gc(num_iter));
@@ -180,7 +173,7 @@ fn test_complecated_multiple_thread_gc(num_iter: usize, threads: usize) -> (Dura
180173
for h in handles {
181174
times.push(h.join().unwrap());
182175
}
183-
times.sort_by(|k1, k2| (k1.0 + k1.1).cmp(&(k2.0 + k2.1)));
176+
times.sort_by(|k1, k2| (k1).cmp(k2));
184177
times.pop().unwrap()
185178
}
186179

@@ -200,8 +193,8 @@ criterion_group!(
200193
benches,
201194
immix_benchmark_multi_thread,
202195
immix_benchmark_single_thread,
203-
immix_benchmark_single_thread_mark,
204-
immix_benchmark_single_thread_sweep,
196+
// immix_benchmark_single_thread_mark,
197+
// immix_benchmark_single_thread_sweep,
205198
immix_benchmark_single_thread_alloc,
206199
);
207200
criterion_main!(benches);

immix/benches/immix_stress_bench.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ extern "C" fn gctest_vtable(
7676

7777
unsafe fn alloc_test_obj(gc: &mut Collector) -> *mut GCTestObj {
7878
let a = gc.alloc(size_of::<GCTestObj>(), ObjectType::Complex) as *mut GCTestObj;
79+
if a.is_null() {
80+
panic!("oom")
81+
}
7982
a.write(GCTestObj {
8083
_vtable: gctest_vtable,
8184
b: std::ptr::null_mut(),

immix/llvm/plimmixprinter.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void PLImmixGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter
3939
AP.emitAlignment(llvm::Align(8));
4040
// Put this in the data section.
4141
AP.OutStreamer.get()->SwitchSection(AP.getObjFileLowering().getDataSection());
42-
std::string symbol ;
42+
std::string symbol;
4343
symbol += "_IMMIX_GC_MAP_";
4444
symbol += M.getSourceFileName();
4545
// printf("symbol: %s \n", symbol.c_str());
@@ -140,10 +140,23 @@ void PLImmixGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter
140140
for (auto GI = M.global_begin(), GE = M.global_end(); GI != GE; ++GI)
141141
{
142142
const GlobalValue *GV = &*GI;
143-
if (GV->getName().contains("llvm."))
143+
if (GV->getName().contains("llvm.")) // skip magic variables e.g. @llvm.global_ctors
144+
{
145+
continue;
146+
}
147+
148+
if (GV->isManifestConstant()) // skip constants
144149
{
145150
continue;
146151
}
152+
153+
if (GV->getName().startswith("_IMMIX_GC_MAP") ||
154+
GV->getName().contains("_@IMMIX_OBJTYPE_") ||
155+
GV->getName().startswith(".str")) // skip generated globals
156+
{
157+
continue;
158+
}
159+
147160
ii++;
148161
}
149162
auto g = ii; // skip magic variables e.g. @llvm.global_ctors

0 commit comments

Comments
 (0)