diff options
Diffstat (limited to 'deps/v8/src/execution/isolate.h')
-rw-r--r-- | deps/v8/src/execution/isolate.h | 187 |
1 files changed, 71 insertions, 116 deletions
diff --git a/deps/v8/src/execution/isolate.h b/deps/v8/src/execution/isolate.h index 1f374165b6..929435239f 100644 --- a/deps/v8/src/execution/isolate.h +++ b/deps/v8/src/execution/isolate.h @@ -32,6 +32,7 @@ #include "src/execution/stack-guard.h" #include "src/handles/handles.h" #include "src/handles/traced-handles.h" +#include "src/heap/base/stack.h" #include "src/heap/factory.h" #include "src/heap/heap.h" #include "src/heap/read-only-heap.h" @@ -510,6 +511,7 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>; V(WasmLoadSourceMapCallback, wasm_load_source_map_callback, nullptr) \ V(WasmSimdEnabledCallback, wasm_simd_enabled_callback, nullptr) \ V(WasmExceptionsEnabledCallback, wasm_exceptions_enabled_callback, nullptr) \ + V(WasmGCEnabledCallback, wasm_gc_enabled_callback, nullptr) \ /* State for Relocatable. */ \ V(Relocatable*, relocatable_top, nullptr) \ V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \ @@ -538,8 +540,6 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>; V(int, embedder_wrapper_type_index, -1) \ V(int, embedder_wrapper_object_index, -1) \ V(compiler::NodeObserver*, node_observer, nullptr) \ - /* Used in combination with --script-run-delay-once */ \ - V(bool, did_run_script_delay, false) \ V(bool, javascript_execution_assert, true) \ V(bool, javascript_execution_throws, true) \ V(bool, javascript_execution_dump, true) \ @@ -553,7 +553,7 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>; inline type name() const { return thread_local_top()->name##_; } #define THREAD_LOCAL_TOP_ADDRESS(type, name) \ - type* name##_address() { return &thread_local_top()->name##_; } + inline type* name##_address() { return &thread_local_top()->name##_; } // HiddenFactory exists so Isolate can privately inherit from it without making // Factory's members available to Isolate directly. @@ -680,7 +680,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // at the same time, this should be prevented using external locking. void Enter(); - // Exits the current thread. The previosuly entered Isolate is restored + // Exits the current thread. The previously entered Isolate is restored // for the thread. // Not thread-safe. Multiple threads should not Enter/Exit the same isolate // at the same time, this should be prevented using external locking. @@ -768,6 +768,10 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { bool IsSharedArrayBufferConstructorEnabled(Handle<Context> context); + bool IsWasmGCEnabled(Handle<Context> context); + bool IsWasmStringRefEnabled(Handle<Context> context); + bool IsWasmInliningEnabled(Handle<Context> context); + THREAD_LOCAL_TOP_ADDRESS(Context, pending_handler_context) THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_entrypoint) THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_constant_pool) @@ -1155,8 +1159,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // compression cage, and the kPtrComprCageBaseRegister is set to this // value. When pointer compression is off, this is always kNullAddress. Address cage_base() const { - DCHECK_IMPLIES(!COMPRESS_POINTERS_IN_ISOLATE_CAGE_BOOL && - !COMPRESS_POINTERS_IN_SHARED_CAGE_BOOL, + DCHECK_IMPLIES(!COMPRESS_POINTERS_BOOL, isolate_data()->cage_base() == kNullAddress); return isolate_data()->cage_base(); } @@ -1343,6 +1346,19 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { #ifdef DEBUG static size_t non_disposed_isolates() { return non_disposed_isolates_; } + + // Turbofan's string builder optimization can introduce SlicedString that are + // less than SlicedString::kMinLength characters. Their live range and scope + // are pretty limitted, but they can be visible to the GC, which shouldn't + // treat them as invalid. When such short SlicedString are introduced, + // Turbofan will set has_turbofan_string_builders_ to true, which + // SlicedString::SlicedStringVerify will check when verifying SlicedString to + // decide if a too-short SlicedString is an issue or not. + // See the compiler's StringBuilderOptimizer class for more details. + bool has_turbofan_string_builders() { return has_turbofan_string_builders_; } + void set_has_turbofan_string_builders() { + has_turbofan_string_builders_ = true; + } #endif v8::internal::Factory* factory() { @@ -1478,6 +1494,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { } void UpdateTypedArraySpeciesLookupChainProtectorOnSetPrototype( Handle<JSObject> object); + void UpdateNumberStringPrototypeNoReplaceProtectorOnSetPrototype( + Handle<JSObject> object); void UpdateNoElementsProtectorOnNormalizeElements(Handle<JSObject> object) { UpdateNoElementsProtectorOnSetElement(object); } @@ -1518,7 +1536,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { DCHECK_NOT_NULL(optimizing_compile_dispatcher_); return optimizing_compile_dispatcher_; } - // Flushes all pending concurrent optimzation jobs from the optimizing + // Flushes all pending concurrent optimization jobs from the optimizing // compile dispatcher's queue. void AbortConcurrentOptimization(BlockingBehavior blocking_behavior); @@ -1556,9 +1574,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // with the provided mask. int GenerateIdentityHash(uint32_t mask); - // Given an address occupied by a live code object, return that object. - CodeLookupResult FindCodeObject(Address a); - int NextOptimizationId() { int id = next_optimization_id_++; if (!Smi::IsValid(next_optimization_id_)) { @@ -1695,8 +1710,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // shared heap object cache holds objects in shared among Isolates. Otherwise // this object cache is per-Isolate like the startup object cache. std::vector<Object>* shared_heap_object_cache() { - if (has_shared_heap()) { - return &shared_heap_isolate()->shared_heap_object_cache_; + if (has_shared_space()) { + return &shared_space_isolate()->shared_heap_object_cache_; } return &shared_heap_object_cache_; } @@ -1710,8 +1725,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { } // Hashes bits of the Isolate that are relevant for embedded builtins. In - // particular, the embedded blob requires builtin Code object layout and the - // builtins constants table to remain unchanged from build-time. + // particular, the embedded blob requires builtin InstructionStream object + // layout and the builtins constants table to remain unchanged from + // build-time. size_t HashIsolateForEmbeddedBlob(); static const uint8_t* CurrentEmbeddedBlobCode(); @@ -1727,7 +1743,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { const uint8_t* embedded_blob_data() const; uint32_t embedded_blob_data_size() const; - // Returns true if short bultin calls optimization is enabled for the Isolate. + // Returns true if short builtin calls optimization is enabled for the + // Isolate. bool is_short_builtin_calls_enabled() const { return V8_SHORT_BUILTIN_CALLS_BOOL && is_short_builtin_calls_enabled_; } @@ -1966,43 +1983,19 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { using IsDebugActive = HasAsyncEventDelegate::Next<bool, 1>; }; - bool is_shared() const { return is_shared_; } - Isolate* shared_isolate() const { - DCHECK(attached_to_shared_isolate_); - return shared_isolate_; - } - + // Returns true when this isolate contains the shared spaces. bool is_shared_space_isolate() const { return is_shared_space_isolate_; } - Isolate* shared_space_isolate() const { - return shared_space_isolate_.value(); - } - - void set_shared_isolate(Isolate* shared_isolate) { - DCHECK(shared_isolate->is_shared()); - DCHECK_NULL(shared_isolate_); - DCHECK(!attached_to_shared_isolate_); - DCHECK(!v8_flags.shared_space); - shared_isolate_ = shared_isolate; - owns_shareable_data_ = false; - } - - // Returns true when this isolate supports allocation in shared spaces. - bool has_shared_heap() const { - return v8_flags.shared_space ? shared_space_isolate() : shared_isolate(); - } // Returns the isolate that owns the shared spaces. - Isolate* shared_heap_isolate() const { - DCHECK(has_shared_heap()); - Isolate* isolate = - v8_flags.shared_space ? shared_space_isolate() : shared_isolate(); - DCHECK_NOT_NULL(isolate); + Isolate* shared_space_isolate() const { + DCHECK(has_shared_space()); + Isolate* isolate = shared_space_isolate_.value(); + DCHECK(has_shared_space()); return isolate; } - bool is_shared_heap_isolate() const { - return is_shared() || is_shared_space_isolate(); - } + // Returns true when this isolate supports allocation in shared spaces. + bool has_shared_space() const { return shared_space_isolate_.value(); } GlobalSafepoint* global_safepoint() const { return global_safepoint_.get(); } @@ -2013,16 +2006,20 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // TODO(pthier): Unify with owns_shareable_data() once the flag // --shared-string-table is removed. bool OwnsStringTables() { - return !v8_flags.shared_string_table || is_shared() || - is_shared_space_isolate(); + return !v8_flags.shared_string_table || is_shared_space_isolate(); } #if USE_SIMULATOR SimulatorData* simulator_data() { return simulator_data_; } #endif + ::heap::base::Stack& stack() { return stack_; } + #ifdef V8_ENABLE_WEBASSEMBLY wasm::StackMemory*& wasm_stacks() { return wasm_stacks_; } + // Update the thread local's Stack object so that it is aware of the new stack + // start and the inactive stacks. + void RecordStackSwitchForScanning(); #endif // Access to the global "locals block list cache". Caches outer-stack @@ -2035,12 +2032,13 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // Returns either `TheHole` or `StringSet`. Object LocalsBlockListCacheGet(Handle<ScopeInfo> scope_info); + void VerifyStaticRoots(); + private: - explicit Isolate(std::unique_ptr<IsolateAllocator> isolate_allocator, - bool is_shared); + explicit Isolate(std::unique_ptr<IsolateAllocator> isolate_allocator); ~Isolate(); - static Isolate* Allocate(bool is_shared); + static Isolate* Allocate(); bool Init(SnapshotData* startup_snapshot_data, SnapshotData* read_only_snapshot_data, @@ -2097,18 +2095,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { EntryStackItem* previous_item; }; - // When a feature flag that requires the shared heap is passed, a shared - // isolate is created to hold the shared allocations. The shared isolate is - // created by the first isolate to be created in the process, which is - // considered the main isolate and owns the lifetime of the shared - // isolate. The main isolate deletes the shared isolate when it itself is - // deleted. - static base::LazyMutex process_wide_shared_isolate_mutex_; - static Isolate* process_wide_shared_isolate_; - - static Isolate* GetProcessWideSharedIsolate(bool* created_shared_isolate); - static void DeleteProcessWideSharedIsolate(); - static Isolate* process_wide_shared_space_isolate_; void Deinit(); @@ -2153,24 +2139,11 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // Returns the Exception sentinel. Object ThrowInternal(Object exception, MessageLocation* location); - // These methods add/remove the isolate to/from the list of clients in the - // shared isolate. Isolates in the client list need to participate in a global - // safepoint. - void AttachToSharedIsolate(); - void DetachFromSharedIsolate(); - - void AttachToSharedSpaceIsolate(Isolate* shared_space_isolate); - void DetachFromSharedSpaceIsolate(); - // This class contains a collection of data accessible from both C++ runtime // and compiled code (including assembly stubs, builtins, interpreter bytecode // handlers and optimized code). IsolateData isolate_data_; - // Set to true if this isolate is used as shared heap. This field must be set - // before Heap is constructed, as Heap's constructor consults it. - const bool is_shared_; - // Set to true if this isolate is used as main isolate with a shared space. bool is_shared_space_isolate_{false}; @@ -2291,7 +2264,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // True if this isolate was initialized from a snapshot. bool initialized_from_snapshot_ = false; - // True if short bultin calls optimization is enabled. + // True if short builtin calls optimization is enabled. bool is_short_builtin_calls_enabled_ = false; // True if the isolate is in background. This flag is used @@ -2306,11 +2279,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // Only false for client isolates attached to a shared isolate. bool owns_shareable_data_ = true; - // True if this isolate is attached to a shared isolate, and this isolate is - // the main isolate in the process and owns the lifetime of the shared - // isolate. - bool owns_shared_isolate_ = false; - bool log_object_relocation_ = false; #ifdef V8_EXTERNAL_CODE_SPACE @@ -2326,6 +2294,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { static std::atomic<size_t> non_disposed_isolates_; JSObject::SpillInformation js_spill_information_; + + std::atomic<bool> has_turbofan_string_builders_ = false; #endif Debug* debug_ = nullptr; @@ -2422,6 +2392,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { void InitializeDefaultEmbeddedBlob(); void CreateAndSetEmbeddedBlob(); + void InitializeIsShortBuiltinCallsEnabled(); void MaybeRemapEmbeddedBuiltinsIntoCodeRange(); void TearDownEmbeddedBlob(); void SetEmbeddedBlob(const uint8_t* code, uint32_t code_size, @@ -2476,12 +2447,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { base::Mutex thread_data_table_mutex_; ThreadDataTable thread_data_table_; - // Stores the shared isolate for this client isolate. nullptr for shared - // isolates or when no shared isolate is used. - // - // When non-null, it is identical to process_wide_shared_isolate_. - Isolate* shared_isolate_ = nullptr; - // Stores the isolate containing the shared space. base::Optional<Isolate*> shared_space_isolate_; @@ -2492,13 +2457,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { kNullExternalPointerHandle; #endif -#if DEBUG - // Set to true once during isolate initialization right when attaching to the - // shared isolate. If there was no shared isolate given it will still be set - // to true. After this point invocations of shared_isolate() are valid. - bool attached_to_shared_isolate_ = false; -#endif // DEBUG - // Used to track and safepoint all client isolates attached to this shared // isolate. std::unique_ptr<GlobalSafepoint> global_safepoint_; @@ -2514,6 +2472,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { // The mutex only guards adding pages, the retrieval is signal safe. base::Mutex code_pages_mutex_; + // Stack information for the main thread. + ::heap::base::Stack stack_; + #ifdef V8_ENABLE_WEBASSEMBLY wasm::StackMemory* wasm_stacks_; #endif @@ -2549,6 +2510,7 @@ extern thread_local Isolate* g_current_isolate_ V8_CONSTINIT; #undef FIELD_ACCESSOR #undef THREAD_LOCAL_TOP_ACCESSOR +#undef THREAD_LOCAL_TOP_ADDRESS // SaveContext scopes save the current context on the Isolate on creation, and // restore it on destruction. @@ -2558,15 +2520,9 @@ class V8_EXPORT_PRIVATE SaveContext { ~SaveContext(); - Handle<Context> context() { return context_; } - - // Returns true if this save context is below a given JavaScript frame. - bool IsBelowFrame(CommonFrame* frame); - private: Isolate* const isolate_; Handle<Context> context_; - Address c_entry_fp_; }; // Like SaveContext, but also switches the Context to a new one in the @@ -2629,34 +2585,33 @@ class StackLimitCheck { } static bool HasOverflowed(LocalIsolate* local_isolate); + // Use this to check for stack-overflow when entering runtime from JS code. + bool JsHasOverflowed(uintptr_t gap = 0) const; + // Use this to check for interrupt request in C++ code. V8_INLINE bool InterruptRequested() { StackGuard* stack_guard = isolate_->stack_guard(); return GetCurrentStackPosition() < stack_guard->climit(); } - // Handle interripts if InterruptRequested was true. + // Precondition: InterruptRequested == true. // Returns true if any interrupt (overflow or termination) was handled, in - // which case the caller should prevent further JS execution. - V8_EXPORT_PRIVATE bool HandleInterrupt(Isolate* isolate); - - // Use this to check for stack-overflow when entering runtime from JS code. - bool JsHasOverflowed(uintptr_t gap = 0) const; + // which case the caller must prevent further JS execution. + V8_EXPORT_PRIVATE bool HandleStackOverflowAndTerminationRequest(); private: - Isolate* isolate_; + Isolate* const isolate_; }; // This macro may be used in context that disallows JS execution. // That is why it checks only for a stack overflow and termination. -#define STACK_CHECK(isolate, result_value) \ - do { \ - StackLimitCheck stack_check(isolate); \ - if (stack_check.InterruptRequested()) { \ - if (stack_check.HandleInterrupt(isolate)) { \ - return result_value; \ - } \ - } \ +#define STACK_CHECK(isolate, result_value) \ + do { \ + StackLimitCheck stack_check(isolate); \ + if (V8_UNLIKELY(stack_check.InterruptRequested()) && \ + V8_UNLIKELY(stack_check.HandleStackOverflowAndTerminationRequest())) { \ + return result_value; \ + } \ } while (false) class StackTraceFailureMessage { |