GeezerVison is showing github.com — deps: V8: cherry-pick 475c8cdf9a95 · nodejs/node@00dab30
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: deps/v8/BUILD.gn +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -500,6 +500,7 @@ if (v8_enable_short_builtin_calls == "") { | 500 | 500 | if (v8_enable_external_code_space == "") { | 501 | 501 | v8_enable_external_code_space = | 502 | 502 | v8_enable_pointer_compression && | | 503 | + v8_enable_pointer_compression_shared_cage && | 503 | 504 | (v8_current_cpu == "x64" || v8_current_cpu == "arm64") | 504 | 505 | } | 505 | 506 | if (v8_enable_maglev == "") { | @@ -683,6 +684,12 @@ assert( | 683 | 684 | !v8_enable_pointer_compression_shared_cage || v8_enable_pointer_compression, | 684 | 685 | "Can't share a pointer compression cage if pointers aren't compressed") | 685 | 686 |
| | 687 | +assert( | | 688 | + !v8_enable_pointer_compression || | | 689 | + v8_enable_pointer_compression_shared_cage || | | 690 | + !v8_enable_external_code_space, | | 691 | + "Multi-cage pointer compression mode is not compatible with external code space") | | 692 | + | 686 | 693 | assert( | 687 | 694 | !v8_enable_pointer_compression_shared_cage || v8_current_cpu == "x64" || | 688 | 695 | v8_current_cpu == "arm64" || v8_current_cpu == "riscv64" || | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/api/api.cc +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9227,6 +9227,14 @@ void Isolate::TerminateExecution() { | 9227 | 9227 |
| 9228 | 9228 | bool Isolate::IsExecutionTerminating() { | 9229 | 9229 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this); | | 9230 | +#ifdef DEBUG | | 9231 | + // This method might be called on a thread that's not bound to any Isolate | | 9232 | + // and thus pointer compression schemes might have cage base value unset. | | 9233 | + // Read-only roots accessors contain type DCHECKs which require access to | | 9234 | + // V8 heap in order to check the object type. So, allow heap access here | | 9235 | + // to let the checks work. | | 9236 | + i::PtrComprCageAccessScope ptr_compr_cage_access_scope(i_isolate); | | 9237 | +#endif // DEBUG | 9230 | 9238 | return i_isolate->is_execution_terminating(); | 9231 | 9239 | } | 9232 | 9240 |
| @@ -9898,6 +9906,14 @@ void Isolate::LowMemoryNotification() { | 9898 | 9906 | i::NestedTimedHistogramScope idle_notification_scope( | 9899 | 9907 | i_isolate->counters()->gc_low_memory_notification()); | 9900 | 9908 | TRACE_EVENT0("v8", "V8.GCLowMemoryNotification"); | | 9909 | +#ifdef DEBUG | | 9910 | + // This method might be called on a thread that's not bound to any Isolate | | 9911 | + // and thus pointer compression schemes might have cage base value unset. | | 9912 | + // Read-only roots accessors contain type DCHECKs which require access to | | 9913 | + // V8 heap in order to check the object type. So, allow heap access here | | 9914 | + // to let the checks work. | | 9915 | + i::PtrComprCageAccessScope ptr_compr_cage_access_scope(i_isolate); | | 9916 | +#endif // DEBUG | 9901 | 9917 | i_isolate->heap()->CollectAllAvailableGarbage( | 9902 | 9918 | i::GarbageCollectionReason::kLowMemoryNotification); | 9903 | 9919 | } | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/common/ptr-compr-inl.h +27-4Lines changed: 27 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -91,11 +91,16 @@ Address V8HeapCompressionScheme::DecompressTaggedSigned(Tagged_t raw_value) { | 91 | 91 | template <typename TOnHeapAddress> | 92 | 92 | Address V8HeapCompressionScheme::DecompressTagged(TOnHeapAddress on_heap_addr, | 93 | 93 | Tagged_t raw_value) { | 94 | | -#if defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE) | | 94 | +#ifdef V8_COMPRESS_POINTERS | 95 | 95 | Address cage_base = base(); | | 96 | +#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | | 97 | + DCHECK_WITH_MSG(cage_base != kNullAddress, | | 98 | + "V8HeapCompressionScheme::base is not initialized for " | | 99 | + "current thread"); | | 100 | +#endif // V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | 96 | 101 | #else | 97 | 102 | Address cage_base = GetPtrComprCageBaseAddress(on_heap_addr); | 98 | | -#endif | | 103 | +#endif // V8_COMPRESS_POINTERS | 99 | 104 | Address result = cage_base + static_cast<Address>(raw_value); | 100 | 105 | V8_ASSUME(static_cast<uint32_t>(result) == raw_value); | 101 | 106 | return result; | @@ -191,11 +196,16 @@ Address ExternalCodeCompressionScheme::DecompressTaggedSigned( | 191 | 196 | template <typename TOnHeapAddress> | 192 | 197 | Address ExternalCodeCompressionScheme::DecompressTagged( | 193 | 198 | TOnHeapAddress on_heap_addr, Tagged_t raw_value) { | 194 | | -#if defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE) | | 199 | +#ifdef V8_COMPRESS_POINTERS | 195 | 200 | Address cage_base = base(); | | 201 | +#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | | 202 | + DCHECK_WITH_MSG(cage_base != kNullAddress, | | 203 | + "ExternalCodeCompressionScheme::base is not initialized for " | | 204 | + "current thread"); | | 205 | +#endif // V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | 196 | 206 | #else | 197 | 207 | Address cage_base = GetPtrComprCageBaseAddress(on_heap_addr); | 198 | | -#endif | | 208 | +#endif // V8_COMPRESS_POINTERS | 199 | 209 | Address result = cage_base + static_cast<Address>(raw_value); | 200 | 210 | V8_ASSUME(static_cast<uint32_t>(result) == raw_value); | 201 | 211 | return result; | @@ -275,6 +285,19 @@ V8_INLINE PtrComprCageBase GetPtrComprCageBase(Tagged<HeapObject> object) { | 275 | 285 | return GetPtrComprCageBaseFromOnHeapAddress(object.ptr()); | 276 | 286 | } | 277 | 287 |
| | 288 | +#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | | 289 | + | | 290 | +PtrComprCageAccessScope::PtrComprCageAccessScope(Isolate* isolate) | | 291 | + : cage_base_(V8HeapCompressionScheme::base()) { | | 292 | + V8HeapCompressionScheme::InitBase(isolate->cage_base()); | | 293 | +} | | 294 | + | | 295 | +PtrComprCageAccessScope::~PtrComprCageAccessScope() { | | 296 | + V8HeapCompressionScheme::InitBase(cage_base_); | | 297 | +} | | 298 | + | | 299 | +#endif // V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | | 300 | + | 278 | 301 | } // namespace internal | 279 | 302 | } // namespace v8 | 280 | 303 |
| |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/common/ptr-compr.h +25-2Lines changed: 25 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,8 +55,8 @@ class V8HeapCompressionScheme { | 55 | 55 | private: | 56 | 56 | // These non-inlined accessors to base_ field are used in component builds | 57 | 57 | // where cross-component access to thread local variables is not allowed. | 58 | | - static Address base_non_inlined(); | 59 | | - static void set_base_non_inlined(Address base); | | 58 | + static V8_EXPORT_PRIVATE Address base_non_inlined(); | | 59 | + static V8_EXPORT_PRIVATE void set_base_non_inlined(Address base); | 60 | 60 |
| 61 | 61 | #ifdef V8_COMPRESS_POINTERS_IN_SHARED_CAGE | 62 | 62 | static V8_EXPORT_PRIVATE uintptr_t base_ V8_CONSTINIT; | @@ -156,6 +156,29 @@ static inline void WriteMaybeUnalignedValue(Address p, V value) { | 156 | 156 | } | 157 | 157 | } | 158 | 158 |
| | 159 | +// When multi-cage pointer compression mode is enabled this scope object | | 160 | +// saves current cage's base values and sets them according to given Isolate. | | 161 | +// For all other configurations this scope object is a no-op. | | 162 | +class PtrComprCageAccessScope final { | | 163 | + public: | | 164 | +#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | | 165 | + V8_INLINE explicit PtrComprCageAccessScope(Isolate* isolate); | | 166 | + V8_INLINE ~PtrComprCageAccessScope(); | | 167 | +#else | | 168 | + V8_INLINE explicit PtrComprCageAccessScope(Isolate* isolate) {} | | 169 | + V8_INLINE ~PtrComprCageAccessScope() {} | | 170 | +#endif | | 171 | + | | 172 | + private: | | 173 | +#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | | 174 | + const Address cage_base_; | | 175 | +#ifdef V8_EXTERNAL_CODE_SPACE | | 176 | +// In case this configuration is necessary the code cage base must be saved too. | | 177 | +#error Multi-cage pointer compression with external code space is not supported | | 178 | +#endif // V8_EXTERNAL_CODE_SPACE | | 179 | +#endif // V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE | | 180 | +}; | | 181 | + | 159 | 182 | } // namespace v8::internal | 160 | 183 |
| 161 | 184 | #endif // V8_COMMON_PTR_COMPR_H_ |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/execution/isolate.cc +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3933,6 +3933,14 @@ Isolate::~Isolate() { | 3933 | 3933 |
| 3934 | 3934 | void Isolate::InitializeThreadLocal() { | 3935 | 3935 | thread_local_top()->Initialize(this); | | 3936 | +#ifdef DEBUG | | 3937 | + // This method might be called on a thread that's not bound to any Isolate | | 3938 | + // and thus pointer compression schemes might have cage base value unset. | | 3939 | + // Read-only roots accessors contain type DCHECKs which require access to | | 3940 | + // V8 heap in order to check the object type. So, allow heap access here | | 3941 | + // to let the checks work. | | 3942 | + i::PtrComprCageAccessScope ptr_compr_cage_access_scope(this); | | 3943 | +#endif // DEBUG | 3936 | 3944 | clear_pending_exception(); | 3937 | 3945 | clear_pending_message(); | 3938 | 3946 | clear_scheduled_exception(); | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/execution/v8threads.cc +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,6 +124,10 @@ bool ThreadManager::RestoreThread() { | 124 | 124 | InitThread(access); | 125 | 125 | return false; | 126 | 126 | } | | 127 | + // In case multi-cage pointer compression mode is enabled ensure that | | 128 | + // current thread's cage base values are properly initialized. | | 129 | + PtrComprCageAccessScope ptr_compr_cage_access_scope(isolate_); | | 130 | + | 127 | 131 | ThreadState* state = per_thread->thread_state(); | 128 | 132 | char* from = state->data(); | 129 | 133 | from = isolate_->handle_scope_implementer()->RestoreThread(from); | @@ -274,6 +278,14 @@ void ThreadManager::EagerlyArchiveThread() { | 274 | 278 | } | 275 | 279 |
| 276 | 280 | void ThreadManager::FreeThreadResources() { | | 281 | +#ifdef DEBUG | | 282 | + // This method might be called on a thread that's not bound to any Isolate | | 283 | + // and thus pointer compression schemes might have cage base value unset. | | 284 | + // Read-only roots accessors contain type DCHECKs which require access to | | 285 | + // V8 heap in order to check the object type. So, allow heap access here | | 286 | + // to let the checks work. | | 287 | + PtrComprCageAccessScope ptr_compr_cage_access_scope(isolate_); | | 288 | +#endif // DEBUG | 277 | 289 | DCHECK(!isolate_->has_pending_exception()); | 278 | 290 | DCHECK(!isolate_->external_caught_exception()); | 279 | 291 | DCHECK_NULL(isolate_->try_catch_handler()); | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/heap/collection-barrier.cc +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,7 +51,12 @@ class BackgroundCollectionInterruptTask : public CancelableTask { | 51 | 51 |
| 52 | 52 | private: | 53 | 53 | // v8::internal::CancelableTask overrides. | 54 | | - void RunInternal() override { heap_->CheckCollectionRequested(); } | | 54 | + void RunInternal() override { | | 55 | + // In case multi-cage pointer compression mode is enabled ensure that | | 56 | + // current thread's cage base values are properly initialized. | | 57 | + PtrComprCageAccessScope ptr_compr_cage_access_scope(heap_->isolate()); | | 58 | + heap_->CheckCollectionRequested(); | | 59 | + } | 55 | 60 |
| 56 | 61 | Heap* heap_; | 57 | 62 | }; | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/heap/concurrent-marking.cc +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -153,6 +153,11 @@ class ConcurrentMarking::JobTaskMajor : public v8::JobTask { | 153 | 153 |
| 154 | 154 | // v8::JobTask overrides. | 155 | 155 | void Run(JobDelegate* delegate) override { | | 156 | + // In case multi-cage pointer compression mode is enabled ensure that | | 157 | + // current thread's cage base values are properly initialized. | | 158 | + PtrComprCageAccessScope ptr_compr_cage_access_scope( | | 159 | + concurrent_marking_->heap_->isolate()); | | 160 | + | 156 | 161 | if (delegate->IsJoiningThread()) { | 157 | 162 | // TRACE_GC is not needed here because the caller opens the right scope. | 158 | 163 | concurrent_marking_->RunMajor(delegate, code_flush_mode_, | @@ -197,6 +202,11 @@ class ConcurrentMarking::JobTaskMinor : public v8::JobTask { | 197 | 202 |
| 198 | 203 | // v8::JobTask overrides. | 199 | 204 | void Run(JobDelegate* delegate) override { | | 205 | + // In case multi-cage pointer compression mode is enabled ensure that | | 206 | + // current thread's cage base values are properly initialized. | | 207 | + PtrComprCageAccessScope ptr_compr_cage_access_scope( | | 208 | + concurrent_marking_->heap_->isolate()); | | 209 | + | 200 | 210 | if (delegate->IsJoiningThread()) { | 201 | 211 | TRACE_GC_WITH_FLOW(concurrent_marking_->heap_->tracer(), | 202 | 212 | GCTracer::Scope::MINOR_MS_MARK_PARALLEL, trace_id_, | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/heap/incremental-marking-job.cc +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -91,6 +91,9 @@ void IncrementalMarkingJob::Task::RunInternal() { | 91 | 91 | VMState<GC> state(isolate()); | 92 | 92 | TRACE_EVENT_CALL_STATS_SCOPED(isolate(), "v8", | 93 | 93 | "V8.IncrementalMarkingJob.Task"); | | 94 | + // In case multi-cage pointer compression mode is enabled ensure that | | 95 | + // current thread's cage base values are properly initialized. | | 96 | + PtrComprCageAccessScope ptr_compr_cage_access_scope(isolate()); | 94 | 97 |
| 95 | 98 | isolate()->stack_guard()->ClearStartIncrementalMarking(); | 96 | 99 |
| |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/heap/local-heap.cc +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,6 +48,7 @@ void LocalHeap::VerifyCurrent() const { | 48 | 48 | LocalHeap::LocalHeap(Heap* heap, ThreadKind kind, | 49 | 49 | std::unique_ptr<PersistentHandles> persistent_handles) | 50 | 50 | : heap_(heap), | | 51 | + ptr_compr_cage_access_scope_(heap->isolate()), | 51 | 52 | is_main_thread_(kind == ThreadKind::kMain), | 52 | 53 | state_(ThreadState::Parked()), | 53 | 54 | allocation_failed_(false), | |
|