Skip to content

Commit

Permalink
feat: lowMemoryLimit can accept more than 1 page value
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrCai0907 committed Jun 24, 2024
1 parent 78963c5 commit d242ab5
Show file tree
Hide file tree
Showing 161 changed files with 1,234 additions and 1,397 deletions.
2 changes: 1 addition & 1 deletion cli/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
},
"lowMemoryLimit": {
"category": "Features",
"description": "Enforces very low (<64k) memory constraints.",
"description": "Enforces memory constraints, memory usage will not exceed the given value.",
"default": 0,
"type": "i"
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class Options {
noUnsafe: bool = false;
/** If true, enables pedantic diagnostics. */
pedantic: bool = false;
/** Indicates a very low (<64k) memory limit. */
/** Indicates a memory limit. */
lowMemoryLimit: u32 = 0;
/** If true, exports the runtime helpers. */
exportRuntime: bool = false;
Expand Down
15 changes: 4 additions & 11 deletions std/assembly/rt/tlsf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ function prepareBlock(root: Root, block: Block, size: usize): void {
/** Adds more memory to the pool. */
function addMemory(root: Root, start: usize, endU64: u64): bool {
let end = <usize>endU64;
if (ASC_LOW_MEMORY_LIMIT) {
end = <u64>ASC_LOW_MEMORY_LIMIT;
}
if (DEBUG) assert(<u64>start <= endU64); // must be valid
start = ((start + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;
end &= ~AL_MASK;
Expand Down Expand Up @@ -427,10 +430,6 @@ function addMemory(root: Root, start: usize, endU64: u64): bool {

/** Grows memory to fit at least another block of the specified size. */
function growMemory(root: Root, size: usize): void {
if (ASC_LOW_MEMORY_LIMIT) {
unreachable();
return;
}
// Here, both rounding performed in searchBlock ...
if (size >= SB_SIZE) {
size = roundSize(size);
Expand Down Expand Up @@ -479,13 +478,7 @@ function initialize(): void {
}
}
let memStart = rootOffset + ROOT_SIZE;
if (ASC_LOW_MEMORY_LIMIT) {
const memEnd = <u64>ASC_LOW_MEMORY_LIMIT & ~AL_MASK;
if (memStart <= memEnd) addMemory(root, memStart, memEnd);
else unreachable(); // low memory limit already exceeded
} else {
addMemory(root, memStart, <u64>memory.size() << 16);
}
addMemory(root, memStart, <u64>memory.size() << 16);
ROOT = root;
}

Expand Down
20 changes: 9 additions & 11 deletions tests/compiler/assignment-chain.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@
local.get $endU64
i32.wrap_i64
local.set $end
i32.const 0
drop
i32.const 1
drop
local.get $start
Expand All @@ -1041,7 +1043,7 @@
if
i32.const 0
i32.const 368
i32.const 382
i32.const 385
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1087,7 +1089,7 @@
if
i32.const 0
i32.const 368
i32.const 389
i32.const 392
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1119,7 +1121,7 @@
if
i32.const 0
i32.const 368
i32.const 402
i32.const 405
i32.const 5
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1320,8 +1322,6 @@
i32.const 1572
i32.add
local.set $memStart
i32.const 0
drop
local.get $root
local.get $memStart
memory.size
Expand Down Expand Up @@ -1363,7 +1363,7 @@
if
i32.const 0
i32.const 368
i32.const 562
i32.const 555
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1692,7 +1692,7 @@
if
i32.const 32
i32.const 368
i32.const 461
i32.const 460
i32.const 29
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1926,8 +1926,6 @@
(local $6 i32)
(local $pagesWanted i32)
(local $pagesAfter i32)
i32.const 0
drop
local.get $size
i32.const 256
i32.ge_u
Expand Down Expand Up @@ -2137,7 +2135,7 @@
if
i32.const 0
i32.const 368
i32.const 499
i32.const 492
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -2157,7 +2155,7 @@
if
i32.const 0
i32.const 368
i32.const 501
i32.const 494
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down
14 changes: 7 additions & 7 deletions tests/compiler/assignment-chain.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@
if
i32.const 0
i32.const 1392
i32.const 382
i32.const 385
i32.const 14
call $~lib/builtins/abort
unreachable
Expand All @@ -664,7 +664,7 @@
if
i32.const 0
i32.const 1392
i32.const 389
i32.const 392
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -691,7 +691,7 @@
if
i32.const 0
i32.const 1392
i32.const 402
i32.const 405
i32.const 5
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1054,7 +1054,7 @@
if
i32.const 0
i32.const 1392
i32.const 562
i32.const 555
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1289,7 +1289,7 @@
if
i32.const 1056
i32.const 1392
i32.const 461
i32.const 460
i32.const 29
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1391,7 +1391,7 @@
if
i32.const 0
i32.const 1392
i32.const 499
i32.const 492
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -1406,7 +1406,7 @@
if
i32.const 0
i32.const 1392
i32.const 501
i32.const 494
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down
20 changes: 9 additions & 11 deletions tests/compiler/bindings/esm.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,8 @@
local.get $endU64
i32.wrap_i64
local.set $end
i32.const 0
drop
i32.const 1
drop
local.get $start
Expand All @@ -1146,7 +1148,7 @@
if
i32.const 0
i32.const 672
i32.const 382
i32.const 385
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1192,7 +1194,7 @@
if
i32.const 0
i32.const 672
i32.const 389
i32.const 392
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1224,7 +1226,7 @@
if
i32.const 0
i32.const 672
i32.const 402
i32.const 405
i32.const 5
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1425,8 +1427,6 @@
i32.const 1572
i32.add
local.set $memStart
i32.const 0
drop
local.get $root
local.get $memStart
memory.size
Expand Down Expand Up @@ -1468,7 +1468,7 @@
if
i32.const 0
i32.const 672
i32.const 562
i32.const 555
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1797,7 +1797,7 @@
if
i32.const 336
i32.const 672
i32.const 461
i32.const 460
i32.const 29
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2031,8 +2031,6 @@
(local $6 i32)
(local $pagesWanted i32)
(local $pagesAfter i32)
i32.const 0
drop
local.get $size
i32.const 256
i32.ge_u
Expand Down Expand Up @@ -2242,7 +2240,7 @@
if
i32.const 0
i32.const 672
i32.const 499
i32.const 492
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -2262,7 +2260,7 @@
if
i32.const 0
i32.const 672
i32.const 501
i32.const 494
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down
14 changes: 7 additions & 7 deletions tests/compiler/bindings/esm.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@
if
i32.const 0
i32.const 1696
i32.const 382
i32.const 385
i32.const 14
call $~lib/builtins/abort
unreachable
Expand All @@ -784,7 +784,7 @@
if
i32.const 0
i32.const 1696
i32.const 389
i32.const 392
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -811,7 +811,7 @@
if
i32.const 0
i32.const 1696
i32.const 402
i32.const 405
i32.const 5
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1174,7 +1174,7 @@
if
i32.const 0
i32.const 1696
i32.const 562
i32.const 555
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1409,7 +1409,7 @@
if
i32.const 1360
i32.const 1696
i32.const 461
i32.const 460
i32.const 29
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1511,7 +1511,7 @@
if
i32.const 0
i32.const 1696
i32.const 499
i32.const 492
i32.const 16
call $~lib/builtins/abort
unreachable
Expand All @@ -1526,7 +1526,7 @@
if
i32.const 0
i32.const 1696
i32.const 501
i32.const 494
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down
Loading

0 comments on commit d242ab5

Please sign in to comment.