aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/runtime/gc_leaking.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-02-17 20:19:08 +0100
committerAyke van Laethem <[email protected]>2019-07-01 13:03:07 +0200
commit00e91ec56975c3fbc600d4ed164ac2e493327624 (patch)
treeb4674a24fbd0ff25999596f45357f15d3565f680 /src/runtime/gc_leaking.go
parent1fd0c8d48cde0228244be0c2d5ea720eddb683d6 (diff)
downloadtinygo-00e91ec56975c3fbc600d4ed164ac2e493327624.tar.gz
tinygo-00e91ec56975c3fbc600d4ed164ac2e493327624.zip
all: rename garbage collectors
dumb -> leaking: make it more clear what this "GC" does: leak everything. marksweep -> conservative: "marksweep" is too generic, use "conservative" to differentiate between future garbage collectors: precise marksweep / mark-compact / refcounting.
Diffstat (limited to 'src/runtime/gc_leaking.go')
-rw-r--r--src/runtime/gc_leaking.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/runtime/gc_leaking.go b/src/runtime/gc_leaking.go
new file mode 100644
index 000000000..fb0f9086e
--- /dev/null
+++ b/src/runtime/gc_leaking.go
@@ -0,0 +1,47 @@
+// +build gc.leaking
+
+package runtime
+
+// This GC implementation is the simplest useful memory allocator possible: it
+// only allocates memory and never frees it. For some constrained systems, it
+// may be the only memory allocator possible.
+
+import (
+ "unsafe"
+)
+
+// Ever-incrementing pointer: no memory is freed.
+var heapptr = heapStart
+
+func alloc(size uintptr) unsafe.Pointer {
+ // TODO: this can be optimized by not casting between pointers and ints so
+ // much. And by using platform-native data types (e.g. *uint8 for 8-bit
+ // systems).
+ size = align(size)
+ addr := heapptr
+ heapptr += size
+ if heapptr >= heapEnd {
+ runtimePanic("out of memory")
+ }
+ for i := uintptr(0); i < uintptr(size); i += 4 {
+ ptr := (*uint32)(unsafe.Pointer(addr + i))
+ *ptr = 0
+ }
+ return unsafe.Pointer(addr)
+}
+
+func free(ptr unsafe.Pointer) {
+ // Memory is never freed.
+}
+
+func GC() {
+ // No-op.
+}
+
+func KeepAlive(x interface{}) {
+ // Unimplemented. Only required with SetFinalizer().
+}
+
+func SetFinalizer(obj interface{}, finalizer interface{}) {
+ // Unimplemented.
+}