Skip to content

Commit e4daafe

Browse files
author
meister
committed
Added all files
1 parent 2cf8384 commit e4daafe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3699
-0
lines changed

dummyvm/Cargo.toml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[package]
2+
name = "mmtk_dummyvm"
3+
version = "0.0.1"
4+
authors = [" <>"]
5+
edition = "2021"
6+
7+
[lib]
8+
name = "mmtk_dummyvm"
9+
# be careful - LTO is only allowed for certain crate types
10+
# We know that cdylib should work for LTO.
11+
# We keep rlib here as we need to use the crate from benches.
12+
crate-type = ["cdylib", "rlib"]
13+
14+
[profile.release]
15+
lto = true
16+
17+
[dependencies]
18+
mmtk = { path = "../../", version = "*" }
19+
libc = "0.2"
20+
lazy_static = "1.1"
21+
atomic_refcell = "0.1.7"
22+
atomic = "0.4.6"
23+
log = "0.4"
24+
25+
[dev-dependencies]
26+
criterion = "0.4"
27+
28+
[[bench]]
29+
name = "main"
30+
harness = false
31+
32+
[features]
33+
default = []
34+
is_mmtk_object = ["mmtk/is_mmtk_object"]
35+
malloc_counted_size = ["mmtk/malloc_counted_size"]
36+
malloc_mark_sweep = ["mmtk/malloc_mark_sweep"]
37+
vo_bit = ["mmtk/vo_bit"]
38+
extreme_assertions = ["mmtk/extreme_assertions"]
39+
nogc_lock_free=["mmtk/nogc_lock_free"]
40+
41+
# Feature to control which benchmarks to run. See benches/main.rs
42+
bench_sft = []
43+
bench_alloc = []

dummyvm/api/mmtk.h

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// This is an example of native API for the single instance MMTk.
2+
3+
// Note: the mmtk core does not directly provide this API. However, it provides
4+
// a similar multi-instance Rust API. A VM binding should write their own C
5+
// header file (possibly based on this example with their own extension and
6+
// modification), and expose the Rust API based on their native API.
7+
8+
#ifndef MMTK_H
9+
#define MMTK_H
10+
11+
#include <stdbool.h>
12+
#include <stddef.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
typedef void* MMTk_Mutator;
19+
20+
// Initialize an MMTk instance
21+
extern void mmtk_init(size_t heap_size);
22+
23+
// Request MMTk to create a new mutator for the given `tls` thread
24+
extern MMTk_Mutator mmtk_bind_mutator(void* tls);
25+
26+
// Reclaim mutator that is no longer needed
27+
extern void mmtk_destroy_mutator(MMTk_Mutator mutator);
28+
29+
// Flush mutator local state
30+
extern void mmtk_flush_mutator(MMTk_Mutator mutator);
31+
32+
// Initialize MMTk scheduler and GC workers
33+
extern void mmtk_initialize_collection(void* tls);
34+
35+
// Allow MMTk to perform a GC when the heap is full
36+
extern void mmtk_enable_collection();
37+
38+
// Disallow MMTk to perform a GC when the heap is full
39+
extern void mmtk_disable_collection();
40+
41+
// Allocate memory for an object
42+
extern void* mmtk_alloc(MMTk_Mutator mutator,
43+
size_t size,
44+
size_t align,
45+
size_t offset,
46+
int allocator);
47+
48+
// Slowpath allocation for an object
49+
extern void* mmtk_alloc_slow(MMTk_Mutator mutator,
50+
size_t size,
51+
size_t align,
52+
size_t offset,
53+
int allocator);
54+
55+
// Perform post-allocation hooks or actions such as initializing object metadata
56+
extern void mmtk_post_alloc(MMTk_Mutator mutator,
57+
void* refer,
58+
int bytes,
59+
int allocator);
60+
61+
// Return if the object pointed to by `ref` is live
62+
extern bool mmtk_is_live_object(void* ref);
63+
64+
// Return if the object pointed to by `ref` is in mapped memory
65+
extern bool mmtk_is_mapped_object(void* ref);
66+
67+
// Return if the address pointed to by `addr` is in mapped memory
68+
extern bool mmtk_is_mapped_address(void* addr);
69+
70+
// Return if object pointed to by `object` will never move
71+
extern bool mmtk_will_never_move(void* object);
72+
73+
// Process an MMTk option. Return true if option was processed successfully
74+
extern bool mmtk_process(char* name, char* value);
75+
76+
// Process MMTk options. Return true if all options were processed successfully
77+
extern bool mmtk_process_bulk(char* options);
78+
79+
// Sanity only. Scan heap for discrepancies and errors
80+
extern void mmtk_scan_region();
81+
82+
// Request MMTk to trigger a GC. Note that this may not actually trigger a GC
83+
extern void mmtk_handle_user_collection_request(void* tls);
84+
85+
// Run the main loop for the GC controller thread. Does not return
86+
extern void mmtk_start_control_collector(void* tls, void* worker);
87+
88+
// Run the main loop for a GC worker. Does not return
89+
extern void mmtk_start_worker(void* tls, void* worker);
90+
91+
// Return the current amount of free memory in bytes
92+
extern size_t mmtk_free_bytes();
93+
94+
// Return the current amount of used memory in bytes
95+
extern size_t mmtk_used_bytes();
96+
97+
// Return the current amount of total memory in bytes
98+
extern size_t mmtk_total_bytes();
99+
100+
// Return the starting address of MMTk's heap
101+
extern void* mmtk_starting_heap_address();
102+
103+
// Return the ending address of MMTk's heap
104+
extern void* mmtk_last_heap_address();
105+
106+
// Add a reference to the list of weak references
107+
extern void mmtk_add_weak_candidate(void* ref);
108+
109+
// Add a reference to the list of soft references
110+
extern void mmtk_add_soft_candidate(void* ref);
111+
112+
// Add a reference to the list of phantom references
113+
extern void mmtk_add_phantom_candidate(void* ref);
114+
115+
// Generic hook to allow benchmarks to be harnessed
116+
extern void mmtk_harness_begin(void* tls);
117+
118+
// Generic hook to allow benchmarks to be harnessed
119+
extern void mmtk_harness_end();
120+
121+
#ifdef __cplusplus
122+
}
123+
#endif
124+
125+
#endif // MMTK_H

