Commit 09db7cf9 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[codegen] Create PersistentHandles instead of DeferredHandles

As a note, we are not yet passing this to the background so we only
have canonical persistent handles on the main thread.

Bug: v8:7790
Change-Id: I15b264cfacc2d5524a3d13f62574a3576bb7e1a4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2330017
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69176}
parent c60e772c
......@@ -173,17 +173,19 @@ class CompilerTracer : public AllStatic {
} // namespace
// A wrapper around a OptimizedCompilationInfo that detaches the Handles from
// the underlying DeferredHandleScope and stores them in info_ on
// the underlying PersistentHandlesScope and stores them in info_ on
// destruction.
class CompilationHandleScope final {
public:
explicit CompilationHandleScope(Isolate* isolate,
OptimizedCompilationInfo* info)
: deferred_(isolate), info_(info) {}
~CompilationHandleScope() { info_->set_deferred_handles(deferred_.Detach()); }
: persistent_(isolate), info_(info) {}
~CompilationHandleScope() {
info_->set_persistent_handles(persistent_.Detach());
}
private:
DeferredHandleScope deferred_;
PersistentHandlesScope persistent_;
OptimizedCompilationInfo* info_;
};
......
......@@ -136,10 +136,10 @@ OptimizedCompilationInfo::~OptimizedCompilationInfo() {
}
}
void OptimizedCompilationInfo::set_deferred_handles(
std::unique_ptr<DeferredHandles> deferred_handles) {
DCHECK_NULL(deferred_handles_);
deferred_handles_ = std::move(deferred_handles);
void OptimizedCompilationInfo::set_persistent_handles(
std::unique_ptr<PersistentHandles> persistent_handles) {
DCHECK_NULL(persistent_handles_);
persistent_handles_ = std::move(persistent_handles);
}
void OptimizedCompilationInfo::ReopenHandlesInNewHandleScope(Isolate* isolate) {
......
......@@ -159,7 +159,8 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
osr_frame_ = osr_frame;
}
void set_deferred_handles(std::unique_ptr<DeferredHandles> deferred_handles);
void set_persistent_handles(
std::unique_ptr<PersistentHandles> persistent_handles);
void ReopenHandlesInNewHandleScope(Isolate* isolate);
......@@ -263,7 +264,7 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
// OptimizedCompilationInfo allocates.
Zone* const zone_;
std::unique_ptr<DeferredHandles> deferred_handles_;
std::unique_ptr<PersistentHandles> persistent_handles_;
BailoutReason bailout_reason_ = BailoutReason::kNoReason;
......
......@@ -2958,7 +2958,7 @@ Isolate::Isolate(std::unique_ptr<i::IsolateAllocator> isolate_allocator)
builtins_(this),
rail_mode_(PERFORMANCE_ANIMATION),
code_event_dispatcher_(new CodeEventDispatcher()),
persistent_handles_list_(new PersistentHandlesList(this)),
persistent_handles_list_(new PersistentHandlesList()),
jitless_(FLAG_jitless),
#if V8_SFI_HAS_UNIQUE_ID
next_unique_sfi_id_(0),
......
......@@ -121,12 +121,8 @@ void PersistentHandlesList::Remove(PersistentHandles* persistent_handles) {
persistent_handles_head_ = persistent_handles->next_;
}
void PersistentHandlesList::Iterate(RootVisitor* visitor) {
#if DEBUG
DCHECK(isolate_->heap()->safepoint()->IsActive());
#else
USE(isolate_);
#endif
void PersistentHandlesList::Iterate(RootVisitor* visitor, Isolate* isolate) {
DCHECK_IMPLIES(FLAG_local_heaps, isolate->heap()->safepoint()->IsActive());
base::MutexGuard guard(&persistent_handles_mutex_);
for (PersistentHandles* current = persistent_handles_head_; current;
current = current->next_) {
......
......@@ -86,20 +86,16 @@ class PersistentHandles {
class PersistentHandlesList {
public:
explicit PersistentHandlesList(Isolate* isolate)
: isolate_(isolate), persistent_handles_head_(nullptr) {}
PersistentHandlesList() : persistent_handles_head_(nullptr) {}
// Iteration is only safe during a safepoint
void Iterate(RootVisitor* visitor);
void Iterate(RootVisitor* visitor, Isolate* isolate);
private:
void Add(PersistentHandles* persistent_handles);
void Remove(PersistentHandles* persistent_handles);
Isolate* isolate_;
base::Mutex persistent_handles_mutex_;
PersistentHandles* persistent_handles_head_ = nullptr;
PersistentHandles* persistent_handles_head_;
friend class PersistentHandles;
};
......
......@@ -4588,10 +4588,13 @@ void Heap::IterateRoots(RootVisitor* v, base::EnumSet<SkipRoot> options) {
if (FLAG_local_heaps) {
safepoint_->Iterate(&left_trim_visitor);
safepoint_->Iterate(v);
isolate_->persistent_handles_list()->Iterate(&left_trim_visitor);
isolate_->persistent_handles_list()->Iterate(v);
}
isolate_->persistent_handles_list()->Iterate(&left_trim_visitor, isolate_);
isolate_->persistent_handles_list()->Iterate(v, isolate_);
// TODO(solanes): Delete these two iterations once we delete all
// DeferredHandle uses.
isolate_->IterateDeferredHandles(&left_trim_visitor);
isolate_->IterateDeferredHandles(v);
v->Synchronize(VisitorSynchronization::kHandleScope);
......
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