Skip to content

Return if a GC ran or not for handle_user_collection_request #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/memory_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,21 @@ pub fn total_bytes<VM: VMBinding>(mmtk: &MMTK<VM>) -> usize {
mmtk.get_plan().get_total_pages() << LOG_BYTES_IN_PAGE
}

/// Trigger a garbage collection as requested by the user.
/// The application code has requested a collection. This is just a GC hint, and
/// we may ignore it.
///
/// Returns whether a GC was ran or not. If MMTk triggers a GC, this method will block the
/// calling thread and return true when the GC finishes. Otherwise, this method returns
/// false immediately.
///
/// Arguments:
/// * `mmtk`: A reference to an MMTk instance.
/// * `tls`: The thread that triggers this collection request.
pub fn handle_user_collection_request<VM: VMBinding>(mmtk: &MMTK<VM>, tls: VMMutatorThread) {
mmtk.handle_user_collection_request(tls, false, false);
pub fn handle_user_collection_request<VM: VMBinding>(
mmtk: &MMTK<VM>,
tls: VMMutatorThread,
) -> bool {
mmtk.handle_user_collection_request(tls, false, false)
}

/// Is the object alive?
Expand Down
11 changes: 9 additions & 2 deletions src/mmtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ impl<VM: VMBinding> MMTK<VM> {
/// The application code has requested a collection. This is just a GC hint, and
/// we may ignore it.
///
/// Returns whether a GC was ran or not. If MMTk triggers a GC, this method will block the
/// calling thread and return true when the GC finishes. Otherwise, this method returns
/// false immediately.
///
/// # Arguments
/// * `tls`: The mutator thread that requests the GC
/// * `force`: The request cannot be ignored (except for NoGC)
Expand All @@ -412,11 +416,11 @@ impl<VM: VMBinding> MMTK<VM> {
tls: VMMutatorThread,
force: bool,
exhaustive: bool,
) {
) -> bool {
use crate::vm::Collection;
if !self.get_plan().constraints().collects_garbage {
warn!("User attempted a collection request, but the plan can not do GC. The request is ignored.");
return;
return false;
}

if force || !*self.options.ignore_system_gc && VM::VMCollection::is_collection_enabled() {
Expand All @@ -432,7 +436,10 @@ impl<VM: VMBinding> MMTK<VM> {
.store(true, Ordering::Relaxed);
self.gc_requester.request();
VM::VMCollection::block_for_gc(tls);
return true;
}

false
}

/// MMTK has requested stop-the-world activity (e.g., stw within a concurrent gc).
Expand Down
Loading