diff options
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r-- | src/pkg/runtime/arm/vlop.s | 2 | ||||
-rw-r--r-- | src/pkg/runtime/closure_test.go | 53 | ||||
-rw-r--r-- | src/pkg/runtime/linux/mem.c | 12 | ||||
-rw-r--r-- | src/pkg/runtime/linux/thread.c | 2 | ||||
-rw-r--r-- | src/pkg/runtime/mprof.goc | 2 | ||||
-rw-r--r-- | src/pkg/runtime/proc_test.go | 9 | ||||
-rw-r--r-- | src/pkg/runtime/runtime-gdb.py | 4 | ||||
-rw-r--r-- | src/pkg/runtime/runtime.h | 2 | ||||
-rw-r--r-- | src/pkg/runtime/windows/386/sys.s | 16 | ||||
-rw-r--r-- | src/pkg/runtime/windows/thread.c | 40 |
10 files changed, 123 insertions, 19 deletions
diff --git a/src/pkg/runtime/arm/vlop.s b/src/pkg/runtime/arm/vlop.s index 2c5d7ebe1..fc679f0ee 100644 --- a/src/pkg/runtime/arm/vlop.s +++ b/src/pkg/runtime/arm/vlop.s @@ -105,7 +105,7 @@ loop: /* * compare numerator to denominator - * if less, subtract and set quotent bit + * if less, subtract and set quotient bit */ CMP R(D), R(N) ORR.HS $1, R(Q) diff --git a/src/pkg/runtime/closure_test.go b/src/pkg/runtime/closure_test.go new file mode 100644 index 000000000..ea65fbd5f --- /dev/null +++ b/src/pkg/runtime/closure_test.go @@ -0,0 +1,53 @@ +// 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 runtime_test + +import "testing" + +var s int + +func BenchmarkCallClosure(b *testing.B) { + for i := 0; i < b.N; i++ { + s += func(ii int) int { return 2 * ii }(i) + } +} + +func BenchmarkCallClosure1(b *testing.B) { + for i := 0; i < b.N; i++ { + j := i + s += func(ii int) int { return 2*ii + j }(i) + } +} + +var ss *int + +func BenchmarkCallClosure2(b *testing.B) { + for i := 0; i < b.N; i++ { + j := i + s += func() int { + ss = &j + return 2 + }() + } +} + +func addr1(x int) *int { + return func() *int { return &x }() +} + +func BenchmarkCallClosure3(b *testing.B) { + for i := 0; i < b.N; i++ { + ss = addr1(i) + } +} + +func addr2() (x int, p *int) { + return 0, func() *int { return &x }() +} + +func BenchmarkCallClosure4(b *testing.B) { + for i := 0; i < b.N; i++ { + _, ss = addr2() + } +} diff --git a/src/pkg/runtime/linux/mem.c b/src/pkg/runtime/linux/mem.c index ce1a8aa70..02f798732 100644 --- a/src/pkg/runtime/linux/mem.c +++ b/src/pkg/runtime/linux/mem.c @@ -39,13 +39,19 @@ runtime·SysFree(void *v, uintptr n) void* runtime·SysReserve(void *v, uintptr n) { + void *p; + // On 64-bit, people with ulimit -v set complain if we reserve too // much address space. Instead, assume that the reservation is okay // and check the assumption in SysMap. if(sizeof(void*) == 8) return v; - return runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); + p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); + if(p < (void*)4096) { + return nil; + } + return p; } enum @@ -63,6 +69,8 @@ runtime·SysMap(void *v, uintptr n) // On 64-bit, we don't actually have v reserved, so tread carefully. if(sizeof(void*) == 8) { p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0); + if(p == (void*)ENOMEM) + runtime·throw("runtime: out of memory"); if(p != v) { runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p); runtime·throw("runtime: address space conflict"); @@ -71,7 +79,7 @@ runtime·SysMap(void *v, uintptr n) } p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0); - if(p == (void*)-ENOMEM) + if(p == (void*)ENOMEM) runtime·throw("runtime: out of memory"); if(p != v) runtime·throw("runtime: cannot map pages in arena address space"); diff --git a/src/pkg/runtime/linux/thread.c b/src/pkg/runtime/linux/thread.c index 6c506236f..7c7ca7b4e 100644 --- a/src/pkg/runtime/linux/thread.c +++ b/src/pkg/runtime/linux/thread.c @@ -116,7 +116,7 @@ again: // // We only really care that (v&1) == 1 (the lock is held), // and in fact there is a futex variant that could - // accomodate that check, but let's not get carried away.) + // accommodate that check, but let's not get carried away.) futexsleep(&l->key, v+2); // We're awake: remove ourselves from the count. diff --git a/src/pkg/runtime/mprof.goc b/src/pkg/runtime/mprof.goc index aae3d183f..517f96a31 100644 --- a/src/pkg/runtime/mprof.goc +++ b/src/pkg/runtime/mprof.goc @@ -113,7 +113,7 @@ static uintptr addrmem; // hashMultiplier is the bottom 32 bits of int((sqrt(5)-1)/2 * (1<<32)). // This is a good multiplier as suggested in CLR, Knuth. The hash // value is taken to be the top AddrHashBits bits of the bottom 32 bits -// of the muliplied value. +// of the multiplied value. enum { HashMultiplier = 2654435769U }; diff --git a/src/pkg/runtime/proc_test.go b/src/pkg/runtime/proc_test.go index a15b2d80a..cac4f9eea 100644 --- a/src/pkg/runtime/proc_test.go +++ b/src/pkg/runtime/proc_test.go @@ -24,20 +24,23 @@ func TestStopTheWorldDeadlock(t *testing.T) { t.Logf("skipping during short test") return } - runtime.GOMAXPROCS(3) - compl := make(chan int, 1) + maxprocs := runtime.GOMAXPROCS(3) + compl := make(chan bool, 2) go func() { for i := 0; i != 1000; i += 1 { runtime.GC() } - compl <- 0 + compl <- true }() go func() { for i := 0; i != 1000; i += 1 { runtime.GOMAXPROCS(3) } + compl <- true }() go perpetuumMobile() <-compl + <-compl stop <- true + runtime.GOMAXPROCS(maxprocs) } diff --git a/src/pkg/runtime/runtime-gdb.py b/src/pkg/runtime/runtime-gdb.py index 3f767fbdd..a96f3f382 100644 --- a/src/pkg/runtime/runtime-gdb.py +++ b/src/pkg/runtime/runtime-gdb.py @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -"""GDB Pretty printers and convencience functions for Go's runtime structures. +"""GDB Pretty printers and convenience functions for Go's runtime structures. This script is loaded by GDB when it finds a .debug_gdb_scripts section in the compiled binary. The [68]l linkers emit this with a @@ -393,7 +393,7 @@ class GoIfaceCmd(gdb.Command): # so Itype will start with a commontype which has kind = interface # -# Register all convience functions and CLI commands +# Register all convenience functions and CLI commands # for k in vars().values(): if hasattr(k, 'invoke'): diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index f2f8dcd5b..2b2b34a3c 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -306,7 +306,7 @@ enum { /* * defined macros - * you need super-goru privilege + * you need super-gopher-guru privilege * to add this list. */ #define nelem(x) (sizeof(x)/sizeof((x)[0])) diff --git a/src/pkg/runtime/windows/386/sys.s b/src/pkg/runtime/windows/386/sys.s index 15f7f95b8..d38405075 100644 --- a/src/pkg/runtime/windows/386/sys.s +++ b/src/pkg/runtime/windows/386/sys.s @@ -59,15 +59,21 @@ TEXT runtime·setlasterror(SB),7,$0 TEXT runtime·sigtramp(SB),7,$0 PUSHL BP // cdecl + PUSHL BX + PUSHL SI + PUSHL DI PUSHL 0(FS) CALL runtime·sigtramp1(SB) POPL 0(FS) + POPL DI + POPL SI + POPL BX POPL BP RET -TEXT runtime·sigtramp1(SB),0,$16-28 +TEXT runtime·sigtramp1(SB),0,$16-40 // unwinding? - MOVL info+12(FP), BX + MOVL info+24(FP), BX MOVL 4(BX), CX // exception flags ANDL $6, CX MOVL $1, AX @@ -75,15 +81,15 @@ TEXT runtime·sigtramp1(SB),0,$16-28 // place ourselves at the top of the SEH chain to // ensure SEH frames lie within thread stack bounds - MOVL frame+16(FP), CX // our SEH frame + MOVL frame+28(FP), CX // our SEH frame MOVL CX, 0(FS) // copy arguments for call to sighandler MOVL BX, 0(SP) MOVL CX, 4(SP) - MOVL context+20(FP), BX + MOVL context+32(FP), BX MOVL BX, 8(SP) - MOVL dispatcher+24(FP), BX + MOVL dispatcher+36(FP), BX MOVL BX, 12(SP) CALL runtime·sighandler(SB) diff --git a/src/pkg/runtime/windows/thread.c b/src/pkg/runtime/windows/thread.c index 2ce92dcfb..2ce8fae15 100644 --- a/src/pkg/runtime/windows/thread.c +++ b/src/pkg/runtime/windows/thread.c @@ -324,13 +324,31 @@ runtime·ctrlhandler1(uint32 type) return 0; } +// Will keep all callbacks in a linked list, so they don't get garbage collected. +typedef struct Callback Callback; +struct Callback { + Callback* link; + void* gobody; + byte asmbody; +}; + +typedef struct Callbacks Callbacks; +struct Callbacks { + Lock; + Callback* link; + int32 n; +}; + +static Callbacks cbs; + // Call back from windows dll into go. byte * runtime·compilecallback(Eface fn, bool cleanstack) { Func *f; int32 argsize, n; - byte *ret, *p; + byte *p; + Callback *c; if(fn.type->kind != KindFunc) runtime·panicstring("not a function"); @@ -348,7 +366,23 @@ runtime·compilecallback(Eface fn, bool cleanstack) if(cleanstack) n += 2; // ... argsize - ret = p = runtime·mal(n); + runtime·lock(&cbs); + for(c = cbs.link; c != nil; c = c->link) { + if(c->gobody == fn.data) { + runtime·unlock(&cbs); + return &c->asmbody; + } + } + if(cbs.n >= 20) + runtime·throw("too many callback functions"); + c = runtime·mal(sizeof *c + n); + c->gobody = fn.data; + c->link = cbs.link; + cbs.link = c; + cbs.n++; + runtime·unlock(&cbs); + + p = &c->asmbody; // MOVL fn, AX *p++ = 0xb8; @@ -376,7 +410,7 @@ runtime·compilecallback(Eface fn, bool cleanstack) } else *p = 0xc3; - return ret; + return &c->asmbody; } void |