Skip to content

Commit 662747e

Browse files
committed
Enable growable shared array buffers
Currently this is still behind a flag so we never turn it on by default. Fixes: #24287
1 parent 26cec80 commit 662747e

File tree

7 files changed

+25
-4
lines changed

7 files changed

+25
-4
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ commands:
320320
CHROME_FLAGS_BASE: "--no-first-run -start-maximized --no-sandbox --use-gl=swiftshader --user-data-dir=/tmp/chrome-emscripten-profile --enable-experimental-web-platform-features --enable-features=JavaScriptSourcePhaseImports"
321321
# Increase the window size to avoid flaky sdl tests see #24236.
322322
CHROME_FLAGS_HEADLESS: "--headless=new --window-size=1024,768 --remote-debugging-port=1234"
323-
CHROME_FLAGS_WASM: "--enable-experimental-webassembly-features --js-flags=\"--experimental-wasm-stack-switching --experimental-wasm-type-reflection\""
323+
CHROME_FLAGS_WASM: "--enable-experimental-webassembly-features --js-flags=\"--experimental-wasm-stack-switching --experimental-wasm-type-reflection --experimental-wasm-rab-integration\""
324324
CHROME_FLAGS_NOCACHE: "--disk-cache-dir=/dev/null --disk-cache-size=1 --media-cache-size=1 --disable-application-cache --incognito"
325325
# The runners lack sound hardware so fallback to a dummy device (and
326326
# bypass the user gesture so audio tests work without interaction)
@@ -820,6 +820,7 @@ jobs:
820820
other.test_gen_struct_info
821821
other.test_native_call_before_init
822822
other.test_node_unhandled_rejection
823+
other.test_pthread_growth_growable_sab
823824
core2.test_hello_world
824825
core2.test_esm_integration*
825826
core0.test_esm_integration*

src/runtime_common.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "runtime_safe_heap.js"
1313
#endif
1414

15-
#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH
15+
#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH && !GROWABLE_SAB
1616
#include "growableHeap.js"
1717
#endif
1818

@@ -132,7 +132,11 @@ var runtimeExited = false;
132132
}}}
133133

