summaryrefslogtreecommitdiff
path: root/runtime/handle_scope-inl.h
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 /runtime/handle_scope-inl.h
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
Diffstat (limited to 'runtime/handle_scope-inl.h')
-rw-r--r--runtime/handle_scope-inl.h18
1 files changed, 15 insertions, 3 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())