Commit 856c6e0f authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

Add a stack limit to LocalIsolate

Eventually this should be used to prevent OS stack overflow
on background threads.

Drive-by change: make more things const.

Bug: v8:10974
Change-Id: Ie659e53992f58c7c08920985d54175d61c5ee796
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2474117Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70650}
parent 8bc9a794
...@@ -85,6 +85,7 @@ class HandleScopeImplementer; ...@@ -85,6 +85,7 @@ class HandleScopeImplementer;
class HeapObjectToIndexHashMap; class HeapObjectToIndexHashMap;
class HeapProfiler; class HeapProfiler;
class InnerPointerToCodeCache; class InnerPointerToCodeCache;
class LocalIsolate;
class Logger; class Logger;
class MaterializedObjectStore; class MaterializedObjectStore;
class Microtask; class Microtask;
...@@ -2066,6 +2067,7 @@ class StackLimitCheck { ...@@ -2066,6 +2067,7 @@ class StackLimitCheck {
StackGuard* stack_guard = isolate_->stack_guard(); StackGuard* stack_guard = isolate_->stack_guard();
return GetCurrentStackPosition() < stack_guard->real_climit(); return GetCurrentStackPosition() < stack_guard->real_climit();
} }
static bool HasOverflowed(LocalIsolate* local_isolate);
// Use this to check for interrupt request in C++ code. // Use this to check for interrupt request in C++ code.
bool InterruptRequested() { bool InterruptRequested() {
......
...@@ -13,11 +13,11 @@ namespace v8 { ...@@ -13,11 +13,11 @@ namespace v8 {
namespace internal { namespace internal {
Address LocalIsolate::isolate_root() const { return isolate_->isolate_root(); } Address LocalIsolate::isolate_root() const { return isolate_->isolate_root(); }
ReadOnlyHeap* LocalIsolate::read_only_heap() { ReadOnlyHeap* LocalIsolate::read_only_heap() const {
return isolate_->read_only_heap(); return isolate_->read_only_heap();
} }
Object LocalIsolate::root(RootIndex index) { Object LocalIsolate::root(RootIndex index) const {
DCHECK(RootsTable::IsImmortalImmovable(index)); DCHECK(RootsTable::IsImmortalImmovable(index));
return isolate_->root(index); return isolate_->root(index);
} }
......
...@@ -17,7 +17,10 @@ LocalIsolate::LocalIsolate(Isolate* isolate, ThreadKind kind) ...@@ -17,7 +17,10 @@ LocalIsolate::LocalIsolate(Isolate* isolate, ThreadKind kind)
heap_(isolate->heap(), kind), heap_(isolate->heap(), kind),
isolate_(isolate), isolate_(isolate),
logger_(new LocalLogger(isolate)), logger_(new LocalLogger(isolate)),
thread_id_(ThreadId::Current()) {} thread_id_(ThreadId::Current()),
stack_limit_(kind == ThreadKind::kMain
? isolate->stack_guard()->real_climit()
: GetCurrentStackPosition() - FLAG_stack_size * KB) {}
LocalIsolate::~LocalIsolate() = default; LocalIsolate::~LocalIsolate() = default;
...@@ -29,10 +32,15 @@ int LocalIsolate::GetNextUniqueSharedFunctionInfoId() { ...@@ -29,10 +32,15 @@ int LocalIsolate::GetNextUniqueSharedFunctionInfoId() {
} }
#endif // V8_SFI_HAS_UNIQUE_ID #endif // V8_SFI_HAS_UNIQUE_ID
bool LocalIsolate::is_collecting_type_profile() { bool LocalIsolate::is_collecting_type_profile() const {
// TODO(leszeks): Figure out if it makes sense to check this asynchronously. // TODO(leszeks): Figure out if it makes sense to check this asynchronously.
return isolate_->is_collecting_type_profile(); return isolate_->is_collecting_type_profile();
} }
// static
bool StackLimitCheck::HasOverflowed(LocalIsolate* local_isolate) {
return GetCurrentStackPosition() < local_isolate->stack_limit();
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -48,10 +48,10 @@ class V8_EXPORT_PRIVATE LocalIsolate final : private HiddenLocalFactory { ...@@ -48,10 +48,10 @@ class V8_EXPORT_PRIVATE LocalIsolate final : private HiddenLocalFactory {
LocalHeap* heap() { return &heap_; } LocalHeap* heap() { return &heap_; }
inline Address isolate_root() const; inline Address isolate_root() const;
inline ReadOnlyHeap* read_only_heap(); inline ReadOnlyHeap* read_only_heap() const;
inline Object root(RootIndex index); inline Object root(RootIndex index) const;
StringTable* string_table() { return isolate_->string_table(); } StringTable* string_table() const { return isolate_->string_table(); }
v8::internal::LocalFactory* factory() { v8::internal::LocalFactory* factory() {
// Upcast to the privately inherited base-class using c-style casts to avoid // Upcast to the privately inherited base-class using c-style casts to avoid
...@@ -75,10 +75,11 @@ class V8_EXPORT_PRIVATE LocalIsolate final : private HiddenLocalFactory { ...@@ -75,10 +75,11 @@ class V8_EXPORT_PRIVATE LocalIsolate final : private HiddenLocalFactory {
int GetNextUniqueSharedFunctionInfoId(); int GetNextUniqueSharedFunctionInfoId();
#endif // V8_SFI_HAS_UNIQUE_ID #endif // V8_SFI_HAS_UNIQUE_ID
bool is_collecting_type_profile(); bool is_collecting_type_profile() const;
LocalLogger* logger() { return logger_.get(); } LocalLogger* logger() const { return logger_.get(); }
ThreadId thread_id() { return thread_id_; } ThreadId thread_id() const { return thread_id_; }
Address stack_limit() const { return stack_limit_; }
private: private:
friend class v8::internal::LocalFactory; friend class v8::internal::LocalFactory;
...@@ -87,10 +88,11 @@ class V8_EXPORT_PRIVATE LocalIsolate final : private HiddenLocalFactory { ...@@ -87,10 +88,11 @@ class V8_EXPORT_PRIVATE LocalIsolate final : private HiddenLocalFactory {
// TODO(leszeks): Extract out the fields of the Isolate we want and store // TODO(leszeks): Extract out the fields of the Isolate we want and store
// those instead of the whole thing. // those instead of the whole thing.
Isolate* isolate_; Isolate* const isolate_;
std::unique_ptr<LocalLogger> logger_; std::unique_ptr<LocalLogger> logger_;
ThreadId thread_id_; ThreadId const thread_id_;
Address const stack_limit_;
}; };
} // namespace internal } // namespace internal
......
...@@ -126,7 +126,7 @@ class V8_EXPORT_PRIVATE LocalHeap { ...@@ -126,7 +126,7 @@ class V8_EXPORT_PRIVATE LocalHeap {
AllocationOrigin origin = AllocationOrigin::kRuntime, AllocationOrigin origin = AllocationOrigin::kRuntime,
AllocationAlignment alignment = kWordAligned); AllocationAlignment alignment = kWordAligned);
bool is_main_thread() { return is_main_thread_; } bool is_main_thread() const { return is_main_thread_; }
private: private:
enum class ThreadState { enum class ThreadState {
......
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