-
Notifications
You must be signed in to change notification settings - Fork 951
Add -gc=custom option #3302
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
Add -gc=custom option #3302
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b3d1d87
Add -gc=custom option
anuraaga 74aed5e
Drift
anuraaga 79f62b2
Load stack in init and markStack
anuraaga e27e61e
Merge branch 'dev' of github.com:tinygo-org/tinygo into custom-gc
anuraaga d0124d7
Update compileopts/config.go
anuraaga d9b9d94
Revert loading stack change and require addRoots
anuraaga 0fcce65
Merge branch 'custom-gc' of github.com:anuraaga/tinygo into custom-gc
anuraaga 63b2944
Revert newline
anuraaga 9f57f63
Merge branch 'dev' of github.com:tinygo-org/tinygo into custom-gc
anuraaga 36a73df
Revert unintended mingw update
anuraaga f58fe76
Remove methods that were moved
anuraaga 857e613
Document runtime.markStack
anuraaga ca895bf
Merge branch 'dev' of github.com:tinygo-org/tinygo into custom-gc
anuraaga 75e0fc1
Merge branch 'dev' of github.com:tinygo-org/tinygo into custom-gc
anuraaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build gc.custom | ||
// +build gc.custom | ||
|
||
package runtime | ||
|
||
// This GC strategy allows an external GC to be plugged in instead of the builtin | ||
// implementations. | ||
// | ||
// The interface defined in this file is not stable and can be broken at anytime, even | ||
// across minor versions. | ||
// | ||
// runtime.markStack() must be called at the beginning of any GC cycle. //go:linkname | ||
// on a function without a body can be used to access this internal function. | ||
// | ||
// The custom implementation must provide the following functions in the runtime package | ||
// using the go:linkname directive: | ||
// | ||
// - func initHeap() | ||
// - func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer | ||
// - func free(ptr unsafe.Pointer) | ||
// - func markRoots(start, end uintptr) | ||
// - func GC() | ||
// | ||
// | ||
// In addition, if targeting wasi, the following functions should be exported for interoperability | ||
// with wasi libraries that use them. Note, this requires the export directive, not go:linkname. | ||
// | ||
// - func malloc(size uintptr) unsafe.Pointer | ||
// - func free(ptr unsafe.Pointer) | ||
// - func calloc(nmemb, size uintptr) unsafe.Pointer | ||
// - func realloc(oldPtr unsafe.Pointer, size uintptr) unsafe.Pointer | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
// initHeap is called when the heap is first initialized at program start. | ||
func initHeap() | ||
|
||
// alloc is called to allocate memory. layout is currently not used. | ||
func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer | ||
|
||
// free is called to explicitly free a previously allocated pointer. | ||
func free(ptr unsafe.Pointer) | ||
|
||
// markRoots is called with the start and end addresses to scan for references. | ||
// It is currently only called with the top and bottom of the stack. | ||
func markRoots(start, end uintptr) | ||
|
||
// GC is called to explicitly run garbage collection. | ||
func GC() | ||
|
||
func setHeapEnd(newHeapEnd uintptr) { | ||
// Heap is in custom GC so ignore for when called from wasm initialization. | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are normally defined by the runtime, and call
runtime.alloc
/runtime.free
as needed. Would it be possible to keep it that way and let the custom GC only provide the functions above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We added the custommalloc build tag and this intends to replace it with just the concept of a custom GC.
Replacing malloc with an implementation that doesn't delegate to Go GC (in my case mimalloc) had a dramatic improvement in performance and is important for allowing high performance. I'd be fine with keeping the current tag though if it seems better.