[regexp] Don't allocate dynamic stacks when static stacks suffice

In https://chromium-review.googlesource.com/c/v8/v8/+/1866771 we added
a static regexp stack area to ensure a stack always exists. We
apparently forgot to update EnsureCapacity s.t. we skip
dynamically-allocating a stack when the static stack suffices.

Found by lizeb@, thanks!

Bug: v8:11540
Change-Id: Ie63b0b5e5959fbf0768cc3597f63943b1775fbf2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2749015
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73337}
This commit is contained in:
Jakob Gruber 2021-03-11 09:46:45 +01:00 committed by Commit Bot
parent 5204c32ad6
commit d18b37ce1a
2 changed files with 5 additions and 3 deletions

View File

@ -12,8 +12,7 @@ namespace internal {
RegExpStackScope::RegExpStackScope(Isolate* isolate)
: regexp_stack_(isolate->regexp_stack()) {
// Initialize, if not already initialized.
regexp_stack_->EnsureCapacity(0);
DCHECK(regexp_stack_->IsValid());
// Irregexp is not reentrant in several ways; in particular, the
// RegExpStackScope is not reentrant since the destructor frees allocated
// memory. Protect against reentrancy here.
@ -80,8 +79,8 @@ void RegExpStack::ThreadLocal::FreeAndInvalidate() {
Address RegExpStack::EnsureCapacity(size_t size) {
if (size > kMaximumStackSize) return kNullAddress;
if (size < kMinimumDynamicStackSize) size = kMinimumDynamicStackSize;
if (thread_local_.memory_size_ < size) {
if (size < kMinimumDynamicStackSize) size = kMinimumDynamicStackSize;
byte* new_memory = NewArray<byte>(size);
if (thread_local_.memory_size_ > 0) {
// Copy original memory into top of new memory.

View File

@ -133,6 +133,9 @@ class RegExpStack {
// you have to call EnsureCapacity before using it again.
void Reset();
// Whether the ThreadLocal storage has been invalidated.
bool IsValid() const { return thread_local_.memory_ != nullptr; }
ThreadLocal thread_local_;
Isolate* isolate_;