]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove trailing empty arrays in structs
authorKeith Randall <khr@golang.org>
Wed, 7 Jan 2015 04:38:44 +0000 (20:38 -0800)
committerKeith Randall <khr@golang.org>
Wed, 7 Jan 2015 16:05:16 +0000 (16:05 +0000)
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/2420
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/gc/export.c
src/runtime/iface.go
src/runtime/malloc2.go
src/runtime/runtime2.go
src/runtime/sys_windows_386.s
src/runtime/sys_windows_amd64.s
src/runtime/type.go

index aeee552362f2826bb7a4edf1626366f731869455..47c0545d55a9c0e872d53698133e404081ed51fb 100644 (file)
@@ -551,6 +551,7 @@ dumpasmhdr(void)
                        t = n->type;
                        if(t->etype != TSTRUCT || t->map != T || t->funarg)
                                break;
+                       Bprint(b, "#define %s__size %d\n", t->sym->name, (int)t->width);
                        for(t=t->type; t != T; t=t->down)
                                if(!isblanksym(t->sym))
                                        Bprint(b, "#define %s_%s %d\n", n->sym->name, t->sym->name, (int)t->width);
index b453bbfaf73530cb1de9b9d2a69350730fd73f99..811a31bcd9cf292391f412b5c59174bf75574b9e 100644 (file)
@@ -35,8 +35,7 @@ func getitab(inter *interfacetype, typ *_type, canfail bool) *itab {
                if canfail {
                        return nil
                }
-               i := (*imethod)(add(unsafe.Pointer(inter), unsafe.Sizeof(interfacetype{})))
-               panic(&TypeAssertionError{"", *typ._string, *inter.typ._string, *i.name})
+               panic(&TypeAssertionError{"", *typ._string, *inter.typ._string, *inter.mhdr[0].name})
        }
 
        // compiler has provided some good hash codes for us.
@@ -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._type = typ
 
@@ -89,15 +88,15 @@ search:
        nt := len(x.mhdr)
        j := 0
        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
                ipkgpath := i.pkgpath
                itype := i._type
                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 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
                        }
index 3766da886f23132ea8d12ee972b93f832b3f33ef..8cdf668214b1a20e72da15d8502e0dc744faa45c 100644 (file)
@@ -498,7 +498,7 @@ type bitvector struct {
 type stackmap struct {
        n        int32   // number of bitmaps
        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
index 3afc67baff6eeb1b69f488941ec98b5a89875942..2a721fd4f665ffc2f8db8fa44d2cb149eb37f3a6 100644 (file)
@@ -215,7 +215,6 @@ type g struct {
        gopc         uintptr // pc of go statement that created this goroutine
        racectx      uintptr
        waiting      *sudog // sudog structures this g is waiting on (that have a valid elem ptr)
-       end          [0]byte
 }
 
 type mts struct {
@@ -298,7 +297,6 @@ type m struct {
        notesig *int8
        errstr  *byte
        //#endif
-       end [0]byte
 }
 
 type p struct {
@@ -425,7 +423,7 @@ type itab struct {
        link   *itab
        bad    int32
        unused int32
-       fun    [0]uintptr
+       fun    [1]uintptr // variable sized
 }
 
 // Lock-free stack node.
index c8a830cdf8e36fb6f649acc8e31a335cea5d3fd3..9c2692b93d5972a274865c799beb7221f29cfed4 100644 (file)
@@ -189,22 +189,22 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0
        MOVL    SP, DX
 
        // setup dummy m, g
-       SUBL    $m_end, SP              // space for M
+       SUBL    $m__size, SP            // space for M
        MOVL    SP, 0(SP)
-       MOVL    $m_end, 4(SP)
+       MOVL    $m__size, 4(SP)
        CALL    runtime·memclr(SB)     // smashes AX,BX,CX
 
        LEAL    m_tls(SP), CX
        MOVL    CX, 0x14(FS)
        MOVL    SP, BX
-       SUBL    $g_end, SP              // space for G
+       SUBL    $g__size, SP            // space for G
        MOVL    SP, g(CX)
        MOVL    SP, m_g0(BX)
 
        MOVL    SP, 0(SP)
-       MOVL    $g_end, 4(SP)
+       MOVL    $g__size, 4(SP)
        CALL    runtime·memclr(SB)     // smashes AX,BX,CX
-       LEAL    g_end(SP), BX
+       LEAL    g__size(SP), BX
        MOVL    BX, g_m(SP)
        LEAL    -8192(SP), CX
        MOVL    CX, (g_stack+stack_lo)(SP)
index 68f7cd3924d62d58441ff507d1fa35e5f20f7fc7..27e48bf9c28dd0f87e79098f954fbf612167152e 100644 (file)
@@ -225,22 +225,22 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0
        MOVQ    SP, DX
 
        // setup dummy m, g
-       SUBQ    $m_end, SP              // space for M
+       SUBQ    $m__size, SP            // space for M
        MOVQ    SP, 0(SP)
-       MOVQ    $m_end, 8(SP)
+       MOVQ    $m__size, 8(SP)
        CALL    runtime·memclr(SB)     // smashes AX,BX,CX
 
        LEAQ    m_tls(SP), CX
        MOVQ    CX, 0x28(GS)
        MOVQ    SP, BX
-       SUBQ    $g_end, SP              // space for G
+       SUBQ    $g__size, SP            // space for G
        MOVQ    SP, g(CX)
        MOVQ    SP, m_g0(BX)
 
        MOVQ    SP, 0(SP)
-       MOVQ    $g_end, 8(SP)
+       MOVQ    $g__size, 8(SP)
        CALL    runtime·memclr(SB)     // smashes AX,BX,CX
-       LEAQ    g_end(SP), BX
+       LEAQ    g__size(SP), BX
        MOVQ    BX, g_m(SP)
 
        LEAQ    -8192(SP), CX
index 943d7bfd0e75ac672a5bd2e6f2052dbd42ba96b8..d092f248a1771159f49be5551e19b72c19c7df7b 100644 (file)
@@ -47,7 +47,6 @@ type uncommontype struct {
        name    *string
        pkgpath *string
        mhdr    []method
-       m       [0]method
 }
 
 type imethod struct {
@@ -59,7 +58,6 @@ type imethod struct {
 type interfacetype struct {
        typ  _type
        mhdr []imethod
-       m    [0]imethod
 }
 
 type maptype struct {