]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove duplicated Go constants
authorRuss Cox <rsc@golang.org>
Tue, 16 Sep 2014 14:22:15 +0000 (10:22 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 16 Sep 2014 14:22:15 +0000 (10:22 -0400)
The C header files are the single point of truth:
every C enum constant Foo is available to Go as _Foo.
Remove or redirect duplicate Go declarations so they
cannot be out of sync.

Eventually we will need to put constants in Go, but for now having
them be out of sync with C is too risky. These predate the build
support for auto-generating Go constants from the C definitions.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/141510043

27 files changed:
src/cmd/api/goapi.go
src/cmd/dist/buildruntime.c
src/runtime/arch_386.go
src/runtime/arch_amd64.go
src/runtime/arch_amd64p32.go
src/runtime/arch_arm.go
src/runtime/chan.go
src/runtime/malloc.c
src/runtime/malloc.go
src/runtime/mgc0.c
src/runtime/mgc0.go
src/runtime/mgc0.h
src/runtime/os_darwin.go
src/runtime/os_freebsd.go
src/runtime/os_linux.go
src/runtime/os_nacl.go
src/runtime/os_netbsd.go
src/runtime/os_openbsd.go
src/runtime/os_plan9.go
src/runtime/os_solaris.go
src/runtime/os_windows.go
src/runtime/runtime.h
src/runtime/sema.go
src/runtime/slice.go
src/runtime/string.go
src/runtime/typekind.go
src/runtime/typekind.h

index 8494a3f61bdcb8a43fc882d0278889e3b86913fe..78b7d6edf16f82e685eeb719ee421fa310c4efcb 100644 (file)
@@ -423,6 +423,52 @@ func (w *Walker) parseFile(dir, file string) (*ast.File, error) {
                        " _Genqueue = 7;" +
                        " _Gcopystack = 8;" +
                        " _NSIG = 32;" +
+                       " _FlagNoScan = iota;" +
+                       " _FlagNoZero;" +
+                       " _TinySize;" +
+                       " _TinySizeClass;" +
+                       " _MaxSmallSize;" +
+                       " _PageShift;" +
+                       " _PageSize;" +
+                       " _PageMask;" +
+                       " _BitsPerPointer;" +
+                       " _BitsMask;" +
+                       " _PointersPerByte;" +
+                       " _MaxGCMask;" +
+                       " _BitsDead;" +
+                       " _BitsPointer;" +
+                       " _MSpanInUse;" +
+                       " _ConcurrentSweep;" +
+                       " _KindBool;" +
+                       " _KindInt;" +
+                       " _KindInt8;" +
+                       " _KindInt16;" +
+                       " _KindInt32;" +
+                       " _KindInt64;" +
+                       " _KindUint;" +
+                       " _KindUint8;" +
+                       " _KindUint16;" +
+                       " _KindUint32;" +
+                       " _KindUint64;" +
+                       " _KindUintptr;" +
+                       " _KindFloat32;" +
+                       " _KindFloat64;" +
+                       " _KindComplex64;" +
+                       " _KindComplex128;" +
+                       " _KindArray;" +
+                       " _KindChan;" +
+                       " _KindFunc;" +
+                       " _KindInterface;" +
+                       " _KindMap;" +
+                       " _KindPtr;" +
+                       " _KindSlice;" +
+                       " _KindString;" +
+                       " _KindStruct;" +
+                       " _KindUnsafePointer;" +
+                       " _KindDirectIface;" +
+                       " _KindGCProg;" +
+                       " _KindNoPointers;" +
+                       " _KindMask;" +
                        ")"
                f, err = parser.ParseFile(fset, filename, src, 0)
                if err != nil {
index 36efb5711c6006a8cc5ce4f2291469ec4d36ae7b..1257d5b811b2b22395e6bef34451a579b6c36456 100644 (file)
@@ -329,6 +329,8 @@ mkzsys(char *dir, char *file)
 
 static char *runtimedefs[] = {
        "defs.c",
+       "malloc.c",
+       "mgc0.c",
        "proc.c",
        "parfor.c",
 };
@@ -337,8 +339,8 @@ static char *runtimedefs[] = {
 // which contains Go struct definitions equivalent to the C ones.
 // Mostly we just write the output of 6c -q to the file.
 // However, we run it on multiple files, so we have to delete
-// the duplicated definitions, and we don't care about the funcs
-// and consts, so we delete those too.
+// the duplicated definitions, and we don't care about the funcs,
+// so we delete those too.
 // 
 void
 mkzruntimedefs(char *dir, char *file)
index 287b67e2705f04f2586811ec6f7c3d88b8d3170c..79d38c7ab1bcda9c65e509558293188d28eadf63 100644 (file)
@@ -4,9 +4,5 @@
 
 package runtime
 
-const (
-       cacheLineSize = 64
-)
-
 type uintreg uint32
 type intptr int32 // TODO(rsc): remove
index fe60c706607bc21a223bebb359eba31667471700..270cd7b9573b1a1f96b2735be5bca77a2f723722 100644 (file)
@@ -4,9 +4,5 @@
 
 package runtime
 
-const (
-       cacheLineSize = 64
-)
-
 type uintreg uint64
 type intptr int64 // TODO(rsc): remove
index 90766b404f56588fa6352f375bd172a56cf8fe4c..5c636aeab2fbc5d313528b001bf6a8389f9bb83f 100644 (file)
@@ -4,9 +4,5 @@
 
 package runtime
 
-const (
-       cacheLineSize = 64
-)
-
 type uintreg uint64
 type intptr int32 // TODO(rsc): remove
index 23f2711f6d9ed2fbff2f469205bd3f1183a8080e..79d38c7ab1bcda9c65e509558293188d28eadf63 100644 (file)
@@ -4,9 +4,5 @@
 
 package runtime
 
-const (
-       cacheLineSize = 32
-)
-
 type uintreg uint32
 type intptr int32 // TODO(rsc): remove
index 226b824065f5802898c54f730dd37e3490712183..48925b2e3e7595eeab4b4fde3135cc22906b3711 100644 (file)
@@ -26,7 +26,7 @@ func makechan(t *chantype, size int64) *hchan {
        if hchanSize%maxAlign != 0 || elem.align > maxAlign {
                gothrow("makechan: bad alignment")
        }
-       if size < 0 || int64(uintptr(size)) != size || (elem.size > 0 && uintptr(size) > (maxMem-hchanSize)/uintptr(elem.size)) {
+       if size < 0 || int64(uintptr(size)) != size || (elem.size > 0 && uintptr(size) > (maxmem-hchanSize)/uintptr(elem.size)) {
                panic("makechan: size out of range")
        }
 
index b56f42531ec950e66ee9a40f25395fa12d2890a6..e5c7e095928dfe6eb2ab5a7cf4c4a5f7e8ee5422 100644 (file)
@@ -102,9 +102,9 @@ uintptr runtime·sizeof_C_MStats = sizeof(MStats) - (NumSizeClasses - 61) * size
 
 #define MaxArena32 (2U<<30)
 
-// For use by Go.  It can't be a constant in Go, unfortunately,
-// because it depends on the OS.
-uintptr runtime·maxMem = MaxMem;
+// For use by Go. If it were a C enum it would be made available automatically,
+// but the value of MaxMem is too large for enum.
+uintptr runtime·maxmem = MaxMem;
 
 void
 runtime·mallocinit(void)
index d6f1a1a4a2b282e2ad0e704facb6099c4eee525c..7bb85057f4da04dc57b73edadac7c5b2dd75c4e7 100644 (file)
@@ -11,49 +11,41 @@ import (
 const (
        debugMalloc = false
 
-       flagNoScan = 1 << 0 // GC doesn't have to scan object
-       flagNoZero = 1 << 1 // don't zero memory
+       flagNoScan = _FlagNoScan
+       flagNoZero = _FlagNoZero
 
-       maxTinySize   = 16
-       tinySizeClass = 2
-       maxSmallSize  = 32 << 10
+       maxTinySize   = _TinySize
+       tinySizeClass = _TinySizeClass
+       maxSmallSize  = _MaxSmallSize
 
-       pageShift = 13
-       pageSize  = 1 << pageShift
-       pageMask  = pageSize - 1
+       pageShift = _PageShift
+       pageSize  = _PageSize
+       pageMask  = _PageMask
 
-       bitsPerPointer  = 2
-       bitsMask        = 1<<bitsPerPointer - 1
-       pointersPerByte = 8 / bitsPerPointer
-       bitPtrMask      = bitsMask << 2
-       maxGCMask       = 64
-       bitsDead        = 0
-       bitsPointer     = 2
+       bitsPerPointer  = _BitsPerPointer
+       bitsMask        = _BitsMask
+       pointersPerByte = _PointersPerByte
+       maxGCMask       = _MaxGCMask
+       bitsDead        = _BitsDead
+       bitsPointer     = _BitsPointer
 
-       bitBoundary = 1
-       bitMarked   = 2
-       bitMask     = bitBoundary | bitMarked
+       mSpanInUse = _MSpanInUse
 
-       mSpanInUse = 0
-
-       concurrentSweep = true
+       concurrentSweep = _ConcurrentSweep != 0
 )
 
 // Page number (address>>pageShift)
 type pageID uintptr
 
-// All zero-sized allocations return a pointer to this byte.
-var zeroObject byte
-
-// Maximum possible heap size.
-var maxMem uintptr
+// base address for all 0-byte allocations
+var zerobase uintptr
 
 // Allocate an object of size bytes.
 // Small objects are allocated from the per-P cache's free lists.
 // Large objects (> 32 kB) are allocated straight from the heap.
 func mallocgc(size uintptr, typ *_type, flags int) unsafe.Pointer {
        if size == 0 {
-               return unsafe.Pointer(&zeroObject)
+               return unsafe.Pointer(&zerobase)
        }
        size0 := size
 
@@ -357,7 +349,7 @@ func newarray(typ *_type, n uintptr) unsafe.Pointer {
        if typ.kind&kindNoPointers != 0 {
                flags |= flagNoScan
        }
-       if int(n) < 0 || (typ.size > 0 && n > maxMem/uintptr(typ.size)) {
+       if int(n) < 0 || (typ.size > 0 && n > maxmem/uintptr(typ.size)) {
                panic("runtime: allocation size out of range")
        }
        return mallocgc(uintptr(typ.size)*n, typ, flags)
index 30a8ea2c9c812cb11dfbda3c848a4676ed14a80e..eac6e704beb3f2fb68c66b9fbb92c0aaff43f89d 100644 (file)
@@ -123,7 +123,7 @@ static FinBlock     *allfin;        // list of all blocks
 BitVector      runtime·gcdatamask;
 BitVector      runtime·gcbssmask;
 
-extern Mutex   runtime·gclock;
+Mutex  runtime·gclock;
 
 static Workbuf* getempty(Workbuf*);
 static Workbuf* getfull(Workbuf*);
index 130e8262adc72602427c9e01e821762607917258..bd5ebab46e00073e4a7b688d379a8f6c907ad4c8 100644 (file)
@@ -69,18 +69,6 @@ func clearpools() {
        }
 }
 
-// State of background sweep.
-// Protected by gclock.
-// Must match mgc0.c.
-var sweep struct {
-       g           *g
-       parked      bool
-       spanidx     uint32 // background sweeper position
-       nbgsweep    uint32
-       npausesweep uint32
-}
-
-var gclock mutex // also in mgc0.c
 func gosweepone() uintptr
 func gosweepdone() bool
 
index 0daf7511b674015629a413cd1f04561b7b2f8914..10f24d009fa14477f9a7b7af132170adddb2434d 100644 (file)
@@ -68,9 +68,9 @@ enum {
 // there.  On a 64-bit system the off'th word in the arena is tracked by
 // the off/16+1'th word before mheap.arena_start.  (On a 32-bit system,
 // the only difference is that the divisor is 8.)
-
-#define bitBoundary    ((uintptr)1) // boundary of an object
-#define bitMarked      ((uintptr)2) // marked object
-
-#define bitMask                ((uintptr)bitBoundary|bitMarked)
-#define bitPtrMask     ((uintptr)BitsMask<<2)
+enum {
+       bitBoundary = 1, // boundary of an object
+       bitMarked = 2, // marked object
+       bitMask = bitBoundary | bitMarked,
+       bitPtrMask = BitsMask<<2,
+};
index e0f63ddb901babce8666c4ffb60bca505cbf1882..4327ced91482357d85b8e2c33e6262973699cfa1 100644 (file)
@@ -22,5 +22,3 @@ func mach_semaphore_wait(sema uint32) int32
 func mach_semaphore_timedwait(sema, sec, nsec uint32) int32
 func mach_semaphore_signal(sema uint32) int32
 func mach_semaphore_signal_all(sema uint32) int32
-
-const stackSystem = 0
index 96964f1e1e750c5d21f0b84774fa8181dbe6bbf6..59708049c8aa95031713cdaf06267260354355af 100644 (file)
@@ -15,5 +15,3 @@ func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, nds
 func getrlimit(kind int32, limit unsafe.Pointer) int32
 func raise(sig int32)
 func sys_umtx_op(addr unsafe.Pointer, mode int32, val uint32, ptr2, ts unsafe.Pointer) int32
-
-const stackSystem = 0
index a6799cd4142db43ce29752569021573a8cea7294..41123ad57092c2301c30e6c3cbce19fd53acc654 100644 (file)
@@ -15,5 +15,3 @@ func rtsigprocmask(sig int32, new, old unsafe.Pointer, size int32)
 func getrlimit(kind int32, limit unsafe.Pointer) int32
 func raise(sig int32)
 func sched_getaffinity(pid, len uintptr, buf *uintptr) int32
-
-const stackSystem = 0
index a6c409c091c99b01bd9c950146cce2b776758f31..8dd43ff06f1e58a295b709802ac42cd048980551 100644 (file)
@@ -23,8 +23,6 @@ func nacl_cond_timed_wait_abs(cond, lock int32, ts unsafe.Pointer) int32
 func nacl_thread_create(fn, stk, tls, xx unsafe.Pointer) int32
 func nacl_nanosleep(ts, extra unsafe.Pointer) int32
 
-const stackSystem = 0
-
 func os_sigpipe() {
        gothrow("too many writes on closed pipe")
 }
index 8792f497e4558c7465af062cec983dac20dc4ebf..f000c5e9f64fe04e2df9a986fbfe4d0fe3e6a760 100644 (file)
@@ -18,5 +18,3 @@ func lwp_create(ctxt unsafe.Pointer, flags uintptr, lwpid unsafe.Pointer) int32
 func lwp_park(abstime unsafe.Pointer, unpark int32, hint, unparkhint unsafe.Pointer) int32
 func lwp_unpark(lwp int32, hint unsafe.Pointer) int32
 func lwp_self() int32
-
-const stackSystem = 0
index 19e2b45a15cd9da140134d5f3d820118ec2bd36e..a000f963e33ae10bdd512496997a03015f55cde0 100644 (file)
@@ -15,5 +15,3 @@ func raise(sig int32)
 func tfork(param unsafe.Pointer, psize uintptr, mm, gg, fn unsafe.Pointer) int32
 func thrsleep(ident unsafe.Pointer, clock_id int32, tsp, lock, abort unsafe.Pointer) int32
 func thrwakeup(ident unsafe.Pointer, n int32) int32
-
-const stackSystem = 0
index c7b5bf70505a8fd3c3043e1a599269ca691dc25f..20e47bf42e5cd20bf451be7e0c3c1dc61f12949f 100644 (file)
@@ -24,10 +24,6 @@ func setfpmasks()
 func tstart_plan9(newm *m)
 func errstr() string
 
-// The size of the note handler frame varies among architectures,
-// but 512 bytes should be enough for every implementation.
-const stackSystem = 512
-
 type _Plink uintptr
 
 func os_sigpipe() {
index 3cffff3e2970fbe3a41d1e83945d695a66a3ada6..ca13151204a5e213cec566103e234f17cf22f722 100644 (file)
@@ -98,5 +98,3 @@ func sysvicall6(fn *libcFunc, a1, a2, a3, a4, a5, a6 uintptr) uintptr {
        asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(libcall))
        return libcall.r1
 }
-
-const stackSystem = 0
index da4c736adda56adb38bfa4e7f11ee3eee905c731..1528d2fd1396daaf3a1284f01a0047aa6c78a0a3 100644 (file)
@@ -26,8 +26,6 @@ func netpollopen(fd uintptr, pd *pollDesc) int32
 func netpollclose(fd uintptr) int32
 func netpollarm(pd *pollDesc, mode int)
 
-const stackSystem = 512 * ptrSize
-
 func os_sigpipe() {
        gothrow("too many writes on closed pipe")
 }
index abd53c4ba1194cf577a4872c91ca60c16d3e0bb5..4aa9a963f571cdfd4e380697bfabe20800c9e2a2 100644 (file)
@@ -697,7 +697,6 @@ enum
  * external data
  */
 extern String  runtime·emptystring;
-extern uintptr runtime·zerobase;
 extern G**     runtime·allg;
 extern Slice   runtime·allgs; // []*G
 extern uintptr runtime·allglen;
index 87ba5463b609515ba87c2def75c0425d0db80737..beacd671621b066b053609707abe961943a2b79e 100644 (file)
@@ -35,7 +35,7 @@ const semTabSize = 251
 
 var semtable [semTabSize]struct {
        root semaRoot
-       pad  [cacheLineSize - unsafe.Sizeof(semaRoot{})]byte
+       pad  [_CacheLineSize - unsafe.Sizeof(semaRoot{})]byte
 }
 
 // Called from sync/net packages.
index 3b88927c64e2c42a7d3dd5675e7aeb9e5936571d..171087d7f6fe51c0c243e77d6338c04b4eff7282 100644 (file)
@@ -22,11 +22,11 @@ func makeslice(t *slicetype, len64 int64, cap64 int64) sliceStruct {
        // but since the cap is only being supplied implicitly, saying len is clearer.
        // See issue 4085.
        len := int(len64)
-       if len64 < 0 || int64(len) != len64 || t.elem.size > 0 && uintptr(len) > maxMem/uintptr(t.elem.size) {
+       if len64 < 0 || int64(len) != len64 || t.elem.size > 0 && uintptr(len) > maxmem/uintptr(t.elem.size) {
                panic(errorString("makeslice: len out of range"))
        }
        cap := int(cap64)
-       if cap < len || int64(cap) != cap64 || t.elem.size > 0 && uintptr(cap) > maxMem/uintptr(t.elem.size) {
+       if cap < len || int64(cap) != cap64 || t.elem.size > 0 && uintptr(cap) > maxmem/uintptr(t.elem.size) {
                panic(errorString("makeslice: cap out of range"))
        }
        p := newarray(t.elem, uintptr(cap))
@@ -42,7 +42,7 @@ func growslice(t *slicetype, old sliceStruct, n int64) sliceStruct {
        cap64 := int64(old.cap) + n
        cap := int(cap64)
 
-       if int64(cap) != cap64 || cap < old.cap || t.elem.size > 0 && uintptr(cap) > maxMem/uintptr(t.elem.size) {
+       if int64(cap) != cap64 || cap < old.cap || t.elem.size > 0 && uintptr(cap) > maxmem/uintptr(t.elem.size) {
                panic(errorString("growslice: cap out of range"))
        }
 
@@ -72,7 +72,7 @@ func growslice(t *slicetype, old sliceStruct, n int64) sliceStruct {
                }
        }
 
-       if uintptr(newcap) >= maxMem/uintptr(et.size) {
+       if uintptr(newcap) >= maxmem/uintptr(et.size) {
                panic(errorString("growslice: cap out of range"))
        }
        lenmem := uintptr(old.len) * uintptr(et.size)
index c84f673427e9e4c864162f87abefd6070ae94be0..0809f89bc1fe1796b3fcb54885185cb270522814 100644 (file)
@@ -225,7 +225,7 @@ func rawbyteslice(size int) (b []byte) {
 
 // rawruneslice allocates a new rune slice. The rune slice is not zeroed.
 func rawruneslice(size int) (b []rune) {
-       if uintptr(size) > maxMem/4 {
+       if uintptr(size) > maxmem/4 {
                gothrow("out of memory")
        }
        mem := goroundupsize(uintptr(size) * 4)
index 5985536289470a2d71879e1c744a72f332f31d07..b64ec44f9ecbc04b40f71c79bddf546491af2d84 100644 (file)
@@ -5,37 +5,37 @@
 package runtime
 
 const (
-       kindBool = 1 + iota
-       kindInt
-       kindInt8
-       kindInt16
-       kindInt32
-       kindInt64
-       kindUint
-       kindUint8
-       kindUint16
-       kindUint32
-       kindUint64
-       kindUintptr
-       kindFloat32
-       kindFloat64
-       kindComplex64
-       kindComplex128
-       kindArray
-       kindChan
-       kindFunc
-       kindInterface
-       kindMap
-       kindPtr
-       kindSlice
-       kindString
-       kindStruct
-       kindUnsafePointer
+       kindBool          = _KindBool
+       kindInt           = _KindInt
+       kindInt8          = _KindInt8
+       kindInt16         = _KindInt16
+       kindInt32         = _KindInt32
+       kindInt64         = _KindInt64
+       kindUint          = _KindUint
+       kindUint8         = _KindUint8
+       kindUint16        = _KindUint16
+       kindUint32        = _KindUint32
+       kindUint64        = _KindUint64
+       kindUintptr       = _KindUintptr
+       kindFloat32       = _KindFloat32
+       kindFloat64       = _KindFloat64
+       kindComplex64     = _KindComplex64
+       kindComplex128    = _KindComplex128
+       kindArray         = _KindArray
+       kindChan          = _KindChan
+       kindFunc          = _KindFunc
+       kindInterface     = _KindInterface
+       kindMap           = _KindMap
+       kindPtr           = _KindPtr
+       kindSlice         = _KindSlice
+       kindString        = _KindString
+       kindStruct        = _KindStruct
+       kindUnsafePointer = _KindUnsafePointer
 
-       kindDirectIface = 1 << 5
-       kindGCProg      = 1 << 6 // Type.gc points to GC program
-       kindNoPointers  = 1 << 7
-       kindMask        = (1 << 5) - 1
+       kindDirectIface = _KindDirectIface
+       kindGCProg      = _KindGCProg
+       kindNoPointers  = _KindNoPointers
+       kindMask        = _KindMask
 )
 
 // isDirectIface reports whether t is stored directly in an interface value.
index 7c611e8ba601ae97fbdd835474f003799f6ee7d2..e0fe177bb75a7a7f24806c84f96edced452d3643 100644 (file)
@@ -2,9 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// PtrSize vs sizeof(void*): This file is also included from src/cmd/ld/...
-// which defines PtrSize to be different from sizeof(void*) when crosscompiling.
-
 enum {
        KindBool = 1,
        KindInt,