134134
function updateMemoryViews() {
135+
#if GROWABLE_SAB
136+
var b = wasmMemory.toResizableBuffer();
137+
#else
135138
var b = wasmMemory.buffer;
139+
#endif
136140
{{{ maybeExportHeap('HEAP8') }}}HEAP8 = new Int8Array(b);
137141
{{{ maybeExportHeap('HEAP16') }}}HEAP16 = new Int16Array(b);
138142
{{{ maybeExportHeap('HEAPU8') }}}HEAPU8 = new Uint8Array(b);

src/settings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,11 @@ var WASM_ESM_INTEGRATION = false;
21842184
// [link]
21852185
var JS_BASE64_API = false;
21862186

2187+
// Enable support for GrowableSharedArrayBuffer.
2188+
// This features is only available behind a flag in recent versions of
2189+
// node/chrome.
2190+
var GROWABLE_SAB = false;
2191+
21872192
// Experimental support for WebAssembly js-types proposal.
21882193
// It's currently only available under a flag in certain browsers,
21892194
// so we disable it by default to save on code size.

test/test_browser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,6 +4728,7 @@ def test_pthread_hello_thread(self, opts, modularize):
47284728
# Tests that a pthreads build of -sMINIMAL_RUNTIME works well in different build modes
47294729
@parameterized({
47304730
'': ([],),
4731+
'growable_sab': (['-sGROWABLE_SAB'],),
47314732
'modularize': (['-sMODULARIZE', '-sEXPORT_NAME=MyModule'],),
47324733
'O3': (['-O3'],),
47334734
'O3_modularize': (['-O3', '-sMODULARIZE', '-sEXPORT_NAME=MyModule'],),
@@ -4739,6 +4740,7 @@ def test_minimal_runtime_hello_thread(self, opts):
47394740
# Tests memory growth in pthreads mode, but still on the main thread.
47404741
@parameterized({
47414742
'': ([], 1),
4743+
'growable_sab': (['-sGROWABLE_SAB'], 1),
47424744
'proxy': (['-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'], 2),
47434745
})
47444746
@no_2gb('uses INITIAL_MEMORY')

test/test_other.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14290,22 +14290,30 @@ def test_pthread_kill(self):
1429014290
@node_pthreads
1429114291
@parameterized({
1429214292
'': ([], 1),
14293+
'growable_sab': (['-sGROWABLE_SAB'], 1),
1429314294
'proxy': (['-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'], 2),
1429414295
})
1429514296
def test_pthread_growth_mainthread(self, cflags, pthread_pool_size):
14297+
if '-sGROWABLE_SAB' in cflags:
14298+
self.node_args.append('--experimental-wasm-rab-integration')
14299+
self.require_node_canary()
1429614300
self.set_setting('PTHREAD_POOL_SIZE', pthread_pool_size)
1429714301
self.do_runf('pthread/test_pthread_memory_growth_mainthread.c', cflags=['-Wno-pthreads-mem-growth', '-pthread', '-sALLOW_MEMORY_GROWTH', '-sINITIAL_MEMORY=32MB', '-sMAXIMUM_MEMORY=256MB'] + cflags)
1429814302

1429914303
# Tests memory growth in a pthread.
1430014304
@node_pthreads
1430114305
@parameterized({
1430214306
'': ([],),
14307+
'growable_sab': (['-sGROWABLE_SAB'],),
1430314308
'assert': (['-sASSERTIONS'],),
1430414309
'proxy': (['-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'], 2),
1430514310
'minimal': (['-sMINIMAL_RUNTIME', '-sMODULARIZE', '-sEXPORT_NAME=MyModule'],),
1430614311
})
1430714312
def test_pthread_growth(self, cflags, pthread_pool_size = 1):
1430814313
self.set_setting('PTHREAD_POOL_SIZE', pthread_pool_size)
14314+
if '-sGROWABLE_SAB' in cflags:
14315+
self.node_args.append('--experimental-wasm-rab-integration')
14316+
self.require_node_canary()
1430914317
self.do_runf('pthread/test_pthread_memory_growth.c', cflags=['-Wno-pthreads-mem-growth', '-pthread', '-sALLOW_MEMORY_GROWTH', '-sINITIAL_MEMORY=32MB', '-sMAXIMUM_MEMORY=256MB'] + cflags)
1431014318

1431114319
@node_pthreads

tools/building.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ def little_endian_heap(js_file):
10591059

10601060

10611061
def apply_wasm_memory_growth(js_file):
1062+
assert not settings.GROWABLE_SAB
10621063
logger.debug('supporting wasm memory growth with pthreads')
10631064
return acorn_optimizer(js_file, ['growableHeap'])
10641065

tools/link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def setup_pthreads():
509509
diagnostics.warning('experimental', '-sMAIN_MODULE + pthreads is experimental')
510510
elif settings.LINKABLE:
511511
diagnostics.warning('experimental', '-sLINKABLE + pthreads is experimental')
512-
if settings.ALLOW_MEMORY_GROWTH:
512+
if settings.ALLOW_MEMORY_GROWTH and not settings.GROWABLE_SAB:
513513
diagnostics.warning('pthreads-mem-growth', '-pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271')
514514

515515
default_setting('DEFAULT_PTHREAD_STACK_SIZE', settings.STACK_SIZE)
@@ -2330,7 +2330,7 @@ def phase_binaryen(target, options, wasm_target):
23302330
# unsigning pass.
23312331
# we also must do this after the asan or safe_heap instrumentation, as they
23322332
# wouldn't be able to recognize patterns produced by the growth pass.
2333-
if settings.SHARED_MEMORY and settings.ALLOW_MEMORY_GROWTH:
2333+
if settings.SHARED_MEMORY and settings.ALLOW_MEMORY_GROWTH and not settings.GROWABLE_SAB:
23342334
with ToolchainProfiler.profile_block('apply_wasm_memory_growth'):
23352335
final_js = building.apply_wasm_memory_growth(final_js)
23362336

0 commit comments

Comments
 (0)