Commit ced07dd5 authored by Toon Verwaest's avatar Toon Verwaest Committed by V8 LUCI CQ

[handles] Allow PersistentHandlesScopes in the context of SealedHandleScopes

Otherwise opening a HandleScope nested in a SHS also wouldn't allow PHS. This
currently happens in maglev..

Bug: v8:7700
Change-Id: Id279cf7ad8c83f68a3ba0050a0df718892636e9f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3650601Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80559}
parent f4eb4c6e
...@@ -10584,23 +10584,19 @@ char* HandleScopeImplementer::Iterate(RootVisitor* v, char* storage) { ...@@ -10584,23 +10584,19 @@ char* HandleScopeImplementer::Iterate(RootVisitor* v, char* storage) {
} }
std::unique_ptr<PersistentHandles> HandleScopeImplementer::DetachPersistent( std::unique_ptr<PersistentHandles> HandleScopeImplementer::DetachPersistent(
Address* prev_limit) { Address* first_block) {
std::unique_ptr<PersistentHandles> ph(new PersistentHandles(isolate())); std::unique_ptr<PersistentHandles> ph(new PersistentHandles(isolate()));
DCHECK_NOT_NULL(prev_limit); DCHECK_NOT_NULL(first_block);
while (!blocks_.empty()) { Address* block_start;
Address* block_start = blocks_.back(); do {
Address* block_limit = &block_start[kHandleBlockSize]; block_start = blocks_.back();
// We should not need to check for SealHandleScope here. Assert this.
DCHECK_IMPLIES(block_start <= prev_limit && prev_limit <= block_limit,
prev_limit == block_limit);
if (prev_limit == block_limit) break;
ph->blocks_.push_back(blocks_.back()); ph->blocks_.push_back(blocks_.back());
#if DEBUG #if DEBUG
ph->ordered_blocks_.insert(blocks_.back()); ph->ordered_blocks_.insert(blocks_.back());
#endif #endif
blocks_.pop_back(); blocks_.pop_back();
} } while (block_start != first_block);
// ph->blocks_ now contains the blocks installed on the // ph->blocks_ now contains the blocks installed on the
// HandleScope stack since BeginDeferredScope was called, but in // HandleScope stack since BeginDeferredScope was called, but in
...@@ -10612,7 +10608,7 @@ std::unique_ptr<PersistentHandles> HandleScopeImplementer::DetachPersistent( ...@@ -10612,7 +10608,7 @@ std::unique_ptr<PersistentHandles> HandleScopeImplementer::DetachPersistent(
std::swap(ph->blocks_.front(), ph->blocks_.back()); std::swap(ph->blocks_.front(), ph->blocks_.back());
ph->block_next_ = isolate()->handle_scope_data()->next; ph->block_next_ = isolate()->handle_scope_data()->next;
Address* block_start = ph->blocks_.back(); block_start = ph->blocks_.back();
ph->block_limit_ = block_start + kHandleBlockSize; ph->block_limit_ = block_start + kHandleBlockSize;
DCHECK_NOT_NULL(last_handle_before_deferred_block_); DCHECK_NOT_NULL(last_handle_before_deferred_block_);
......
...@@ -425,7 +425,7 @@ class HandleScopeImplementer { ...@@ -425,7 +425,7 @@ class HandleScopeImplementer {
} }
void BeginDeferredScope(); void BeginDeferredScope();
std::unique_ptr<PersistentHandles> DetachPersistent(Address* prev_limit); std::unique_ptr<PersistentHandles> DetachPersistent(Address* first_block);
Isolate* isolate_; Isolate* isolate_;
DetachableVector<Address*> blocks_; DetachableVector<Address*> blocks_;
......
...@@ -139,14 +139,13 @@ PersistentHandlesScope::PersistentHandlesScope(Isolate* isolate) ...@@ -139,14 +139,13 @@ PersistentHandlesScope::PersistentHandlesScope(Isolate* isolate)
// Check that at least one HandleScope with at least one Handle in it exists, // Check that at least one HandleScope with at least one Handle in it exists,
// see the class description. // see the class description.
DCHECK(!impl_->blocks()->empty()); DCHECK(!impl_->blocks()->empty());
// Check that we are not in a SealHandleScope.
DCHECK(data->limit == &impl_->blocks()->back()[kHandleBlockSize]);
impl_->blocks()->push_back(new_next); impl_->blocks()->push_back(new_next);
#ifdef DEBUG #ifdef DEBUG
prev_level_ = data->level; prev_level_ = data->level;
#endif #endif
data->level++; data->level++;
first_block_ = new_next;
prev_limit_ = data->limit; prev_limit_ = data->limit;
prev_next_ = data->next; prev_next_ = data->next;
data->next = new_next; data->next = new_next;
...@@ -160,7 +159,7 @@ PersistentHandlesScope::~PersistentHandlesScope() { ...@@ -160,7 +159,7 @@ PersistentHandlesScope::~PersistentHandlesScope() {
} }
std::unique_ptr<PersistentHandles> PersistentHandlesScope::Detach() { std::unique_ptr<PersistentHandles> PersistentHandlesScope::Detach() {
std::unique_ptr<PersistentHandles> ph = impl_->DetachPersistent(prev_limit_); std::unique_ptr<PersistentHandles> ph = impl_->DetachPersistent(first_block_);
HandleScopeData* data = impl_->isolate()->handle_scope_data(); HandleScopeData* data = impl_->isolate()->handle_scope_data();
data->next = prev_next_; data->next = prev_next_;
data->limit = prev_limit_; data->limit = prev_limit_;
......
...@@ -112,6 +112,7 @@ class V8_NODISCARD PersistentHandlesScope { ...@@ -112,6 +112,7 @@ class V8_NODISCARD PersistentHandlesScope {
V8_EXPORT_PRIVATE std::unique_ptr<PersistentHandles> Detach(); V8_EXPORT_PRIVATE std::unique_ptr<PersistentHandles> Detach();
private: private:
Address* first_block_;
Address* prev_limit_; Address* prev_limit_;
Address* prev_next_; Address* prev_next_;
HandleScopeImplementer* const impl_; HandleScopeImplementer* const impl_;
......
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