Skip to content

Remove STATIC* JS vars and STATIC_BUMP setting #12176

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

Merged
merged 4 commits into from
Sep 12, 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
2 changes: 1 addition & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ def check(input_file):

shared.Settings.EXPORTED_FUNCTIONS += ['_stackSave', '_stackRestore', '_stackAlloc']
# We need to preserve the __data_end symbol so that wasm-emscripten-finalize can determine
# the STATIC_BUMP value.
# where static data ends (and correspondingly where the stack begins).
shared.Settings.EXPORTED_FUNCTIONS += ['___data_end']
if not shared.Settings.STANDALONE_WASM:
# in standalone mode, crt1 will call the constructors from inside the wasm
Expand Down
25 changes: 7 additions & 18 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ def align_memory(addr):
return (addr + 15) & -16


def align_static_bump(metadata):
# TODO: remove static bump entirely
metadata['staticBump'] = align_memory(metadata['staticBump'])
return metadata['staticBump']


def update_settings_glue(metadata, DEBUG):
optimize_syscalls(metadata['declares'], DEBUG)

Expand Down Expand Up @@ -159,7 +153,7 @@ def read_proxied_function_signatures(asmConsts):

shared.Settings.PROXIED_FUNCTION_SIGNATURES = read_proxied_function_signatures(metadata['asmConsts'])

shared.Settings.STATIC_BUMP = align_static_bump(metadata)
metadata['staticBump'] = align_memory(metadata['staticBump'])

shared.Settings.BINARYEN_FEATURES = metadata['features']
shared.Settings.WASM_TABLE_SIZE = metadata['tableSize']
Expand Down Expand Up @@ -188,7 +182,6 @@ def apply_static_code_hooks(code):
def apply_forwarded_data(forwarded_data):
forwarded_json = json.loads(forwarded_data)
# Be aware of JS static allocations
shared.Settings.STATIC_BUMP = forwarded_json['STATIC_BUMP']
# Be aware of JS static code hooks
StaticCodeHooks.atinits = str(forwarded_json['ATINITS'])
StaticCodeHooks.atmains = str(forwarded_json['ATMAINS'])
Expand Down Expand Up @@ -216,15 +209,15 @@ def compile_settings(temp_files):


class Memory():
def __init__(self):
def __init__(self, metadata):
# Note: if RELOCATABLE, then only relative sizes can be computed, and we don't
# actually write out any absolute memory locations ({{{ STACK_BASE }}}
# does not exist, etc.)

# Memory layout:
# * first the static globals
self.global_base = shared.Settings.GLOBAL_BASE
self.static_bump = shared.Settings.STATIC_BUMP
self.static_bump = metadata['staticBump']
# * then the stack (up on fastcomp, down on upstream)
self.stack_low = align_memory(self.global_base + self.static_bump)
self.stack_high = align_memory(self.stack_low + shared.Settings.TOTAL_STACK)
Expand All @@ -237,9 +230,9 @@ def __init__(self):
exit_with_error('Memory is not large enough for static data (%d) plus the stack (%d), please increase INITIAL_MEMORY (%d) to at least %d' % (self.static_bump, shared.Settings.TOTAL_STACK, shared.Settings.INITIAL_MEMORY, self.dynamic_base))


def apply_memory(js):
def apply_memory(js, metadata):
# Apply the statically-at-compile-time computed memory locations.
memory = Memory()
memory = Memory(metadata)

# Write it all out
js = js.replace('{{{ STATIC_BUMP }}}', str(memory.static_bump))
Expand Down Expand Up @@ -447,8 +440,6 @@ def emscript(infile, outfile, memfile, temp_files, DEBUG):

global_initializers = ', '.join('{ func: function() { %s() } }' % i for i in metadata['initializers'])

staticbump = shared.Settings.STATIC_BUMP

