summaryrefslogtreecommitdiff
path: root/runtime/gc/heap.h
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2014-05-06 10:57:27 -0700
committer Mathieu Chartier <mathieuc@google.com> 2014-05-07 15:28:35 -0700
commit78f7b4c04ab6e8b5581921bc95b67a9beee1c246 (patch)
tree78b93c72007478b5bfc3b88ab413fa3d772da723 /runtime/gc/heap.h
parent052a647973b590c9d5007a2e16f313f4e32a70bd (diff)
Add concurrent reference processing.
Concurrent reference processing currently works by going into native code from java.lang.ref.Reference.get(). From there, we have a fast path if the references aren't being processed which returns the referent without needing to access any locks. In the slow path we block until reference processing is complete. It may be possible to improve the slow path if the referent is blackened. TODO: Investigate doing the fast path in java code by using racy reads of a static volatile boolean. This will work as long as there are no suspend points inbetween the boolean read and referent read. Bug: 14381653 Change-Id: I1546b55be4691fe4ff4aa6d857b234cce7187d87
Diffstat (limited to 'runtime/gc/heap.h')
-rw-r--r--runtime/gc/heap.h40
1 files changed, 11 insertions, 29 deletions
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 7a9ef1e3b1..f71de1ac89 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -35,7 +35,7 @@
#include "jni.h"
#include "object_callbacks.h"
#include "offsets.h"
-#include "reference_queue.h"
+#include "reference_processor.h"
#include "safe_map.h"
#include "thread_pool.h"
#include "verify_object.h"
@@ -54,6 +54,9 @@ namespace mirror {
} // namespace mirror
namespace gc {
+
+class ReferenceProcessor;
+
namespace accounting {
class HeapBitmap;
class ModUnionTable;
@@ -215,7 +218,7 @@ class Heap {
// Check sanity of all live references.
void VerifyHeap() LOCKS_EXCLUDED(Locks::heap_bitmap_lock_);
- bool VerifyHeapReferences()
+ bool VerifyHeapReferences(bool verify_referents = true)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
bool VerifyMissingCardMarks()
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
@@ -314,21 +317,6 @@ class Heap {
return discontinuous_spaces_;
}
- static mirror::Object* PreserveSoftReferenceCallback(mirror::Object* obj, void* arg);
- void ProcessSoftReferences(TimingLogger& timings, bool clear_soft,
- IsMarkedCallback* is_marked_callback,
- MarkObjectCallback* mark_object_callback,
- ProcessMarkStackCallback* process_mark_stack_callback, void* arg)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
- EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
- void ProcessReferences(TimingLogger& timings, bool clear_soft,
- IsMarkedCallback* is_marked_callback,
- MarkObjectCallback* mark_object_callback,
- ProcessMarkStackCallback* process_mark_stack_callback,
- void* arg)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
- EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
-
// Enable verification of object references when the runtime is sufficiently initialized.
void EnableObjectValidation() {
verify_object_mode_ = kVerifyObjectSupport;
@@ -565,6 +553,10 @@ class Heap {
}
bool HasImageSpace() const;
+ ReferenceProcessor* GetReferenceProcessor() {
+ return &reference_processor_;
+ }
+
private:
void Compact(space::ContinuousMemMapAllocSpace* target_space,
space::ContinuousMemMapAllocSpace* source_space)
@@ -631,12 +623,6 @@ class Heap {
bool IsValidContinuousSpaceObjectAddress(const mirror::Object* obj) const
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- void EnqueueClearedReferences();
- // Returns true if the reference object has not yet been enqueued.
- void DelayReferenceReferent(mirror::Class* klass, mirror::Reference* ref,
- IsMarkedCallback is_marked_callback, void* arg)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
// Run the finalizers.
void RunFinalization(JNIEnv* env);
@@ -797,12 +783,8 @@ class Heap {
Mutex* gc_complete_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
UniquePtr<ConditionVariable> gc_complete_cond_ GUARDED_BY(gc_complete_lock_);
- // Reference queues.
- ReferenceQueue soft_reference_queue_;
- ReferenceQueue weak_reference_queue_;
- ReferenceQueue finalizer_reference_queue_;
- ReferenceQueue phantom_reference_queue_;
- ReferenceQueue cleared_references_;
+ // Reference processor;
+ ReferenceProcessor reference_processor_;
// True while the garbage collector is running.
volatile CollectorType collector_type_running_ GUARDED_BY(gc_complete_lock_);