Commit e5281ef4 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[handle] Zap local and persistent handles

Zap freed local and persistent handles similar to main thread handles.
As a drive-by change, fix the creation of local handles without
LocalHandleScope.

Bug: v8:10315
Change-Id: Ia71bc5419c62ae073928751f57fc221ea11de254
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2323362
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69121}
parent 328fb7f4
...@@ -264,6 +264,8 @@ class HandleScope { ...@@ -264,6 +264,8 @@ class HandleScope {
friend class DeferredHandleScope; friend class DeferredHandleScope;
friend class HandleScopeImplementer; friend class HandleScopeImplementer;
friend class Isolate; friend class Isolate;
friend class LocalHandles;
friend class PersistentHandles;
DISALLOW_COPY_AND_ASSIGN(HandleScope); DISALLOW_COPY_AND_ASSIGN(HandleScope);
}; };
......
...@@ -43,11 +43,13 @@ LocalHandleScope::~LocalHandleScope() { ...@@ -43,11 +43,13 @@ LocalHandleScope::~LocalHandleScope() {
handles->scope_.level--; handles->scope_.level--;
if (old_limit != handles->scope_.limit) { if (old_limit != handles->scope_.limit) {
handles->RemoveBlocks(); handles->RemoveUnusedBlocks();
old_limit = handles->scope_.limit; old_limit = handles->scope_.limit;
} }
// TODO(dinfuehr): Zap handles #ifdef ENABLE_HANDLE_ZAPPING
LocalHandles::ZapRange(handles->scope_.next, old_limit);
#endif
MSAN_ALLOCATED_UNINITIALIZED_MEMORY( MSAN_ALLOCATED_UNINITIALIZED_MEMORY(
handles->scope_.next, handles->scope_.next,
......
...@@ -11,6 +11,11 @@ namespace v8 { ...@@ -11,6 +11,11 @@ namespace v8 {
namespace internal { namespace internal {
LocalHandles::LocalHandles() { scope_.Initialize(); } LocalHandles::LocalHandles() { scope_.Initialize(); }
LocalHandles::~LocalHandles() {
scope_.limit = nullptr;
RemoveUnusedBlocks();
DCHECK(blocks_.empty());
}
void LocalHandles::Iterate(RootVisitor* visitor) { void LocalHandles::Iterate(RootVisitor* visitor) {
for (int i = 0; i < static_cast<int>(blocks_.size()) - 1; i++) { for (int i = 0; i < static_cast<int>(blocks_.size()) - 1; i++) {
...@@ -49,13 +54,16 @@ bool LocalHandles::Contains(Address* location) { ...@@ -49,13 +54,16 @@ bool LocalHandles::Contains(Address* location) {
Address* LocalHandles::AddBlock() { Address* LocalHandles::AddBlock() {
DCHECK_EQ(scope_.next, scope_.limit); DCHECK_EQ(scope_.next, scope_.limit);
Address* block = NewArray<Address>(kHandleBlockSize); Address* block = NewArray<Address>(kHandleBlockSize);
#ifdef ENABLE_HANDLE_ZAPPING
ZapRange(block, block + kHandleBlockSize);
#endif
blocks_.push_back(block); blocks_.push_back(block);
scope_.next = block; scope_.next = block;
scope_.limit = block + kHandleBlockSize; scope_.limit = block + kHandleBlockSize;
return block; return block;
} }
void LocalHandles::RemoveBlocks() { void LocalHandles::RemoveUnusedBlocks() {
while (!blocks_.empty()) { while (!blocks_.empty()) {
Address* block_start = blocks_.back(); Address* block_start = blocks_.back();
Address* block_limit = block_start + kHandleBlockSize; Address* block_limit = block_start + kHandleBlockSize;
...@@ -66,11 +74,19 @@ void LocalHandles::RemoveBlocks() { ...@@ -66,11 +74,19 @@ void LocalHandles::RemoveBlocks() {
blocks_.pop_back(); blocks_.pop_back();
// TODO(dinfuehr): Zap handles in block #ifdef ENABLE_HANDLE_ZAPPING
ZapRange(block_start, block_limit);
#endif
DeleteArray(block_start); DeleteArray(block_start);
} }
} }
#ifdef ENABLE_HANDLE_ZAPPING
void LocalHandles::ZapRange(Address* start, Address* end) {
HandleScope::ZapRange(start, end);
}
#endif
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -19,6 +19,7 @@ class RootVisitor; ...@@ -19,6 +19,7 @@ class RootVisitor;
class LocalHandles { class LocalHandles {
public: public:
LocalHandles(); LocalHandles();
~LocalHandles();
void Iterate(RootVisitor* visitor); void Iterate(RootVisitor* visitor);
...@@ -31,7 +32,11 @@ class LocalHandles { ...@@ -31,7 +32,11 @@ class LocalHandles {
std::vector<Address*> blocks_; std::vector<Address*> blocks_;
V8_EXPORT_PRIVATE Address* AddBlock(); V8_EXPORT_PRIVATE Address* AddBlock();
V8_EXPORT_PRIVATE void RemoveBlocks(); V8_EXPORT_PRIVATE void RemoveUnusedBlocks();
#ifdef ENABLE_HANDLE_ZAPPING
V8_EXPORT_PRIVATE static void ZapRange(Address* start, Address* end);
#endif
friend class LocalHandleScope; friend class LocalHandleScope;
}; };
......
...@@ -26,6 +26,9 @@ PersistentHandles::~PersistentHandles() { ...@@ -26,6 +26,9 @@ PersistentHandles::~PersistentHandles() {
isolate_->persistent_handles_list()->Remove(this); isolate_->persistent_handles_list()->Remove(this);
for (Address* block_start : blocks_) { for (Address* block_start : blocks_) {
#if ENABLE_HANDLE_ZAPPING
HandleScope::ZapRange(block_start, block_start + block_size_);
#endif
DeleteArray(block_start); DeleteArray(block_start);
} }
} }
......
...@@ -66,7 +66,7 @@ class PersistentHandles { ...@@ -66,7 +66,7 @@ class PersistentHandles {
Isolate* isolate_; Isolate* isolate_;
std::vector<Address*> blocks_; std::vector<Address*> blocks_;
size_t block_size_; const size_t block_size_;
Address* block_next_; Address* block_next_;
Address* block_limit_; Address* block_limit_;
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#include "src/base/platform/condition-variable.h" #include "src/base/platform/condition-variable.h"
#include "src/base/platform/mutex.h" #include "src/base/platform/mutex.h"
#include "src/base/platform/semaphore.h" #include "src/base/platform/semaphore.h"
#include "src/common/globals.h"
#include "src/handles/handles-inl.h" #include "src/handles/handles-inl.h"
#include "src/handles/local-handles-inl.h" #include "src/handles/local-handles-inl.h"
#include "src/handles/local-handles.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/heap/local-heap.h" #include "src/heap/local-heap.h"
#include "src/heap/safepoint.h" #include "src/heap/safepoint.h"
...@@ -94,6 +96,17 @@ TEST(CreateLocalHandles) { ...@@ -94,6 +96,17 @@ TEST(CreateLocalHandles) {
thread->Join(); thread->Join();
} }
TEST(CreateLocalHandlesWithoutLocalHandleScope) {
CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate();
{
LocalHeap local_heap(isolate->heap());
handle(Smi::FromInt(17), &local_heap);
}
}
TEST(DereferenceLocalHandle) { TEST(DereferenceLocalHandle) {
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true; FLAG_local_heaps = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment