Commit 1dd0163c authored by Keith Randall's avatar Keith Randall

runtime: remove trailing empty arrays in structs

The ones at the end of M and G are just used to compute
their size for use in assembly.  Generate the size explicitly.
The one at the end of itab is variable-sized, and at least one.
The ones at the end of interfacetype and uncommontype are not
needed, as the preceding slice references them (the slice was
originally added for use by reflect?).
The one at the end of stackmap is already accessed correctly,
and the runtime never allocates one.

Update #9401

Change-Id: Ia75e3aaee38425f038c506868a17105bd64c712f
Reviewed-on: https://go-review.googlesource.com/2420Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent ce5cb037
...@@ -551,6 +551,7 @@ dumpasmhdr(void) ...@@ -551,6 +551,7 @@ dumpasmhdr(void)
t = n->type; t = n->type;
if(t->etype != TSTRUCT || t->map != T || t->funarg) if(t->etype != TSTRUCT || t->map != T || t->funarg)
break; break;
Bprint(b, "#define %s__size %d\n", t->sym->name, (int)t->width);
for(t=t->type; t != T; t=t->down) for(t=t->type; t != T; t=t->down)
if(!isblanksym(t->sym)) if(!isblanksym(t->sym))
Bprint(b, "#define %s_%s %d\n", n->sym->name, t->sym->name, (int)t->width); Bprint(b, "#define %s_%s %d\n", n->sym->name, t->sym->name, (int)t->width);
......
...@@ -35,8 +35,7 @@ func getitab(inter *interfacetype, typ *_type, canfail bool) *itab { ...@@ -35,8 +35,7 @@ func getitab(inter *interfacetype, typ *_type, canfail bool) *itab {
if canfail { if canfail {
return nil return nil
} }
i := (*imethod)(add(unsafe.Pointer(inter), unsafe.Sizeof(interfacetype{}))) panic(&TypeAssertionError{"", *typ._string, *inter.typ._string, *inter.mhdr[0].name})
panic(&TypeAssertionError{"", *typ._string, *inter.typ._string, *i.name})
} }
// compiler has provided some good hash codes for us. // compiler has provided some good hash codes for us.
...@@ -76,7 +75,7 @@ func getitab(inter *interfacetype, typ *_type, canfail bool) *itab { ...@@ -76,7 +75,7 @@ func getitab(inter *interfacetype, typ *_type, canfail bool) *itab {
} }
} }
m = (*itab)(persistentalloc(unsafe.Sizeof(itab{})+uintptr(len(inter.mhdr))*ptrSize, 0, &memstats.other_sys)) m = (*itab)(persistentalloc(unsafe.Sizeof(itab{})+uintptr(len(inter.mhdr)-1)*ptrSize, 0, &memstats.other_sys))
m.inter = inter m.inter = inter
m._type = typ m._type = typ
...@@ -89,15 +88,15 @@ search: ...@@ -89,15 +88,15 @@ search:
nt := len(x.mhdr) nt := len(x.mhdr)
j := 0 j := 0
for k := 0; k < ni; k++ { for k := 0; k < ni; k++ {
i := (*imethod)(add(unsafe.Pointer(inter), unsafe.Sizeof(interfacetype{})+uintptr(k)*unsafe.Sizeof(imethod{}))) i := &inter.mhdr[k]
iname := i.name iname := i.name
ipkgpath := i.pkgpath ipkgpath := i.pkgpath
itype := i._type itype := i._type
for ; j < nt; j++ { for ; j < nt; j++ {
t := (*method)(add(unsafe.Pointer(x), unsafe.Sizeof(uncommontype{})+uintptr(j)*unsafe.Sizeof(method{}))) t := &x.mhdr[j]
if t.mtyp == itype && t.name == iname && t.pkgpath == ipkgpath { if t.mtyp == itype && t.name == iname && t.pkgpath == ipkgpath {
if m != nil { if m != nil {
*(*unsafe.Pointer)(add(unsafe.Pointer(m), unsafe.Sizeof(itab{})+uintptr(k)*ptrSize)) = t.ifn *(*unsafe.Pointer)(add(unsafe.Pointer(&m.fun[0]), uintptr(k)*ptrSize)) = t.ifn
} }
goto nextimethod goto nextimethod
} }
......
...@@ -498,7 +498,7 @@ type bitvector struct { ...@@ -498,7 +498,7 @@ type bitvector struct {
type stackmap struct { type stackmap struct {
n int32 // number of bitmaps n int32 // number of bitmaps
nbit int32 // number of bits in each bitmap nbit int32 // number of bits in each bitmap
bytedata [0]byte // bitmaps, each starting on a 32-bit boundary bytedata [1]byte // bitmaps, each starting on a 32-bit boundary
} }
// Returns pointer map data for the given stackmap index // Returns pointer map data for the given stackmap index
......
...@@ -215,7 +215,6 @@ type g struct { ...@@ -215,7 +215,6 @@ type g struct {
gopc uintptr // pc of go statement that created this goroutine gopc uintptr // pc of go statement that created this goroutine
racectx uintptr racectx uintptr
waiting *sudog // sudog structures this g is waiting on (that have a valid elem ptr) waiting *sudog // sudog structures this g is waiting on (that have a valid elem ptr)
end [0]byte
} }
type mts struct { type mts struct {
...@@ -298,7 +297,6 @@ type m struct { ...@@ -298,7 +297,6 @@ type m struct {
notesig *int8 notesig *int8
errstr *byte errstr *byte
//#endif //#endif
end [0]byte
} }
type p struct { type p struct {
...@@ -425,7 +423,7 @@ type itab struct { ...@@ -425,7 +423,7 @@ type itab struct {
link *itab link *itab
bad int32 bad int32
unused int32 unused int32
fun [0]uintptr fun [1]uintptr // variable sized
} }
// Lock-free stack node. // Lock-free stack node.
......
...@@ -189,22 +189,22 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0 ...@@ -189,22 +189,22 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0
MOVL SP, DX MOVL SP, DX
// setup dummy m, g // setup dummy m, g
SUBL $m_end, SP // space for M SUBL $m__size, SP // space for M
MOVL SP, 0(SP) MOVL SP, 0(SP)
MOVL $m_end, 4(SP) MOVL $m__size, 4(SP)
CALL runtime·memclr(SB) // smashes AX,BX,CX CALL runtime·memclr(SB) // smashes AX,BX,CX
LEAL m_tls(SP), CX LEAL m_tls(SP), CX
MOVL CX, 0x14(FS) MOVL CX, 0x14(FS)
MOVL SP, BX MOVL SP, BX
SUBL $g_end, SP // space for G SUBL $g__size, SP // space for G
MOVL SP, g(CX) MOVL SP, g(CX)
MOVL SP, m_g0(BX) MOVL SP, m_g0(BX)
MOVL SP, 0(SP) MOVL SP, 0(SP)
MOVL $g_end, 4(SP) MOVL $g__size, 4(SP)
CALL runtime·memclr(SB) // smashes AX,BX,CX CALL runtime·memclr(SB) // smashes AX,BX,CX
LEAL g_end(SP), BX LEAL g__size(SP), BX
MOVL BX, g_m(SP) MOVL BX, g_m(SP)
LEAL -8192(SP), CX LEAL -8192(SP), CX
MOVL CX, (g_stack+stack_lo)(SP) MOVL CX, (g_stack+stack_lo)(SP)
......
...@@ -225,22 +225,22 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0 ...@@ -225,22 +225,22 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0
MOVQ SP, DX MOVQ SP, DX
// setup dummy m, g // setup dummy m, g
SUBQ $m_end, SP // space for M SUBQ $m__size, SP // space for M
MOVQ SP, 0(SP) MOVQ SP, 0(SP)
MOVQ $m_end, 8(SP) MOVQ $m__size, 8(SP)
CALL runtime·memclr(SB) // smashes AX,BX,CX CALL runtime·memclr(SB) // smashes AX,BX,CX
LEAQ m_tls(SP), CX LEAQ m_tls(SP), CX
MOVQ CX, 0x28(GS) MOVQ CX, 0x28(GS)
MOVQ SP, BX MOVQ SP, BX
SUBQ $g_end, SP // space for G SUBQ $g__size, SP // space for G
MOVQ SP, g(CX) MOVQ SP, g(CX)
MOVQ SP, m_g0(BX) MOVQ SP, m_g0(BX)
MOVQ SP, 0(SP) MOVQ SP, 0(SP)
MOVQ $g_end, 8(SP) MOVQ $g__size, 8(SP)
CALL runtime·memclr(SB) // smashes AX,BX,CX CALL runtime·memclr(SB) // smashes AX,BX,CX
LEAQ g_end(SP), BX LEAQ g__size(SP), BX
MOVQ BX, g_m(SP) MOVQ BX, g_m(SP)
LEAQ -8192(SP), CX LEAQ -8192(SP), CX
......
...@@ -47,7 +47,6 @@ type uncommontype struct { ...@@ -47,7 +47,6 @@ type uncommontype struct {
name *string name *string
pkgpath *string pkgpath *string
mhdr []method mhdr []method
m [0]method
} }
type imethod struct { type imethod struct {
...@@ -59,7 +58,6 @@ type imethod struct { ...@@ -59,7 +58,6 @@ type imethod struct {
type interfacetype struct { type interfacetype struct {
typ _type typ _type
mhdr []imethod mhdr []imethod
m [0]imethod
} }
type maptype struct { type maptype struct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment