-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathlib.rs
More file actions
190 lines (165 loc) · 6.83 KB
/
lib.rs
File metadata and controls
190 lines (165 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#[macro_use]
extern crate lazy_static;
use std::collections::HashMap;
use std::ops::Range;
use std::ptr::null_mut;
use std::sync::atomic::AtomicUsize;
use std::sync::Mutex;
use libc::{c_char, c_void, uintptr_t};
use mmtk::util::alloc::AllocationError;
use mmtk::util::opaque_pointer::*;
use mmtk::util::{Address, ObjectReference};
use mmtk::vm::VMBinding;
use mmtk::{MMTKBuilder, Mutator, MMTK};
mod abi;
pub mod active_plan;
pub mod api;
mod build_info;
pub mod collection;
mod gc_work;
pub mod object_model;
mod object_scanning;
pub mod reference_glue;
pub mod scanning;
pub(crate) mod vm_metadata;
#[repr(C)]
pub struct NewBuffer {
pub ptr: *mut Address,
pub capacity: usize,
}
/// A closure for reporting mutators. The C++ code should pass `data` back as the last argument.
#[repr(C)]
pub struct MutatorClosure {
pub func: extern "C" fn(mutator: *mut Mutator<OpenJDK>, data: *mut libc::c_void),
pub data: *mut libc::c_void,
}
impl MutatorClosure {
fn from_rust_closure<F>(callback: &mut F) -> Self
where
F: FnMut(&'static mut Mutator<OpenJDK>),
{
Self {
func: Self::call_rust_closure::<F>,
data: callback as *mut F as *mut libc::c_void,
}
}
extern "C" fn call_rust_closure<F>(
mutator: *mut Mutator<OpenJDK>,
callback_ptr: *mut libc::c_void,
) where
F: FnMut(&'static mut Mutator<OpenJDK>),
{
let callback: &mut F = unsafe { &mut *(callback_ptr as *mut F) };
callback(unsafe { &mut *mutator });
}
}
/// A closure for reporting root edges. The C++ code should pass `data` back as the last argument.
#[repr(C)]
pub struct EdgesClosure {
pub func: extern "C" fn(
buf: *mut Address,
size: usize,
cap: usize,
data: *mut libc::c_void,
) -> NewBuffer,
pub data: *const libc::c_void,
}
#[repr(C)]
pub struct OpenJDK_Upcalls {
pub stop_all_mutators: extern "C" fn(
tls: VMWorkerThread,
scan_mutators_in_safepoint: bool,
closure: MutatorClosure,
),
pub resume_mutators: extern "C" fn(tls: VMWorkerThread),
pub spawn_gc_thread: extern "C" fn(tls: VMThread, kind: libc::c_int, ctx: *mut libc::c_void),
pub block_for_gc: extern "C" fn(),
pub out_of_memory: extern "C" fn(tls: VMThread, err_kind: AllocationError),
pub get_mutators: extern "C" fn(closure: MutatorClosure),
pub scan_object: extern "C" fn(trace: *mut c_void, object: ObjectReference, tls: OpaquePointer),
pub dump_object: extern "C" fn(object: ObjectReference),
pub get_object_size: extern "C" fn(object: ObjectReference) -> usize,
pub get_mmtk_mutator: extern "C" fn(tls: VMMutatorThread) -> *mut Mutator<OpenJDK>,
pub is_mutator: extern "C" fn(tls: VMThread) -> bool,
pub harness_begin: extern "C" fn(),
pub harness_end: extern "C" fn(),
pub compute_klass_mem_layout_checksum: extern "C" fn() -> usize,
pub offset_of_static_fields: extern "C" fn() -> i32,
pub static_oop_field_count_offset: extern "C" fn() -> i32,
pub referent_offset: extern "C" fn() -> i32,
pub discovered_offset: extern "C" fn() -> i32,
pub dump_object_string: extern "C" fn(object: ObjectReference) -> *const c_char,
pub scan_roots_in_all_mutator_threads: extern "C" fn(closure: EdgesClosure),
pub scan_roots_in_mutator_thread: extern "C" fn(closure: EdgesClosure, tls: VMMutatorThread),
pub scan_universe_roots: extern "C" fn(closure: EdgesClosure),
pub scan_jni_handle_roots: extern "C" fn(closure: EdgesClosure),
pub scan_object_synchronizer_roots: extern "C" fn(closure: EdgesClosure),
pub scan_management_roots: extern "C" fn(closure: EdgesClosure),
pub scan_jvmti_export_roots: extern "C" fn(closure: EdgesClosure),
pub scan_aot_loader_roots: extern "C" fn(closure: EdgesClosure),
pub scan_system_dictionary_roots: extern "C" fn(closure: EdgesClosure),
pub scan_code_cache_roots: extern "C" fn(closure: EdgesClosure),
pub scan_string_table_roots: extern "C" fn(closure: EdgesClosure),
pub scan_class_loader_data_graph_roots: extern "C" fn(closure: EdgesClosure),
pub scan_weak_processor_roots: extern "C" fn(closure: EdgesClosure),
pub scan_vm_thread_roots: extern "C" fn(closure: EdgesClosure),
pub number_of_mutators: extern "C" fn() -> usize,
pub schedule_finalizer: extern "C" fn(),
pub prepare_for_roots_re_scanning: extern "C" fn(),
pub enqueue_references: extern "C" fn(objects: *const ObjectReference, len: usize),
}
pub static mut UPCALLS: *const OpenJDK_Upcalls = null_mut();
#[no_mangle]
pub static GLOBAL_SIDE_METADATA_BASE_ADDRESS: uintptr_t =
mmtk::util::metadata::side_metadata::GLOBAL_SIDE_METADATA_BASE_ADDRESS.as_usize();
#[no_mangle]
pub static GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS: uintptr_t =
mmtk::util::metadata::side_metadata::GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS.as_usize();
#[no_mangle]
pub static VO_BIT_ADDRESS: uintptr_t =
mmtk::util::metadata::side_metadata::VO_BIT_SIDE_METADATA_ADDR.as_usize();
#[no_mangle]
pub static FREE_LIST_ALLOCATOR_SIZE: uintptr_t =
std::mem::size_of::<mmtk::util::alloc::FreeListAllocator<OpenJDK>>();
#[derive(Default)]
pub struct OpenJDK;
/// The type of edges in OpenJDK.
///
/// TODO: We currently make it an alias to Address to make the change minimal.
/// If we support CompressedOOPs, we should define an enum type to support both
/// compressed and uncompressed OOPs.
pub type OpenJDKEdge = Address;
impl VMBinding for OpenJDK {
type VMObjectModel = object_model::VMObjectModel;
type VMScanning = scanning::VMScanning;
type VMCollection = collection::VMCollection;
type VMActivePlan = active_plan::VMActivePlan;
type VMReferenceGlue = reference_glue::VMReferenceGlue;
type VMEdge = OpenJDKEdge;
type VMMemorySlice = Range<Address>;
const MIN_ALIGNMENT: usize = 8;
const MAX_ALIGNMENT: usize = 8;
const USE_ALLOCATION_OFFSET: bool = false;
}
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
pub static MMTK_INITIALIZED: AtomicBool = AtomicBool::new(false);
lazy_static! {
pub static ref BUILDER: Mutex<MMTKBuilder> = Mutex::new(MMTKBuilder::new());
pub static ref SINGLETON: MMTK<OpenJDK> = {
let builder = BUILDER.lock().unwrap();
assert!(!MMTK_INITIALIZED.load(Ordering::Relaxed));
let ret = mmtk::memory_manager::mmtk_init(&builder);
MMTK_INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
*ret
};
}
#[no_mangle]
pub static MMTK_MARK_COMPACT_HEADER_RESERVED_IN_BYTES: usize =
mmtk::util::alloc::MarkCompactAllocator::<OpenJDK>::HEADER_RESERVED_IN_BYTES;
lazy_static! {
/// A global storage for all the cached CodeCache root pointers
static ref CODE_CACHE_ROOTS: Mutex<HashMap<Address, Vec<Address>>> = Mutex::new(HashMap::new());
}
/// A counter tracking the total size of the `CODE_CACHE_ROOTS`.
static CODE_CACHE_ROOTS_SIZE: AtomicUsize = AtomicUsize::new(0);