Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round the number of pages passed to Memory.grow. NFC #22362

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ addToLibrary({

// Grows the wasm memory to the given byte size, and updates the JS views to
// it. Returns 1 on success, 0 on error.
$growMemory__deps: ['$alignMemory'],
$growMemory: (size) => {
var b = wasmMemory.buffer;
var pages = (size - b.byteLength + {{{ WASM_PAGE_SIZE - 1 }}}) / {{{ WASM_PAGE_SIZE }}};
var pages = alignMemory(size - b.byteLength, {{{ WASM_PAGE_SIZE }}}) / {{{ WASM_PAGE_SIZE }}};
#if RUNTIME_DEBUG
dbg(`growMemory: ${size} (+${size - b.byteLength} bytes / ${pages} pages)`);
#endif
Expand Down Expand Up @@ -2262,7 +2263,7 @@ addToLibrary({
#if ASSERTIONS
assert(alignment, "alignment argument is required");
#endif
return Math.ceil(size / alignment) * alignment;
return ((size + (alignment - 1)) / alignment) | 0;
},

// Allocate memory for an mmap operation. This allocates space of the right
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_dylink.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13895
13887
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_grow.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2570
2575
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_grow.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5344
5355
Loading