OSDN Git Service

Fix ScopedArenaAllocator::Reset() for Create()d allocators.
authorVladimir Marko <vmarko@google.com>
Fri, 10 Oct 2014 14:39:11 +0000 (15:39 +0100)
committerVladimir Marko <vmarko@google.com>
Fri, 10 Oct 2014 14:40:01 +0000 (15:40 +0100)
Change-Id: I88cbb329911ed489768772218b49b6f1756ffd86

compiler/utils/scoped_arena_allocator.cc
compiler/utils/scoped_arena_allocator.h

index aeb2f76..2616150 100644 (file)
@@ -115,10 +115,18 @@ ScopedArenaAllocator::ScopedArenaAllocator(ArenaStack* arena_stack)
 }
 
 ScopedArenaAllocator::~ScopedArenaAllocator() {
-  Reset();
+  DoReset();
 }
 
 void ScopedArenaAllocator::Reset() {
+  DoReset();
+  // If this allocator was Create()d, we need to move the arena_stack_->top_ptr_ past *this.
+  if (mark_ptr_ == reinterpret_cast<uint8_t*>(this)) {
+    arena_stack_->top_ptr_ = mark_ptr_ + RoundUp(sizeof(ScopedArenaAllocator), 8);
+  }
+}
+
+void ScopedArenaAllocator::DoReset() {
   DebugStackReference::CheckTop();
   DebugStackRefCounter::CheckNoRefs();
   arena_stack_->UpdatePeakStatsAndRestore(*this);
index 62ea330..523f158 100644 (file)
@@ -132,6 +132,8 @@ class ScopedArenaAllocator
   uint8_t* mark_ptr_;
   uint8_t* mark_end_;
 
+  void DoReset();
+
   template <typename T>
   friend class ScopedArenaAllocatorAdapter;