Skip to content

Commit

Permalink
Fix GCWorker ownership
Browse files Browse the repository at this point in the history
GCWorker instances are now owned by worker threads.  This eliminated a
need of unsafely converting &GCWorker to &mut GCWorker.
  • Loading branch information
wks committed Jan 17, 2022
1 parent 1ee047d commit cbe670a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub extern "C" fn will_never_move(object: ObjectReference) -> bool {
// We trust the worker pointer is valid.
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn start_worker(tls: VMWorkerThread, worker: *mut GCWorker<OpenJDK>) {
memory_manager::start_worker::<OpenJDK>(tls, unsafe { worker.as_mut().unwrap() }, &SINGLETON)
let mut worker = unsafe { Box::from_raw(worker) };
memory_manager::start_worker::<OpenJDK>(tls, &mut worker, &SINGLETON)
}

#[no_mangle]
Expand Down
4 changes: 2 additions & 2 deletions mmtk/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl Collection<OpenJDK> for VMCollection {
}
}

fn spawn_worker_thread(tls: VMThread, ctx: Option<&GCWorker<OpenJDK>>) {
fn spawn_worker_thread(tls: VMThread, ctx: Option<Box<GCWorker<OpenJDK>>>) {
let ctx_ptr = if let Some(r) = ctx {
r as *const GCWorker<OpenJDK> as *mut GCWorker<OpenJDK>
unsafe { Box::into_raw(r) }
} else {
std::ptr::null_mut()
};
Expand Down

0 comments on commit cbe670a

Please sign in to comment.