diff options
author | 2020-02-11 10:01:18 -0800 | |
---|---|---|
committer | 2020-02-12 19:15:04 +0000 | |
commit | c55032774cfec4b5222b362a81a3b8b69e133710 (patch) | |
tree | f925d517eec0d7c00a8d4a421fd6c83818cec155 | |
parent | e0ac2f36724e15f3e328ede92877fb9e512d3fc6 (diff) |
Use stack for first scope in VariableSizedHandleScope
VariableSizedHandleScope commonly doesn't have that many handles,
avoid doing an allocation for those cases.
Test: test-art-host
Change-Id: Iaf6c502723a239b1a2e861152efa37f4ef66431b
-rw-r--r-- | runtime/handle_scope-inl.h | 10 | ||||
-rw-r--r-- | runtime/handle_scope.h | 1 |
2 files changed, 7 insertions, 4 deletions
diff --git a/runtime/handle_scope-inl.h b/runtime/handle_scope-inl.h index 6d8a05dcd2..90cf5970dd 100644 --- a/runtime/handle_scope-inl.h +++ b/runtime/handle_scope-inl.h @@ -211,16 +211,18 @@ inline MutableHandle<MirrorType> VariableSizedHandleScope::NewHandle(ObjPtr<Mirr inline VariableSizedHandleScope::VariableSizedHandleScope(Thread* const self) : BaseHandleScope(self->GetTopHandleScope()), - self_(self) { - current_scope_ = new LocalScopeType(/*link=*/ nullptr); + self_(self), + current_scope_(&first_scope_), + first_scope_(/*link=*/ nullptr) { self_->PushHandleScope(this); } inline VariableSizedHandleScope::~VariableSizedHandleScope() { BaseHandleScope* top_handle_scope = self_->PopHandleScope(); DCHECK_EQ(top_handle_scope, this); - while (current_scope_ != nullptr) { - LocalScopeType* next = reinterpret_cast<LocalScopeType*>(current_scope_->GetLink()); + // Don't delete first_scope_ since it is not heap allocated. + while (current_scope_ != &first_scope_) { + LocalScopeType* next = down_cast<LocalScopeType*>(current_scope_->GetLink()); delete current_scope_; current_scope_ = next; } diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h index 61f99b03c9..b173453df0 100644 --- a/runtime/handle_scope.h +++ b/runtime/handle_scope.h @@ -271,6 +271,7 @@ class VariableSizedHandleScope : public BaseHandleScope { using LocalScopeType = FixedSizeHandleScope<kNumReferencesPerScope>; static_assert(sizeof(LocalScopeType) <= kMaxLocalScopeSize, "Unexpected size of LocalScopeType"); LocalScopeType* current_scope_; + LocalScopeType first_scope_; DISALLOW_COPY_AND_ASSIGN(VariableSizedHandleScope); }; |