diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-13 14:14:06 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-13 14:14:06 -0800 |
commit | a224eb135b2a9bff2a186324e8645aad560114e2 (patch) | |
tree | 053de572362d4635a96cfdd8d7495836ecbf1843 | |
parent | a5d305c2737d56870a55cc21e2f7906e58fd11e4 (diff) |
reorganize initial allocations to the stack, so that static memory for globals begins exactly where the stack ends
-rw-r--r-- | src/jsifier.js | 4 | ||||
-rw-r--r-- | src/preamble.js | 9 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 7c6dcf83..6ad9fae7 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1353,8 +1353,8 @@ function JSify(data, functionsOnly, givenFunctions) { if (phase == 'pre' && !Variables.generatedGlobalBase) { Variables.generatedGlobalBase = true; if (Variables.nextIndexedOffset > 0) { - // Variables have been calculated, print out the base generation before we print them - print('var GLOBAL_BASE = STATICTOP;\n'); + // Variables have been calculated, get to base generation before we print them + print('var GLOBAL_BASE = STATICTOP; assert(GLOBAL_BASE == STACK_MAX); \n'); print('STATICTOP += ' + Variables.nextIndexedOffset + ';\n'); print('assert(STATICTOP < TOTAL_MEMORY);\n'); } diff --git a/src/preamble.js b/src/preamble.js index b28dfc0d..78a718e2 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -697,10 +697,10 @@ Module['HEAPF64'] = HEAPF64; #endif STACK_ROOT = STACKTOP = Runtime.alignMemory(1); -STACK_MAX = STACK_ROOT + TOTAL_STACK; +STACK_MAX = TOTAL_STACK; // we lose a little stack here, but TOTAL_STACK is nice and round so use that as the max #if USE_TYPED_ARRAYS == 2 -var tempDoublePtr = Runtime.alignMemory(STACK_MAX, 8); +var tempDoublePtr = allocate(8, 'i8', ALLOC_STACK); function copyTempFloat(ptr) { // functions, because inlining this code is increases code size too much HEAP8[tempDoublePtr] = HEAP8[ptr]; HEAP8[tempDoublePtr+1] = HEAP8[ptr+1]; @@ -717,14 +717,13 @@ function copyTempDouble(ptr) { HEAP8[tempDoublePtr+6] = HEAP8[ptr+6]; HEAP8[tempDoublePtr+7] = HEAP8[ptr+7]; } -STACK_MAX = tempDoublePtr + 8; #endif STATICTOP = alignMemoryPage(STACK_MAX); - +assert(STATICTOP == STACK_MAX); // STACK_MAX must be aligned assert(STATICTOP < TOTAL_MEMORY); // Stack must fit in TOTAL_MEMORY; allocations from here on may enlarge TOTAL_MEMORY -var nullString = allocate(intArrayFromString('(null)'), 'i8', ALLOC_STATIC); +var nullString = allocate(intArrayFromString('(null)'), 'i8', ALLOC_STACK); function callRuntimeCallbacks(callbacks) { while(callbacks.length > 0) { |