From 655075e5e0e09ae3d9a3247d04343c020d87162e Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 15 Dec 2022 21:24:17 +0100 Subject: runtime: implement precise GC This implements the block-based GC as a partially precise GC. This means that for most heap allocations it is known which words contain a pointer and which don't. This should in theory make the GC faster (because it can skip non-pointer object) and have fewer false positives in a GC cycle. It does however use a bit more RAM to store the layout of each object. Right now this GC seems to be slower than the conservative GC, but should be less likely to run out of memory as a result of false positives. --- compileopts/config.go | 4 ++-- compileopts/options.go | 2 +- compileopts/options_test.go | 2 +- compileopts/target.go | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) (limited to 'compileopts') diff --git a/compileopts/config.go b/compileopts/config.go index 6eaf5d623..7afdded31 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -90,7 +90,7 @@ func (c *Config) CgoEnabled() bool { } // GC returns the garbage collection strategy in use on this platform. Valid -// values are "none", "leaking", and "conservative". +// values are "none", "leaking", "conservative" and "precise". func (c *Config) GC() string { if c.Options.GC != "" { return c.Options.GC @@ -105,7 +105,7 @@ func (c *Config) GC() string { // that can be traced by the garbage collector. func (c *Config) NeedsStackObjects() bool { switch c.GC() { - case "conservative": + case "conservative", "precise": for _, tag := range c.BuildTags() { if tag == "tinygo.wasm" { return true diff --git a/compileopts/options.go b/compileopts/options.go index ba3950f53..884a722a7 100644 --- a/compileopts/options.go +++ b/compileopts/options.go @@ -8,7 +8,7 @@ import ( ) var ( - validGCOptions = []string{"none", "leaking", "conservative"} + validGCOptions = []string{"none", "leaking", "conservative", "precise"} validSchedulerOptions = []string{"none", "tasks", "asyncify"} validSerialOptions = []string{"none", "uart", "usb"} validPrintSizeOptions = []string{"none", "short", "full"} diff --git a/compileopts/options_test.go b/compileopts/options_test.go index 2845be3a4..e6c75d291 100644 --- a/compileopts/options_test.go +++ b/compileopts/options_test.go @@ -9,7 +9,7 @@ import ( func TestVerifyOptions(t *testing.T) { - expectedGCError := errors.New(`invalid gc option 'incorrect': valid values are none, leaking, conservative`) + expectedGCError := errors.New(`invalid gc option 'incorrect': valid values are none, leaking, conservative, precise`) expectedSchedulerError := errors.New(`invalid scheduler option 'incorrect': valid values are none, tasks, asyncify`) expectedPrintSizeError := errors.New(`invalid size option 'incorrect': valid values are none, short, full`) expectedPanicStrategyError := errors.New(`invalid panic option 'incorrect': valid values are print, trap`) diff --git a/compileopts/target.go b/compileopts/target.go index 2841db4ed..6c01f339e 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -250,6 +250,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { GOOS: goos, GOARCH: goarch, BuildTags: []string{goos, goarch}, + GC: "precise", Scheduler: "tasks", Linker: "cc", DefaultStackSize: 1024 * 64, // 64kB -- cgit v1.2.3