1
0
mirror of https://github.com/golang/go synced 2024-10-03 13:21:22 -06:00
Commit Graph

572 Commits

Author SHA1 Message Date
Keith Randall
fbc56cf050 runtime: hashmap: move overflow pointer to end of bucket
Pointers to zero-sized values may end up pointing to the next
object in memory, and possibly off the end of a span.  This
can cause memory leaks and/or confuse the garbage collector.

By putting the overflow pointer at the end of the bucket, we
make sure that pointers to any zero-sized keys or values don't
accidentally point to the next object in memory.

fixes #9384

Change-Id: I5d434df176984cb0210b4d0195dd106d6eb28f73
Reviewed-on: https://go-review.googlesource.com/1869
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-22 22:25:48 +00:00
Alex Brainman
79a4a779a7 syscall: clean up TestStdcallAndCDeclCallbacks to have no warnings
Fixes #9188

Change-Id: Ifbf5d9fa78a4f4ceb7f92d42494fe37fa7878c45
Reviewed-on: https://go-review.googlesource.com/1930
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-22 00:31:57 +00:00
mischief
640c0f3849 runtime: fix brk_ signature for plan9
with uintptr, the check for < 0 will never succeed in mem_plan9.go's
sbrk() because the brk_ syscall returns -1 on failure. fixes the plan9/amd64 build.

this failed on plan9/amd64 because of the attempt to allocate 136GB in mallocinit(),
which failed. it was just by chance that on plan9/386 allocations never failed.

Change-Id: Ia3059cf5eb752e20d9e60c9619e591b80e8fb03c
Reviewed-on: https://go-review.googlesource.com/1590
Reviewed-by: Anthony Martin <ality@pbrane.org>
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
2014-12-20 21:41:44 +00:00
Matthew Dempsky
481ce36ec4 runtime: simplify cpuprof hash calculation
"x*41" computes the same value as "x*31 + x*7 + x*3" and (when
compiled by gc) requires just one multiply instruction instead of
three.

Alternatively, the expression could be written as "(x<<2+x)<<3 + x" to
use shifts instead of multiplies (which is how GCC optimizes "x*41").
But gc currently emits suboptimal instructions for this expression
anyway (e.g., separate SHL+ADD instructions rather than LEA on
386/amd64). Also, if such an optimization was worthwhile, it would
seem better to implement it as part of gc's strength reduction logic.

Change-Id: I7156b793229d723bbc9a52aa9ed6111291335277
Reviewed-on: https://go-review.googlesource.com/1830
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-19 02:50:40 +00:00
Alex Brainman
3f19541752 runtime: use go generate for zcallback_windows.go
replacement for CL 180640043

Change-Id: I8ff36645cfcbbda338faf7b29cbfdb95c47d5ec4
Reviewed-on: https://go-review.googlesource.com/1765
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-19 02:45:40 +00:00
Shenghou Ma
340ef004d6 runtime/cgo: guard against redefinition of PTHREAD_KEYS_MAX
Fixes #9374.

Change-Id: Ic53757eba98fc43bcd24e25e03876fef917b4da1
Reviewed-on: https://go-review.googlesource.com/1751
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2014-12-18 21:23:25 +00:00
Guobiao Mei
6ce3cd18fa runtime: fix a minor typo in comments
Change-Id: I13a8aacd1b8243c992b539ab6bf7b5dff2a1393a
Reviewed-on: https://go-review.googlesource.com/1757
Reviewed-by: Minux Ma <minux@golang.org>
2014-12-18 20:35:56 +00:00
Rick Hudson
1b0b0db6fb runtime: add profiling infrastructure for the Concurrent GC
Change-Id: Ia7a007444eeb1503cec27367a5c6699ce0bf4af6
Reviewed-on: https://go-review.googlesource.com/1441
Reviewed-by: Austin Clements <austin@google.com>
2014-12-16 22:15:51 +00:00
Keith Randall
50bc3d5bbc runtime: fix deadlock in runtime.Stack
It shouldn't semacquire() inside an acquirem(), the runtime
thinks that means deadlock.  It actually isn't a deadlock, but it
looks like it because acquirem() does m.locks++.

Candidate for inclusion in 1.4.1.  runtime.Stack with all=true
is pretty unuseable in GOMAXPROCS>1 environment.

fixes #9321

Change-Id: Iac6b664217d24763b9878c20e49229a1ecffc805
Reviewed-on: https://go-review.googlesource.com/1600
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2014-12-16 17:04:45 +00:00
Brad Fitzpatrick
fccd942803 runtime: gofmt
Fixes #9339

Change-Id: I22faf2593cb73f42612c2c2bfe38de001fb2746b
Reviewed-on: https://go-review.googlesource.com/1630
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-16 06:16:00 +00:00
Keith Randall
df1739c77d runtime: if key type is reflexive, don't call equal(k, k)
Most types are reflexive (k == k for all k of type t), so don't
bother calling equal(k, k) when the key type is reflexive.

Change-Id: Ia716b4198b8b298687843b94b878dbc5e8fc2c65
Reviewed-on: https://go-review.googlesource.com/1480
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-15 21:43:49 +00:00
David Crawshaw
324f38a222 runtime: shrink initial arena if reservation fails
Fixes #9311

Change-Id: I2f142e65a54c0391084316d79a42714ba42dd8b9
Reviewed-on: https://go-review.googlesource.com/1514
Reviewed-by: Keith Randall <khr@golang.org>
2014-12-15 20:55:33 +00:00
Russ Cox
557a61d270 cmd/gc: add //go:nowritebarrier to diagnose unintended write barriers
//go:nowritebarrier can only be used in package runtime.
It does not disable write barriers; it is an assertion, checked
by the compiler, that the following function needs no write
barriers.

Change-Id: Id7978b779b66dc1feea39ee6bda9fd4d80280b7c
Reviewed-on: https://go-review.googlesource.com/1224
Reviewed-by: Rick Hudson <rlh@golang.org>
2014-12-12 20:48:10 +00:00
Keith Randall
1757b5cc74 runtime: fix nacl build
Change-Id: Ifa8b2d1d1cebe72f795db34974584a888d55cbd8
Reviewed-on: https://go-review.googlesource.com/1362
Reviewed-by: Keith Randall <khr@golang.org>
2014-12-11 07:31:32 +00:00
Keith Randall
7a4a64e8f3 runtime: faster aeshash implementation
The aesenc instruction has high latency.  For hashing large objects,
hash several streams in parallel.

benchmark                         old ns/op     new ns/op     delta
BenchmarkHash5                    7.02          7.45          +6.13%
BenchmarkHash16                   6.53          6.94          +6.28%
BenchmarkHash32                   8.38          8.26          -1.43%
BenchmarkHash64                   12.6          12.0          -4.76%
BenchmarkHash1024                 247           62.9          -74.53%
BenchmarkHash65536                17335         2966          -82.89%
BenchmarkHashInt32Speed           14.7          14.9          +1.36%
BenchmarkHashInt64Speed           14.6          14.9          +2.05%
BenchmarkHashBytesSpeed           35.4          28.6          -19.21%
BenchmarkHashStringSpeed          22.0          20.4          -7.27%
BenchmarkHashStringArraySpeed     65.8          56.3          -14.44%

Change-Id: Ia8ba03063acc64a9066b8ab2d79f2c9aaac1770f
Reviewed-on: https://go-review.googlesource.com/1330
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-11 05:23:00 +00:00
David Crawshaw
bee8ae1185 runtime: send android stderr to /dev/log/main
I tried to submit this in Go 1.4 as cl/107540044 but tripped over the
changes for getting C off the G stack. This is a rewritten version that
avoids cgo and works directly with the underlying log device.

Change-Id: I14c227dbb4202690c2c67c5a613d6c6689a6662a
Reviewed-on: https://go-review.googlesource.com/1285
Reviewed-by: Keith Randall <khr@golang.org>
2014-12-10 22:06:13 +00:00
Keith Randall
6820be25da runtime: clean up & go-ify the hash function seeder
Change-Id: I0e95f8a5962c547da20e19a356ae1cf8375c9107
Reviewed-on: https://go-review.googlesource.com/1270
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-10 21:15:35 +00:00
Keith Randall
b796cbc406 runtime: fix finalizer iterator
It could only handle one finalizer before it raised an out-of-bounds error.

Fixes issue #9172

Change-Id: Ibb4d0c8aff2d78a1396e248c7129a631176ab427
Reviewed-on: https://go-review.googlesource.com/1201
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-10 16:33:26 +00:00
Rick Hudson
2937d88af5 runtime: fix some comment formatting
Change-Id: Ife7d6ce1131ff26444f09e8fda4f61344e669e21
Reviewed-on: https://go-review.googlesource.com/1260
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-09 22:08:45 +00:00
Austin Clements
76f71959c8 runtime: restore error message on early needm
needm used to print an error before exiting when it was called too
early, but this error was lost in the transition to Go.  Bring back
the error so we don't silently exit(1) when this happens.

