Get the latest tech news

How to store Go pointers from assembly


The standard Go toolchain comes with an assembler out of the box. Said assembler is highly idiosyncratic, using syntax inherited from Plan 9 and choosing its own names for platform-specific instructions and registers. But it's great to have it readily available. More mundanely, Go comes with a garbage collector. This post explains how to make these two components play nice, if we want to manipulate Go pointers from our assembly.

This final stack rescanning procedure could often take uncomfortably long, and therefore Go switched to a broader write barrier, which roughly consists of adding both the old and the new reference to the GC queue: The details are fiddly, but involving both the old and new pointer let the Go developers remove the final stack-scanning, decreasing the duration of stop-the-world pauses by two orders of magnitude. However we face a challenge: when writing to a slot from assembly, we need to inform Go’s GC of the store that just happened, or else pay the cost of rare and hard-to-debug faults, given that we’re breaking invariants central to the correctness of Go’s garbage collection.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of assembly

assembly

Photo of Pointers

Pointers

Related news:

News photo

Learning Assembly for Fun, Performance and Profit

News photo

ARM Linux Kernel May Shift To Generic Entry Code: Less Assembly But Lower Performance

News photo

Pointers Are Complicated II, or: We need better language specs (2020)