20 if (
v8_flags.trace_wasm_stack_switching) {
25 auto next_segment = segment->next_segment_;
27 segment = next_segment;
33 SimulatorStack::JSStackLimitMargin();
37 static std::atomic<int> next_id(1);
38 id_ = next_id.fetch_add(1);
39 size_t kJsStackSizeKB =
v8_flags.wasm_stack_switching_stack_size;
42 const size_t size_limit =
v8_flags.stack_size;
44 auto page_size = allocator->AllocatePageSize();
45 size_t initial_size = std::min<size_t>(
47 kJsStackSizeKB * KB + SimulatorStack::JSStackLimitMargin());
53 if (
v8_flags.trace_wasm_stack_switching) {
54 PrintF(
"Allocate stack #%d (limit: %p, base: %p, size: %zu)\n",
id_,
limit_,
68 size_ = pages * allocator->AllocatePageSize();
69 limit_ =
static_cast<uint8_t*
>(
70 allocator->AllocatePages(
nullptr,
size_, allocator->AllocatePageSize(),
74 "StackMemory::StackSegment::StackSegment");
91 auto page_size = allocator->AllocatePageSize();
94 size_t room_to_grow = size_limit -
size_;
96 if (new_size < page_size) {
98 if (
v8_flags.trace_wasm_stack_switching) {
99 PrintF(
"Stack #%d reached the grow limit %zu bytes\n",
id_, size_limit);
103 auto new_segment =
new StackSegment(new_size / page_size);
110 if (
v8_flags.trace_wasm_stack_switching) {
111 PrintF(
"Grow stack #%d by %zu bytes (limit: %p, base: %p)\n",
id_,
125 if (
v8_flags.trace_wasm_stack_switching) {
126 PrintF(
"Shrink stack #%d (limit: %p, base: %p)\n",
id_,
136 if (stack_address <= active_segment_->
base() &&
152 size_ -= freelist_.back()->allocated_size();
153 freelist_.pop_back();
155 std::unique_ptr<StackMemory>
stack;
156 if (freelist_.empty()) {
159 stack = std::move(freelist_.back());
160 freelist_.pop_back();
161 size_ -= stack->allocated_size();
174 size_ += stack->allocated_size();
176 freelist_.push_back(std::move(stack));
constexpr size_t size() const
constexpr T * begin() const
static V8_EXPORT_PRIVATE void FatalProcessOutOfMemory(Isolate *isolate, const char *location, const OOMDetails &details=kNoOOMDetails)
StackSegment * prev_segment_
StackSegment * next_segment_
StackSegment(size_t size)
static std::unique_ptr< StackMemory > New()
void ShrinkTo(Address stack_address)
StackSegment * first_segment_
StackSegment * active_segment_
bool Grow(Address current_fp)
static StackMemory * GetCentralStackView(Isolate *isolate)
std::unique_ptr< StackMemory > GetOrAllocate()
void Add(std::unique_ptr< StackMemory > stack)
void ReleaseFinishedStacks()
ZoneStack< RpoNumber > & stack
static ValueType value_type()
v8::PageAllocator * GetPlatformPageAllocator()
void PrintF(const char *format,...)
constexpr uint32_t kZapValue
V8_EXPORT_PRIVATE FlagValues v8_flags
static constexpr int kMaxSize
#define DCHECK_NOT_NULL(val)
#define DCHECK_NE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
constexpr T RoundUp(T x, intptr_t m)