diff options
Diffstat (limited to 'libgo/go/runtime')
-rw-r--r-- | libgo/go/runtime/debug.go | 26 | ||||
-rw-r--r-- | libgo/go/runtime/error.go | 39 | ||||
-rw-r--r-- | libgo/go/runtime/gc_test.go | 6 | ||||
-rw-r--r-- | libgo/go/runtime/pprof/pprof.go | 38 | ||||
-rw-r--r-- | libgo/go/runtime/runtime_test.go | 40 | ||||
-rw-r--r-- | libgo/go/runtime/sig.go | 16 | ||||
-rw-r--r-- | libgo/go/runtime/softfloat64.go | 2 | ||||
-rw-r--r-- | libgo/go/runtime/type.go | 211 |
8 files changed, 142 insertions, 236 deletions
diff --git a/libgo/go/runtime/debug.go b/libgo/go/runtime/debug.go index 4f09146fac1..bd6dcc971a1 100644 --- a/libgo/go/runtime/debug.go +++ b/libgo/go/runtime/debug.go @@ -95,11 +95,37 @@ func (r *MemProfileRecord) Stack() []uintptr { // where r.AllocBytes > 0 but r.AllocBytes == r.FreeBytes. // These are sites where memory was allocated, but it has all // been released back to the runtime. +// // Most clients should use the runtime/pprof package or // the testing package's -test.memprofile flag instead // of calling MemProfile directly. func MemProfile(p []MemProfileRecord, inuseZero bool) (n int, ok bool) +// A ThreadProfileRecord describes the execution stack that +// caused a new thread to be created. +type ThreadProfileRecord struct { + Stack0 [32]uintptr // stack trace for this record; ends at first 0 entry +} + +// Stack returns the stack trace associated with the record, +// a prefix of r.Stack0. +func (r *ThreadProfileRecord) Stack() []uintptr { + for i, v := range r.Stack0 { + if v == 0 { + return r.Stack0[0:i] + } + } + return r.Stack0[0:] +} + +// ThreadProfile returns n, the number of records in the current thread profile. +// If len(p) >= n, ThreadProfile copies the profile into p and returns n, true. +// If len(p) < n, ThreadProfile does not change p and returns n, false. +// +// Most clients should use the runtime/pprof package instead +// of calling ThreadProfile directly. +func ThreadProfile(p []ThreadProfileRecord) (n int, ok bool) + // CPUProfile returns the next chunk of binary CPU profiling stack trace data, // blocking until data is available. If profiling is turned off and all the profile // data accumulated while it was on has been returned, CPUProfile returns nil. diff --git a/libgo/go/runtime/error.go b/libgo/go/runtime/error.go index c5168a74be7..d3913ec27b8 100644 --- a/libgo/go/runtime/error.go +++ b/libgo/go/runtime/error.go @@ -17,9 +17,6 @@ type Error interface { // A TypeAssertionError explains a failed type assertion. type TypeAssertionError struct { - interfaceType *Type // interface had this type - concreteType *Type // concrete value had this type - assertedType *Type // asserted type interfaceString string concreteString string assertedString string @@ -33,7 +30,7 @@ func (e *TypeAssertionError) Error() string { if inter == "" { inter = "interface" } - if e.concreteType == nil { + if e.concreteString == "" { return "interface conversion: " + inter + " is nil, not " + e.assertedString } if e.missingMethod == "" { @@ -44,40 +41,10 @@ func (e *TypeAssertionError) Error() string { ": missing method " + e.missingMethod } -// Concrete returns the type of the concrete value in the failed type assertion. -// If the interface value was nil, Concrete returns nil. -func (e *TypeAssertionError) Concrete() *Type { - return e.concreteType -} - -// Asserted returns the type incorrectly asserted by the type assertion. -func (e *TypeAssertionError) Asserted() *Type { - return e.assertedType -} - -// If the type assertion is to an interface type, MissingMethod returns the -// name of a method needed to satisfy that interface type but not implemented -// by Concrete. If there are multiple such methods, -// MissingMethod returns one; which one is unspecified. -// If the type assertion is not to an interface type, MissingMethod returns an empty string. -func (e *TypeAssertionError) MissingMethod() string { - return e.missingMethod -} - // For calling from C. -func NewTypeAssertionError(pt1, pt2, pt3 *Type, ps1, ps2, ps3 *string, pmeth *string, ret *interface{}) { - var t1, t2, t3 *Type +func NewTypeAssertionError(ps1, ps2, ps3 *string, pmeth *string, ret *interface{}) { var s1, s2, s3, meth string - if pt1 != nil { - t1 = pt1 - } - if pt2 != nil { - t2 = pt2 - } - if pt3 != nil { - t3 = pt3 - } if ps1 != nil { s1 = *ps1 } @@ -90,7 +57,7 @@ func NewTypeAssertionError(pt1, pt2, pt3 *Type, ps1, ps2, ps3 *string, pmeth *st if pmeth != nil { meth = *pmeth } - *ret = &TypeAssertionError{t1, t2, t3, s1, s2, s3, meth} + *ret = &TypeAssertionError{s1, s2, s3, meth} } // An errorString represents a runtime error described by a single string. diff --git a/libgo/go/runtime/gc_test.go b/libgo/go/runtime/gc_test.go index 739ebcba2ff..65894a6fd01 100644 --- a/libgo/go/runtime/gc_test.go +++ b/libgo/go/runtime/gc_test.go @@ -15,7 +15,11 @@ func TestGcSys(t *testing.T) { runtime.ReadMemStats(memstats) sys := memstats.Sys - for i := 0; i < 1000000; i++ { + itercount := 1000000 + if testing.Short() { + itercount = 100000 + } + for i := 0; i < itercount; i++ { workthegc() } diff --git a/libgo/go/runtime/pprof/pprof.go b/libgo/go/runtime/pprof/pprof.go index a8e78e0ea75..42f04f320a7 100644 --- a/libgo/go/runtime/pprof/pprof.go +++ b/libgo/go/runtime/pprof/pprof.go @@ -110,6 +110,44 @@ func WriteHeapProfile(w io.Writer) error { return b.Flush() } +// WriteThreadProfile writes a pprof-formatted thread creation profile to w. +// If a write to w returns an error, WriteThreadProfile returns that error. +// Otherwise, WriteThreadProfile returns nil. +func WriteThreadProfile(w io.Writer) error { + // Find out how many records there are (ThreadProfile(nil)), + // allocate that many records, and get the data. + // There's a race—more records (threads) might be added between + // the two calls—so allocate a few extra records for safety + // and also try again if we're very unlucky. + // The loop should only execute one iteration in the common case. + var p []runtime.ThreadProfileRecord + n, ok := runtime.ThreadProfile(nil) + for { + // Allocate room for a slightly bigger profile, + // in case a few more entries have been added + // since the call to ThreadProfile. + p = make([]runtime.ThreadProfileRecord, n+10) + n, ok = runtime.ThreadProfile(p) + if ok { + p = p[0:n] + break + } + // Profile grew; try again. + } + + b := bufio.NewWriter(w) + fmt.Fprintf(b, "thread creation profile: %d threads\n", n) + for i := range p { + r := &p[i] + fmt.Fprintf(b, "@") + for _, pc := range r.Stack() { + fmt.Fprintf(b, " %#x", pc) + } + fmt.Fprintf(b, "\n") + } + return b.Flush() +} + var cpu struct { sync.Mutex profiling bool diff --git a/libgo/go/runtime/runtime_test.go b/libgo/go/runtime/runtime_test.go new file mode 100644 index 00000000000..d68b363e998 --- /dev/null +++ b/libgo/go/runtime/runtime_test.go @@ -0,0 +1,40 @@ +// Copyright 2012 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_test + +import ( + "io" + "testing" +) + +var errf error + +func errfn() error { + return errf +} + +func errfn1() error { + return io.EOF +} + +func BenchmarkIfaceCmp100(b *testing.B) { + for i := 0; i < b.N; i++ { + for j := 0; j < 100; j++ { + if errfn() == io.EOF { + b.Fatal("bad comparison") + } + } + } +} + +func BenchmarkIfaceCmpNil100(b *testing.B) { + for i := 0; i < b.N; i++ { + for j := 0; j < 100; j++ { + if errfn1() == nil { + b.Fatal("bad comparison") + } + } + } +} diff --git a/libgo/go/runtime/sig.go b/libgo/go/runtime/sig.go deleted file mode 100644 index 6d560b90077..00000000000 --- a/libgo/go/runtime/sig.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2009 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 - -// Sigrecv returns a bitmask of signals that have arrived since the last call to Sigrecv. -// It blocks until at least one signal arrives. -func Sigrecv() uint32 - -// Signame returns a string describing the signal, or "" if the signal is unknown. -func Signame(sig int32) string - -// Siginit enables receipt of signals via Sigrecv. It should typically -// be called during initialization. -func Siginit() diff --git a/libgo/go/runtime/softfloat64.go b/libgo/go/runtime/softfloat64.go index e0c3b7b738d..4fcf8f26901 100644 --- a/libgo/go/runtime/softfloat64.go +++ b/libgo/go/runtime/softfloat64.go @@ -4,7 +4,7 @@ // Software IEEE754 64-bit floating point. // Only referred to (and thus linked in) by arm port -// and by gotest in this directory. +// and by tests in this directory. package runtime diff --git a/libgo/go/runtime/type.go b/libgo/go/runtime/type.go index b59f2e4c383..c15c1c10c85 100644 --- a/libgo/go/runtime/type.go +++ b/libgo/go/runtime/type.go @@ -4,205 +4,52 @@ /* * Runtime type representation. - * - * The following files know the exact layout of these - * data structures and must be kept in sync with this file: - * - * ../../cmd/gc/reflect.c - * ../../cmd/ld/dwarf.c decodetype_* - * ../reflect/type.go - * type.h + * This file exists only to provide types that 6l can turn into + * DWARF information for use by gdb. Nothing else uses these. + * They should match the same types in ../reflect/type.go. + * For comments see ../reflect/type.go. */ package runtime import "unsafe" -// All types begin with a few common fields needed for -// the interface runtime. type commonType struct { - Kind uint8 // type kind - align uint8 // alignment of variable with this type - fieldAlign uint8 // alignment of struct field with this type - size uintptr // size in bytes - hash uint32 // hash of type; avoids computation in hash tables + Kind uint8 + align uint8 + fieldAlign uint8 + size uintptr + hash uint32 - hashfn func(unsafe.Pointer, uintptr) uintptr // hash function - equalfn func(unsafe.Pointer, unsafe.Pointer, uintptr) bool // equality function + hashfn func(unsafe.Pointer, uintptr) uintptr + equalfn func(unsafe.Pointer, unsafe.Pointer, uintptr) bool - string *string // string form; unnecessary but undeniably useful - *uncommonType // (relatively) uncommon fields - ptrToThis *Type // pointer to this type, if used in binary or has methods + string *string + *uncommonType + ptrToThis *commonType } -// Values for commonType.kind. -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 - - // Not currently generated by gccgo. - // kindNoPointers = 1 << 7 // OR'ed into kind -) - -// Externally visible name. -type Type commonType - -// Method on non-interface type -type _method struct { // underscore is to avoid collision with C - name *string // name of method - pkgPath *string // nil for exported Names; otherwise import path - mtyp *Type // method type (without receiver) - typ *Type // .(*FuncType) underneath (with receiver) - tfn unsafe.Pointer // fn used for normal method call +type _method struct { + name *string + pkgPath *string + mtyp *commonType + typ *commonType + tfn unsafe.Pointer } -// uncommonType is present only for types with names or methods -// (if T is a named type, the uncommonTypes for T and *T have methods). -// Using a pointer to this struct reduces the overall size required -// to describe an unnamed type with no methods. type uncommonType struct { - name *string // name of type - pkgPath *string // import path; nil for built-in types like int, string - methods []_method // methods associated with type -} - -// BoolType represents a boolean type. -type BoolType commonType - -// FloatType represents a float type. -type FloatType commonType - -// ComplexType represents a complex type. -type ComplexType commonType - -// IntType represents an int type. -type IntType commonType - -// UintType represents a uint type. -type UintType commonType - -// StringType represents a string type. -type StringType commonType - -// UintptrType represents a uintptr type. -type UintptrType commonType - -// UnsafePointerType represents an unsafe.Pointer type. -type UnsafePointerType commonType - -// ArrayType represents a fixed array type. -type ArrayType struct { - commonType - elem *Type // array element type - slice *Type // slice type - len uintptr -} - -// SliceType represents a slice type. -type SliceType struct { - commonType - elem *Type // slice element type -} - -// ChanDir represents a channel type's direction. -type ChanDir int - -const ( - RecvDir ChanDir = 1 << iota // <-chan - SendDir // chan<- - BothDir = RecvDir | SendDir // chan -) - -// ChanType represents a channel type. -type ChanType struct { - commonType - elem *Type // channel element type - dir uintptr // channel direction (ChanDir) -} - -// FuncType represents a function type. -type FuncType struct { - commonType - dotdotdot bool // last input parameter is ... - in []*Type // input parameter types - out []*Type // output parameter types -} - -// Method on interface type -type _imethod struct { // underscore is to avoid collision with C - name *string // name of method - pkgPath *string // nil for exported Names; otherwise import path - typ *Type // .(*FuncType) underneath -} - -// InterfaceType represents an interface type. -type InterfaceType struct { - commonType - methods []_imethod // sorted by hash + name *string + pkgPath *string + methods []_method } -// MapType represents a map type. -type MapType struct { - commonType - key *Type // map key type - elem *Type // map element (value) type -} - -// PtrType represents a pointer type. -type PtrType struct { - commonType - elem *Type // pointer element (pointed at) type -} - -// Struct field -type structField struct { - name *string // nil for embedded fields - pkgPath *string // nil for exported Names; otherwise import path - typ *Type // type of field - tag *string // nil if no tag - offset uintptr // byte offset of field within struct +type _imethod struct { + name *string + pkgPath *string + typ *commonType } -// StructType represents a struct type. -type StructType struct { +type interfaceType struct { commonType - fields []structField // sorted by offset -} - -/* - * 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 - Type *Type - link *Itable - bad int32 - unused int32 - Fn [100000]uintptr // bigger than we'll ever see + methods []_imethod } |