Skip to content

Commit 62e78c0

Browse files
niaowaykevl
authored andcommitted
runtime (gc): add garbage collector that uses an external allocator
1 parent 57320c0 commit 62e78c0

File tree

11 files changed

+683
-25
lines changed

11 files changed

+683
-25
lines changed

compileopts/config.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,37 @@ func (c *Config) CgoEnabled() bool {
9696
}
9797

9898
// GC returns the garbage collection strategy in use on this platform. Valid
99-
// values are "none", "leaking", and "conservative".
99+
// values are "none", "leaking", "extalloc", and "conservative".
100100
func (c *Config) GC() string {
101101
if c.Options.GC != "" {
102102
return c.Options.GC
103103
}
104104
if c.Target.GC != "" {
105105
return c.Target.GC
106106
}
107-
return "conservative"
107+
for _, tag := range c.Target.BuildTags {
108+
if tag == "baremetal" || tag == "wasm" {
109+
return "conservative"
110+
}
111+
}
112+
return "extalloc"
108113
}
109114

110115
// NeedsStackObjects returns true if the compiler should insert stack objects
111116
// that can be traced by the garbage collector.
112117
func (c *Config) NeedsStackObjects() bool {
113-
if c.GC() != "conservative" {
114-
return false
115-
}
116-
for _, tag := range c.BuildTags() {
117-
if tag == "baremetal" {
118-
return false
118+
switch c.GC() {
119+
case "conservative", "extalloc":
120+
for _, tag := range c.BuildTags() {
121+
if tag == "baremetal" {
122+
return false
123+
}
119124
}
120-
}
121125

122-
return true
126+
return true
127+
default:
128+
return false
129+
}
123130
}
124131

125132
// Scheduler returns the scheduler implementation. Valid values are "coroutines"

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func handleCompilerError(err error) {
701701
func main() {
702702
outpath := flag.String("o", "", "output filename")
703703
opt := flag.String("opt", "z", "optimization level: 0, 1, 2, s, z")
704-
gc := flag.String("gc", "", "garbage collector to use (none, leaking, conservative)")
704+
gc := flag.String("gc", "", "garbage collector to use (none, leaking, extalloc, conservative)")
705705
panicStrategy := flag.String("panic", "print", "panic strategy (print, trap)")
706706
scheduler := flag.String("scheduler", "", "which scheduler to use (coroutines, tasks)")
707707
printIR := flag.Bool("printir", false, "print LLVM IR")

0 commit comments

Comments
 (0)