aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-12-15 21:24:17 +0100
committerAyke <[email protected]>2023-01-17 19:32:18 +0100
commit655075e5e0e09ae3d9a3247d04343c020d87162e (patch)
tree25f8f2677484aa38e9be0fe0cb6c9ed2385f84d5 /compileopts
parentf9d0ff3becbe6835d32a146895d797d53a09fc15 (diff)
downloadtinygo-655075e5e0e09ae3d9a3247d04343c020d87162e.tar.gz
tinygo-655075e5e0e09ae3d9a3247d04343c020d87162e.zip
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.
Diffstat (limited to 'compileopts')
-rw-r--r--compileopts/config.go4
-rw-r--r--compileopts/options.go2
-rw-r--r--compileopts/options_test.go2
-rw-r--r--compileopts/target.go1
4 files changed, 5 insertions, 4 deletions
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