You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DYNAMICTOP_PTR has been a pointer to where DYNAMICTOP is stored,
which represented the top of "dynamic" memory (not static, and not stack; or
in other words, dynamic == managed by sbrk/malloc). We represented it on the
JS side so that we could allocate from JS directly, in particular during startup.
However, that has caused a bunch of complexity that is not really worth it, and
it's also work done after link that we'd like to remove (WebAssembly/binaryen#3043).
This PR moves us to a place where malloc-like allocation is disallowed from
JS during startup. Instead, JS should call sbrk or malloc normally (which can
only be done after startup).
This change removes the final static allocation from JS, which means that we
no longer adjust memory layout after link, and therefore this PR removes the
special updating of the stack pointer and sbrk location that we used to do.
(This just removes the --pass-arg stuff for those in emcc.py, to show that
this works and passes tests - there is a bunch more code that can be removed
but is deferred to keep this as small as possible.)
Dynamic linking, however is an exception: we need to allocate room for
dynamic libraries during startup (the main module needs them before it
starts to run). To support that, this PR still keeps around getMemory()
(which does a dynamic allocation during startup) and dynamicAlloc in
a simplified form. That form just updates __heap_base as we allocate,
and then when the main program starts, __heap_base is a normal
extern global that it receives, and it initializes sbrk using that (after
that point, dynamic allocations are disallowed and asserted against).
This change should not be user-visible, except for removing the allocate()
JS function's ALLOC_DYNAMIC option (since we no longer allow that type
of allocation).
This can only land when it removes the last static allocation from JS.
This has a small code size benefit, basically it removes things like
these:
340,341d339
< var DYNAMIC_BASE = 5263904, DYNAMICTOP_PTR = 20992;
<
361,362d358
< HEAP32[DYNAMICTOP_PTR >> 2] = DYNAMIC_BASE;
<
The benefit to pthreads builds is larger as it removes a bunch of special
code for DYNAMICTOP_PTR that we had there.
Note that I'm not totally happy with the sbrk implementation, but we
can improve it once malloc is not linked in by default (see comment).
Copy file name to clipboardExpand all lines: site/source/docs/api_reference/preamble.js.rst
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -404,7 +404,7 @@ The :ref:`emscripten-memory-model` uses a typed array buffer (``ArrayBuffer``) t
404
404
.. COMMENT (not rendered) : The following methods are explicitly not part of the public API and not documented. Note that in some case referred to by function name, other cases by Module assignment.
405
405
406
406
function allocate(slab, types, allocator, ptr) — Internal and use is discouraged. Documentation can remain in source code but not here.
Copy file name to clipboardExpand all lines: src/memoryprofiler.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -486,7 +486,11 @@ var emscriptenMemoryProfiler = {
486
486
html+='<br />STACK memory area used now (should be zero): '+self.formatBytes(STACKTOP-STACK_BASE)+'.'+colorBar('#FFFF00')+' STACK watermark highest seen usage (approximate lower-bound!): '+self.formatBytes(Math.abs(self.stackTopWatermark-STACK_BASE));
487
487
488
488
varDYNAMIC_BASE={{{getQuoted('DYNAMIC_BASE')}}};
489
-
varDYNAMICTOP=HEAP32[DYNAMICTOP_PTR>>2];
489
+
// During startup sbrk may not be defined yet. Ideally we should probably
490
+
// refactor memoryprofiler so that it only gets here after compiled code is
491
+
// ready to be called. For now, if the runtime is not yet initialized,
0 commit comments