if shared.Settings.MINIMAL_RUNTIME:
# In minimal runtime, global initializers are run after the Wasm Module instantiation has finished.
global_initializers = ''
Expand All @@ -458,11 +449,9 @@ def emscript(infile, outfile, memfile, temp_files, DEBUG):
''' % ('if (!ENVIRONMENT_IS_PTHREAD)' if shared.Settings.USE_PTHREADS else '',
global_initializers)

pre = pre.replace('STATICTOP = STATIC_BASE + 0;', '''STATICTOP = STATIC_BASE + %d;
%s
''' % (staticbump, global_initializers))
pre += '\n' + global_initializers + '\n'

pre = apply_memory(pre)
pre = apply_memory(pre, metadata)
pre = apply_static_code_hooks(pre) # In regular runtime, atinits etc. exist in the preamble part
post = apply_static_code_hooks(post) # In MINIMAL_RUNTIME, atinit exists in the postamble part

Expand Down
6 changes: 0 additions & 6 deletions src/jsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,6 @@ function JSify(data, functionsOnly) {
//

if (!mainPass) {
if (!Variables.generatedGlobalBase) {
Variables.generatedGlobalBase = true;
// Globals are done, here is the rest of static memory
// emit "metadata" in a comment. FIXME make this nicer
print('// STATICTOP = STATIC_BASE + ' + alignMemory(Variables.nextIndexedOffset) + ';\n');
}
var generated = itemsDict.function.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.GlobalVariable);
print(generated.map(function(item) { return item.JS; }).join('\n'));

Expand Down
2 changes: 1 addition & 1 deletion src/library_trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ var LibraryTracing = {
emscripten_trace_report_memory_layout: function() {
if (EmscriptenTrace.postEnabled) {
var memory_layout = {
'static_base': STATIC_BASE,
'static_base': {{{ GLOBAL_BASE }}},
'stack_base': STACK_BASE,
'stack_top': STACKTOP,
'stack_max': STACK_MAX,
Expand Down
4 changes: 2 additions & 2 deletions src/memoryprofiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ var emscriptenMemoryProfiler = {

var width = (nBits(HEAP8.length) + 3) / 4; // Pointer 'word width'
var html = 'Total HEAP size: ' + self.formatBytes(HEAP8.length) + '.';
html += '<br />' + colorBar('#202020') + 'STATIC memory area size: ' + self.formatBytes(Math.min(STACK_BASE, STACK_MAX) - STATIC_BASE);
html += '. STATIC_BASE: ' + toHex(STATIC_BASE, width);
html += '<br />' + colorBar('#202020') + 'STATIC memory area size: ' + self.formatBytes(Math.min(STACK_BASE, STACK_MAX) - {{{ GLOBAL_BASE }}});
html += '. {{{ GLOBAL_BASE }}}: ' + toHex({{{ GLOBAL_BASE }}}, width);

html += '<br />' + colorBar('#FF8080') + 'STACK memory area size: ' + self.formatBytes(Math.abs(STACK_MAX - STACK_BASE));
html += '. STACK_BASE: ' + toHex(STACK_BASE, width);
Expand Down
1 change: 0 additions & 1 deletion src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ var PassManager = {
print('\n//FORWARDED_DATA:' + JSON.stringify({
Functions: Functions,
EXPORTED_FUNCTIONS: EXPORTED_FUNCTIONS,
STATIC_BUMP: STATIC_BUMP, // updated with info from JS
ATINITS: ATINITS.join('\n'),
ATMAINS: ATMAINS.join('\n'),
ATEXITS: ATEXITS.join('\n'),
Expand Down
3 changes: 1 addition & 2 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ function updateGlobalBufferAndViews(buf) {
Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
}

var STATIC_BASE = {{{ GLOBAL_BASE }}},
STACK_BASE = {{{ getQuoted('STACK_BASE') }}},
var STACK_BASE = {{{ getQuoted('STACK_BASE') }}},
STACKTOP = STACK_BASE,
STACK_MAX = {{{ getQuoted('STACK_MAX') }}},
DYNAMIC_BASE = {{{ getQuoted('DYNAMIC_BASE') }}};
Expand Down
5 changes: 0 additions & 5 deletions src/preamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,11 @@ Module['wasm'] = base64Decode('{{{ getQuoted("WASM_BINARY_DATA") }}}');
#include "runtime_strings.js"

#if USE_PTHREADS
var STATIC_BASE = {{{ GLOBAL_BASE }}};

if (!ENVIRONMENT_IS_PTHREAD) {
#endif

var GLOBAL_BASE = {{{ GLOBAL_BASE }}},
TOTAL_STACK = {{{ TOTAL_STACK }}},
#if !USE_PTHREADS
STATIC_BASE = {{{ GLOBAL_BASE }}},
#endif
STACK_BASE = {{{ getQuoted('STACK_BASE') }}},
STACKTOP = STACK_BASE,
STACK_MAX = {{{ getQuoted('STACK_MAX') }}}
Expand Down
5 changes: 0 additions & 5 deletions src/settings_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ var MEM_INIT_IN_WASM = 0;
// This is set internally when needed (SINGLE_FILE)
var SUPPORT_BASE64_EMBEDDING = 0;

// the total static allocation, that is, how much to bump the start of memory
// for static globals. received from the backend, and possibly increased due
// to JS static allocations
var STATIC_BUMP = -1;

// the total initial wasm table size.
var WASM_TABLE_SIZE = 0;

Expand Down
1 change: 0 additions & 1 deletion src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ var ENVIRONMENT_IS_WORKER = ENVIRONMENT_IS_PTHREAD = typeof importScripts === 'f
#if MODULARIZE
if (ENVIRONMENT_IS_WORKER) {
var buffer = {{{EXPORT_NAME}}}.buffer;
var STATICTOP = {{{EXPORT_NAME}}}.STATICTOP;
var STACK_BASE = {{{EXPORT_NAME}}}.STACK_BASE;
var STACKTOP = {{{EXPORT_NAME}}}.STACKTOP;
var STACK_MAX = {{{EXPORT_NAME}}}.STACK_MAX;
Expand Down
3 changes: 1 addition & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7676,8 +7676,7 @@ def test_memprof_requirements(self):
create_test_file('lib.js', '''
mergeInto(LibraryManager.library, {
check_memprof_requirements: function() {
if (typeof STATIC_BASE === 'number' &&
typeof STACK_BASE === 'number' &&
if (typeof STACK_BASE === 'number' &&
typeof STACK_MAX === 'number' &&
typeof STACKTOP === 'number' &&
typeof DYNAMIC_BASE === 'number') {
Expand Down
2 changes: 0 additions & 2 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,6 @@ class JS(object):
memory_initializer_pattern = r'/\* memory initializer \*/ allocate\(\[([\d, ]*)\], "i8", ALLOC_NONE, ([\d+\.GLOBAL_BASEHgb]+)\);'
no_memory_initializer_pattern = r'/\* no memory initializer \*/'

memory_staticbump_pattern = r'STATICTOP = STATIC_BASE \+ (\d+);'

global_initializers_pattern = r'/\* global initializers \*/ __ATINIT__.push\((.+)\);'

emscripten_license = '''\
Expand Down