Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of WASM setting in library JS #12122

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,9 @@ LibraryManager.library = {
var oldHeapSize = buffer.byteLength;
#endif
try {
#if WASM
// round size grow request up to wasm page size (fixed 64KB per spec)
wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16); // .grow() takes a delta compared to the previous size
updateGlobalBufferAndViews(wasmMemory.buffer);
#else // asm.js:
var newBuffer = new ArrayBuffer(size);
if (newBuffer.byteLength != size) return /*undefined, allocation did not succeed*/;
new Int8Array(newBuffer).set(/**@type{!Int8Array}*/(HEAP8));
_emscripten_replace_memory(newBuffer);
updateGlobalBufferAndViews(newBuffer);
#endif
#if MEMORYPROFILER
if (typeof emscriptenMemoryProfiler !== 'undefined') {
emscriptenMemoryProfiler.onMemoryResize(oldHeapSize, buffer.byteLength);
Expand Down Expand Up @@ -949,7 +941,6 @@ LibraryManager.library = {
}

var result = lib.module[modSymbol];
#if WASM
// Attempt to get the real "unwrapped" symbol so we have more chance of
// getting wasm function which can be added to a table.
if (isMainModule) {
Expand All @@ -958,11 +949,10 @@ LibraryManager.library = {
result = lib.module["asm"][asmSymbol];
}
}
#endif
if (typeof result !== 'function')
return result;

#if WASM && EMULATE_FUNCTION_POINTER_CASTS
#if EMULATE_FUNCTION_POINTER_CASTS
// for wasm with emulated function pointers, the i64 ABI is used for all
// function calls, so we can't just call addFunction on something JS
// can call (which does not use that ABI), as the function pointer would
Expand All @@ -980,16 +970,10 @@ LibraryManager.library = {
return result;
#else // WASM && EMULATE_FUNCTION_POINTER_CASTS

#if WASM
// Insert the function into the wasm table. Since we know the function
// comes directly from the loaded wasm module we can insert it directly
// into the table, avoiding any JS interaction.
return addFunctionWasm(result);
#else
// convert the exported function into a function pointer using our generic
// JS mechanism.
return addFunction(result);
#endif // WASM
#endif // WASM && EMULATE_FUNCTION_POINTER_CASTS
},

Expand Down
2 changes: 0 additions & 2 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ var LibraryBrowser = {
};
Module['preloadPlugins'].push(audioPlugin);

#if WASM
#if MAIN_MODULE
var wasmPlugin = {};
wasmPlugin['asyncWasmLoadPromise'] = new Promise(
Expand All @@ -261,7 +260,6 @@ var LibraryBrowser = {
};
Module['preloadPlugins'].push(wasmPlugin);
#endif // MAIN_MODULE
#endif // WASM

// Canvas event setup

Expand Down
21 changes: 8 additions & 13 deletions src/library_emmalloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@

mergeInto(LibraryManager.library, {
emmalloc_unclaimed_heap_memory: function() {
var dynamicTop = _sbrk();
var dynamicTop = _sbrk();
#if ALLOW_MEMORY_GROWTH
#if WASM
#if MAXIMUM_MEMORY != -1
// Using MAXIMUM_MEMORY to constrain max heap size.
return {{{ MAXIMUM_MEMORY }}} - dynamicTop;
// Using MAXIMUM_MEMORY to constrain max heap size.
return {{{ MAXIMUM_MEMORY }}} - dynamicTop;
#else
// Not using a Wasm memory bound.
return 2*1024*1024*1024 - 65536 - dynamicTop;
// Not using a Wasm memory bound.
return 2*1024*1024*1024 - 65536 - dynamicTop;
#endif
#else
// asm.js:
return 2*1024*1024*1024 - 16777216 - dynamicTop;
#endif
#else
// ALLOW_MEMORY_GROWTH is disabled, the current heap size
// is all we got.
return HEAPU8.length - dynamicTop;
// ALLOW_MEMORY_GROWTH is disabled, the current heap size
// is all we got.
return HEAPU8.length - dynamicTop;
#endif
}
});
13 changes: 4 additions & 9 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2728,15 +2728,10 @@ var LibraryJSEvents = {
var t = performance.now();
var n = t + msecs;
if ({{{ makeDynCall('idi', 'cb') }}}(t, userData)) {
setTimeout(tick,
#if WASM
// Save a little bit of code space: modern browsers should treat negative setTimeout as timeout of 0 (https://stackoverflow.com/questions/8430966/is-calling-settimeout-with-a-negative-delay-ok)
t - performance.now()
#else
// For old browsers, cap the timeout to zero.
Math.max(0, t - performance.now())
#endif
);
// Save a little bit of code space: modern browsers should treat
// negative setTimeout as timeout of 0
// (https://stackoverflow.com/questions/8430966/is-calling-settimeout-with-a-negative-delay-ok)
setTimeout(tick, t - performance.now());
}
}
return setTimeout(tick, 0);
Expand Down
7 changes: 1 addition & 6 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ var LibraryPThread = {
}
#endif

#if ASSERTIONS && WASM
#if ASSERTIONS
assert(wasmMemory instanceof WebAssembly.Memory, 'WebAssembly memory should have been loaded by now!');
assert(wasmModule instanceof WebAssembly.Module, 'WebAssembly Module should have been loaded by now!');
#endif
Expand All @@ -394,7 +394,6 @@ var LibraryPThread = {
// object in Module['mainScriptUrlOrBlob'], or a URL to it, so that pthread Workers can
// independently load up the same main application file.
'urlOrBlob': Module['mainScriptUrlOrBlob'] || _scriptDir,
#if WASM
#if WASM2JS
// the polyfill WebAssembly.Memory instance has function properties,
// which will fail in postMessage, so just send a custom object with the
Expand All @@ -410,10 +409,6 @@ var LibraryPThread = {
#if USE_OFFSET_CONVERTER
'wasmOffsetConverter': wasmOffsetConverter,
#endif
#else
'buffer': HEAPU8.buffer,
'asmJsUrlOrBlob': Module["asmJsUrlOrBlob"],
#endif
#if !MINIMAL_RUNTIME
'DYNAMIC_BASE': DYNAMIC_BASE
#endif
Expand Down
25 changes: 3 additions & 22 deletions src/postamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ function initRuntime(asm) {
{{{ getQuoted('ATINITS') }}}
}

#if WASM

// Initialize wasm (asynchronous)

var imports = {
Expand All @@ -94,11 +92,11 @@ var imports = {

// In non-fastcomp non-asm.js builds, grab wasm exports to outer scope
// for emscripten_get_exported_function() to be able to access them.
#if LibraryManager.has('library_exports.js') && WASM
#if LibraryManager.has('library_exports.js')
var asm;
#endif

#if USE_PTHREADS && WASM
#if USE_PTHREADS
var wasmModule;
#if PTHREAD_POOL_SIZE
function loadWasmModuleToWorkers() {
Expand Down Expand Up @@ -151,7 +149,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
wasmModule = output.module || Module['wasm'];
#endif

#if !(LibraryManager.has('library_exports.js') && WASM) && !EMBIND
#if !LibraryManager.has('library_exports.js') && !EMBIND
// If not using the emscripten_get_exported_function() API or embind, keep the 'asm'
// exports variable in local scope to this instantiate function to save code size.
// (otherwise access it without to export it to outer scope)
Expand Down Expand Up @@ -234,22 +232,5 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
#endif // ASSERTIONS || WASM == 2
;

#else

// Initialize asm.js (synchronous)
initRuntime(asm);

#if USE_PTHREADS && PTHREAD_POOL_SIZE
if (!ENVIRONMENT_IS_PTHREAD) loadWasmModuleToWorkers();
#if !PTHREAD_POOL_DELAY_LOAD
else
#endif
ready();
#else
ready();
#endif

#endif

{{GLOBAL_VARS}}

16 changes: 1 addition & 15 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,6 @@ var TOTAL_STACK = {{{ TOTAL_STACK }}};
#if ASSERTIONS
if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime')
#endif
#if MAIN_MODULE && !WASM
// JS side modules use this value to decide their stack size.
Module['TOTAL_STACK'] = TOTAL_STACK;
#endif

{{{ makeModuleReceiveWithVar('INITIAL_INITIAL_MEMORY', 'INITIAL_MEMORY', INITIAL_MEMORY) }}}

Expand Down Expand Up @@ -429,8 +425,6 @@ if (typeof SharedArrayBuffer === 'undefined' || typeof Atomics === 'undefined')
#endif
#endif

#include "runtime_sab_polyfill.js"

#if STANDALONE_WASM
#if ASSERTIONS
// In standalone mode, the wasm creates the memory, and the user can't provide it.
Expand Down Expand Up @@ -664,7 +658,7 @@ function removeRunDependency(id) {

Module["preloadedImages"] = {}; // maps url to image data
Module["preloadedAudios"] = {}; // maps url to audio data
#if WASM && MAIN_MODULE
#if MAIN_MODULE
Module["preloadedWasm"] = {}; // maps url to wasm instance exports
#endif

Expand Down Expand Up @@ -692,14 +686,10 @@ function abort(what) {
what = output;
#endif // ASSERTIONS

#if WASM
// Use a wasm runtime error, because a JS error might be seen as a foreign
// exception, which means we'd run destructors on it. We need the error to
// simply make the program stop.
var e = new WebAssembly.RuntimeError(what);
#else
var e = what;
#endif

#if MODULARIZE
readyPromiseReject(e);
Expand Down Expand Up @@ -732,7 +722,6 @@ addOnPreRun(function() {
}
}
// if we can load dynamic libraries synchronously, do so, otherwise, preload
#if WASM
if (Module['dynamicLibraries'] && Module['dynamicLibraries'].length > 0 && !readBinary) {
// we can't read binary data synchronously, so preload
addRunDependency('preload_dynamicLibraries');
Expand All @@ -744,7 +733,6 @@ addOnPreRun(function() {
});
return;
}
#endif
loadDynamicLibraries(Module['dynamicLibraries']);
});

Expand Down Expand Up @@ -805,7 +793,6 @@ function createExportWrapper(name, fixedasm) {
}
#endif

#if WASM
var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}';
if (!isDataURI(wasmBinaryFile)) {
wasmBinaryFile = locateFile(wasmBinaryFile);
Expand Down Expand Up @@ -1132,7 +1119,6 @@ function createWasm() {
return Module['asm']; // exports were assigned here
#endif
}
#endif

// Globals used by JS i64 conversions
var tempDouble;
Expand Down
17 changes: 0 additions & 17 deletions src/preamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Module['wasm'] = base64Decode('{{{ getQuoted("WASM_BINARY_DATA") }}}');

#include "runtime_functions.js"
#include "runtime_strings.js"
#include "runtime_sab_polyfill.js"

#if USE_PTHREADS
var STATIC_BASE = {{{ GLOBAL_BASE }}};
Expand All @@ -72,8 +71,6 @@ var GLOBAL_BASE = {{{ GLOBAL_BASE }}},
STACK_MAX = {{{ getQuoted('STACK_MAX') }}}
;

#if WASM

#if ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1
var wasmMaximumMemory = {{{ MAXIMUM_MEMORY >>> 16 }}};
#else
Expand Down Expand Up @@ -101,20 +98,6 @@ assert(buffer instanceof SharedArrayBuffer, 'requested a shared WebAssembly.Memo

#include "runtime_init_table.js"

#else

#if USE_PTHREADS
var buffer = new SharedArrayBuffer({{{ INITIAL_MEMORY }}});
#else
var buffer = new ArrayBuffer({{{ INITIAL_MEMORY }}});
#endif

#if USE_PTHREADS
}
#endif

#endif

#if ASSERTIONS
var WASM_PAGE_SIZE = {{{ WASM_PAGE_SIZE }}};
#if USE_PTHREADS
Expand Down
2 changes: 0 additions & 2 deletions src/runtime_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* SPDX-License-Identifier: MIT
*/

#if WASM
// Wraps a JS function as a wasm function with a given signature.
function convertJsFunctionToWasm(func, sig) {
#if WASM2JS
Expand Down Expand Up @@ -170,7 +169,6 @@ function removeFunctionWasm(index) {
functionsInTableMap.delete(wasmTable.get(index));
freeTableIndexes.push(index);
}
#endif

// 'sig' parameter is required for the llvm backend but only when func is not
// already a WebAssembly function.
Expand Down
19 changes: 1 addition & 18 deletions src/runtime_init_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ if (ENVIRONMENT_IS_PTHREAD) {
buffer = Module['buffer'];
} else {
#endif // USE_PTHREADS
#if WASM

#if expectToReceiveOnModule('wasmMemory')
if (Module['wasmMemory']) {
Expand Down Expand Up @@ -47,34 +46,18 @@ if (ENVIRONMENT_IS_PTHREAD) {
#endif
}

#else // WASM

if (Module['buffer']) {
buffer = Module['buffer'];
}
#ifdef USE_PTHREADS
else if (typeof SharedArrayBuffer !== 'undefined') {
buffer = new SharedArrayBuffer(INITIAL_INITIAL_MEMORY);
}
#endif
else {
buffer = new ArrayBuffer(INITIAL_INITIAL_MEMORY);
}
#endif // WASM
#if USE_PTHREADS
}
#endif

#if WASM
if (wasmMemory) {
buffer = wasmMemory.buffer;
}
#endif

// If the user provides an incorrect length, just use that length instead rather than providing the user to
// specifically provide the memory length with Module['INITIAL_MEMORY'].
INITIAL_INITIAL_MEMORY = buffer.byteLength;
#ifdef ASSERTIONS && WASM
#ifdef ASSERTIONS
assert(INITIAL_INITIAL_MEMORY % WASM_PAGE_SIZE === 0);
#ifdef ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1
assert({{{ WASM_PAGE_SIZE }}} % WASM_PAGE_SIZE === 0);
Expand Down
Loading