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) {
}
std::unique_ptr<PersistentHandles> HandleScopeImplementer::DetachPersistent(
Address* prev_limit) {
Address* first_block) {
std::unique_ptr<PersistentHandles> ph(new PersistentHandles(isolate()));
DCHECK_NOT_NULL(prev_limit);
while (!blocks_.empty()) {
Address* block_start = blocks_.back();
Address* block_limit = &block_start[kHandleBlockSize];
// 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;
DCHECK_NOT_NULL(first_block);
Address* block_start;
do {
block_start = blocks_.back();
ph->blocks_.push_back(blocks_.back());
#if DEBUG
ph->ordered_blocks_.insert(blocks_.back());
#endif
blocks_.pop_back();
}
} while (block_start != first_block);
// ph->blocks_ now contains the blocks installed on the
// HandleScope stack since BeginDeferredScope was called, but in
......@@ -10612,7 +10608,7 @@ std::unique_ptr<PersistentHandles> HandleScopeImplementer::DetachPersistent(
std::swap(ph->blocks_.front(), ph->blocks_.back());
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;
DCHECK_NOT_NULL(last_handle_before_deferred_block_);
......
......@@ -425,7 +425,7 @@ class HandleScopeImplementer {
}
void BeginDeferredScope();
std::unique_ptr<PersistentHandles> DetachPersistent(Address* prev_limit);
std::unique_ptr<PersistentHandles> DetachPersistent(Address* first_block);
Isolate* isolate_;
DetachableVector<Address*> blocks_;
......
......@@ -139,14 +139,13 @@ PersistentHandlesScope::PersistentHandlesScope(Isolate* isolate)
// Check that at least one HandleScope with at least one Handle in it exists,
// see the class description.
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);
#ifdef DEBUG
prev_level_ = data->level;
#endif
data->level++;
first_block_ = new_next;
prev_limit_ = data->limit;
prev_next_ = data->next;
data->next = new_next;
......@@ -160,7 +159,7 @@ PersistentHandlesScope::~PersistentHandlesScope() {
}
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();
data->next = prev_next_;
data->limit = prev_limit_;
......
......@@ -112,6 +112,7 @@ class V8_NODISCARD PersistentHandlesScope {
V8_EXPORT_PRIVATE std::unique_ptr<PersistentHandles> Detach();
private:
Address* first_block_;
Address* prev_limit_;
Address* prev_next_;
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