Revert "[heap] Introduce LocalIsolate for main thread"

This reverts commit e95e1b6234.

Reason for revert:
https://ci.chromium.org/p/v8/builders/ci/V8%20Linux%20-%20arm%20-%20sim%20-%20debug/23064

Original change's description:
> [heap] Introduce LocalIsolate for main thread
>
> Add a LocalIsolate for the main thread to Isolate. This LocalIsolate is
> kept alive during the whole lifetime of the Isolate. The main thread
> LocalIsolate starts in the Running state in contrast to the background
> thread LocalIsolates (those start in Parked).
>
> Code paths in Turbofan that used to create a LocalIsolate on the main
> thread can now simply use the main thread LocalIsolate.
>
> LocalIsolate for the main thread will help in reducing differences
> between the main and background threads. The goal is that the main
> thread behaves more like a background thread.
>
> The main thread LocalIsolate should also make it simpler to share code
> between main thread and background threads by using LocalIsolate for
> both.
>
> Bug: v8:10315
> Change-Id: I7fd61d305a6fd7079e2319d75c291c1021e70018
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509593
> Reviewed-by: Simon Zünd <szuend@chromium.org>
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Reviewed-by: Georg Neis <neis@chromium.org>
> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#71226}

TBR=ulan@chromium.org,yangguo@chromium.org,neis@chromium.org,leszeks@chromium.org,szuend@chromium.org,dinfuehr@chromium.org

Change-Id: Ia70b4bfe3b8fa26bf8d6a7dc612a310b0ed54073
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:10315
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2543937
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71228}
This commit is contained in:
Michael Achenbach 2020-11-17 12:29:51 +00:00 committed by Commit Bot
parent 8b7a837b71
commit 9235f25874
33 changed files with 129 additions and 195 deletions

View File

