You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Broken even in Go 1.2 but legal according to what we've typically said about the use of
SliceHeader. It's not clear what to do. The simplest thing might be to make any GC
program treat *SliceHeader the same as unsafe.Pointer, so that the collection uses the
heap type information to follow the pointer.
http://play.golang.org/p/FusOBSDXlo
package main
import (
"reflect"
"runtime"
"unsafe"
)
func main() {
var all []interface{}
for i := 0; i < 100; i++ {
p := new([]int)
*p = append(*p, 1, 2, 3, 4)
h := (*reflect.SliceHeader)(unsafe.Pointer(p))
all = append(all, h, p)
}
runtime.GC()
for i := 0; i < 100; i++ {
p := *all[2*i+1].(*[]int)
if p[0] != 1 || p[1] != 2 || p[2] != 3 || p[3] != 4 {
println("bad slice1 at index", i, p[0], p[1], p[2], p[3])
}
}
}
The text was updated successfully, but these errors were encountered:
We should have a list of types in the runtime that we know are "bogus". We should not
propagate them when doing GC.
reflect.SliceHeader
reflect.StringHeader
there are probably a few others.
Ever since the precise heap went in, it treats all *T where T itself has no pointers as
being like unsafe.Pointer. That handles the variant of this case called test2 in CL
100470045's test program.
The handling of interfaces did not have the same conservative behavior; in CL 100470045
it will match what we already did for concrete pointers.
To be clear, the 'conservative' here is not interpreting integers as pointers. It is
merely saying to the garbage collector 'I don't trust my static type information, look
in your allocation records please'.
I'm happy to explore what happens if we use the static type information for pointer
traversal in 1.4. Of course, if we move to pointer bitmaps for the whole heap as the
primary metadata used during collection, there would be no static type information to
worry about and this would all be moot.
The text was updated successfully, but these errors were encountered: