GeezerVison is showing github.com — deps: V8: backport bef0d9c1bc90 · nodejs/node@44f64f1
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: common.gypi +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 38 | 38 |
| 39 | 39 | # Reset this number to 0 on major V8 upgrades. | 40 | 40 | # Increment by one for each non-official patch applied to deps/v8. | 41 | | - 'v8_embedder_string': '-node.12', | | 41 | + 'v8_embedder_string': '-node.13', | 42 | 42 |
| 43 | 43 | ##### V8 defaults for Node.js ##### | 44 | 44 |
| |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/include/v8-initialization.h +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -253,6 +253,35 @@ class V8_EXPORT V8 { | 253 | 253 | static size_t GetSandboxReservationSizeInBytes(); | 254 | 254 | #endif // V8_ENABLE_SANDBOX | 255 | 255 |
| | 256 | + enum class WasmMemoryType { | | 257 | + kMemory32, | | 258 | + kMemory64, | | 259 | + }; | | 260 | + | | 261 | + /** | | 262 | + * Returns the virtual address space reservation size (in bytes) needed | | 263 | + * for one WebAssembly memory instance of the given capacity. | | 264 | + * | | 265 | + * \param type Whether this is a memory32 or memory64 instance. | | 266 | + * \param byte_capacity The maximum size, in bytes, of the WebAssembly | | 267 | + * memory. Values exceeding the engine's maximum allocatable memory | | 268 | + * size for the given type (determined by max_mem32_pages or | | 269 | + * max_mem64_pages) are clamped. | | 270 | + * | | 271 | + * When trap-based bounds checking is enabled by | | 272 | + * EnableWebAssemblyTrapHandler(), the amount of virtual address space | | 273 | + * that V8 needs to reserve for each WebAssembly memory instance can | | 274 | + * be much bigger than the requested size. If the process does | | 275 | + * not have enough virtual memory available, WebAssembly memory allocation | | 276 | + * would fail. During the initialization of V8, embedders can use this method | | 277 | + * to estimate whether the process has enough virtual memory for their | | 278 | + * usage of WebAssembly, and decide whether to enable the trap handler | | 279 | + * via EnableWebAssemblyTrapHandler(), or to skip it and reduce the amount of | | 280 | + * virtual memory required to keep the application running. | | 281 | + */ | | 282 | + static size_t GetWasmMemoryReservationSizeInBytes(WasmMemoryType type, | | 283 | + size_t byte_capacity); | | 284 | + | 256 | 285 | /** | 257 | 286 | * Activate trap-based bounds checking for WebAssembly. | 258 | 287 | * | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/api/api.cc +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 152 | 152 | #include "src/wasm/value-type.h" | 153 | 153 | #include "src/wasm/wasm-engine.h" | 154 | 154 | #include "src/wasm/wasm-js.h" | | 155 | +#include "src/wasm/wasm-limits.h" | 155 | 156 | #include "src/wasm/wasm-objects-inl.h" | 156 | 157 | #include "src/wasm/wasm-result.h" | 157 | 158 | #include "src/wasm/wasm-serialization.h" | @@ -6358,6 +6359,26 @@ bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) { | 6358 | 6359 | } | 6359 | 6360 | #endif | 6360 | 6361 |
| | 6362 | +size_t V8::GetWasmMemoryReservationSizeInBytes(WasmMemoryType type, | | 6363 | + size_t byte_capacity) { | | 6364 | +#if V8_ENABLE_WEBASSEMBLY | | 6365 | + bool is_memory64 = type == WasmMemoryType::kMemory64; | | 6366 | + uint64_t max_byte_capacity = | | 6367 | + is_memory64 ? i::wasm::max_mem64_bytes() : i::wasm::max_mem32_bytes(); | | 6368 | + if (byte_capacity > max_byte_capacity) { | | 6369 | + byte_capacity = static_cast<size_t>(max_byte_capacity); | | 6370 | + } | | 6371 | +#if V8_TRAP_HANDLER_SUPPORTED | | 6372 | + if (!is_memory64 || i::v8_flags.wasm_memory64_trap_handling) { | | 6373 | + return i::BackingStore::GetWasmReservationSize( | | 6374 | + /* has_guard_regions */ true, byte_capacity, | | 6375 | + /* is_wasm_memory64 */ is_memory64); | | 6376 | + } | | 6377 | +#endif // V8_TRAP_HANDLER_SUPPORTED | | 6378 | +#endif // V8_ENABLE_WEBASSEMBLY | | 6379 | + return byte_capacity; | | 6380 | +} | | 6381 | + | 6361 | 6382 | bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) { | 6362 | 6383 | #if V8_ENABLE_WEBASSEMBLY | 6363 | 6384 | return i::trap_handler::EnableTrapHandler(use_v8_signal_handler); | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/objects/backing-store.cc +22-20Lines changed: 22 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,8 +51,25 @@ enum class AllocationStatus { | 51 | 51 | kOtherFailure // Failed for an unknown reason | 52 | 52 | }; | 53 | 53 |
| 54 | | -size_t GetReservationSize(bool has_guard_regions, size_t byte_capacity, | 55 | | - bool is_wasm_memory64) { | | 54 | +base::AddressRegion GetReservedRegion(bool has_guard_regions, | | 55 | + bool is_wasm_memory64, void* buffer_start, | | 56 | + size_t byte_capacity) { | | 57 | + return base::AddressRegion( | | 58 | + reinterpret_cast<Address>(buffer_start), | | 59 | + BackingStore::GetWasmReservationSize(has_guard_regions, byte_capacity, | | 60 | + is_wasm_memory64)); | | 61 | +} | | 62 | + | | 63 | +void RecordStatus(Isolate* isolate, AllocationStatus status) { | | 64 | + isolate->counters()->wasm_memory_allocation_result()->AddSample( | | 65 | + static_cast<int>(status)); | | 66 | +} | | 67 | + | | 68 | +} // namespace | | 69 | + | | 70 | +size_t BackingStore::GetWasmReservationSize(bool has_guard_regions, | | 71 | + size_t byte_capacity, | | 72 | + bool is_wasm_memory64) { | 56 | 73 | #if V8_TARGET_ARCH_64_BIT && V8_ENABLE_WEBASSEMBLY | 57 | 74 | DCHECK_IMPLIES(is_wasm_memory64 && has_guard_regions, | 58 | 75 | v8_flags.wasm_memory64_trap_handling); | @@ -73,21 +90,6 @@ size_t GetReservationSize(bool has_guard_regions, size_t byte_capacity, | 73 | 90 | return byte_capacity; | 74 | 91 | } | 75 | 92 |
| 76 | | -base::AddressRegion GetReservedRegion(bool has_guard_regions, | 77 | | - bool is_wasm_memory64, void* buffer_start, | 78 | | - size_t byte_capacity) { | 79 | | - return base::AddressRegion( | 80 | | - reinterpret_cast<Address>(buffer_start), | 81 | | - GetReservationSize(has_guard_regions, byte_capacity, is_wasm_memory64)); | 82 | | -} | 83 | | - | 84 | | -void RecordStatus(Isolate* isolate, AllocationStatus status) { | 85 | | - isolate->counters()->wasm_memory_allocation_result()->AddSample( | 86 | | - static_cast<int>(status)); | 87 | | -} | 88 | | - | 89 | | -} // namespace | 90 | | - | 91 | 93 | // The backing store for a Wasm shared memory remembers all the isolates | 92 | 94 | // with which it has been shared. | 93 | 95 | struct SharedWasmMemoryData { | @@ -169,7 +171,7 @@ BackingStore::~BackingStore() { | 169 | 171 |
| 170 | 172 | #if V8_ENABLE_WEBASSEMBLY | 171 | 173 | if (is_wasm_memory()) { | 172 | | - size_t reservation_size = GetReservationSize( | | 174 | + size_t reservation_size = GetWasmReservationSize( | 173 | 175 | has_guard_regions(), byte_capacity_, is_wasm_memory64()); | 174 | 176 | TRACE_BS( | 175 | 177 | "BSw:free bs=%p mem=%p (length=%zu, capacity=%zu, reservation=%zu)\n", | @@ -319,8 +321,8 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateAndPartiallyCommitMemory( | 319 | 321 | }; | 320 | 322 |
| 321 | 323 | size_t byte_capacity = maximum_pages * page_size; | 322 | | - size_t reservation_size = | 323 | | - GetReservationSize(has_guard_regions, byte_capacity, is_wasm_memory64); | | 324 | + size_t reservation_size = GetWasmReservationSize( | | 325 | + has_guard_regions, byte_capacity, is_wasm_memory64); | 324 | 326 |
| 325 | 327 | //-------------------------------------------------------------------------- | 326 | 328 | // Allocate pages (inaccessible by default). | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/objects/backing-store.h +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -202,6 +202,11 @@ class V8_EXPORT_PRIVATE BackingStore : public BackingStoreBase { | 202 | 202 |
| 203 | 203 | uint32_t id() const { return id_; } | 204 | 204 |
| | 205 | + // Return the size of the reservation needed for a wasm backing store. | | 206 | + static size_t GetWasmReservationSize(bool has_guard_regions, | | 207 | + size_t byte_capacity, | | 208 | + bool is_wasm_memory64); | | 209 | + | 205 | 210 | private: | 206 | 211 | friend class GlobalBackingStoreRegistry; | 207 | 212 |
| |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/unittests/api/api-wasm-unittest.cc +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,6 +124,22 @@ void WasmStreamingMoreFunctionsCanBeSerializedCallback( | 124 | 124 | streaming->SetMoreFunctionsCanBeSerializedCallback([](CompiledWasmModule) {}); | 125 | 125 | } | 126 | 126 |
| | 127 | +TEST_F(ApiWasmTest, GetWasmMemoryReservationSizeInBytes) { | | 128 | + constexpr size_t kCapacity = 64 * 1024; // 64 KiB | | 129 | + size_t reservation = V8::GetWasmMemoryReservationSizeInBytes( | | 130 | + V8::WasmMemoryType::kMemory32, kCapacity); | | 131 | + size_t reservation64 = V8::GetWasmMemoryReservationSizeInBytes( | | 132 | + V8::WasmMemoryType::kMemory64, kCapacity); | | 133 | + | | 134 | +#if V8_TRAP_HANDLER_SUPPORTED | | 135 | + EXPECT_GE(reservation, kCapacity); | | 136 | + EXPECT_GE(reservation64, kCapacity); | | 137 | +#else | | 138 | + EXPECT_EQ(reservation, kCapacity); | | 139 | + EXPECT_EQ(reservation64, kCapacity); | | 140 | +#endif // V8_TRAP_HANDLER_SUPPORTED | | 141 | +} | | 142 | + | 127 | 143 | TEST_F(ApiWasmTest, WasmStreamingCallback) { | 128 | 144 | TestWasmStreaming(WasmStreamingCallbackTestCallbackIsCalled, | 129 | 145 | Promise::kPending); | |
|