GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — deps: V8: backport bef0d9c1bc90 · nodejs/node@44f64f1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • common.gypi
  • deps/v8
    • include
      • v8-initialization.h
    • src
      • api
        • api.cc
      • objects
        • backing-store.cc
        • backing-store.h
    • test/unittests/api
      • api-wasm-unittest.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.12',
41+
'v8_embedder_string': '-node.13',
4242

4343
##### V8 defaults for Node.js #####
4444

Collapse file

‎deps/v8/include/v8-initialization.h‎

Copy file name to clipboardExpand all lines: deps/v8/include/v8-initialization.h
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,35 @@ class V8_EXPORT V8 {
253253
static size_t GetSandboxReservationSizeInBytes();
254254
#endif // V8_ENABLE_SANDBOX
255255

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+
256285
/**
257286
* Activate trap-based bounds checking for WebAssembly.
258287
*
Collapse file

‎deps/v8/src/api/api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/api/api.cc
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
#include "src/wasm/value-type.h"
153153
#include "src/wasm/wasm-engine.h"
154154
#include "src/wasm/wasm-js.h"
155+
#include "src/wasm/wasm-limits.h"
155156
#include "src/wasm/wasm-objects-inl.h"
156157
#include "src/wasm/wasm-result.h"
157158
#include "src/wasm/wasm-serialization.h"
@@ -6358,6 +6359,26 @@ bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) {
63586359
}
63596360
#endif
63606361

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+
63616382
bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) {
63626383
#if V8_ENABLE_WEBASSEMBLY
63636384
return i::trap_handler::EnableTrapHandler(use_v8_signal_handler);
Collapse file

‎deps/v8/src/objects/backing-store.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/objects/backing-store.cc
+22-20Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,25 @@ enum class AllocationStatus {
5151
kOtherFailure // Failed for an unknown reason
5252
};
5353

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) {
5673
#if V8_TARGET_ARCH_64_BIT && V8_ENABLE_WEBASSEMBLY
5774
DCHECK_IMPLIES(is_wasm_memory64 && has_guard_regions,
5875
v8_flags.wasm_memory64_trap_handling);
@@ -73,21 +90,6 @@ size_t GetReservationSize(bool has_guard_regions, size_t byte_capacity,
7390
return byte_capacity;
7491
}
7592

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-
9193
// The backing store for a Wasm shared memory remembers all the isolates
9294
// with which it has been shared.
9395
struct SharedWasmMemoryData {
@@ -169,7 +171,7 @@ BackingStore::~BackingStore() {
169171

170172
#if V8_ENABLE_WEBASSEMBLY
171173
if (is_wasm_memory()) {
172-
size_t reservation_size = GetReservationSize(
174+
size_t reservation_size = GetWasmReservationSize(
173175
has_guard_regions(), byte_capacity_, is_wasm_memory64());
174176
TRACE_BS(
175177
"BSw:free bs=%p mem=%p (length=%zu, capacity=%zu, reservation=%zu)\n",
@@ -319,8 +321,8 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateAndPartiallyCommitMemory(
319321
};
320322

321323
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);
324326

325327
//--------------------------------------------------------------------------
326328
// Allocate pages (inaccessible by default).
Collapse file

‎deps/v8/src/objects/backing-store.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/objects/backing-store.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ class V8_EXPORT_PRIVATE BackingStore : public BackingStoreBase {
202202

203203
uint32_t id() const { return id_; }
204204

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+
205210
private:
206211
friend class GlobalBackingStoreRegistry;
207212

Collapse file

‎deps/v8/test/unittests/api/api-wasm-unittest.cc‎

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 numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ void WasmStreamingMoreFunctionsCanBeSerializedCallback(
124124
streaming->SetMoreFunctionsCanBeSerializedCallback([](CompiledWasmModule) {});
125125
}
126126

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+
127143
TEST_F(ApiWasmTest, WasmStreamingCallback) {
128144
TestWasmStreaming(WasmStreamingCallbackTestCallbackIsCalled,
129145
Promise::kPending);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.