mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: make unsafe use of SliceHeader gc-friendly
Revert workaround in compiler and revert test for compiler workaround. Tested that the 386 build continues to fail if the gc change is made without the reflect change. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5312041
This commit is contained in:
parent
313c8224d5
commit
4e7aac5413
3 changed files with 21 additions and 81 deletions
|
|
@ -3,7 +3,6 @@ package runtime_test
|
|||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func TestGcSys(t *testing.T) {
|
||||
|
|
@ -23,73 +22,3 @@ func TestGcSys(t *testing.T) {
|
|||
func workthegc() []byte {
|
||||
return make([]byte, 1029)
|
||||
}
|
||||
|
||||
func TestGcUintptr(t *testing.T) {
|
||||
p1 := unsafe.Pointer(new(int))
|
||||
*(*int)(unsafe.Pointer(p1)) = 42
|
||||
p2 := uintptr(unsafe.Pointer(new(int)))
|
||||
*(*int)(unsafe.Pointer(p2)) = 42
|
||||
var a1 [1]unsafe.Pointer
|
||||
a1[0] = unsafe.Pointer(new(int))
|
||||
*(*int)(unsafe.Pointer(a1[0])) = 42
|
||||
var a2 [1]uintptr
|
||||
a2[0] = uintptr(unsafe.Pointer(new(int)))
|
||||
*(*int)(unsafe.Pointer(a2[0])) = 42
|
||||
s1 := make([]unsafe.Pointer, 1)
|
||||
s1[0] = unsafe.Pointer(new(int))
|
||||
*(*int)(unsafe.Pointer(s1[0])) = 42
|
||||
s2 := make([]uintptr, 1)
|
||||
s2[0] = uintptr(unsafe.Pointer(new(int)))
|
||||
*(*int)(unsafe.Pointer(s2[0])) = 42
|
||||
m1 := make(map[int]unsafe.Pointer)
|
||||
m1[0] = unsafe.Pointer(new(int))
|
||||
*(*int)(unsafe.Pointer(m1[0])) = 42
|
||||
m2 := make(map[int]uintptr)
|
||||
m2[0] = uintptr(unsafe.Pointer(new(int)))
|
||||
*(*int)(unsafe.Pointer(m2[0])) = 42
|
||||
c1 := make(chan unsafe.Pointer, 1)
|
||||
func() {
|
||||
p := new(int)
|
||||
*p = 42
|
||||
c1 <- unsafe.Pointer(p)
|
||||
}()
|
||||
c2 := make(chan uintptr, 1)
|
||||
func() {
|
||||
p := new(int)
|
||||
*p = 42
|
||||
c2 <- uintptr(unsafe.Pointer(p))
|
||||
}()
|
||||
|
||||
runtime.GC()
|
||||
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(p1))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("p1 is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(p2))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("p2 is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(a1[0]))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("a1[0] is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(a2[0]))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("a2[0] is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(s1[0]))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("s1[0] is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(s2[0]))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("s2[0] is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(m1[0]))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("m1[0] is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(m2[0]))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("m2[0] is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(<-c1))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("<-c1 is freed")
|
||||
}
|
||||
if p, _ := runtime.Lookup((*byte)(unsafe.Pointer(<-c2))); p == nil || *(*int)(unsafe.Pointer(p)) != 42 {
|
||||
t.Fatalf("<-c2 is freed")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue