Dmitriy Vyukov [Wed, 15 May 2013 19:50:32 +0000 (23:50 +0400)]
runtime: fix GC scanning of slices
If a slice points to an array embedded in a struct,
the whole struct can be incorrectly scanned as the slice buffer.
Fixes #5443.
Dmitriy Vyukov [Wed, 15 May 2013 17:22:32 +0000 (21:22 +0400)]
runtime: add simple malloc benchmarks
Allocs of size 16 can bypass atomic set of the allocated bit, while allocs of size 8 can not.
Allocs with and w/o type info hit different paths inside of malloc.
Current results on linux/amd64:
BenchmarkMalloc8 50000000 43.6 ns/op
BenchmarkMalloc16 50000000 46.7 ns/op
BenchmarkMallocTypeInfo8 50000000 61.3 ns/op
BenchmarkMallocTypeInfo16 50000000 63.5 ns/op
Dmitriy Vyukov [Wed, 15 May 2013 14:35:05 +0000 (18:35 +0400)]
runtime: transfer whole span from MCentral to MCache
Finer-grained transfers were relevant with per-M caches,
with per-P caches they are not relevant and harmful for performance.
For few small size classes where it makes difference,
it's fine to grab the whole span (4K).
benchmark old ns/op new ns/op delta
BenchmarkMalloc 42 40 -4.45%
Adam Langley [Wed, 15 May 2013 14:27:34 +0000 (10:27 -0400)]
crypto/rsa: check for minimal PKCS#1 v1.5 padding.
The PKCS#1 spec requires that the PS padding in an RSA message be at
least 8 bytes long. We were not previously checking this. This isn't
important in the most common situation (session key encryption), but
the impact is unclear in other cases.
Adam Langley [Wed, 15 May 2013 14:25:54 +0000 (10:25 -0400)]
crypto/tls: ignore empty TLS records.
OpenSSL can be configured to send empty records in order to randomise
the CBC IV. This is an early version of 1/n-1 record splitting (that Go
does) and is quite reasonable, but it results in tls.Conn.Read
returning (0, nil).
This change ignores up to 100 consecutive, empty records to avoid
returning (0, nil) to callers.
Adam Langley [Wed, 15 May 2013 14:03:22 +0000 (10:03 -0400)]
math/big: save some copies in binaryGCD.
This patch resulted from a bit of quick optimisation in response to a
golang-nuts post. It looks like one could save a couple other copies in
this function, but this addresses the inner loop and is fairly simple.
Dmitriy Vyukov [Wed, 15 May 2013 12:48:41 +0000 (16:48 +0400)]
runtime: unset m->locks after actual lock unlock
This is needed for preemptive scheduler,
it will preempt only when m->locks==0,
and we do not want to be preempted while
we have not completely unlocked the lock.
Alexey Borzenkov [Wed, 15 May 2013 03:24:54 +0000 (13:24 +1000)]
os/user: faster user lookup on Windows
Trying to lookup user's display name with directory services can
take several seconds when user's computer is not in a domain.
As a workaround, check if computer is joined in a domain first,
and don't use directory services if it is not.
Additionally, don't leak tokens in user.Current().
Fixes #5298.
Jonathan Hseu [Wed, 15 May 2013 00:14:59 +0000 (17:14 -0700)]
testing/quick: fix for aliased types, delete duplicate uint8 test, and fix randFloat64() to give random numbers from (-math.MaxFloat64, math.MaxFloat64).
Brad Fitzpatrick [Tue, 14 May 2013 22:50:46 +0000 (15:50 -0700)]
encoding/json: allocate less in NewEncoder
The *Encoder is almost always garbage. It doesn't need an
encodeState inside of it (and its bytes.Buffer), since it's
only needed locally inside of Encode.
benchmark old ns/op new ns/op delta
BenchmarkEncoderEncode 2562 2553 -0.35%
benchmark old bytes new bytes delta
BenchmarkEncoderEncode 283 102 -63.96%
Alberto García Hierro [Tue, 14 May 2013 22:33:46 +0000 (15:33 -0700)]
net/http: Fix basic authentication with empty password
The encoded string must include the : separating the username
and the password, even when the latter is empty. See
http://www.ietf.org/rfc/rfc2617.txt for more information.
Bill Thiede [Tue, 14 May 2013 16:54:16 +0000 (09:54 -0700)]
misc/vim: test.sh seems to only work on Mac OS X.
cmp(1) on FreeBSD requires two file arguments. grep -P on Linux (at least
Ubuntu 12.04) is described in the man page as "This is highly
experimental" and doesn't seem to work. On FreeBSD the man page states
"This option is not supported in FreeBSD." Needed this to work while
debugging some funky behavior of 'Import' in my local vim setup.
Dmitriy Vyukov [Mon, 13 May 2013 06:28:12 +0000 (10:28 +0400)]
runtime/race: improve public documentation
Move the documentation from race.go to doc.go, because
race.go uses +build race, so it's not normally parsed by go doc.
Rephrase the documentation for end users, provide link to race
detector manual.
Fixes #5444.
R=golang-dev, minux.ma, adg, r
CC=golang-dev
https://golang.org/cl/9144050
Ian Lance Taylor [Wed, 8 May 2013 21:58:34 +0000 (14:58 -0700)]
runtime: fix crash in select
runtime.park() can access freed select descriptor
due to a racing free in another thread.
See the comment for details.
Slightly modified version of dvyukov's CL 9259045.
No test yet. Before this CL, the test described in issue 5422
would fail about every 40 times for me. With this CL, I ran
the test 5900 times with no failures.
Fixes #5422.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9311043
Dmitriy Vyukov [Mon, 6 May 2013 23:15:03 +0000 (16:15 -0700)]
runtime: fix crash in badsignal()
The linker can generate split stack prolog when a textflag 7 function
makes an indirect function call. If it happens, badsignal() crashes
trying to dereference g.
Fixes #5337.
Shenghou Ma [Mon, 6 May 2013 22:53:02 +0000 (06:53 +0800)]
runtime: reduce max arena size on windows/amd64 to 32 GiB
Update #5236
Update #5402
This CL reduces gofmt's committed memory from 545864 KiB to 139568 KiB.
Note: Go 1.0.3 uses about 70MiB.
Jeremiah Harmsen [Mon, 6 May 2013 17:15:16 +0000 (10:15 -0700)]
go/doc/example: Fix bug causing false negatives for Example playability.
Allows Examples with KeyValue expressions to be playable in godoc.
During the traversal of the abstract syntax tree any KeyValueExpr Key.Name was incorrectly being added as an unresolved identifier.
Since this identifier could not be provided the Example was marked as unplayable.
This updates the AST traversal to skip Keys (but continue traversing the Values).
Example of problematic AST now fixed (see L99 where "UpperBound" was being added as a missing identifier):
David du Colombier [Wed, 1 May 2013 22:48:13 +0000 (15:48 -0700)]
libmach: fix build on Plan 9
Include libc.h before bio.h in 8.c, because bio.h uses
the UTFmax enum, which is declared in libc.h, since
the recent switch to 21-bit runes in Plan 9.
The 5.c and 6.c files already includes libc.h.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9040047
Ian Lance Taylor [Wed, 1 May 2013 21:30:19 +0000 (14:30 -0700)]
cmd/ld: fix syms that are both cgo_import_static & cgo_import_dynamic
This is needed for SWIG when linking in internal mode. In
internal mode if a symbol was cgo_import_static we used to
forget that it was also cgo_import_dynamic.
R=rsc, r
CC=golang-dev
https://golang.org/cl/9080043
This makes the 'go run' command different from every other command.
For example, 'go test' does not mean 'go test *.go'.
If we were going to handle the no arguments case in 'go run', I would hope that
it would scan the current directory to find a package just like 'go build' or
'go test' would, and then it would require that package to be 'package main',
and then it would run that package. This would make it match 'go test' and 'go
build' and 'go install' and so on. It would mean that if you are working on a
command in a directory that is 'go install'able, then 'go run' will run the
binary for you. The current CL does not accomplish that when build constraints
or file name constraints are involved.
For example, if I am working on a program like:
$ ls
main.go
main_386.s
main_arm.s
main_amd64.s
$
Then 'go run' will fail here because the .s files are ignored.
If instead I am working on a program like:
$ ls
main.go
main_386.go
main_arm.go
main_amd64.go
$
then 'go run' will fail because too many files are included.
I would like to see this command implemented so that it is compatible with the
other go subcommands. Since it is too late to do that for Go 1.1, I would like
to see this CL reverted, to preserve the option to do it better later.
R=golang-dev, iant, r
CC=golang-dev
https://golang.org/cl/8797049
Ian Lance Taylor [Tue, 30 Apr 2013 21:01:05 +0000 (14:01 -0700)]
cmd/ld: emit relocs for DWARF info when doing an external link
I would like opinions on whether this is a good idea for 1.1.
On the one hand it's a moderately important issue. On the
other hand this introduces at least the possibility of
external linker errors due to the additional relocations and
it may be better to wait.
I'm fairly confident that the behaviour is unchanged when not
using an external linker.
Update #5221
This CL is tested lightly on 386 and amd64 and fixes the cases
I tested. I have not tested it on Darwin or Windows.
Rob Pike [Tue, 30 Apr 2013 16:10:10 +0000 (09:10 -0700)]
cmd/ld: fix check for address wrap in relocation
PC-relative needs a signed offset; others need unsigned.
Also fix signedness of 32-bit relocation on Windows.
Rob Pike [Tue, 30 Apr 2013 05:44:40 +0000 (22:44 -0700)]
cmd/gc: fix some overflows in the compiler
Some 64-bit fields were run through 32-bit words, some counts were
not checked for overflow, and relocations must fit in 32 bits.
Tests to follow.
Rob Pike [Tue, 30 Apr 2013 05:44:20 +0000 (22:44 -0700)]
cmd/ld: fix some 64-bit issues
A few places in the linker pushed 64-bit values through 32-bit holes,
including in relocation.
Clean them up, and check for a few other overflows as well.
Tests to follow.
Shenghou Ma [Mon, 29 Apr 2013 20:13:32 +0000 (04:13 +0800)]
runtime: fix stack pointer corruption in runtime.cgocallback_gofunc()
runtime.setmg() calls another function (cgo_save_gm), so it must save
LR onto stack.
Re-enabled TestCthread test in misc/cgo/test.
Fixes #4863.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9019043
database/sql: fix driver Conn refcounting with prepared statements
The refcounting of driver Conns was completedly busted and
would leak (be held open forever) with any reasonable
load. This was a significant regression from Go 1.0.
The core of this patch is removing one line:
s.db.addDep(dc, s)
A database conn (dc) is a resource that be re-created any time
(but cached for speed) should not be held open forever with a
dependency refcount just because the Stmt (s) is alive (which
typically last for long periods of time, like forever).
The meat of the patch is new tests. In fixing the real issue,
a lot of tests then failed due to the fakedb_test.go's paranoia
about closing a fakeConn while it has open fakeStmts on it. I
could've ignored that, but that's been a problem in the past for
other bugs.
Instead, I now track per-Conn open statements and close them
when the the conn closes. The proper way to do this would've
been making *driverStmt a finalCloser and using the dep mechanism,
but it was much more invasive. Added a TODO instead.
I'd like to give a way for drivers to opt-out of caring about
driver.Stmt closes before a driver.Conn close, but that's a TODO
for the future, and that TODO is added in this CL.
I know this is very late for Go 1.1, but database/sql is
currently nearly useless without this.
I'd like to believe all these database/sql bugs in the past
release cycle are the result of increased usage, number of
drivers, and good feedback from increasingly-capable Go
developers, and not the result of me sucking. It's also hard
with all the real drivers being out-of-tree, so I'm having to
add more and more hooks to fakedb_test.go to simulate things
which real drivers end up doing.
Fixes #5323
R=golang-dev, snaury, gwenn.kahz, google, r
CC=golang-dev
https://golang.org/cl/8836045
Anthony Martin [Tue, 23 Apr 2013 23:02:50 +0000 (16:02 -0700)]
cmd/dist: fix line numbers in goc2c generated files
We have to reset the global lineno variable before
processing each file otherwise line numbers will be
offset by the number of lines in the previous file.
The following examples are from the beginning of the
ztime_linux_amd64.c file which is generated from
time.goc in the runtime package.