镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0dec1b7
Don't allow memory growth with pthreads
dschuff Nov 2, 2018
1f94ede
support pthreads+memory growth, and remove unneeded Module.buffer
kripken Mar 8, 2019
63afb6c
wip
kripken Mar 8, 2019
6ca27b6
wip [ci skip]
kripken Mar 27, 2019
1266102
integration [ci skip]
kripken Mar 28, 2019
caac67c
working for now
kripken Mar 28, 2019
1e354b8
Merge branch 'pthreads_growth' into growableHeap
kripken Mar 28, 2019
b2bcf10
Merge remote-tracking branch 'origin/incoming' into growableHeap
kripken Mar 28, 2019
a12ab96
Merge remote-tracking branch 'origin/pthreads-growth' into growableHeap
kripken Mar 28, 2019
598f978
fix [ci skip]
kripken Mar 28, 2019
e0b2261
brk
kripken Mar 28, 2019
812eace
fixe [ci skip]
kripken Mar 28, 2019
abaf515
temp fix
kripken Mar 28, 2019
36373b3
fix [ci skip]
kripken Mar 28, 2019
6a93a95
fix
kripken Mar 28, 2019
c883b5b
other.test_minimal_runtime_code_size: apply slop to code sizes, as th…
kripken Mar 28, 2019
196bd55
Merge branch 'slop' into growableHeap
kripken Mar 28, 2019
e9dba56
cleanup
kripken Mar 28, 2019
2d2c33d
fixes
kripken Mar 28, 2019
8220dbe
test
kripken Mar 28, 2019
2208693
test works
kripken Mar 28, 2019
68c384d
fix return values and buffer setting for asm.js from realloc_buffer
kripken Mar 28, 2019
bcea7d0
fix
kripken Mar 28, 2019
5b82e0a
optimize sbrk - do not call get_heap_size unnecessarily [ci skip]
kripken Mar 28, 2019
defda2d
fix
kripken Mar 29, 2019
14488b1
don't test on an actual worker yet
kripken Mar 29, 2019
59b16c8
flake8
kripken Mar 29, 2019
e49b176
fix modularize mode
kripken Mar 30, 2019
55c231c
add views
kripken Apr 1, 2019
db6943b
docs about this stuff
kripken Apr 1, 2019
c1ab19c
Merge remote-tracking branch 'origin/incoming' into growableHeap
kripken Apr 1, 2019
f06f92f
Merge remote-tracking branch 'origin/incoming' into growableHeap
kripken Apr 3, 2019
1579291
Merge remote-tracking branch 'origin/incoming' into growableHeap
kripken Apr 5, 2019
b28aff5
comment
kripken Apr 5, 2019
ccdbab0
prepare for more testing
kripken Apr 5, 2019
c56168b
try to use chrome unstable so growable memory + pthreads test on the …
kripken Apr 5, 2019
fb917e4
chrome unstable fails on circle, so give up on that - and disable tes…
kripken Apr 5, 2019
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
6 changes: 5 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,11 @@ def check(input_file):
if shared.Settings.USE_PTHREADS == 2:
exit_with_error('USE_PTHREADS=2 is not longer supported')
if shared.Settings.ALLOW_MEMORY_GROWTH:
exit_with_error('Memory growth is not yet supported with pthreads')
if not shared.Settings.WASM:
exit_with_error('Memory growth is not supported with pthreads without wasm')
else:
logging.warning('USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271')
options.force_js_opts = options.js_opts = True # for JS instrumentation
# UTF8Decoder.decode doesn't work with a view of a SharedArrayBuffer
shared.Settings.TEXTDECODER = 0
options.js_libraries.append(shared.path_from_root('src', 'library_pthread.js'))
Expand Down
2 changes: 2 additions & 0 deletions site/source/docs/porting/pthreads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ The Emscripten implementation for the pthreads API should follow the POSIX stand

- Note that the function emscripten_num_logical_cores() will always return the value of navigator.hardwareConcurrency, i.e. the number of logical cores on the system, even when shared memory is not supported. This means that it is possible for emscripten_num_logical_cores() to return a value greater than 1, while at the same time emscripten_has_threading_support() can return false. The return value of emscripten_has_threading_support() denotes whether the browser has shared memory support available.