Change-Id: I8086932783fd29a337d7dea31b9d6facb64cb5c1
Reviewed-on: https://go-review.googlesource.com/1226
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-09 20:12:14 +00:00
Keith Randall
8eb8b40a49 runtime: use doubly-linked lists for channel send/recv queues.
Avoids a potential O(n^2) performance problem when dequeueing
from very popular channels.

benchmark                old ns/op     new ns/op     delta
BenchmarkChanPopular     2563782       627201        -75.54%

Change-Id: I231aaeafea0ecd93d27b268a0b2128530df3ddd6
Reviewed-on: https://go-review.googlesource.com/1200
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-08 19:20:12 +00:00
Austin Clements
006ceb2f1d runtime: fix missing newline when dumping bad symbol table
If the symbol table isn't sorted, we print it and abort.  However, we
were missing the line break after each symbol, resulting in one
gigantic line instead of a nicely formatted table.

Change-Id: Ie5c6f3c256d0e648277cb3db4496512a79d266dd
Reviewed-on: https://go-review.googlesource.com/1182
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-08 18:39:58 +00:00
Russ Cox
31457cef6d all: merge dev.garbage (d1238958d4ae) into default branch
When we start work on Gerrit, ppc64 and garbage collection
work will continue in the master branch, not the dev branches.

(We may still use dev branches for other things later, but
these are ready to be merged, and doing it now, before moving
to Git means we don't have to have dev branches working
in the Gerrit workflow on day one.)

TBR=rlh
CC=golang-codereviews
https://golang.org/cl/183140043
2014-12-05 20:34:45 -05:00
Russ Cox
db40624110 [dev.garbage] runtime: raise StackGuard limit for Windows (again)
640 bytes ought to be enough for anybody.

We'll bring this back down before Go 1.5. That's issue 9214.

TBR=rlh
CC=golang-codereviews
https://golang.org/cl/188730043
2014-12-05 19:50:09 -05:00
Russ Cox
09d92b6bbf all: power64 is now ppc64
Fixes #8654.

LGTM=austin
R=austin
CC=golang-codereviews
https://golang.org/cl/180600043
2014-12-05 19:13:20 -05:00
Russ Cox
fa6c54953c [dev.garbage] runtime: reduce stack footprint of write barriers
This is going to hurt a bit but we'll make it better later.
Now the race detector can be run again.

I added the write barrier optimizations from
CL 183020043 to try to make it hurt a little less.

TBR=rlh
CC=golang-codereviews
https://golang.org/cl/185070043
2014-12-05 16:47:50 -05:00
Russ Cox
dcb2ec3b65 runtime: generate windows callback list with go generate
This is the last system-dependent file written by cmd/dist.
They are all now written by go generate.

cmd/dist is not needed to start building package runtime
for a different system anymore.

Now all the generated files can be assumed generated, so
delete the clumsy hacks in cmd/api.

