summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/handle_scope-inl.h10
-rw-r--r--runtime/handle_scope.h1
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);
};