- Pthreads + memory growth (`ALLOW_MEMORY_GROWTH`) is especially tricky, see `wasm design issue #1271 <https://github.com/WebAssembly/design/issues/1271>`_. This currently causes JS accessing the wasm memory to be slow - but this will likely only be noticeable if the JS does heavy work (wasm runs at full speed, so moving work over can fix this). This also requires that your JS be aware that the HEAP* views may need to be updated - use the `GROWABLE_HEAP_*` helper functions which automatically handle that for you.

Also note that when compiling code that uses pthreads, an additional JavaScript file `NAME.worker.js` is generated alongside the output .js file (where `NAME` is the basename of the main file being emitted). That file must be deployed with the rest of the generated code files. By default, `NAME.worker.js` will be loaded relative to the main HTML page URL. If it is desirable to load the file from a different location e.g. in a CDN environment, then one can define the `Module.locateFile(filename)` function in the main HTML `Module` object to return the URL of the target location of the `NAME.worker.js` entry point. If this function is not defined in `Module`, then the default location relative to the main HTML file is used.

Running code and tests
Expand Down
119 changes: 119 additions & 0 deletions src/growableHeap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Support for growable heap + pthreads, where the buffer may change, so JS views
// must be updated.
function GROWABLE_HEAP_STORE_I8(ptr, value) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
HEAP8[ptr] = value;
}
function GROWABLE_HEAP_STORE_I16(ptr, value) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
HEAP16[ptr >> 1] = value;
}
function GROWABLE_HEAP_STORE_I32(ptr, value) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
HEAP32[ptr >> 2] = value;
}
function GROWABLE_HEAP_STORE_F32(ptr, value) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
HEAPF32[ptr >> 2] = value;
}
function GROWABLE_HEAP_STORE_F64(ptr, value) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
HEAPF64[ptr >> 3] = value;
}

function GROWABLE_HEAP_LOAD_I8(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAP8[ptr];
}
function GROWABLE_HEAP_LOAD_U8(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAPU8[ptr];
}
function GROWABLE_HEAP_LOAD_I16(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAP16[ptr >> 1];
}
function GROWABLE_HEAP_LOAD_U16(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAPU16[ptr >> 1];
}
function GROWABLE_HEAP_LOAD_I32(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAP32[ptr >> 2];
}
function GROWABLE_HEAP_LOAD_U32(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAPU32[ptr >> 2];
}
function GROWABLE_HEAP_LOAD_F32(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAPF32[ptr >> 2];
}
function GROWABLE_HEAP_LOAD_F64(ptr) {
if (wasmMemory.buffer != buffer) {
buffer = wasmMemory.buffer;
updateGlobalBufferViews();
}
return HEAPF64[ptr >> 3];
}
function GROWABLE_HEAP_VIEW_I8(start, end) {
return new Int8Array(wasmMemory.buffer, start, end - start);
}
function GROWABLE_HEAP_VIEW_U8(start, end) {
return new Uint8Array(wasmMemory.buffer, start, end - start);
}
function GROWABLE_HEAP_VIEW_I16(start, end) {
return new Int16Array(wasmMemory.buffer, start >> 1, end - start >> 1);
}
function GROWABLE_HEAP_VIEW_U16(start, end) {
return new Uint16Array(wasmMemory.buffer, start >> 1, end - start >> 1);
}
function GROWABLE_HEAP_VIEW_I32(start, end) {
return new Int32Array(wasmMemory.buffer, start >> 2, end - start >> 2);
}
function GROWABLE_HEAP_VIEW_U32(start, end) {
return new Uint32Array(wasmMemory.buffer, start >> 2, end - start >> 2);
}
function GROWABLE_HEAP_VIEW_F32(start, end) {
return new Float32Array(wasmMemory.buffer, start >> 2, end - start >> 2);
}
function GROWABLE_HEAP_VIEW_F64(start, end) {
return new Float64Array(wasmMemory.buffer, start >> 3, end - start >> 3);
}

Loading