Re-enable api check in run.bash.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/185040044
2014-12-05 16:24:20 -05:00
Russ Cox
7d516079de runtime: convert netbsd/arm to Go
This was the last src/runtime/*.c file.

LGTM=austin
R=austin
CC=golang-codereviews
https://golang.org/cl/187770043
2014-12-05 16:17:09 -05:00
Russ Cox
444839014b [dev.garbage] all: merge dev.cc (81884b89bd88) into dev.garbage
TBR=rlh
CC=golang-codereviews
https://golang.org/cl/181100044
2014-12-05 11:40:41 -05:00
Russ Cox
829b286f2c [dev.cc] all: merge default (8d42099cdc23) into dev.cc
TBR=austin
CC=golang-codereviews
https://golang.org/cl/178700044
2014-12-05 11:18:10 -05:00
Russ Cox
2b62e1eaec runtime: fix hang in GC due to shrinkstack vs netpoll race
During garbage collection, after scanning a stack, we think about
shrinking it to reclaim some memory. The shrinking code (called
while the world is stopped) checked that the status was Gwaiting
or Grunnable and then changed the state to Gcopystack, to essentially
lock the stack so that no other GC thread is scanning it.
The same locking happens for stack growth (and is more necessary there).

        oldstatus = runtime·readgstatus(gp);
        oldstatus &= ~Gscan;
        if(oldstatus == Gwaiting || oldstatus == Grunnable)
                runtime·casgstatus(gp, oldstatus, Gcopystack); // oldstatus is Gwaiting or Grunnable
        else
                runtime·throw("copystack: bad status, not Gwaiting or Grunnable");

Unfortunately, "stop the world" doesn't stop everything. It stops all
normal goroutine execution, but the network polling thread is still
blocked in epoll and may wake up. If it does, and it chooses a goroutine
to mark runnable, and that goroutine is the one whose stack is shrinking,
then it can happen that between readgstatus and casgstatus, the status
changes from Gwaiting to Grunnable.

casgstatus assumes that if the status is not what is expected, it is a
transient change (like from Gwaiting to Gscanwaiting and back, or like
from Gwaiting to Gcopystack and back), and it loops until the status
has been restored to the expected value. In this case, the status has
changed semi-permanently from Gwaiting to Grunnable - it won't
change again until the GC is done and the world can continue, but the
GC is waiting for the status to change back. This wedges the program.

To fix, call a special variant of casgstatus that accepts either Gwaiting
or Grunnable as valid statuses.

Without the fix bug with the extra check+throw in casgstatus, the
program below dies in a few seconds (2-10) with GOMAXPROCS=8
on a 2012 Retina MacBook Pro. With the fix, it runs for minutes
and minutes.

package main

import (
        "io"
        "log"
        "net"
        "runtime"
)

func main() {
        const N = 100
        for i := 0; i < N; i++ {
                l, err := net.Listen("tcp", "127.0.0.1:0")
                if err != nil {
                        log.Fatal(err)
                }
                ch := make(chan net.Conn, 1)
                go func() {
                        var err error
                        c1, err := net.Dial("tcp", l.Addr().String())
                        if err != nil {
                                log.Fatal(err)
                        }
                        ch <- c1
                }()
                c2, err := l.Accept()
                if err != nil {
                        log.Fatal(err)
                }
                c1 := <-ch
                l.Close()
                go netguy(c1, c2)
                go netguy(c2, c1)
                c1.Write(make([]byte, 100))
        }
        for {
                runtime.GC()
        }
}

func netguy(r, w net.Conn) {
        buf := make([]byte, 100)
        for {
                bigstack(1000)
                _, err := io.ReadFull(r, buf)
                if err != nil {
                        log.Fatal(err)
                }
                w.Write(buf)
        }
}

var g int

func bigstack(n int) {
        var buf [100]byte
        if n > 0 {
                bigstack(n - 1)
        }
        g = int(buf[0]) + int(buf[99])
}

Fixes #9186.

LGTM=rlh
R=austin, rlh
CC=dvyukov, golang-codereviews, iant, khr, r
https://golang.org/cl/179680043
2014-12-01 16:32:06 -05:00
Russ Cox
b8540fc288 [dev.garbage] all: merge dev.cc (493ad916c3b1) into dev.garbage
TBR=austin
CC=golang-codereviews
https://golang.org/cl/179290043
2014-11-24 12:07:11 -05:00
Joel Sing
6ddc2cb80c [dev.cc] runtime: convert dragonfly/386 port to Go
LGTM=rsc
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/178210043
2014-11-25 03:15:11 +11:00
Joel Sing
0d76887433 [dev.cc] runtime: convert netbsd/386 port to Go
LGTM=minux
R=rsc, minux
CC=golang-codereviews
https://golang.org/cl/177170043
2014-11-22 22:09:11 +11:00
Joel Sing
cfc8099a9a [dev.cc] runtime: convert netbsd/amd64 port to Go
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/169620043
2014-11-22 16:05:31 +11:00
Shenghou Ma
d3526ea0f6 [dev.cc] runtime: migrate Android/ARM port to Go.
I tested building Go itself, but not any of go.mobile tests.

LGTM=crawshaw
R=crawshaw, rsc
CC=golang-codereviews
https://golang.org/cl/179110043
2014-11-21 18:15:30 -05:00
Shenghou Ma
adbca13cb3 [dev.cc] runtime: explicitly exclude android in zgoos_linux.go
Otherwise both zgoos_linux.go and zgoos_android.go will be compiled
for GOOS=android.

LGTM=crawshaw, rsc
R=rsc, crawshaw
CC=golang-codereviews
https://golang.org/cl/178110043
2014-11-21 18:13:59 -05:00
Rick Hudson
273507aa8f [dev.garbage] runtime: Stop running gs during the GCscan phase.
Ensure that all gs are in a scan state when their stacks are being scanned.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179160044
2014-11-21 16:46:27 -05:00
Russ Cox
8c3f64022a [dev.garbage] runtime: add prefetcht0, prefetcht1, prefetcht2, prefetcht3, prefetchnta for GC
We don't know what we need yet, so add them all.
Add them even on x86 architectures (as no-ops) so that
the GC can refer to them unconditionally.

Eventually we'll know what we want and probably
have just one 'prefetch' with an appropriate meaning
on each architecture.

LGTM=rlh
R=rlh
CC=golang-codereviews
https://golang.org/cl/179160043
2014-11-21 15:57:10 -05:00
David du Colombier
e9c57d8a2d [dev.cc] runtime: convert Plan 9 port to Go
Thanks to Aram Hăvărneanu, Nick Owens
and Russ Cox for the early reviews.

LGTM=aram, rsc
R=rsc, lucio.dere, aram, ality
CC=golang-codereviews, mischief
https://golang.org/cl/175370043
2014-11-21 19:39:01 +01:00
Russ Cox
ad8179281d [dev.cc] runtime: convert nacl support to Go
LGTM=dave
R=minux, dave
CC=golang-codereviews
https://golang.org/cl/181030043
2014-11-21 10:22:18 -05:00
Alex Brainman
841de809bb [dev.cc] runtime: windows does not use _cgo_setenv and _cgo_unsetenv
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/175480043
2014-11-21 15:59:22 +11:00
Alex Brainman
0a38b2cdaf [dev.cc] runtime: fix windows goenvs conversion mistake
uint16 occupies 2 bytes, not 1

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/178100043
2014-11-21 12:15:18 +11:00
Rick Hudson
cc73a44f67 [dev.garbage] runtime: Fix constant overflow on 32 bit machines
LGTM=rsc
R=golang-codereviews
CC=golang-codereviews, rsc
https://golang.org/cl/180040043
2014-11-20 14:24:01 -05:00
Rick Hudson
8cfb084534 [dev.garbage] runtime: Turn concurrent GC on by default. Avoid write barriers for GC internal structures such as free lists.
LGTM=rsc
R=rsc
CC=golang-codereviews, rsc
https://golang.org/cl/179000043
2014-11-20 12:08:13 -05:00
Russ Cox
50e0749f87 [dev.cc] all: merge default (e4ab8f908aac) into dev.cc
TBR=austin
CC=golang-codereviews
https://golang.org/cl/179040044
2014-11-20 11:48:08 -05:00
Dmitriy Vyukov
2b3f379080 runtime: fix atomic operations on non-heap addresses
Race detector runtime does not tolerate operations on addresses
that was not previously declared with __tsan_map_shadow
(namely, data, bss and heap). The corresponding address
checks for atomic operations were removed in
https://golang.org/cl/111310044
Restore these checks.
It's tricker than just not calling into race runtime,
because it is the race runtime that makes the atomic
operations themselves (if we do not call into race runtime
we skip the atomic operation itself as well). So instead we call
__tsan_go_ignore_sync_start/end around the atomic operation.
This forces race runtime to skip all other processing
except than doing the atomic operation itself.
Fixes #9136.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179030043
2014-11-20 09:51:02 -05:00
Alex Brainman
ab4578adef [dev.cc] runtime: convert remaining windows C code to Go
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/177090043
2014-11-20 12:24:03 +11:00
Russ Cox
378c2515ae runtime: remove assumption that noptrdata data bss noptrbss are ordered and contiguous
The assumption can be violated by external linkers reordering them or
inserting non-Go sections in between them. I looked briefly at trying
to write out the _go_.o in external linking mode in a way that forced
the ordering, but no matter what there's no way to force Go's data
and Go's bss to be next to each other. If there is any data or bss from
non-Go objects, it's very likely to get stuck in between them.

Instead, rewrite the two places we know about that make the assumption.
I grepped for noptrdata to look for more and didn't find any.

The added race test (os/exec in external linking mode) fails without
the changes in the runtime. It crashes with an invalid pointer dereference.

Fixes #9133.

LGTM=dneil
R=dneil
CC=dvyukov, golang-codereviews, iant
https://golang.org/cl/179980043
2014-11-19 15:25:33 -05:00
Austin Clements
f4a525452e [dev.cc] runtime: add explicit siginfo.si_addr field
struct siginfo_t's si_addr field is part of a union.
Previously, we represented this union in Go using an opaque
byte array and accessed the si_addr field using unsafe (and
wrong on 386 and arm!) pointer arithmetic.  Since si_addr is
the only field we use from this union, this replaces the
opaque byte array with an explicit declaration of the si_addr
field and accesses it directly.

LGTM=minux, rsc
R=rsc, minux
CC=golang-codereviews
https://golang.org/cl/179970044
2014-11-19 14:56:49 -05:00