Skip to content

Commit

Permalink
Merge pull request #431 from WebAssembly/rm-max-heap
Browse files Browse the repository at this point in the history
Change linear memory max to be a hint
  • Loading branch information
jfbastien committed Oct 29, 2015
2 parents 5b2794f + ac4cd1a commit 6c494bc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion AstSemantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ be an untyped array of bytes, and it is unspecified how embedders map this array
into their process' own [virtual memory][]. The linear memory is sandboxed; it
does not alias the execution engine's internal data structures, the execution
stack, local variables, or other process memory. The initial state of linear
memory is specified by the [module](Modules.md#initial-state-of-linear-memory).
memory is specified by the [module](Modules.md#linear-memory-section).

[virtual memory]: https://en.wikipedia.org/wiki/Virtual_memory

Expand Down
5 changes: 3 additions & 2 deletions BinaryEncoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ Yes:
- A sequence of byte ranges within the binary and corresponding addresses in the linear memory


All strings are encoded as null-terminated UTF8.
Data segments represent initialized data that is loaded directly from the binary into the linear memory when the program starts (see [modules](Modules.md#initial-state-of-linear-memory)).
All strings are encoded as null-terminated UTF8. Data segments represent
initialized data that is loaded directly from the binary into the linear memory
when the program starts (see [modules](Modules.md#linear-memory-section)).

## Serialized AST

Expand Down
23 changes: 17 additions & 6 deletions Modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ is determined by the module it was loaded from.

A module contains:
* a set of [imports and exports](Modules.md#imports-and-exports);
* a section defining the [initial state of linear memory](Modules.md#initial-state-of-linear-memory);
* a section defining [linear memory](Modules.md#linear-memory-section);
* a section containing [code](Modules.md#code-section);
* after the MVP, sections containing [debugging/symbol information](Tooling.md) or
a reference to separate files containing them; and
Expand Down Expand Up @@ -122,12 +122,23 @@ shared `malloc` and coordinated global address ranges). Instead, the
[dynamic linking future feature](DynamicLinking.md) is intended
to allow *explicitly* injecting multiple modules into the same instance.

## Initial state of linear memory
## Linear memory section

A module will contain a section declaring the linear memory size (initial and
maximum size allowed by [`grow_memory`](AstSemantics.md#resizing) and the
initial contents of memory, analogous to `.data`, `.rodata`, `.bss` sections in
native executables (see [binary encoding](BinaryEncoding.md#global-structure)).
A module may contain an optional section declaring the use of linear memory
by the module. If the section is absent, the linear memory operators
`load`, `store`, `memory_size`, and `grow_memory` may not be used in the module.

The linear memory section declares the initial [memory size](AstSemantics.md#linear-memory)
(which may be subsequently increased by [`grow_memory`](AstSemantics.md#resizing)).

The initial contents of linear memory are zero by default. However, the memory
section contains a possibly-empty array of *segments* (analogous to `.data`)
which can specify the initial contents of fixed `(offset, length)` ranges of
memory.

The linear memory section may also contain an optional hint declaring the expected
maximum heap usage. This hint is not semantically visible but can help a
WebAssembly engine to optimize `grow_memory`.

## Code section

Expand Down
5 changes: 5 additions & 0 deletions Rationale.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ to communicate their own implementation details in a useful manner to the
developer.


## Linear memory disabled if no linear memory section

See [#107](https://github.com/WebAssembly/spec/pull/107).


## Control Flow

See [#299](https://github.com/WebAssembly/design/pull/299).
Expand Down

0 comments on commit 6c494bc

Please sign in to comment.