diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-27 20:07:07 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-27 20:07:07 -0700 |
commit | ed88bc7051a61e05c6e85e792d56513826722d2e (patch) | |
tree | d40113a39ebe21626cb193e1a5652f621052e942 /src | |
parent | b1989519a9e66a8c2f5b2174a2eadb53bb8f9f56 (diff) |
memory growth must be manually enabled with ALLOW_MEMORY_GROWTH, in which case the eliminator runs in safe mode
Diffstat (limited to 'src')
-rw-r--r-- | src/preamble.js | 6 | ||||
-rw-r--r-- | src/settings.js | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/preamble.js b/src/preamble.js index b197ef02..24277014 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -576,9 +576,12 @@ var STACK_ROOT, STACKTOP, STACK_MAX; var STATICTOP; #if USE_TYPED_ARRAYS function enlargeMemory() { +#if ALLOW_MEMORY_GROWTH == 0 + abort('Cannot enlarge memory arrays. Adjust TOTAL_MEMORY or compile with ALLOW_MEMORY_GROWTH'); +#else // TOTAL_MEMORY is the current size of the actual array, and STATICTOP is the new top. #if ASSERTIONS - Module.printErr('Warning: Enlarging memory arrays, this is not fast, and can also break in high optimization levels where we assume globals are not modified! ' + [STATICTOP, TOTAL_MEMORY]); // XXX perhaps never do elimination optimizations of calls that can lead to resizing, to avoid HEAP[malloc()] = X; where JS semantic will write to the old HEAP if malloc replaces it + Module.printErr('Warning: Enlarging memory arrays, this is not fast, and ALLOW_MEMORY_GROWTH is not fully tested with all optimizations on! ' + [STATICTOP, TOTAL_MEMORY]); // We perform safe elimination instead of elimination in this mode, but if you see this error, try to disable it and other optimizations entirely assert(STATICTOP >= TOTAL_MEMORY); assert(TOTAL_MEMORY > 4); // So the loop below will not be infinite #endif @@ -609,6 +612,7 @@ function enlargeMemory() { HEAPF64 = new Float64Array(buffer); HEAP8.set(oldHEAP8); #endif +#endif } #endif diff --git a/src/settings.js b/src/settings.js index a1c41de7..7e7caa6f 100644 --- a/src/settings.js +++ b/src/settings.js @@ -48,6 +48,13 @@ var TOTAL_MEMORY = 10*1024*1024; // The total amount of memory to use. Using mor // we need to copy the old heap into a new one in that case. var FAST_MEMORY = 2*1024*1024; // The amount of memory to initialize to 0. This ensures it will be // in a flat array. This only matters in non-typed array builds. +var ALLOW_MEMORY_GROWTH = 0; // If false, we abort with an error if we try to allocate more memory than + // we can (TOTAL_MEMORY). If true, we will grow the memory arrays at + // runtime, seamlessly and dynamically. This has a performance cost though, + // both during the actual growth and in general (the latter is because in + // that case we must be careful about optimizations, in particular the + // eliminator). Note that memory growth is only supported with typed + // arrays. // Code embetterments var MICRO_OPTS = 1; // Various micro-optimizations, like nativizing variables |