-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: add the Boehm-Demers-Weiser GC on Linux
This adds support for the well-known Boehm GC. It's significantly faster than our own naive GC and could be used as an alternative on bigger systems. In the future, this GC might also be supported on WebAssembly with some extra work. Right now it's Linux only (though Windows/MacOS shouldn't be too difficult to add).
- Loading branch information
Showing
17 changed files
with
374 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,71 @@ | ||
package builder | ||
|
||
// The well-known conservative Boehm-Demers-Weiser GC. | ||
// This file provides a way to compile this GC for use with TinyGo. | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/tinygo-org/tinygo/goenv" | ||
) | ||
|
||
var BoehmGC = Library{ | ||
name: "bdwgc", | ||
cflags: func(target, headerPath string) []string { | ||
libdir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/bdwgc") | ||
return []string{ | ||
// use a modern environment | ||
"-DUSE_MMAP", // mmap is available | ||
"-DUSE_MUNMAP", // return memory to the OS using munmap | ||
"-DGC_BUILTIN_ATOMIC", // use compiler intrinsics for atomic operations | ||
"-DNO_EXECUTE_PERMISSION", // don't make the heap executable | ||
|
||
// specific flags for TinyGo | ||
"-DALL_INTERIOR_POINTERS", // scan interior pointers (needed for Go) | ||
"-DIGNORE_DYNAMIC_LOADING", // we don't support dynamic loading at the moment | ||
"-DNO_GETCONTEXT", // musl doesn't support getcontext() | ||
|
||
// Special flag to work around the lack of __data_start in ld.lld. | ||
// TODO: try to fix this in LLVM/lld directly so we don't have to | ||
// work around it anymore. | ||
"-DGC_DONT_REGISTER_MAIN_STATIC_DATA", | ||
|
||
// Do not scan the stack. We have our own mechanism to do this. | ||
"-DSTACK_NOT_SCANNED", | ||
|
||
// Assertions can be enabled while debugging GC issues. | ||
//"-DGC_ASSERTIONS", | ||
|
||
// Threading is not yet supported, so these are disabled. | ||
//"-DGC_THREADS", | ||
//"-DTHREAD_LOCAL_ALLOC", | ||
|
||
"-I" + libdir + "/include", | ||
} | ||
}, | ||
sourceDir: func() string { | ||
return filepath.Join(goenv.Get("TINYGOROOT"), "lib/bdwgc") | ||
}, | ||
librarySources: func(target string) ([]string, error) { | ||
return []string{ | ||
"allchblk.c", | ||
"alloc.c", | ||
"blacklst.c", | ||
"dbg_mlc.c", | ||
"dyn_load.c", | ||
"finalize.c", | ||
"headers.c", | ||
"mach_dep.c", | ||
"malloc.c", | ||
"mark.c", | ||
"mark_rts.c", | ||
"misc.c", | ||
"new_hblk.c", | ||
"obj_map.c", | ||
"os_dep.c", | ||
"pthread_stop_world.c", | ||
"pthread_support.c", | ||
"reclaim.c", | ||
}, nil | ||
}, | ||
} |
This file contains 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 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 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
Oops, something went wrong.