From 757e6cc7782d22891d47de3abe4b98615e114b66 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Tue, 24 Oct 2023 17:28:38 +0800 Subject: [PATCH] Expose `is_emergency_collection` to VM bindings --- src/mmtk.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/mmtk.rs b/src/mmtk.rs index b5487addc0..12f3e77cba 100644 --- a/src/mmtk.rs +++ b/src/mmtk.rs @@ -272,6 +272,24 @@ impl MMTK { *self.state.gc_status.lock().unwrap() == GcStatus::GcProper } + /// Return true if the current GC is an emergency GC. + /// + /// An emergency GC happens when a normal GC cannot reclaim enough memory to satisfy allocation + /// requests. Plans may do full-heap GC, defragmentation, etc. during emergency in order to + /// free up more memory. + /// + /// VM bindings can call this function during GC to check if the current GC is an emergency GC. + /// If it is, the VM binding is recommended to retain fewer objects than normal GCs, to the + /// extent allowed by the specification of the VM or langauge. For example, the VM binding may + /// choose not to retain objects used for caching. Specifically, for Java virtual machines, + /// that means not retaining referents of [`SoftReference`][java-soft-ref] which is primarily + /// designed for implementing memory-sensitive caches. + /// + /// [java-soft-ref]: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/ref/SoftReference.html + pub fn is_emergency_collection(&self) -> bool { + self.state.is_emergency_collection() + } + /// The application code has requested a collection. This is just a GC hint, and /// we may ignore it. ///