Refactor and improve GC root handling
Changed GcRoot to use compressed references. Changed root visiting to
use virtual functions instead of function pointers. Changed root visting
interface to be an array of roots instead of a single root at a time.
Added buffered root marking helper to avoid dispatch overhead.
Root marking seems a bit faster on EvaluateAndApplyChanges due to batch
marking. Pause times unaffected.
Mips64 is untested but might work, maybe.
Before:
MarkConcurrentRoots: Sum: 67.678ms 99% C.I. 2us-664.999us Avg: 161.138us Max: 671us
After:
MarkConcurrentRoots: Sum: 54.806ms 99% C.I. 2us-499.986us Avg: 136.333us Max: 602us
Bug: 19264997
Change-Id: I0a71ebb5928f205b9b3f7945b25db6489d5657ca
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 1d04192..c6db7e5 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -4351,12 +4351,12 @@
verifier::RegTypeCache::ShutDown();
}
-void MethodVerifier::VisitStaticRoots(RootCallback* callback, void* arg) {
- RegTypeCache::VisitStaticRoots(callback, arg);
+void MethodVerifier::VisitStaticRoots(RootVisitor* visitor) {
+ RegTypeCache::VisitStaticRoots(visitor);
}
-void MethodVerifier::VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info) {
- reg_types_.VisitRoots(callback, arg, root_info);
+void MethodVerifier::VisitRoots(RootVisitor* visitor, const RootInfo& root_info) {
+ reg_types_.VisitRoots(visitor, root_info);
}
} // namespace verifier
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index 6b813ef..c813634 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -225,9 +225,9 @@
// Describe VRegs at the given dex pc.
std::vector<int32_t> DescribeVRegs(uint32_t dex_pc);
- static void VisitStaticRoots(RootCallback* callback, void* arg)
+ static void VisitStaticRoots(RootVisitor* visitor)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- void VisitRoots(RootCallback* callback, void* arg, const RootInfo& roots)
+ void VisitRoots(RootVisitor* visitor, const RootInfo& roots)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
// Accessors used by the compiler via CompilerCallback
diff --git a/runtime/verifier/reg_type.cc b/runtime/verifier/reg_type.cc
index 97d0cbe..c8aa4fd 100644
--- a/runtime/verifier/reg_type.cc
+++ b/runtime/verifier/reg_type.cc
@@ -778,8 +778,8 @@
}
}
-void RegType::VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info) const {
- klass_.VisitRootIfNonNull(callback, arg, root_info);
+void RegType::VisitRoots(RootVisitor* visitor, const RootInfo& root_info) const {
+ klass_.VisitRootIfNonNull(visitor, root_info);
}
void UninitializedThisReferenceType::CheckInvariants() const {
diff --git a/runtime/verifier/reg_type.h b/runtime/verifier/reg_type.h
index d260650..e4d2c3e 100644
--- a/runtime/verifier/reg_type.h
+++ b/runtime/verifier/reg_type.h
@@ -262,7 +262,7 @@
virtual ~RegType() {}
- void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info) const
+ void VisitRoots(RootVisitor* visitor, const RootInfo& root_info) const
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
protected:
diff --git a/runtime/verifier/reg_type_cache.cc b/runtime/verifier/reg_type_cache.cc
index 6e57857..b371d7e 100644
--- a/runtime/verifier/reg_type_cache.cc
+++ b/runtime/verifier/reg_type_cache.cc
@@ -557,33 +557,33 @@
}
}
-void RegTypeCache::VisitStaticRoots(RootCallback* callback, void* arg) {
+void RegTypeCache::VisitStaticRoots(RootVisitor* visitor) {
// Visit the primitive types, this is required since if there are no active verifiers they wont
// be in the entries array, and therefore not visited as roots.
if (primitive_initialized_) {
RootInfo ri(kRootUnknown);
- UndefinedType::GetInstance()->VisitRoots(callback, arg, ri);
- ConflictType::GetInstance()->VisitRoots(callback, arg, ri);
- BooleanType::GetInstance()->VisitRoots(callback, arg, ri);
- ByteType::GetInstance()->VisitRoots(callback, arg, ri);
- ShortType::GetInstance()->VisitRoots(callback, arg, ri);
- CharType::GetInstance()->VisitRoots(callback, arg, ri);
- IntegerType::GetInstance()->VisitRoots(callback, arg, ri);
- LongLoType::GetInstance()->VisitRoots(callback, arg, ri);
- LongHiType::GetInstance()->VisitRoots(callback, arg, ri);
- FloatType::GetInstance()->VisitRoots(callback, arg, ri);
- DoubleLoType::GetInstance()->VisitRoots(callback, arg, ri);
- DoubleHiType::GetInstance()->VisitRoots(callback, arg, ri);
+ UndefinedType::GetInstance()->VisitRoots(visitor, ri);
+ ConflictType::GetInstance()->VisitRoots(visitor, ri);
+ BooleanType::GetInstance()->VisitRoots(visitor, ri);
+ ByteType::GetInstance()->VisitRoots(visitor, ri);
+ ShortType::GetInstance()->VisitRoots(visitor, ri);
+ CharType::GetInstance()->VisitRoots(visitor, ri);
+ IntegerType::GetInstance()->VisitRoots(visitor, ri);
+ LongLoType::GetInstance()->VisitRoots(visitor, ri);
+ LongHiType::GetInstance()->VisitRoots(visitor, ri);
+ FloatType::GetInstance()->VisitRoots(visitor, ri);
+ DoubleLoType::GetInstance()->VisitRoots(visitor, ri);
+ DoubleHiType::GetInstance()->VisitRoots(visitor, ri);
for (int32_t value = kMinSmallConstant; value <= kMaxSmallConstant; ++value) {
- small_precise_constants_[value - kMinSmallConstant]->VisitRoots(callback, arg, ri);
+ small_precise_constants_[value - kMinSmallConstant]->VisitRoots(visitor, ri);
}
}
}
-void RegTypeCache::VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info) {
+void RegTypeCache::VisitRoots(RootVisitor* visitor, const RootInfo& root_info) {
// Exclude the static roots that are visited by VisitStaticRoots().
for (size_t i = primitive_count_; i < entries_.size(); ++i) {
- entries_[i]->VisitRoots(callback, arg, root_info);
+ entries_[i]->VisitRoots(visitor, root_info);
}
}
diff --git a/runtime/verifier/reg_type_cache.h b/runtime/verifier/reg_type_cache.h
index 01032a0..4b3105c 100644
--- a/runtime/verifier/reg_type_cache.h
+++ b/runtime/verifier/reg_type_cache.h
@@ -137,9 +137,9 @@
void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
const RegType& RegTypeFromPrimitiveType(Primitive::Type) const;
- void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
+ void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- static void VisitStaticRoots(RootCallback* callback, void* arg)
+ static void VisitStaticRoots(RootVisitor* visitor)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
private: