aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-02 18:53:44 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-02 18:53:44 -0800
commit6d87b565930d921cbb48e2fda97a9e8b0afa3826 (patch)
tree33d1b0470fd6776321a949c3e244e2de65504b0b
parent8bd21f1fff1ddac70f617291dbe2501efa11be30 (diff)
adjust TOTAL_MEMORY at runtime, to take into account last minute changes to Module.TOTAL_MEMORY
-rwxr-xr-xemcc10
-rw-r--r--src/jsifier.js2
-rw-r--r--src/preamble.js15
3 files changed, 16 insertions, 11 deletions
diff --git a/emcc b/emcc
index a4873e7a..621cb340 100755
--- a/emcc
+++ b/emcc
@@ -1228,16 +1228,6 @@ try:
shared.Settings.CORRECT_OVERFLOWS = 1
assert not shared.Settings.PGO, 'cannot run PGO in ASM_JS mode'
- heap = 4096
- while heap < shared.Settings.TOTAL_MEMORY:
- if heap < 16*1024*1024:
- heap *= 2
- else:
- heap += 16*1024*1024
- if heap != shared.Settings.TOTAL_MEMORY:
- logging.warning('increasing TOTAL_MEMORY to %d to be more reasonable for asm.js' % heap)
- shared.Settings.TOTAL_MEMORY = heap
-
if shared.Settings.CORRECT_SIGNS >= 2 or shared.Settings.CORRECT_OVERFLOWS >= 2 or shared.Settings.CORRECT_ROUNDINGS >= 2:
debug_level = 4 # must keep debug info to do line-by-line operations
diff --git a/src/jsifier.js b/src/jsifier.js
index 2d0aadd7..58dc4653 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1810,7 +1810,7 @@ function JSify(data, functionsOnly, givenFunctions) {
print('staticSealed = true; // seal the static portion of memory\n');
print('STACK_MAX = STACK_BASE + ' + TOTAL_STACK + ';\n');
print('DYNAMIC_BASE = DYNAMICTOP = Runtime.alignMemory(STACK_MAX);\n');
- print('assert(DYNAMIC_BASE < TOTAL_MEMORY); // Stack must fit in TOTAL_MEMORY; allocations from here on may enlarge TOTAL_MEMORY\n');
+ print('assert(DYNAMIC_BASE < TOTAL_MEMORY, "TOTAL_MEMORY not big enough for stack");\n');
}
if (asmLibraryFunctions.length > 0) {
diff --git a/src/preamble.js b/src/preamble.js
index 832ec2c3..f9fccdf6 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -866,6 +866,21 @@ var TOTAL_STACK = Module['TOTAL_STACK'] || {{{ TOTAL_STACK }}};
var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || {{{ TOTAL_MEMORY }}};
var FAST_MEMORY = Module['FAST_MEMORY'] || {{{ FAST_MEMORY }}};
+#if ASM_JS
+var totalMemory = 4096;
+while (totalMemory < TOTAL_MEMORY || totalMemory < 2*TOTAL_STACK) {
+ if (totalMemory < 16*1024*1024) {
+ totalMemory *= 2;
+ } else {
+ totalMemory += 16*1024*1024
+ }
+}
+if (totalMemory !== TOTAL_MEMORY) {
+ Module.printErr('increasing TOTAL_MEMORY to ' + totalMemory + ' to be more reasonable');
+ TOTAL_MEMORY = totalMemory;
+}
+#endif
+
// Initialize the runtime's memory
#if USE_TYPED_ARRAYS
// check for full engine support (use string 'subarray' to avoid closure compiler confusion)