diff options
author | Ian Lance Taylor <iant@google.com> | 2011-01-21 18:19:03 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-01-21 18:19:03 +0000 |
commit | ff5f50c52c421d75940ef9392211e3ab24d71332 (patch) | |
tree | 27d8768fb1d25696d3c40b42535eb5e073c278da /libgo/go/runtime | |
parent | d6ed1c8903e728f4233122554bab5910853338bd (diff) | |
download | gcc-ff5f50c52c421d75940ef9392211e3ab24d71332.zip gcc-ff5f50c52c421d75940ef9392211e3ab24d71332.tar.gz gcc-ff5f50c52c421d75940ef9392211e3ab24d71332.tar.bz2 |
Remove the types float and complex.
Update to current version of Go library.
Update testsuite for removed types.
* go-lang.c (go_langhook_init): Omit float_type_size when calling
go_create_gogo.
* go-c.h: Update declaration of go_create_gogo.
From-SVN: r169098
Diffstat (limited to 'libgo/go/runtime')
-rw-r--r-- | libgo/go/runtime/chan_defs.go | 56 | ||||
-rw-r--r-- | libgo/go/runtime/debug.go | 26 | ||||
-rw-r--r-- | libgo/go/runtime/debug/stack.go | 90 | ||||
-rw-r--r-- | libgo/go/runtime/debug/stack_test.go | 55 | ||||
-rw-r--r-- | libgo/go/runtime/extern.go | 18 | ||||
-rw-r--r-- | libgo/go/runtime/hashmap_defs.go | 51 | ||||
-rw-r--r-- | libgo/go/runtime/iface_defs.go | 18 | ||||
-rw-r--r-- | libgo/go/runtime/malloc_defs.go | 130 | ||||
-rw-r--r-- | libgo/go/runtime/mheapmap32_defs.go | 23 | ||||
-rw-r--r-- | libgo/go/runtime/mheapmap64_defs.go | 31 | ||||
-rw-r--r-- | libgo/go/runtime/runtime_defs.go | 200 | ||||
-rw-r--r-- | libgo/go/runtime/type.go | 4 |
12 files changed, 677 insertions, 25 deletions
diff --git a/libgo/go/runtime/chan_defs.go b/libgo/go/runtime/chan_defs.go new file mode 100644 index 0000000..5cfea6e --- /dev/null +++ b/libgo/go/runtime/chan_defs.go @@ -0,0 +1,56 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Go definitions of internal structures. Master is chan.c + +package runtime + +type sudoG struct { + g *g_ + selgen uint32 + offset int16 + isfree int8 + link *sudoG + elem [8]byte +} + +type waitQ struct { + first *sudoG + last *sudoG +} + +type hChan struct { + qcount uint32 + dataqsiz uint32 + elemsize uint16 + closed uint16 + elemalign uint8 + elemalg *alg + senddataq *link + recvdataq *link + recvq waitQ + sendq waitQ + free sudoG + lock +} + +type link struct { + link *link + elem [8]byte +} + +type scase struct { + chan_ *hChan + pc *byte + send uint16 + so uint16 + elemp *byte // union elem [8]byte +} + +type select_ struct { + tcase uint16 + ncase uint16 + link *select_ + scase [1]*scase +} diff --git a/libgo/go/runtime/debug.go b/libgo/go/runtime/debug.go index b5f6571..803ea49 100644 --- a/libgo/go/runtime/debug.go +++ b/libgo/go/runtime/debug.go @@ -4,6 +4,8 @@ package runtime +import "unsafe" + // Breakpoint() executes a breakpoint trap. func Breakpoint() @@ -26,6 +28,9 @@ func GOMAXPROCS(n int) int // Cgocalls returns the number of cgo calls made by the current process. func Cgocalls() int64 +// Goroutines returns the number of goroutines that currently exist. +func Goroutines() int32 + type MemStatsType struct { // General statistics. // Not locked during update; approximate. @@ -34,6 +39,7 @@ type MemStatsType struct { Sys uint64 // bytes obtained from system (should be sum of XxxSys below) Lookups uint64 // number of pointer lookups Mallocs uint64 // number of mallocs + Frees uint64 // number of frees // Main allocation heap statistics. HeapAlloc uint64 // bytes allocated and still in use @@ -55,11 +61,12 @@ type MemStatsType struct { BuckHashSys uint64 // profiling bucket hash table // Garbage collector statistics. - NextGC uint64 - PauseNs uint64 - NumGC uint32 - EnableGC bool - DebugGC bool + NextGC uint64 + PauseTotalNs uint64 + PauseNs [256]uint64 // most recent GC pause times + NumGC uint32 + EnableGC bool + DebugGC bool // Per-size allocation statistics. // Not locked during update; approximate. @@ -70,6 +77,15 @@ type MemStatsType struct { } } +var Sizeof_C_MStats int // filled in by malloc.goc + +func init() { + if Sizeof_C_MStats != unsafe.Sizeof(MemStats) { + println(Sizeof_C_MStats, unsafe.Sizeof(MemStats)) + panic("MStats vs MemStatsType size mismatch") + } +} + // MemStats holds statistics about the memory system. // The statistics are only approximate, as they are not interlocked on update. var MemStats MemStatsType diff --git a/libgo/go/runtime/debug/stack.go b/libgo/go/runtime/debug/stack.go new file mode 100644 index 0000000..e7d56ac --- /dev/null +++ b/libgo/go/runtime/debug/stack.go @@ -0,0 +1,90 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The debug package contains facilities for programs to debug themselves +// while they are running. +package debug + +import ( + "bytes" + "fmt" + "io/ioutil" + "os" + "runtime" +) + +var ( + dunno = []byte("???") + centerDot = []byte("·") + dot = []byte(".") +) + +// PrintStack prints to standard error the stack trace returned by Stack. +func PrintStack() { + os.Stderr.Write(stack()) +} + +// Stack returns a formatted stack trace of the goroutine that calls it. +// For each routine, it includes the source line information and PC value, +// then attempts to discover, for Go functions, the calling function or +// method and the text of the line containing the invocation. +func Stack() []byte { + return stack() +} + +// stack implements Stack, skipping 2 frames +func stack() []byte { + buf := new(bytes.Buffer) // the returned data + // As we loop, we open files and read them. These variables record the currently + // loaded file. + var lines [][]byte + var lastFile string + for i := 2; ; i++ { // Caller we care about is the user, 2 frames up + pc, file, line, ok := runtime.Caller(i) + if !ok { + break + } + // Print this much at least. If we can't find the source, it won't show. + fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc) + if file != lastFile { + data, err := ioutil.ReadFile(file) + if err != nil { + continue + } + lines = bytes.Split(data, []byte{'\n'}, -1) + lastFile = file + } + line-- // in stack trace, lines are 1-indexed but our array is 0-indexed + fmt.Fprintf(buf, "\t%s: %s\n", function(pc), source(lines, line)) + } + return buf.Bytes() +} + +// source returns a space-trimmed slice of the n'th line. +func source(lines [][]byte, n int) []byte { + if n < 0 || n >= len(lines) { + return dunno + } + return bytes.Trim(lines[n], " \t") +} + +// function returns, if possible, the name of the function containing the PC. +func function(pc uintptr) []byte { + fn := runtime.FuncForPC(pc) + if fn == nil { + return dunno + } + name := []byte(fn.Name()) + // The name includes the path name to the package, which is unnecessary + // since the file name is already included. Plus, it has center dots. + // That is, we see + // runtime/debug.*T·ptrmethod + // and want + // *T.ptrmethod + if period := bytes.Index(name, dot); period >= 0 { + name = name[period+1:] + } + name = bytes.Replace(name, centerDot, dot, -1) + return name +} diff --git a/libgo/go/runtime/debug/stack_test.go b/libgo/go/runtime/debug/stack_test.go new file mode 100644 index 0000000..f4bdc46 --- /dev/null +++ b/libgo/go/runtime/debug/stack_test.go @@ -0,0 +1,55 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package debug + +import ( + "strings" + "testing" +) + +type T int + +func (t *T) ptrmethod() []byte { + return Stack() +} +func (t T) method() []byte { + return t.ptrmethod() +} + +/* + The traceback should look something like this, modulo line numbers and hex constants. + Don't worry much about the base levels, but check the ones in our own package. + + /Users/r/go/src/pkg/runtime/debug/stack_test.go:15 (0x13878) + *T.ptrmethod: return Stack() + /Users/r/go/src/pkg/runtime/debug/stack_test.go:18 (0x138dd) + T.method: return t.ptrmethod() + /Users/r/go/src/pkg/runtime/debug/stack_test.go:23 (0x13920) + TestStack: b := T(0).method() + /Users/r/go/src/pkg/testing/testing.go:132 (0x14a7a) + tRunner: test.F(t) + /Users/r/go/src/pkg/runtime/proc.c:145 (0xc970) + ???: runtime·unlock(&runtime·sched); +*/ +func TestStack(t *testing.T) { + b := T(0).method() + lines := strings.Split(string(b), "\n", -1) + if len(lines) <= 6 { + t.Fatal("too few lines") + } + check(t, lines[0], "src/pkg/runtime/debug/stack_test.go") + check(t, lines[1], "\t*T.ptrmethod: return Stack()") + check(t, lines[2], "src/pkg/runtime/debug/stack_test.go") + check(t, lines[3], "\tT.method: return t.ptrmethod()") + check(t, lines[4], "src/pkg/runtime/debug/stack_test.go") + check(t, lines[5], "\tTestStack: b := T(0).method()") + check(t, lines[6], "src/pkg/testing/testing.go") +} + +func check(t *testing.T, line, has string) { + if strings.Index(line, has) < 0 { + t.Errorf("expected %q in %q", has, line) + } +} diff --git a/libgo/go/runtime/extern.go b/libgo/go/runtime/extern.go index 8ab57d0..77c3e8e 100644 --- a/libgo/go/runtime/extern.go +++ b/libgo/go/runtime/extern.go @@ -35,24 +35,6 @@ func Callers(skip int, pc []uintptr) int // given program counter address, or else nil. func FuncForPC(pc uintptr) *Func -// NOTE(rsc): Func must match struct Func in runtime.h - -// Func records information about a function in the program, -// in particular the mapping from program counters to source -// line numbers within that function. -type Func struct { - name string - typ string - src string - pcln []byte - entry uintptr - pc0 uintptr - ln0 int32 - frame int32 - args int32 - locals int32 -} - // Name returns the name of the function. func (f *Func) Name() string { return f.name } diff --git a/libgo/go/runtime/hashmap_defs.go b/libgo/go/runtime/hashmap_defs.go new file mode 100644 index 0000000..57780df --- /dev/null +++ b/libgo/go/runtime/hashmap_defs.go @@ -0,0 +1,51 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Go definitions of internal structures. Master is hashmap.[c,h] + +package runtime + +type hash_hash uintptr + +type hash_entry struct { + hash hash_hash + key byte // dwarf.c substitutes the real type + val byte // for key and val +} + +type hash_subtable struct { + power uint8 + used uint8 + datasize uint8 + max_probes uint8 + limit_bytes int16 + end *hash_entry + entry hash_entry // TODO: [0]hash_entry +} + +type hash struct { + count uint32 + datasize uint8 + max_power uint8 + max_probes uint8 + indirectval uint8 + changes int32 + data_hash func(uint32, uintptr) hash_hash + data_eq func(uint32, uintptr, uintptr) uint32 + data_del func(uint32, uintptr, uintptr) + st *hash_subtable + keysize uint32 + valsize uint32 + datavo uint32 + ko0 uint32 + vo0 uint32 + ko1 uint32 + vo1 uint32 + po1 uint32 + ko2 uint32 + vo2 uint32 + po2 uint32 + keyalg *alg + valalg *alg +} diff --git a/libgo/go/runtime/iface_defs.go b/libgo/go/runtime/iface_defs.go new file mode 100644 index 0000000..69d52ef --- /dev/null +++ b/libgo/go/runtime/iface_defs.go @@ -0,0 +1,18 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package runtime + +/* + * Must match iface.c:/Itable and compilers. + * NOTE: type.go has an Itable, that is the version of Itab used by the reflection code. + */ +type itab struct { + Itype *Type + Type *Type + link *itab + bad int32 + unused int32 + Fn func() // TODO: [0]func() +} diff --git a/libgo/go/runtime/malloc_defs.go b/libgo/go/runtime/malloc_defs.go new file mode 100644 index 0000000..11d6627 --- /dev/null +++ b/libgo/go/runtime/malloc_defs.go @@ -0,0 +1,130 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Go definitions of internal structures. Master is malloc.h + +package runtime + +import "unsafe" + +const ( + pageShift = 12 + pageSize = 1 << pageShift + pageMask = pageSize - 1 +) + +type pageID uintptr + +const ( + numSizeClasses = 67 + maxSmallSize = 32 << 10 + fixAllocChunk = 128 << 10 + maxMCacheListLen = 256 + maxMCacheSize = 2 << 20 + maxMHeapList = 1 << 8 // 1 << (20 - pageShift) + heapAllocChunk = 1 << 20 +) + +type mLink struct { + next *mLink +} + +type fixAlloc struct { + size uintptr + alloc func(uintptr) + first func(unsafe.Pointer, *byte) + arg unsafe.Pointer + list *mLink + chunk *byte + nchunk uint32 + inuse uintptr + sys uintptr +} + + +// MStats? used to be in extern.go + +type mCacheList struct { + list *mLink + nlist uint32 + nlistmin uint32 +} + +type mCache struct { + list [numSizeClasses]mCacheList + size uint64 + local_alloc int64 + local_objects int64 + next_sample int32 +} + +type mSpan struct { + next *mSpan + prev *mSpan + allnext *mSpan + start pageID + npages uintptr + freelist *mLink + ref uint32 + sizeclass uint32 + state uint32 + // union { + gcref *uint32 // sizeclass > 0 + // gcref0 uint32; // sizeclass == 0 + // } +} + +type mCentral struct { + // lock + sizeclass int32 + nonempty mSpan + empty mSpan + nfree int32 +} + +type mHeap struct { + // lock + free [maxMHeapList]mSpan + large mSpan + allspans *mSpan + // map_ mHeapMap + min *byte + max *byte + closure_min *byte + closure_max *byte + + central [numSizeClasses]struct { + pad [64]byte + // union: mCentral + } + + spanalloc fixAlloc + cachealloc fixAlloc +} + +const ( + refFree = iota + refStack + refNone + refSome + refcountOverhead = 4 + refNoPointers = 0x80000000 + refHasFinalizer = 0x40000000 + refProfiled = 0x20000000 + refNoProfiling = 0x10000000 + refFlags = 0xFFFF0000 +) + +const ( + mProf_None = iota + mProf_Sample + mProf_All +) + +type finalizer struct { + next *finalizer + fn func(unsafe.Pointer) + arg unsafe.Pointer + nret int32 +} diff --git a/libgo/go/runtime/mheapmap32_defs.go b/libgo/go/runtime/mheapmap32_defs.go new file mode 100644 index 0000000..755725b --- /dev/null +++ b/libgo/go/runtime/mheapmap32_defs.go @@ -0,0 +1,23 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package runtime + +const ( + mHeapMap_Level1Bits = 10 + mHeapMap_Level2Bits = 10 + mHeapMap_TotalBits = mHeapMap_Level1Bits + mHeapMap_Level2Bits + + mHeapMap_Level1Mask = (1 << mHeapMap_Level1Bits) - 1 + mHeapMap_Level2Mask = (1 << mHeapMap_Level2Bits) - 1 +) + +type mHeapMap struct { + allocator func(uintptr) + p [1 << mHeapMap_Level1Bits]*mHeapMapNode2 +} + +type mHeapMapNode2 struct { + s [1 << mHeapMap_Level2Bits]*mSpan +} diff --git a/libgo/go/runtime/mheapmap64_defs.go b/libgo/go/runtime/mheapmap64_defs.go new file mode 100644 index 0000000..d7ba2b4 --- /dev/null +++ b/libgo/go/runtime/mheapmap64_defs.go @@ -0,0 +1,31 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package runtime + +const ( + mHeapMap_Level1Bits = 18 + mHeapMap_Level2Bits = 18 + mHeapMap_Level3Bits = 16 + mHeapMap_TotalBits = mHeapMap_Level1Bits + mHeapMap_Level2Bits + mHeapMap_Level3Bits + + mHeapMap_Level1Mask = (1 << mHeapMap_Level1Bits) - 1 + mHeapMap_Level2Mask = (1 << mHeapMap_Level2Bits) - 1 + mHeapMap_Level3Mask = (1 << mHeapMap_Level3Bits) - 1 +) + +type mHeapMap struct { + allocator func(uintptr) + p [1 << mHeapMap_Level1Bits]*mHeapMapNode2 +} + + +type mHeapMapNode2 struct { + p [1 << mHeapMap_Level2Bits]*mHeapMapNode3 +} + + +type mHeapMapNode3 struct { + s [1 << mHeapMap_Level3Bits]*mSpan +} diff --git a/libgo/go/runtime/runtime_defs.go b/libgo/go/runtime/runtime_defs.go new file mode 100644 index 0000000..deea320 --- /dev/null +++ b/libgo/go/runtime/runtime_defs.go @@ -0,0 +1,200 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Go definitions of internal structures. Master is runtime.h + +// TODO(lvd): automate conversion to all the _defs.go files + +package runtime + +import "unsafe" + +const ( + gidle = iota + grunnable + grunning + gsyscall + gwaiting + gmoribund + gdead + grecovery +) + +// const ( Structrnd = sizeof(uintptr) ) + +type string_ struct { + str *byte + len int32 +} + +type iface struct { + // tab *itab + data unsafe.Pointer +} + +type eface struct { + type_ *Type + data unsafe.Pointer +} + +type complex64 struct { + real float32 + imag float32 +} + +type complex128 struct { + real float64 + imag float64 +} + +type slice struct { + array *byte + len uint32 + cap uint32 +} + +type gobuf struct { + sp unsafe.Pointer + pc unsafe.Pointer + g *g_ +} + +type g_ struct { + stackguard unsafe.Pointer + stackbase unsafe.Pointer + defer_ *defer_ + panic_ *panic_ + sched gobuf + stack0 unsafe.Pointer + entry unsafe.Pointer + alllink *g_ + param unsafe.Pointer + status int16 + goid int32 + selgen uint32 + schedlink *g_ + readyonstop bool + ispanic bool + m *m_ + lockedm *m_ + sig int32 + sigcode0 uintptr + sigcode1 uintptr +} + +type m_ struct { + g0 *g_ + morepc unsafe.Pointer + moreargp unsafe.Pointer + morebuf gobuf + moreframesize uint32 + moreargsize uint32 + cret uintptr + procid uint64 + gsignal *g_ + tls [8]uint32 + sched gobuf + curg *g_ + id int32 + mallocing int32 + gcing int32 + locks int32 + nomemprof int32 + waitnextg int32 + // havenextg note + nextg *g_ + alllink *m_ + schedlink *m_ + machport uint32 + mcache *mCache + lockedg *g_ + freg [8]uint64 + // gostack unsafe.Pointer // __WINDOWS__ +} + +type stktop struct { + stackguard *uint8 + stackbase *uint8 + gobuf gobuf + args uint32 + fp *uint8 + free bool + panic_ bool +} + +type alg struct { + hash func(uint32, unsafe.Pointer) uintptr + equal func(uint32, unsafe.Pointer, unsafe.Pointer) uint32 + print func(uint32, unsafe.Pointer) + copy func(uint32, unsafe.Pointer, unsafe.Pointer) +} + +type sigtab struct { + flags int32 + name *int8 +} + +const ( + sigCatch = (1 << iota) + sigIgnore + sigRestart + sigQueue + sigPanic +) + +type Func struct { + name string + typ string + src string + pcln []byte + entry uintptr + pc0 uintptr + ln0 int32 + frame int32 + args int32 + locals int32 +} + +const ( + aMEM = iota + aNOEQ + aSTRING + aINTER + aNILINTER + aMEMWORD + amax +) + +type defer_ struct { + siz int32 + sp unsafe.Pointer + pc unsafe.Pointer + fn unsafe.Pointer + link *defer_ + args [8]byte // padded to actual size +} + +type panic_ struct { + arg eface + stackbase unsafe.Pointer + link *panic_ + recovered bool +} + +/* + * External data. + */ + +var ( + algarray [amax]alg + emptystring string + allg *g_ + allm *m_ + goidgen int32 + gomaxprocs int32 + panicking int32 + fd int32 + gcwaiting int32 + goos *int8 +) diff --git a/libgo/go/runtime/type.go b/libgo/go/runtime/type.go index a16809f..645e364 100644 --- a/libgo/go/runtime/type.go +++ b/libgo/go/runtime/type.go @@ -48,10 +48,8 @@ const ( kindUint32 kindUint64 kindUintptr - kindFloat kindFloat32 kindFloat64 - kindComplex kindComplex64 kindComplex128 kindArray @@ -195,6 +193,8 @@ type StructType struct { /* * Must match iface.c:/Itab and compilers. + * NOTE: this is the version used by the reflection code, there is another + * one in iface_defs.go that is closer to the original C version. */ type Itable struct { Itype *Type // (*tab.inter).(*InterfaceType) is the interface type |