summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hans Boehm <hboehm@google.com> 2024-06-24 16:07:06 -0700
committer Hans Boehm <hboehm@google.com> 2024-06-26 16:21:00 +0000
commit22a9432fde26d356211f435c0e7bc395c6e91b52 (patch)
tree5c9601bf9335c2fa7efa9efa0e95dec8b0ca526c
parentef83ca8a6c42dddf8e2903827fbacb733ab0e3b8 (diff)
Better document GcRoot
Based on discussion with Nicolas and Lokesh. Test: Treehugger; comment-only change Change-Id: Ic58b2a3baf9c264174d1ee4aee7b409c16ea9f18
-rw-r--r--runtime/gc_root.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/runtime/gc_root.h b/runtime/gc_root.h
index da9d3af6cb..ea85ca7de8 100644
--- a/runtime/gc_root.h
+++ b/runtime/gc_root.h
@@ -183,6 +183,10 @@ class GcRootSource {
DISALLOW_COPY_AND_ASSIGN(GcRootSource);
};
+// A small CompressedReference wrapper class that makes it harder to forget about read barriers.
+// Used for references that are roots for an object graph, whether or not they are actually traced
+// from. Requires an explicit VisitRoots call for tracing. See also Handle (implicitly traced by a
+// GC) and StackReference (traced explicitly, but not as the result of a read barrier).
template<class MirrorType>
class GcRoot {
public:
@@ -190,6 +194,10 @@ class GcRoot {
ALWAYS_INLINE MirrorType* Read(GcRootSource* gc_root_source = nullptr) const
REQUIRES_SHARED(Locks::mutator_lock_);
+ // TODO: This is often called repeatedly from functions to process an explicit array of roots.
+ // And it calls a function that takes an array of roots. By processing a single root at a time
+ // here and turning it into a 1-element array, do we lose performance? Or does the compiler
+ // eliminate the extra work?
void VisitRoot(RootVisitor* visitor, const RootInfo& info) const
REQUIRES_SHARED(Locks::mutator_lock_) {
DCHECK(!IsNull());