diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-05-03 16:40:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-05-04 19:53:45 -0700 |
commit | eadd89b7c87921ea3274e76017046b8bf884b336 (patch) | |
tree | 8c77b931a6323823542f33836ba765f46d6ff97c /src/runtime.js | |
parent | 0560adda8a6c0259478a54e5b514ceaafe8fc10c (diff) |
make memory management sane: 0 is null, then static including globals, then stack, then dynamic/sbrk. deprecate shared libs (BUILD_AS_SHARED_LIB)
Diffstat (limited to 'src/runtime.js')
-rw-r--r-- | src/runtime.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/runtime.js b/src/runtime.js index 9daab820..9bedfe68 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -61,8 +61,16 @@ var RuntimeGenerator = { // An allocation that cannot normally be free'd (except through sbrk, which once // called, takes control of STATICTOP) staticAlloc: function(size) { + if (ASSERTIONS) size = '(assert(!staticSealed),' + size + ')'; // static area must not be sealed var ret = RuntimeGenerator.alloc(size, 'STATIC', INIT_HEAP); - if (USE_TYPED_ARRAYS) ret += '; if (STATICTOP >= TOTAL_MEMORY) enlargeMemory();' + return ret; + }, + + // allocation on the top of memory, adjusted dynamically by sbrk + dynamicAlloc: function(size) { + if (ASSERTIONS) size = '(assert(DYNAMICTOP > 0),' + size + ')'; // dynamic area must be ready + var ret = RuntimeGenerator.alloc(size, 'DYNAMIC', INIT_HEAP); + if (USE_TYPED_ARRAYS) ret += '; if (DYNAMICTOP >= TOTAL_MEMORY) enlargeMemory();' return ret; }, @@ -466,6 +474,7 @@ var Runtime = { Runtime.stackAlloc = unInline('stackAlloc', ['size']); Runtime.staticAlloc = unInline('staticAlloc', ['size']); +Runtime.dynamicAlloc = unInline('dynamicAlloc', ['size']); Runtime.alignMemory = unInline('alignMemory', ['size', 'quantum']); Runtime.makeBigInt = unInline('makeBigInt', ['low', 'high', 'unsigned']); @@ -529,3 +538,9 @@ function reSign(value, bits, ignore, sig) { return value; } +// The address globals begin at. Very low in memory, for code size and optimization opportunities. +// Above 0 is static memory, starting with globals. +// Then the stack. +// Then 'dynamic' memory for sbrk. +Runtime.GLOBAL_BASE = Runtime.alignMemory(1); + |