Commit ced65be6 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by V8 LUCI CQ

[wasm] Move some code from .h to .cc file

The src/wasm/stacks.h file became progressively bigger, create a
cc file for it and move some function definitions there.

R=clemensb@chromium.org

Bug: v8:12191
Change-Id: I6880a4e11884856bd2f4d777cb745a3c06c71841
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3874936Reviewed-by: 's avatarManos Koukoutos <manoskouk@chromium.org>
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83039}
parent 0a1a579a
......@@ -2531,6 +2531,7 @@ filegroup(
"src/wasm/signature-map.h",
"src/wasm/simd-shuffle.cc",
"src/wasm/simd-shuffle.h",
"src/wasm/stacks.cc",
"src/wasm/stacks.h",
"src/wasm/streaming-decoder.cc",
"src/wasm/streaming-decoder.h",
......
......@@ -4847,6 +4847,7 @@ v8_source_set("v8_base_without_compiler") {
"src/wasm/names-provider.cc",
"src/wasm/signature-map.cc",
"src/wasm/simd-shuffle.cc",
"src/wasm/stacks.cc",
"src/wasm/streaming-decoder.cc",
"src/wasm/sync-streaming-decoder.cc",
"src/wasm/value-type.cc",
......
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/wasm/stacks.h"
namespace v8::internal::wasm {
// static
StackMemory* StackMemory::GetCurrentStackView(Isolate* isolate) {
byte* limit = reinterpret_cast<byte*>(isolate->stack_guard()->real_jslimit());
return new StackMemory(isolate, limit);
}
StackMemory::~StackMemory() {
if (v8_flags.trace_wasm_stack_switching) {
PrintF("Delete stack #%d\n", id_);
}
PageAllocator* allocator = GetPlatformPageAllocator();
if (owned_) allocator->DecommitPages(limit_, size_);
// We don't need to handle removing the last stack from the list (next_ ==
// this). This only happens on isolate tear down, otherwise there is always
// at least one reachable stack (the active stack).
isolate_->wasm_stacks() = next_;
prev_->next_ = next_;
next_->prev_ = prev_;
}
void StackMemory::Add(StackMemory* stack) {
stack->next_ = this->next_;
stack->prev_ = this;
this->next_->prev_ = stack;
this->next_ = stack;
}
StackMemory::StackMemory(Isolate* isolate) : isolate_(isolate), owned_(true) {
static std::atomic<int> next_id(1);
id_ = next_id.fetch_add(1);
PageAllocator* allocator = GetPlatformPageAllocator();
int kJsStackSizeKB = 4;
size_ = (kJsStackSizeKB + kJSLimitOffsetKB) * KB;
size_ = RoundUp(size_, allocator->AllocatePageSize());
limit_ = static_cast<byte*>(
allocator->AllocatePages(nullptr, size_, allocator->AllocatePageSize(),
PageAllocator::kReadWrite));
if (v8_flags.trace_wasm_stack_switching) {
PrintF("Allocate stack #%d (limit: %p, base: %p)\n", id_, limit_,
limit_ + size_);
}
}
// Overload to represent a view of the libc stack.
StackMemory::StackMemory(Isolate* isolate, byte* limit)
: isolate_(isolate),
limit_(limit),
size_(v8_flags.stack_size * KB),
owned_(false) {
id_ = 0;
}
} // namespace v8::internal::wasm
......@@ -13,9 +13,7 @@
#include "src/execution/isolate.h"
#include "src/utils/allocation.h"
namespace v8 {
namespace internal {
namespace wasm {
namespace v8::internal::wasm {
struct JumpBuffer {
Address sp;
......@@ -37,38 +35,16 @@ class StackMemory {
static StackMemory* New(Isolate* isolate) { return new StackMemory(isolate); }
// Returns a non-owning view of the current stack.
static StackMemory* GetCurrentStackView(Isolate* isolate) {
byte* limit =
reinterpret_cast<byte*>(isolate->stack_guard()->real_jslimit());
return new StackMemory(isolate, limit);
}
~StackMemory() {
if (v8_flags.trace_wasm_stack_switching) {
PrintF("Delete stack #%d\n", id_);
}
PageAllocator* allocator = GetPlatformPageAllocator();
if (owned_) allocator->DecommitPages(limit_, size_);
// We don't need to handle removing the last stack from the list (next_ ==
// this). This only happens on isolate tear down, otherwise there is always
// at least one reachable stack (the active stack).
isolate_->wasm_stacks() = next_;
prev_->next_ = next_;
next_->prev_ = prev_;
}
static StackMemory* GetCurrentStackView(Isolate* isolate);
~StackMemory();
void* jslimit() const { return limit_ + kJSLimitOffsetKB; }
Address base() const { return reinterpret_cast<Address>(limit_ + size_); }
JumpBuffer* jmpbuf() { return &jmpbuf_; }
int id() { return id_; }
// Insert a stack in the linked list after this stack.
void Add(StackMemory* stack) {
stack->next_ = this->next_;
stack->prev_ = this;
this->next_->prev_ = stack;
this->next_ = stack;
}
void Add(StackMemory* stack);
StackMemory* next() { return next_; }
......@@ -84,29 +60,10 @@ class StackMemory {
#endif
// This constructor allocates a new stack segment.
explicit StackMemory(Isolate* isolate) : isolate_(isolate), owned_(true) {
static std::atomic<int> next_id(1);
id_ = next_id.fetch_add(1);
PageAllocator* allocator = GetPlatformPageAllocator();
int kJsStackSizeKB = 4;
size_ = (kJsStackSizeKB + kJSLimitOffsetKB) * KB;
size_ = RoundUp(size_, allocator->AllocatePageSize());
limit_ = static_cast<byte*>(
allocator->AllocatePages(nullptr, size_, allocator->AllocatePageSize(),
PageAllocator::kReadWrite));
if (v8_flags.trace_wasm_stack_switching) {
PrintF("Allocate stack #%d\n", id_);
}
}
explicit StackMemory(Isolate* isolate);
// Overload to represent a view of the libc stack.
StackMemory(Isolate* isolate, byte* limit)
: isolate_(isolate),
limit_(limit),
size_(v8_flags.stack_size * KB),
owned_(false) {
id_ = 0;
}
StackMemory(Isolate* isolate, byte* limit);
Isolate* isolate_;
byte* limit_;
......@@ -119,8 +76,6 @@ class StackMemory {
StackMemory* prev_ = this;
};
} // namespace wasm
} // namespace internal
} // namespace v8
} // namespace v8::internal::wasm
#endif // V8_WASM_STACKS_H_
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