Skip to content

Implement reference counting #592

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 193 commits into from
Jun 5, 2019
Merged

Implement reference counting #592

merged 193 commits into from
Jun 5, 2019

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented May 15, 2019

As a continuation of the runtime branch. this is the new tracking PR for everything runtime and RC. What this essentially does is implement and integrate reference counting, best explained by this test case resulting in this output.

Changes to master are significant in that

  • all runtime information is now stored in a single runtime header shared by both the allocator and the reference counting implementation.
    // ╒════════════════ Common block layout (32-bit) ═════════════════╕
    //    3                   2                   1
    //  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0  bits
    // ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤
    // │                           MM info                             │ -16
    // ├───────────────────────────────────────────────────────────────┤
    // │                           GC info                             │ -12
    // ├───────────────────────────────────────────────────────────────┤
    // │                          runtime id                           │ -8
    // ├───────────────────────────────────────────────────────────────┤
    // │                         runtime size                          │ -4
    // ╞═══════════════════════════════════════════════════════════════╡
    // │                              ...                              │ ref
  • ArrayBuffer and String don't expose the runtime header (or even .byteLength, .length) anymore but their data starts right at their reference, which is achieved by relocating the header as mentioned above. In turn, previous helper macros like LOAD are gone because one can now simply do a load instead.
  • a user cannot pick a memory allocator anymore by means of import "..." but instead has to select an appropriate runtime implementation. By default that's full, which is essentially TLSF + PureRC, half which is the same but without exported runtime hooks, stub which is essentially Arena + no GC and none which is the same without exported runtime hooks. The none implementation, even though runtime hooks are still inserted by the compiler, essentially evaporates after optimizations. Also, though unlikely, custom implementations are possible by means of --runtime yourRuntimeImplementation which implements all the runtime hooks.
  • the memory allocator and collector interfaces are gone and there's no memory.allocate and memory.free anymore. When done, the recommended way of allocating a chunk of raw memory will be new ArrayBuffer.
  • the previous interchangeable GC integration is gone because it turned out that trying to support both tracing and reference counting interchangeably is insane.
  • dynamic instanceof (i.e. animal instanceof Cat) is implemented on top of runtime type information, that is embedded as a memory segment. For each class there are 4 bytes base class id + 4 bytes flags with alignments, managed status etc..
  • guaranteed alignment is now 16 bytes to properly fit up to v128 values.
  • reallocation is done on memory manager level.
  • various TLSF issues have been fixed and there's now a visual debugger with a variety of buttons to press.
  • nullability checks have been implemented in flows, so the compiler can now infer where a reference is guaranteed to be non-null or emit an error otherwise.
  • standard library is not optional anymore, so --noLib is gone. This significantly reduces the amount of checks the compiler has to do when doing anything standard library related. This doesn't matter effectively, because if one doesn't use let's say Strings nothing of the related library components becomes compiled anyway.
  • compiler-level tree shaking is always on now (equals previous default behavior), so --noTreeShaking is gone. We'll eventually want to replace this with a pre-pass checker anyway.
  • the function table is not exported anymore in order to allow Binaryen to do all its optimizations, including converting indirect calls to direct calls after other passes.

There's probably quite a lot more that I don't remember anymore because this has clearly taken too long already. The test case linked above gives an overview of what's still to do on the integration side, plus I have yet to test the actual "full" runtime implementation. The concept should be figured out now, though.

to be continued...

@dcodeIO dcodeIO merged commit 0484a6b into master Jun 5, 2019
petersalomonsen added a commit to petersalomonsen/javascriptmusic that referenced this pull request Jun 7, 2019
new song "good times"
adjustments for memory allocations in assemblyscript ref:
AssemblyScript/assemblyscript#592
more instruments
@dcodeIO dcodeIO deleted the dev branch September 20, 2019 09:06
jewel528 added a commit to jewel528/Jsmusic that referenced this pull request Feb 15, 2024
new song "good times"
adjustments for memory allocations in assemblyscript ref:
AssemblyScript/assemblyscript#592
more instruments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants