v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
regexp-stack.cc
Go to the documentation of this file.
1// Copyright 2009 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
8#include "src/utils/memcopy.h"
9
10namespace v8 {
11namespace internal {
12
14 : regexp_stack_(isolate->regexp_stack()),
15 old_sp_top_delta_(regexp_stack_->sp_top_delta()) {
17}
18
23
24RegExpStack::RegExpStack() : thread_local_(this) {}
25
27
30 // Force dynamic stacks prior to archiving. Any growth will do. A dynamic
31 // stack is needed because stack archival & restoration rely on `memory_`
32 // pointing at a fixed-location backing store, whereas the static stack is
33 // tied to a RegExpStack instance.
36 }
37
38 MemCopy(reinterpret_cast<void*>(to), &thread_local_, kThreadLocalSize);
40 return to + kThreadLocalSize;
41}
42
43
44char* RegExpStack::RestoreStack(char* from) {
45 MemCopy(&thread_local_, reinterpret_cast<void*>(from), kThreadLocalSize);
46 return from + kThreadLocalSize;
47}
48
60
62 if (owns_memory_) DeleteArray(memory_);
63
64 // This stack may not be used after being freed. Just reset to invalid values
65 // to ensure we don't accidentally use old memory areas.
66 memory_ = nullptr;
67 memory_top_ = nullptr;
68 memory_size_ = 0;
69 stack_pointer_ = nullptr;
71}
72
74 if (size > kMaximumStackSize) return kNullAddress;
75 if (thread_local_.memory_size_ < size) {
77 uint8_t* new_memory = NewArray<uint8_t>(size);
79 // Copy original memory into top of new memory.
80 MemCopy(new_memory + size - thread_local_.memory_size_,
83 }
84 ptrdiff_t delta = sp_top_delta();
85 thread_local_.memory_ = new_memory;
86 thread_local_.memory_top_ = new_memory + size;
90 reinterpret_cast<Address>(new_memory) + kStackLimitSlackSize;
92 }
93 return reinterpret_cast<Address>(thread_local_.memory_top_);
94}
95
96
97} // namespace internal
98} // namespace v8
RegExpStack *const regexp_stack_
RegExpStackScope(Isolate *isolate)
const ptrdiff_t old_sp_top_delta_
static constexpr size_t kThreadLocalSize
char * ArchiveStack(char *to)
static constexpr int kStackLimitSlackSize
static const Address kMemoryTop
ptrdiff_t sp_top_delta() const
static constexpr size_t kStaticStackSize
Address EnsureCapacity(size_t size)
char * RestoreStack(char *from)
uint8_t static_stack_[kStaticStackSize]
static constexpr size_t kMinimumDynamicStackSize
static constexpr size_t kMaximumStackSize
const int limit_
Definition isolate.cc:1114
void DeleteArray(T *array)
Definition allocation.h:63
static constexpr Address kNullAddress
Definition v8-internal.h:53
void MemCopy(void *dest, const void *src, size_t size)
Definition memcopy.h:124
T * NewArray(size_t size)
Definition allocation.h:43
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482
void ResetToStaticStack(RegExpStack *regexp_stack)