summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2021-01-12 10:33:53 -0800
committer Treehugger Robot <treehugger-gerrit@google.com> 2021-01-12 22:13:16 +0000
commit0ddba9a4239477a2319fbf4317ca8782308c2c35 (patch)
tree1076f2838d6081b85f12c65c3c080d7a03980804
parentb52515830da6688524bfde8bb79f1fa781451cda (diff)
Support null-filled HandleScopes without mutator_lock_
Creating a HandleScope used to always require (via assert) the mutator_lock_ be held. When the scope is filled with null (as it normally is) this is not needed however. Test: ./test.py --host Change-Id: I47acbcaeafc7617f264233a5ab869eded6a22473
-rw-r--r--runtime/handle_scope-inl.h18
-rw-r--r--runtime/handle_scope.h8
2 files changed, 22 insertions, 4 deletions
diff --git a/runtime/handle_scope-inl.h b/runtime/handle_scope-inl.h
index 90cf5970dd..0539059f03 100644
--- a/runtime/handle_scope-inl.h
+++ b/runtime/handle_scope-inl.h
@@ -44,6 +44,16 @@ inline FixedSizeHandleScope<kNumReferences>::FixedSizeHandleScope(BaseHandleScop
}
template<size_t kNumReferences>
+inline FixedSizeHandleScope<kNumReferences>::FixedSizeHandleScope(BaseHandleScope* link)
+ : HandleScope(link, kNumReferences) {
+ static_assert(kNumReferences >= 1, "FixedSizeHandleScope must contain at least 1 reference");
+ DCHECK_EQ(&storage_[0], GetReferences()); // TODO: Figure out how to use a compile assert.
+ for (size_t i = 0; i < kNumReferences; ++i) {
+ SetReferenceToNull(i);
+ }
+}
+
+template<size_t kNumReferences>
inline StackHandleScope<kNumReferences>::StackHandleScope(Thread* self,
ObjPtr<mirror::Object> fill_value)
: FixedSizeHandleScope<kNumReferences>(self->GetTopHandleScope(), fill_value),
@@ -56,9 +66,6 @@ template<size_t kNumReferences>
inline StackHandleScope<kNumReferences>::~StackHandleScope() {
BaseHandleScope* top_handle_scope = self_->PopHandleScope();
DCHECK_EQ(top_handle_scope, this);
- if (kDebugLocking) {
- Locks::mutator_lock_->AssertSharedHeld(self_);
- }
}
inline size_t HandleScope::SizeOf(uint32_t num_references) {
@@ -154,6 +161,11 @@ inline void FixedSizeHandleScope<kNumReferences>::SetReference(size_t i,
GetReferences()[i].Assign(object);
}
+template<size_t kNumReferences>
+inline void FixedSizeHandleScope<kNumReferences>::SetReferenceToNull(size_t i) {
+ DCHECK_LT(i, kNumReferences);
+ GetReferences()[i].Assign(nullptr);
+}
// Number of references contained within this handle scope.
inline uint32_t BaseHandleScope::NumberOfReferences() const {
return LIKELY(!IsVariableSized())
diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h
index b173453df0..ed77e19c08 100644
--- a/runtime/handle_scope.h
+++ b/runtime/handle_scope.h
@@ -195,10 +195,16 @@ class PACKED(4) FixedSizeHandleScope : public HandleScope {
}
private:
+ explicit ALWAYS_INLINE FixedSizeHandleScope(BaseHandleScope* link);
explicit ALWAYS_INLINE FixedSizeHandleScope(BaseHandleScope* link,
- ObjPtr<mirror::Object> fill_value = nullptr);
+ ObjPtr<mirror::Object> fill_value)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
ALWAYS_INLINE ~FixedSizeHandleScope() {}
+ // Helper to set references to null without any mutator-locks.
+ ALWAYS_INLINE void SetReferenceToNull(size_t i);
+
template<class T>
ALWAYS_INLINE MutableHandle<T> GetHandle(size_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
DCHECK_LT(i, kNumReferences);