@ -2716,7 +2716,6 @@ v8_source_set("v8_base_without_compiler") {
"src/heap/paged-spaces.cc",
"src/heap/paged-spaces.h",
"src/heap/parallel-work-item.h",
"src/heap/parked-scope.h",
"src/heap/read-only-heap-inl.h",
"src/heap/read-only-heap.cc",
"src/heap/read-only-heap.h",

View File

@ -25,7 +25,6 @@ include_rules = [
# TODO(v8:10496): Don't expose memory chunk outside of heap/.
"+src/heap/memory-chunk.h",
"+src/heap/memory-chunk-inl.h",
"+src/heap/parked-scope.h",
"+src/heap/read-only-heap-inl.h",
"+src/heap/read-only-heap.h",
"+src/heap/safepoint.h",

View File

@ -37,7 +37,6 @@
#include "src/heap/local-factory-inl.h"
#include "src/heap/local-heap-inl.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/init/bootstrapper.h"
#include "src/interpreter/interpreter.h"
#include "src/logging/log-inl.h"
@ -969,10 +968,9 @@ bool GetOptimizedCodeNow(OptimizedCompilationJob* job, Isolate* isolate,
}
{
// Park main thread here to be in the same state as background threads.
ParkedScope parked_scope(isolate->main_thread_local_isolate());
LocalIsolate local_isolate(isolate, ThreadKind::kMain);
if (job->ExecuteJob(isolate->counters()->runtime_call_stats(),
isolate->main_thread_local_isolate())) {
&local_isolate)) {
CompilerTracer::TraceAbortedJob(isolate, compilation_info);
return false;
}

View File

@ -10,7 +10,6 @@
#include "src/execution/isolate.h"
#include "src/execution/local-isolate.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/init/v8.h"
#include "src/logging/counters.h"
#include "src/logging/log.h"

View File

@ -18,7 +18,6 @@
#include "src/handles/handles.h"
#include "src/handles/persistent-handles.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/interpreter/bytecode-array-accessor.h"
#include "src/objects/code-kind.h"
#include "src/objects/feedback-vector.h"

View File

@ -3034,8 +3034,8 @@ MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
}
{
LocalIsolateScope local_isolate_scope(data.broker(), info,
isolate->main_thread_local_isolate());
LocalIsolate local_isolate(isolate, ThreadKind::kMain);
LocalIsolateScope local_isolate_scope(data.broker(), info, &local_isolate);
if (data.broker()->is_concurrent_inlining()) {
if (!pipeline.CreateGraph()) return MaybeHandle<Code>();
}

View File

@ -39,7 +39,6 @@
#include "src/diagnostics/compilation-statistics.h"
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/local-isolate.h"
#include "src/execution/messages.h"
#include "src/execution/microtask-queue.h"
#include "src/execution/protectors-inl.h"
@ -2912,7 +2911,6 @@ void Isolate::Delete(Isolate* isolate) {
Isolate* saved_isolate = reinterpret_cast<Isolate*>(
base::Thread::GetThreadLocal(isolate->isolate_key_));
SetIsolateThreadLocals(isolate, nullptr);
isolate->set_thread_id(ThreadId::Current());
isolate->Deinit();
@ -3111,8 +3109,6 @@ void Isolate::Deinit() {
// This stops cancelable tasks (i.e. concurrent marking tasks)
cancelable_task_manager()->CancelAndWait();
main_thread_local_isolate_.reset();
heap_.TearDown();
FILE* logfile = logger_->TearDownAndGetLogFile();
if (logfile != nullptr) base::Fclose(logfile);
@ -3544,10 +3540,6 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
ReadOnlyHeap::SetUp(this, read_only_snapshot_data, can_rehash);
heap_.SetUpSpaces();
// Create LocalIsolate/LocalHeap for the main thread and set state to Running.
main_thread_local_isolate_.reset(new LocalIsolate(this, ThreadKind::kMain));
main_thread_local_heap()->Unpark();
isolate_data_.external_reference_table()->Init(this);
// Setup the wasm engine.
@ -4764,10 +4756,6 @@ void Isolate::RemoveContextIdCallback(const v8::WeakCallbackInfo<void>& data) {
isolate->recorder_context_id_map_.erase(context_id);
}
LocalHeap* Isolate::main_thread_local_heap() {
return main_thread_local_isolate()->heap();
}
// |chunk| is either a Page or an executable LargePage.
void Isolate::RemoveCodeMemoryChunk(MemoryChunk* chunk) {
// We only keep track of individual code pages/allocations if we are on arm32,

View File

@ -1625,12 +1625,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
MaybeLocal<v8::Context> GetContextFromRecorderContextId(
v8::metrics::Recorder::ContextId id);
LocalIsolate* main_thread_local_isolate() {
return main_thread_local_isolate_.get();
}
LocalHeap* main_thread_local_heap();
#ifdef V8_HEAP_SANDBOX
ExternalPointerTable& external_pointer_table() {
return isolate_data_.external_pointer_table_;
@ -1967,8 +1961,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
bool promise_hook_or_debug_is_active_or_async_event_delegate_ = false;
int async_task_count_ = 0;
std::unique_ptr<LocalIsolate> main_thread_local_isolate_;
v8::Isolate::AbortOnUncaughtExceptionCallback
abort_on_uncaught_exception_callback_ = nullptr;

View File

@ -7,8 +7,6 @@
#include "src/api/api.h"
#include "src/base/logging.h"
#include "src/codegen/optimized-compilation-info.h"
#include "src/execution/isolate.h"
#include "src/execution/thread-id.h"
#include "src/handles/maybe-handles.h"
#include "src/objects/objects-inl.h"
#include "src/roots/roots-inl.h"
@ -45,19 +43,8 @@ bool HandleBase::IsDereferenceAllowed() const {
}
if (isolate->IsBuiltinsTableHandleLocation(location_)) return true;
if (FLAG_local_heaps) {
LocalHeap* local_heap = LocalHeap::Current();
if (local_heap == nullptr) {
// We are on the main thread and can thus load the LocalHeap from the
// Isolate itself. The DCHECK makes sure that we are not accidentally
// dereferencing a handle on a background thread without an active
// LocalHeap.
DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
local_heap = isolate->main_thread_local_heap();
}
// Local heap can't access handles when parked
LocalHeap* local_heap = LocalHeap::Current();
if (FLAG_local_heaps && local_heap) {
if (!local_heap->IsHandleDereferenceAllowed()) {
StdoutStream{} << "Cannot dereference handle owned by "
<< "non-running local heap\n";

View File

@ -23,9 +23,8 @@ AllocationResult ConcurrentAllocator::AllocateRaw(int object_size,
// TODO(dinfuehr): Add support for allocation observers
CHECK(FLAG_concurrent_allocation);
#ifdef DEBUG
local_heap_->VerifyCurrent();
#endif
// Ensure that we are on the right thread
DCHECK_EQ(LocalHeap::Current(), local_heap_);
if (object_size > kMaxLabObjectSize) {
return AllocateOutsideLab(object_size, alignment, origin);

View File

@ -12,7 +12,6 @@
#include "src/heap/local-heap.h"
#include "src/heap/marking.h"
#include "src/heap/memory-chunk.h"
#include "src/heap/parked-scope.h"
namespace v8 {
namespace internal {

View File

@ -16,7 +16,7 @@ AllocationResult LocalHeap::AllocateRaw(int size_in_bytes, AllocationType type,
AllocationOrigin origin,
AllocationAlignment alignment) {
#if DEBUG
VerifyCurrent();
DCHECK_EQ(LocalHeap::Current(), this);
DCHECK(AllowHandleAllocation::IsAllowed());
DCHECK(AllowHeapAllocation::IsAllowed());
DCHECK(AllowGarbageCollection::IsAllowed());

View File

@ -6,16 +6,13 @@
#include <memory>
#include "src/base/logging.h"
#include "src/base/platform/mutex.h"
#include "src/common/globals.h"
#include "src/execution/isolate.h"
#include "src/handles/local-handles.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap-write-barrier.h"
#include "src/heap/local-heap-inl.h"
#include "src/heap/marking-barrier.h"
#include "src/heap/parked-scope.h"
#include "src/heap/safepoint.h"
namespace v8 {
@ -27,17 +24,6 @@ thread_local LocalHeap* current_local_heap = nullptr;
LocalHeap* LocalHeap::Current() { return current_local_heap; }
#ifdef DEBUG
void LocalHeap::VerifyCurrent() {
LocalHeap* current = LocalHeap::Current();
if (is_main_thread())
DCHECK_NULL(current);
else
DCHECK_EQ(current, this);
}
#endif
LocalHeap::LocalHeap(Heap* heap, ThreadKind kind,
std::unique_ptr<PersistentHandles> persistent_handles)
: heap_(heap),
@ -52,7 +38,7 @@ LocalHeap::LocalHeap(Heap* heap, ThreadKind kind,
marking_barrier_(new MarkingBarrier(this)),
old_space_allocator_(this, heap->old_space()) {
heap_->safepoint()->AddLocalHeap(this, [this] {
if (FLAG_local_heaps && !is_main_thread()) {
if (FLAG_local_heaps) {
WriteBarrier::SetForThread(marking_barrier_.get());
if (heap_->incremental_marking()->IsMarking()) {
marking_barrier_->Activate(
@ -65,7 +51,7 @@ LocalHeap::LocalHeap(Heap* heap, ThreadKind kind,
persistent_handles_->Attach(this);
}
DCHECK_NULL(current_local_heap);
if (!is_main_thread()) current_local_heap = this;
current_local_heap = this;
}
LocalHeap::~LocalHeap() {
@ -75,16 +61,14 @@ LocalHeap::~LocalHeap() {
heap_->safepoint()->RemoveLocalHeap(this, [this] {
old_space_allocator_.FreeLinearAllocationArea();
if (FLAG_local_heaps && !is_main_thread()) {
if (FLAG_local_heaps) {
marking_barrier_->Publish();
WriteBarrier::ClearForThread(marking_barrier_.get());
}
});
if (!is_main_thread()) {
DCHECK_EQ(current_local_heap, this);
current_local_heap = nullptr;
}
DCHECK_EQ(current_local_heap, this);
current_local_heap = nullptr;
}
void LocalHeap::EnsurePersistentHandles() {
@ -117,17 +101,13 @@ bool LocalHeap::ContainsLocalHandle(Address* location) {
}
bool LocalHeap::IsHandleDereferenceAllowed() {
#ifdef DEBUG
VerifyCurrent();
#endif
DCHECK_EQ(LocalHeap::Current(), this);
return state_ == ThreadState::Running;
}
#endif
bool LocalHeap::IsParked() {
#ifdef DEBUG
VerifyCurrent();
#endif
DCHECK_EQ(LocalHeap::Current(), this);
return state_ == ThreadState::Parked;
}

View File

@ -113,10 +113,6 @@ class V8_EXPORT_PRIVATE LocalHeap {
// with the current thread.
static LocalHeap* Current();
#ifdef DEBUG
void VerifyCurrent();
#endif
// Allocate an uninitialized object.
V8_WARN_UNUSED_RESULT inline AllocationResult AllocateRaw(
int size_in_bytes, AllocationType allocation,
@ -191,7 +187,47 @@ class V8_EXPORT_PRIVATE LocalHeap {
friend class ParkedScope;
friend class UnparkedScope;
friend class ConcurrentAllocator;
friend class Isolate;
};
// Scope that explicitly parks LocalHeap prohibiting access to the heap and the
// creation of Handles.
class ParkedScope {
public:
explicit ParkedScope(LocalHeap* local_heap) : local_heap_(local_heap) {
local_heap_->Park();
}
~ParkedScope() { local_heap_->Unpark(); }
private:
LocalHeap* const local_heap_;
};
// Scope that explicitly unparks LocalHeap allowing access to the heap and the
// creation of Handles.
class UnparkedScope {
public:
explicit UnparkedScope(LocalHeap* local_heap) : local_heap_(local_heap) {
local_heap_->Unpark();
}
~UnparkedScope() { local_heap_->Park(); }
private:
LocalHeap* const local_heap_;
};
class ParkedMutexGuard {
base::Mutex* guard_;
public:
explicit ParkedMutexGuard(LocalHeap* local_heap, base::Mutex* guard)
: guard_(guard) {
ParkedScope scope(local_heap);
guard_->Lock();
}
~ParkedMutexGuard() { guard_->Unlock(); }
};
} // namespace internal

View File

@ -1,65 +0,0 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_HEAP_PARKED_SCOPE_H_
#define V8_HEAP_PARKED_SCOPE_H_
#include "src/base/platform/mutex.h"
#include "src/execution/local-isolate.h"
#include "src/heap/local-heap.h"
namespace v8 {
namespace internal {
// Scope that explicitly parks a thread, prohibiting access to the heap and the
// creation of handles.
class ParkedScope {
public:
explicit ParkedScope(LocalIsolate* local_isolate)
: ParkedScope(local_isolate->heap()) {}
explicit ParkedScope(LocalHeap* local_heap) : local_heap_(local_heap) {
local_heap_->Park();
}
~ParkedScope() { local_heap_->Unpark(); }
private:
LocalHeap* const local_heap_;
};
// Scope that explicitly unparks a thread, allowing access to the heap and the
// creation of handles.
class UnparkedScope {
public:
explicit UnparkedScope(LocalIsolate* local_isolate)
: UnparkedScope(local_isolate->heap()) {}
explicit UnparkedScope(LocalHeap* local_heap) : local_heap_(local_heap) {
local_heap_->Unpark();
}
~UnparkedScope() { local_heap_->Park(); }
private:
LocalHeap* const local_heap_;
};
class ParkedMutexGuard {
base::Mutex* guard_;
public:
explicit ParkedMutexGuard(LocalIsolate* local_isolate, base::Mutex* guard)
: ParkedMutexGuard(local_isolate->heap(), guard) {}
explicit ParkedMutexGuard(LocalHeap* local_heap, base::Mutex* guard)
: guard_(guard) {
ParkedScope scope(local_heap);
guard_->Lock();
}
~ParkedMutexGuard() { guard_->Unlock(); }
};
} // namespace internal
} // namespace v8
#endif // V8_HEAP_PARKED_SCOPE_H_

View File

@ -4,7 +4,6 @@
#include "src/heap/safepoint.h"
#include "src/base/logging.h"
#include "src/handles/local-handles.h"
#include "src/handles/persistent-handles.h"
#include "src/heap/gc-tracer.h"
@ -26,13 +25,13 @@ void GlobalSafepoint::EnterSafepointScope() {
TRACE_GC(heap_->tracer(), GCTracer::Scope::STOP_THE_WORLD);
local_heaps_mutex_.Lock();
local_heap_of_this_thread_ = LocalHeap::Current();
barrier_.Arm();
DCHECK_NULL(LocalHeap::Current());
for (LocalHeap* current = local_heaps_head_; current;
current = current->next_) {
if (current->is_main_thread()) {
if (current == local_heap_of_this_thread_) {
continue;
}
current->RequestSafepoint();
@ -40,7 +39,8 @@ void GlobalSafepoint::EnterSafepointScope() {
for (LocalHeap* current = local_heaps_head_; current;
current = current->next_) {
if (current->is_main_thread()) {
if (current == local_heap_of_this_thread_) {
DCHECK(current->is_main_thread());
continue;
}
DCHECK(!current->is_main_thread());
@ -58,11 +58,11 @@ void GlobalSafepoint::LeaveSafepointScope() {
DCHECK_GT(active_safepoint_scopes_, 0);
if (--active_safepoint_scopes_ > 0) return;
DCHECK_NULL(LocalHeap::Current());
DCHECK_EQ(local_heap_of_this_thread_, LocalHeap::Current());
for (LocalHeap* current = local_heaps_head_; current;
current = current->next_) {
if (current->is_main_thread()) {
if (current == local_heap_of_this_thread_) {
continue;
}
current->state_mutex_.Unlock();
@ -70,6 +70,7 @@ void GlobalSafepoint::LeaveSafepointScope() {
barrier_.Disarm();
local_heap_of_this_thread_ = nullptr;
local_heaps_mutex_.Unlock();
}

View File

@ -101,6 +101,8 @@ class GlobalSafepoint {
int active_safepoint_scopes_;
LocalHeap* local_heap_of_this_thread_;
friend class SafepointScope;
friend class LocalHeap;
friend class PersistentHandles;

View File

@ -145,7 +145,6 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector,
}
V8InspectorSessionImpl::~V8InspectorSessionImpl() {
v8::Isolate::Scope scope(m_inspector->isolate());
discardInjectedScripts();
m_consoleAgent->disable();
m_profilerAgent->disable();

View File

@ -20,7 +20,6 @@
#include "src/heap/concurrent-allocator-inl.h"
#include "src/heap/heap.h"
#include "src/heap/local-heap-inl.h"
#include "src/heap/parked-scope.h"
#include "src/heap/safepoint.h"
#include "src/objects/heap-number.h"
#include "src/objects/heap-object.h"
@ -127,7 +126,11 @@ UNINITIALIZED_TEST(ConcurrentAllocationInOldSpaceFromMainThread) {
v8::Isolate* isolate = v8::Isolate::New(create_params);
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
AllocateSomeObjects(i_isolate->main_thread_local_heap());
{
LocalHeap local_heap(i_isolate->heap(), ThreadKind::kMain);
UnparkedScope unparked_scope(&local_heap);
AllocateSomeObjects(&local_heap);
}
isolate->Dispose();
}

View File

@ -47,7 +47,6 @@
#include "src/heap/mark-compact.h"
#include "src/heap/memory-chunk.h"
#include "src/heap/memory-reducer.h"
#include "src/heap/parked-scope.h"
#include "src/heap/remembered-set-inl.h"
#include "src/heap/safepoint.h"
#include "src/ic/ic.h"
@ -7119,11 +7118,12 @@ TEST(GarbageCollectionWithLocalHeap) {
ManualGCScope manual_gc_scope;
CcTest::InitializeVM();
LocalHeap* local_heap = CcTest::i_isolate()->main_thread_local_heap();
Heap* heap = CcTest::i_isolate()->heap();
LocalHeap local_heap(heap, ThreadKind::kMain);
UnparkedScope unparked_scope(&local_heap);
CcTest::CollectGarbage(OLD_SPACE);
{ ParkedScope parked_scope(local_heap); }
{ ParkedScope parked_scope(&local_heap); }
CcTest::CollectGarbage(OLD_SPACE);
}

View File

@ -10,7 +10,6 @@
#include "src/heap/heap.h"
#include "src/heap/local-heap-inl.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

View File

@ -12,7 +12,6 @@
#include "src/handles/persistent-handles.h"
#include "src/heap/heap.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

View File

@ -10,7 +10,6 @@
#include "src/heap/heap.h"
#include "src/heap/local-heap-inl.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

View File

@ -9,7 +9,6 @@
#include "src/handles/persistent-handles.h"
#include "src/heap/heap.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/objects/contexts.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

View File

@ -10,7 +10,6 @@
#include "src/heap/heap.h"
#include "src/heap/local-heap-inl.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

View File

@ -8,7 +8,6 @@
#include "src/handles/persistent-handles.h"
#include "src/heap/heap.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/objects/transitions-inl.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

View File

@ -14,7 +14,6 @@
#include "src/handles/local-handles.h"
#include "src/heap/heap.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/heap/safepoint.h"
#include "src/objects/heap-number.h"
#include "test/cctest/cctest.h"
@ -103,7 +102,11 @@ TEST(CreateLocalHandlesWithoutLocalHandleScope) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
handle(Smi::FromInt(17), isolate->main_thread_local_heap());
{
LocalHeap local_heap(isolate->heap(), ThreadKind::kMain);
UnparkedScope scope(&local_heap);
handle(Smi::FromInt(17), &local_heap);
}
}
TEST(DereferenceLocalHandle) {
@ -121,8 +124,7 @@ TEST(DereferenceLocalHandle) {
ph = phs->NewHandle(number);
}
{
LocalHeap local_heap(isolate->heap(), ThreadKind::kBackground,
std::move(phs));
LocalHeap local_heap(isolate->heap(), ThreadKind::kMain, std::move(phs));
UnparkedScope unparked_scope(&local_heap);
LocalHandleScope scope(&local_heap);
Handle<HeapNumber> local_number = handle(*ph, &local_heap);

View File

@ -54,15 +54,13 @@ class DeoptimizeCodeThread : public v8::base::Thread {
void Run() override {
v8::Locker locker(isolate_);
isolate_->Enter();
{
v8::HandleScope handle_scope(isolate_);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate_, context_);
v8::Context::Scope context_scope(context);
// This code triggers deoptimization of some function that will be
// used in a different thread.
CompileRun(source_);
}
v8::HandleScope handle_scope(isolate_);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate_, context_);
v8::Context::Scope context_scope(context);
// This code triggers deoptimization of some function that will be
// used in a different thread.
CompileRun(source_);
isolate_->Exit();
}

View File

@ -14,7 +14,6 @@
#include "src/heap/heap.h"
#include "src/heap/local-heap-inl.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/heap/safepoint.h"
#include "src/objects/heap-number.h"
#include "test/cctest/cctest.h"
@ -130,8 +129,7 @@ TEST(DereferencePersistentHandle) {
ph = phs->NewHandle(number);
}
{
LocalHeap local_heap(isolate->heap(), ThreadKind::kBackground,
std::move(phs));
LocalHeap local_heap(isolate->heap(), ThreadKind::kMain, std::move(phs));
UnparkedScope scope(&local_heap);
CHECK_EQ(42, ph->value());
DisallowHandleDereference disallow_scope;
@ -143,7 +141,7 @@ TEST(NewPersistentHandleFailsWhenParked) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
LocalHeap local_heap(isolate->heap(), ThreadKind::kBackground);
LocalHeap local_heap(isolate->heap(), ThreadKind::kMain);
// Fail here in debug mode: Persistent handles can't be created if local heap
// is parked
local_heap.NewPersistentHandle(Smi::FromInt(1));
@ -153,7 +151,7 @@ TEST(NewPersistentHandleFailsWhenParkedExplicit) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
LocalHeap local_heap(isolate->heap(), ThreadKind::kBackground,
LocalHeap local_heap(isolate->heap(), ThreadKind::kMain,
isolate->NewPersistentHandles());
// Fail here in debug mode: Persistent handles can't be created if local heap
// is parked

View File

@ -38,7 +38,6 @@ class CompilerDispatcherTestFlags {
FLAG_single_threaded = true;
FlagList::EnforceFlagImplications();
FLAG_compiler_dispatcher = true;
FLAG_finalize_streaming_on_background = false;
}
static void RestoreFlags() {

View File

@ -62,7 +62,8 @@ class LocalFactoryTest : public TestWithIsolateAndZone {
isolate(), true, construct_language_mode(FLAG_use_strict),
REPLMode::kNo),
&state_),
local_isolate_(isolate()->main_thread_local_isolate()) {
local_isolate_(isolate(), ThreadKind::kMain),
unparked_scope_(local_isolate_.heap()) {
FLAG_concurrent_allocation = true;
}
@ -106,14 +107,15 @@ class LocalFactoryTest : public TestWithIsolateAndZone {
Handle<Script> script() { return script_; }
LocalIsolate* local_isolate() { return local_isolate_; }
LocalIsolate* local_isolate() { return &local_isolate_; }
LocalFactory* local_factory() { return local_isolate()->factory(); }
private:
SaveFlags save_flags_;
UnoptimizedCompileState state_;
ParseInfo parse_info_;
LocalIsolate* local_isolate_;
LocalIsolate local_isolate_;
UnparkedScope unparked_scope_;
Handle<String> source_string_;
Handle<Script> script_;
};

View File

@ -15,7 +15,15 @@ using LocalHeapTest = TestWithIsolate;
TEST_F(LocalHeapTest, Initialize) {
Heap* heap = i_isolate()->heap();
CHECK(heap->safepoint()->ContainsAnyLocalHeap());
CHECK(!heap->safepoint()->ContainsAnyLocalHeap());
{
LocalHeap lh(heap, ThreadKind::kMain);
CHECK(heap->safepoint()->ContainsLocalHeap(&lh));
}
CHECK(!heap->safepoint()->ContainsAnyLocalHeap());
}
TEST_F(LocalHeapTest, Current) {
@ -25,14 +33,14 @@ TEST_F(LocalHeapTest, Current) {
{
LocalHeap lh(heap, ThreadKind::kMain);
CHECK_NULL(LocalHeap::Current());
CHECK_EQ(&lh, LocalHeap::Current());
}
CHECK_NULL(LocalHeap::Current());
{
LocalHeap lh(heap, ThreadKind::kMain);
CHECK_NULL(LocalHeap::Current());
CHECK_EQ(&lh, LocalHeap::Current());
}
CHECK_NULL(LocalHeap::Current());
@ -65,9 +73,9 @@ TEST_F(LocalHeapTest, CurrentBackground) {
LocalHeap lh(heap, ThreadKind::kMain);
auto thread = std::make_unique<BackgroundThread>(heap);
CHECK(thread->Start());
CHECK_NULL(LocalHeap::Current());
CHECK_EQ(&lh, LocalHeap::Current());
thread->Join();
CHECK_NULL(LocalHeap::Current());
CHECK_EQ(&lh, LocalHeap::Current());
}
CHECK_NULL(LocalHeap::Current());
}

View File

@ -3,12 +3,10 @@
// found in the LICENSE file.
#include "src/heap/safepoint.h"
#include "src/base/platform/mutex.h"
#include "src/base/platform/platform.h"
#include "src/heap/heap.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -146,5 +144,25 @@ TEST_F(SafepointTest, StopRunningThreads) {
CHECK_EQ(safepoint_count, kRuns * kSafepoints);
}
TEST_F(SafepointTest, SkipLocalHeapOfThisThread) {
EnsureFlagLocalHeapsEnabled();
Heap* heap = i_isolate()->heap();
LocalHeap local_heap(heap, ThreadKind::kMain);
UnparkedScope unparked_scope(&local_heap);
{
SafepointScope scope(heap);
local_heap.Safepoint();
}
{
ParkedScope parked_scope(&local_heap);
SafepointScope scope(heap);
local_heap.Safepoint();
}
{
SafepointScope scope(heap);
local_heap.Safepoint();
}
}
} // namespace internal
} // namespace v8