Skip to content

Commit 401803c

Browse files
qinsoonk-sareenwks
authored
Add back DummyVM as a part of the porting guide. Minor changes to MMTk initialization in the porting guide. (#1142)
Following the discussion here: https://mmtk.zulipchat.com/#narrow/stream/315620-Porting/topic/Porting.20MMTK.20to.20Clasp.20Common.20Lisp/near/442123897. It is useful for the language implementers to have a Rust binding crate that implements all the boilerplate code and can compile to start with. This PR adds back `DummyVM` to the porting guide, and includes some minor changes to the porting guide. --------- Co-authored-by: Kunal Sareen <kunal.sareen@anu.edu.au> Co-authored-by: Kunshan Wang <wks1986@gmail.com>
1 parent a9b619a commit 401803c

File tree

15 files changed

+690
-48
lines changed

15 files changed

+690
-48
lines changed

.github/scripts/ci-common.sh

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ project_root=$(dirname "$0")/../..
77

88
cargo_toml=$project_root/Cargo.toml
99

10+
dummyvm_toml=$project_root/docs/dummyvm/Cargo.toml
11+
1012
# Repeat a command for all the features. Requires the command as one argument (with double quotes)
1113
for_all_features() {
1214
# without mutually exclusive features

.github/scripts/ci-doc.sh

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ if ! cat $project_root/src/plan/mod.rs | grep -q "pub mod mygc;"; then
2222
fi
2323
cargo build
2424

25+
# Check dummyvm in portingguide
26+
cargo build --manifest-path $dummyvm_toml
27+
2528
# Install mdbook using the stable toolchain and the default target
2629
unset CARGO_BUILD_TARGET
2730
cargo +stable install mdbook mdbook-admonish mdbook-hide

.github/scripts/ci-style.sh

+1
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ style_check_auxiliary_crate() {
5151
}
5252

5353
style_check_auxiliary_crate macros
54+
style_check_auxiliary_crate docs/dummyvm

.github/scripts/ci-test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ find ./src ./tests -type f -name "mock_test_*" | while read -r file; do
3737
env MMTK_PLAN=$MMTK_PLAN cargo test --features mock_test,"$FEATURES" -- $t;
3838
done
3939
done
40+
41+
# Test the dummy VM
42+
cargo test --manifest-path $dummyvm_toml

docs/dummyvm/Cargo.toml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
crate-type = ["cdylib"]
12+
13+
[profile.release]
14+
lto = true
15+
16+
[dependencies]
17+
# We use a local path as the MMTk dependency here, as we want to test the code with the current version.
18+
# Generally for a binding, you would like to use a specific version, or a git commit.
19+
# mmtk = "0.25.0"
20+
# mmtk = { git = "https://github.com/mmtk/mmtk-core.git", branch = "master" }
21+
mmtk = { path = "../../." }
22+
libc = "0.2"
23+
atomic = "0.6"
24+
25+
[features]
26+
default = []
27+
is_mmtk_object = ["mmtk/is_mmtk_object"]
28+
malloc_counted_size = ["mmtk/malloc_counted_size"]

docs/dummyvm/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
An example of MMTk/Rust-side Binding Implementation
2+
===
3+
4+
A binding needs to implement certain Rust traits and may need to expose MMTk's Rust API to native code.
5+
This Rust crate illustrates a minimal example of what needs to be implemented on the binding side in Rust.
6+
When starting a new port of MMTk, developers can use this crate as a starting point by directly copying
7+
it to their port. For more details, see [the porting guide](https://docs.mmtk.io/portingguide/howto/nogc.html#set-up).

docs/header/mmtk.h docs/dummyvm/include/mmtk.h

+50-45
Original file line numberDiff line numberDiff line change
@@ -17,84 +17,62 @@ extern "C" {
1717

1818
typedef void* MMTk_Mutator;
1919
typedef void* MMTk_Builder;
20-
typedef void* MMTk;
2120

2221
// Initialize an MMTk instance
23-
extern MMTk mmtk_init(MMTk_Builder builder);
22+
extern void mmtk_init(MMTk_Builder builder);
2423

2524
// Request MMTk to create a new mutator for the given `tls` thread
2625
extern MMTk_Mutator mmtk_bind_mutator(void* tls);
2726

2827
// Reclaim mutator that is no longer needed
2928
extern void mmtk_destroy_mutator(MMTk_Mutator mutator);
3029

31-
// Flush mutator local state
32-
extern void mmtk_flush_mutator(MMTk_Mutator mutator);
33-
34-
// Initialize MMTk scheduler and GC workers
35-
extern void mmtk_initialize_collection(void* tls);
36-
3730
// Allocate memory for an object
3831
extern void* mmtk_alloc(MMTk_Mutator mutator,
3932
size_t size,
4033
size_t align,
4134
size_t offset,
4235
int allocator);
4336

44-
// Slowpath allocation for an object
45-
extern void* mmtk_alloc_slow(MMTk_Mutator mutator,
46-
size_t size,
47-
size_t align,
48-
size_t offset,
49-
int allocator);
50-
5137
// Perform post-allocation hooks or actions such as initializing object metadata
5238
extern void mmtk_post_alloc(MMTk_Mutator mutator,
5339
void* refer,
5440
int bytes,
5541
int allocator);
5642

57-
// Return if the object pointed to by `ref` is live
58-
extern bool mmtk_is_live_object(void* ref);
59-
60-
// Return if the object pointed to by `ref` is in mapped memory
61-
extern bool mmtk_is_mapped_object(void* ref);
62-
63-
// Return if the address pointed to by `addr` is in mapped memory
64-
extern bool mmtk_is_mapped_address(void* addr);
65-
66-
// Return if object pointed to by `object` will never move
67-
extern bool mmtk_will_never_move(void* object);
68-
69-
// Process an MMTk option. Return true if option was processed successfully
70-
extern bool mmtk_process(MMTk_Builder builder, char* name, char* value);
71-
72-
// Process MMTk options. Return true if all options were processed successfully
73-
extern bool mmtk_process_bulk(MMTk_Builder builder, char* options);
74-
75-
// Sanity only. Scan heap for discrepancies and errors
76-
extern void mmtk_scan_region();
77-
78-
// Request MMTk to trigger a GC. Note that this may not actually trigger a GC
79-
extern void mmtk_handle_user_collection_request(void* tls);
80-
8143
// Run the main loop for a GC worker. Does not return
8244
extern void mmtk_start_worker(void* tls, void* worker);
8345

84-
// Return the current amount of free memory in bytes
85-
extern size_t mmtk_free_bytes();
46+
// Initialize MMTk scheduler and GC workers
47+
extern void mmtk_initialize_collection(void* tls);
8648

8749
// Return the current amount of used memory in bytes
8850
extern size_t mmtk_used_bytes();
8951

52+
// Return the current amount of free memory in bytes
53+
extern size_t mmtk_free_bytes();
54+
9055
// Return the current amount of total memory in bytes
9156
extern size_t mmtk_total_bytes();
9257

93-
// Return the starting address of MMTk's heap
94-
extern void* mmtk_starting_heap_address();
58+
// Return if the object pointed to by `object` is live
59+
extern bool mmtk_is_live_object(void* object);
9560

96-
// Return the ending address of MMTk's heap
97-
extern void* mmtk_last_heap_address();
61+
// Return if object pointed to by `object` will never move
62+
extern bool mmtk_will_never_move(void* object);
63+
64+
// Return if the address is an object in MMTk heap.
65+
// Only available when the feature is_mmtk_object is enabled.
66+
extern bool mmtk_is_mmtk_object(void* addr);
67+
68+
// Return if the object is in any MMTk space.
69+
extern bool mmtk_is_in_mmtk_spaces(void* object);
70+
71+
// Return if the address pointed to by `addr` is in memory that is mapped by MMTk
72+
extern bool mmtk_is_mapped_address(void* addr);
73+
74+
// Request MMTk to trigger a GC. Note that this may not actually trigger a GC
75+
extern void mmtk_handle_user_collection_request(void* tls);
9876

9977
// Add a reference to the list of weak references
10078
extern void mmtk_add_weak_candidate(void* ref);
@@ -111,6 +89,33 @@ extern void mmtk_harness_begin(void* tls);
11189
// Generic hook to allow benchmarks to be harnessed
11290
extern void mmtk_harness_end();
11391

92+
// Create an MMTKBuilder
93+
extern MMTk_Builder mmtk_create_builder();
94+
95+
// Process an MMTk option. Return true if option was processed successfully
96+
extern bool mmtk_process(MMTk_Builder builder, char* name, char* value);
97+
98+
// Return the starting address of MMTk's heap
99+
extern void* mmtk_starting_heap_address();
100+
101+
// Return the ending address of MMTk's heap
102+
extern void* mmtk_last_heap_address();
103+
104+
// Standard malloc functions
105+
extern void* mmtk_malloc(size_t size);
106+
extern void* mmtk_calloc(size_t num, size_t size);
107+
extern void* mmtk_realloc(void* addr, size_t size);
108+
extern void* mmtk_free(void* addr);
109+
110+
// Counted versions of the malloc functions. The allocation size will be ounted into the MMTk heap.
111+
// Only available when the feature malloc_counted_size is enabled.
112+
extern void* mmtk_counted_malloc(size_t size);
113+
extern void* mmtk_counted_calloc(size_t num, size_t size);
114+
extern void* mmtk_realloc_with_old_size(void* addr, size_t size, size_t old_size);
115+
extern void* mmtk_free_with_size(void* addr, size_t old_size);
116+
// Get the number of active bytes in malloc.
117+
extern size_t mmtk_get_malloc_bytes();
118+
114119
#ifdef __cplusplus
115120
}
116121
#endif

docs/dummyvm/src/active_plan.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// Documentation: https://docs.mmtk.io/api/mmtk/vm/active_plan/trait.ActivePlan.html
9+
impl ActivePlan<DummyVM> for VMActivePlan {
10+
fn number_of_mutators() -> usize {
11+
unimplemented!()
12+
}
13+
14+
fn is_mutator(_tls: VMThread) -> bool {
15+
// FIXME: Properly check if the thread is a mutator
16+
true
17+
}
18+
19+
fn mutator(_tls: VMMutatorThread) -> &'static mut Mutator<DummyVM> {
20+
unimplemented!()
21+
}
22+
23+
fn mutators<'a>() -> Box<dyn Iterator<Item = &'a mut Mutator<DummyVM>> + 'a> {
24+
unimplemented!()
25+
}
26+
}

0 commit comments

Comments
 (0)