1
1
// This is an example of native API for the single instance MMTk.
2
2
3
- // Note: the mmtk core does not directly provide this API. However, it provides a similar multi-instance Rust API.
4
- // A VM binding should write their own C header file (possibly based on this example with their own extension and modification),
5
- // and expose the Rust API based on their native API.
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.
6
7
7
8
#ifndef MMTK_H
8
9
#define MMTK_H
@@ -15,79 +16,113 @@ extern "C" {
15
16
#endif
16
17
17
18
typedef void * MMTk_Mutator ;
18
- typedef void * MMTk_TraceLocal ;
19
19
20
- /**
21
- * Allocation
22
- */
23
- extern MMTk_Mutator bind_mutator (void * tls );
24
- extern void destroy_mutator (MMTk_Mutator mutator );
20
+ // Initialize an MMTk instance
21
+ extern void mmtk_gc_init (size_t heap_size );
25
22
26
- extern void * alloc ( MMTk_Mutator mutator , size_t size ,
27
- size_t align , ssize_t offset , int allocator );
23
+ // Request MMTk to create a new mutator for the given `tls` thread
24
+ extern MMTk_Mutator mmtk_bind_mutator ( void * tls );
28
25
29
- extern void * alloc_slow ( MMTk_Mutator mutator , size_t size ,
30
- size_t align , ssize_t offset , int allocator );
26
+ // Reclaim mutator that is no longer needed
27
+ extern void mmtk_destroy_mutator ( MMTk_Mutator mutator );
31
28
32
- extern void post_alloc ( MMTk_Mutator mutator , void * refer , void * type_refer ,
33
- int bytes , int allocator );
29
+ // Flush mutator local state
30
+ extern void mmtk_flush_mutator ( MMTk_Mutator mutator );
34
31
35
- extern bool is_live_object (void * ref );
36
- extern bool is_mapped_object (void * ref );
37
- extern bool is_mapped_address (void * addr );
38
- extern void modify_check (void * ref );
32
+ // Initialize MMTk scheduler and GC workers
33
+ extern void mmtk_initialize_collection (void * tls );
39
34
40
- /**
41
- * Tracing
42
- */
43
- extern void report_delayed_root_edge (MMTk_TraceLocal trace_local ,
44
- void * addr );
35
+ // Allow MMTk to perform a GC when the heap is full
36
+ extern void mmtk_enable_collection ();
45
37
46
- extern bool will_not_move_in_current_collection ( MMTk_TraceLocal trace_local ,
47
- void * obj );
38
+ // Disallow MMTk to perform a GC when the heap is full
39
+ extern void mmtk_disable_collection ( );
48
40
49
- extern void process_interior_edge (MMTk_TraceLocal trace_local , void * target ,
50
- void * slot , bool root );
41
+ // Allocate memory for an object
42
+ extern void * mmtk_alloc (MMTk_Mutator mutator ,
43
+ size_t size ,
44
+ size_t align ,
45
+ ssize_t offset ,
46
+ int allocator );
51
47
52
- extern void * trace_get_forwarded_referent (MMTk_TraceLocal trace_local , void * obj );
48
+ // Slowpath allocation for an object
49
+ extern void * mmtk_alloc_slow (MMTk_Mutator mutator ,
50
+ size_t size ,
51
+ size_t align ,
52
+ ssize_t offset ,
53
+ int allocator );
53
54
54
- extern void * trace_get_forwarded_reference (MMTk_TraceLocal trace_local , void * obj );
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 );
55
60
56
- extern void * trace_retain_referent (MMTk_TraceLocal trace_local , void * obj );
61
+ // Return if the object pointed to by `ref` is live
62
+ extern bool mmtk_is_live_object (void * ref );
57
63
58
- /**
59
- * Misc
60
- */
61
- extern void gc_init (size_t heap_size );
62
- extern bool will_never_move (void * object );
63
- extern bool process (char * name , char * value );
64
- extern void scan_region ();
65
- extern void handle_user_collection_request (void * tls );
64
+ // Return if the object pointed to by `ref` is in mapped memory
65
+ extern bool mmtk_is_mapped_object (void * ref );
66
66
67
- extern void start_control_collector ( void * tls );
68
- extern void start_worker (void * tls , void * worker );
67
+ // Return if the address pointed to by `addr` is in mapped memory
68
+ extern bool mmtk_is_mapped_address (void * addr );
69
69
70
- /**
71
- * VM Accounting
72
- */
73
- extern size_t free_bytes ();
74
- extern size_t total_bytes ();
75
- extern size_t used_bytes ();
76
- extern void * starting_heap_address ();
77
- extern void * last_heap_address ();
70
+ // Check if a GC is in progress and if the object `ref` is movable
71
+ extern void mmtk_modify_check (void * ref );
78
72
79
- /**
80
- * Reference Processing
81
- */
82
- extern void add_weak_candidate (void * ref , void * referent );
83
- extern void add_soft_candidate (void * ref , void * referent );
84
- extern void add_phantom_candidate (void * ref , void * referent );
73
+ // Return if object pointed to by `object` will never move
74
+ extern bool mmtk_will_never_move (void * object );
85
75
86
- extern void harness_begin (void * tls );
87
- extern void harness_end ();
76
+ // Process an MMTk option. Return true if option was processed successfully
77
+ extern bool mmtk_process (char * name , char * value );
78
+
79
+ // Process MMTk options. Return true if all options were processed successfully
80
+ extern bool mmtk_process_bulk (char * options );
81
+
82
+ // Sanity only. Scan heap for discrepancies and errors
83
+ extern void mmtk_scan_region ();
84
+
85
+ // Request MMTk to trigger a GC. Note that this may not actually trigger a GC
86
+ extern void mmtk_handle_user_collection_request (void * tls );
87
+
88
+ // Run the main loop for the GC controller thread. Does not return
89
+ extern void mmtk_start_control_collector (void * tls );
90
+
91
+ // Run the main loop for a GC worker. Does not return
92
+ extern void mmtk_start_worker (void * tls , void * worker );
93
+
94
+ // Return the current amount of free memory in bytes
95
+ extern size_t mmtk_free_bytes ();
96
+
97
+ // Return the current amount of used memory in bytes
98
+ extern size_t mmtk_used_bytes ();
99
+
100
+ // Return the current amount of total memory in bytes
101
+ extern size_t mmtk_total_bytes ();
102
+
103
+ // Return the starting address of MMTk's heap
104
+ extern void * mmtk_starting_heap_address ();
105
+
106
+ // Return the ending address of MMTk's heap
107
+ extern void * mmtk_last_heap_address ();
108
+
109
+ // Add a reference to the list of weak references
110
+ extern void mmtk_add_weak_candidate (void * ref , void * referent );
111
+
112
+ // Add a reference to the list of soft references
113
+ extern void mmtk_add_soft_candidate (void * ref , void * referent );
114
+
115
+ // Add a reference to the list of phantom references
116
+ extern void mmtk_add_phantom_candidate (void * ref , void * referent );
117
+
118
+ // Generic hook to allow benchmarks to be harnessed
119
+ extern void mmtk_harness_begin (void * tls );
120
+
121
+ // Generic hook to allow benchmarks to be harnessed
122
+ extern void mmtk_harness_end ();
88
123
89
124
#ifdef __cplusplus
90
125
}
91
126
#endif
92
127
93
- #endif // MMTK_H
128
+ #endif // MMTK_H
0 commit comments