dummyvm/benches/bench_alloc.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use criterion::{criterion_group, Criterion};
2+
3+
use mmtk::plan::AllocationSemantics;
4+
use mmtk_dummyvm::api;
5+
use mmtk_dummyvm::test_fixtures::MutatorFixture;
6+
7+
fn alloc(c: &mut Criterion) {
8+
println!("Init MMTK in alloc bench");
9+
// 1GB so we are unlikely to OOM
10+
let fixture = MutatorFixture::create_with_heapsize(1 << 30);
11+
c.bench_function("alloc", |b| {
12+
b.iter(|| {
13+
let _addr = api::mmtk_alloc(fixture.mutator, 8, 8, 0, AllocationSemantics::Default);
14+
})
15+
});
16+
}
17+
18+
criterion_group!(benches, alloc);

dummyvm/benches/bench_sft.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use criterion::{black_box, criterion_group, Criterion};
2+
3+
use mmtk::plan::AllocationSemantics;
4+
use mmtk::vm::ObjectModel;
5+
use mmtk_dummyvm::api;
6+
use mmtk_dummyvm::test_fixtures::FixtureContent;
7+
use mmtk_dummyvm::test_fixtures::MutatorFixture;
8+
9+
fn sft(c: &mut Criterion) {
10+
println!("Init MMTK in sft bench");
11+
let fixture = MutatorFixture::create();
12+
let addr = api::mmtk_alloc(fixture.mutator, 8, 8, 0, AllocationSemantics::Default);
13+
let obj = mmtk_dummyvm::object_model::VMObjectModel::address_to_ref(addr);
14+
15+
c.bench_function("sft read", |b| {
16+
b.iter(|| api::mmtk_is_in_mmtk_spaces(black_box(obj)))
17+
});
18+
}
19+
20+
criterion_group!(benches, sft);

dummyvm/benches/main.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use criterion::criterion_main;
2+
3+
// As we can only initialize one MMTk instance, we have to run each benchmark separately.
4+
// Filtering like `cargo bench -- sft` won't work, as it still evalutes all the benchmark groups (which initialize MMTk).
5+
// We can use conditional compilation, and run with `cargo bench --features bench_sft`. The features are defined in the dummy VM crate.
6+
7+
#[cfg(feature = "bench_sft")]
8+
mod bench_sft;
9+
#[cfg(feature = "bench_sft")]
10+
criterion_main!(bench_sft::benches);
11+
12+
#[cfg(feature = "bench_alloc")]
13+
mod bench_alloc;
14+
#[cfg(feature = "bench_alloc")]
15+
criterion_main!(bench_alloc::benches);

dummyvm/src/active_plan.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::DummyVM;
2+
use mmtk::util::opaque_pointer::*;
3+
use mmtk::vm::ActivePlan;
4+
use mmtk::Mutator;
5+
6+
pub struct VMActivePlan {}
7+
8+
impl ActivePlan<DummyVM> for VMActivePlan {
9+
fn number_of_mutators() -> usize {
10+
unimplemented!()
11+
}
12+
13+
fn is_mutator(_tls: VMThread) -> bool {
14+
// FIXME
15+
true
16+
}
17+
18+
fn mutator(_tls: VMMutatorThread) -> &'static mut Mutator<DummyVM> {
19+
unimplemented!()
20+
}
21+
22+
fn mutators<'a>() -> Box<dyn Iterator<Item = &'a mut Mutator<DummyVM>> + 'a> {
23+
unimplemented!()
24+
}
25+
}

0 commit comments

Comments
 (0)