]> Cypherpunks repositories - gostls13.git/log
gostls13.git
10 years agoruntime: Change memprofrate to memprofilerate
Lynn Boger [Tue, 3 Feb 2015 18:13:31 +0000 (12:13 -0600)]
runtime:  Change memprofrate to memprofilerate

Use memprofilerate in GODEBUG instead of memprofrate to be
consistent with other uses.

Change-Id: Iaf6bd3b378b1fc45d36ecde32f3ad4e63ca1e86b
Reviewed-on: https://go-review.googlesource.com/3800
Reviewed-by: Ian Lance Taylor <iant@golang.org>
10 years agomath/big: implement precise Float to decimal conversion (core functionality)
Robert Griesemer [Tue, 3 Feb 2015 00:31:13 +0000 (16:31 -0800)]
math/big: implement precise Float to decimal conversion (core functionality)

Change-Id: Ic0153397922ded28a5cb362e86ecdfec42e92163
Reviewed-on: https://go-review.googlesource.com/3752
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agomath/big: fix typos
Robert Griesemer [Sat, 31 Jan 2015 00:33:31 +0000 (16:33 -0800)]
math/big: fix typos

Change-Id: Icb1490f97584d61823339ae809b88d423b185e64
Reviewed-on: https://go-review.googlesource.com/3751
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agomath/big: build Float.Format on top of Float.Append
Robert Griesemer [Fri, 30 Jan 2015 23:57:38 +0000 (15:57 -0800)]
math/big: build Float.Format on top of Float.Append

Change-Id: I444eec24467f827caa5c88a1c5ae5bce92508b98
Reviewed-on: https://go-review.googlesource.com/3750
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agoliblink: define fixed A-numbers for common instructions
Russ Cox [Fri, 30 Jan 2015 01:19:07 +0000 (20:19 -0500)]
liblink: define fixed A-numbers for common instructions

This makes names like ANOP, ATEXT, AGLOBL, ACALL, AJMP, ARET
available for use by architecture-independent processing passes.

On arm and ppc64, the alternate names are now aliases for the
official ones (ABL for ACALL, AB or ABR for AJMP, ARETURN for ARET).

Change-Id: Id027771243795af2b3745199c645b6e1bedd7d18
Reviewed-on: https://go-review.googlesource.com/3577
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Austin Clements <austin@google.com>
10 years agoliblink: place DATA size in from3.offset always
Russ Cox [Fri, 30 Jan 2015 00:42:01 +0000 (19:42 -0500)]
liblink: place DATA size in from3.offset always

Like the TEXT/GLOBL flags, this was split between from.scale and reg,
neither of which is appropriate.

Change-Id: I2a16ef066a53b6edb7afb16cce108c0d1d26389c
Reviewed-on: https://go-review.googlesource.com/3576
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Austin Clements <austin@google.com>
10 years agoliblink: the zero Prog is now valid and ready for use
Russ Cox [Thu, 29 Jan 2015 21:16:24 +0000 (16:16 -0500)]
liblink: the zero Prog is now valid and ready for use

Use AXXX instead of AGOK (neither is a valid instruction but AXXX is zero)
for the initial setting of Prog.as, and now there are no non-zero default
field settings.

Remove the arch-specific zprog/zprg in favor of a single global zprog.
Remove the arch-specific prg constructor in favor of emallocz(sizeof(Prog)).

Change-Id: Ia73078726768333d7cdba296f548170c1bea9498
Reviewed-on: https://go-review.googlesource.com/3575
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Austin Clements <austin@google.com>
10 years agoliblink: remove dead computation of p->back in span6/span8
Russ Cox [Thu, 29 Jan 2015 20:35:56 +0000 (15:35 -0500)]
liblink: remove dead computation of p->back in span6/span8

Originally, when this code was part of 6l/8l, every new
Prog was constructed starting with zprg, which set back=2,
and then this code walked over the list setting back=1 for
backward branches, back=0 otherwise. The initial back=2
setting was used to identify forward branches (the branched-to
instruction had back == 2 since it hadn't yet been set to 0 or 1).

When the code was extracted into liblink and linked directly
with 6a/6g/8a/8g, those programs created the Prog struct
and did not set back=2, breaking this backward branch detection.

No one noticed, because the next loop recomputes the information.
The only requirement for the next loop is that p->back == 0 or 1 for
each of the Progs in the list.

The initialization of the zprg with back=2 would cause problems
in this second loop, for the few liblink-internally-generated instructions
that are created by copying zprg, except that the first loop was
making sure that back == 0 or 1.

The first loop's manipulation of p->back can thus be deleted,
provided we also delete the zprg.back = 2 initializations.

This is awful and my fault. I apologize.

While we're here, remove the .scale = 1 from the zprg init too.
Anything that sets up a scaled index should set the scale itself.
(And mostly those come from outside liblink anyway.)

Tested by checking that all generated code is bit-for-bit
identical to before this CL.

Change-Id: I7f6e0b33ce9ccd5b7dc25e0f00429fedd0957c8c
Reviewed-on: https://go-review.googlesource.com/3574
Reviewed-by: Austin Clements <austin@google.com>
10 years agoliblink: renumber ARM conditions to make C_SCOND_NONE == 0
Russ Cox [Thu, 29 Jan 2015 20:18:22 +0000 (15:18 -0500)]
liblink: renumber ARM conditions to make C_SCOND_NONE == 0

A step toward making the zero Prog useful.

Change-Id: I427b98b1ce9bd8f093da825aa4bb83244fc01903
Reviewed-on: https://go-review.googlesource.com/3573
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Austin Clements <austin@google.com>
10 years agoliblink: place TEXT/GLOBL flags in p->from3 always
Russ Cox [Thu, 29 Jan 2015 19:58:54 +0000 (14:58 -0500)]
liblink: place TEXT/GLOBL flags in p->from3 always

Before, amd64 and 386 stored the flags in p->from.scale
and arm and ppc64 stored the flags in p->reg.
Both caused special cases in printing and in handling of the
addresses.

To avoid possible conflicts with the real meaning of p->from
and to avoid storing a non-register value in a reg field,
use from3 to hold a TYPE_CONST value giving the flags.

There is still a special case for printing, because the flags
are specified without a $, and normally a TYPE_CONST prints
with a $. But that's much less special than what came before.

This allows us to remove the textflag and settextflag methods
from LinkArch. They are no longer architecture-specific.

Change-Id: I931da8e1ecd92e127cd9aa44ef5a73c42e730110
Reviewed-on: https://go-review.googlesource.com/3572
Reviewed-by: Austin Clements <austin@google.com>
10 years agoliblink: use same TEXT $frame-arg encoding for all architectures
Russ Cox [Thu, 29 Jan 2015 17:26:21 +0000 (12:26 -0500)]
liblink: use same TEXT $frame-arg encoding for all architectures

Change-Id: I3417a8c5ddd7f405939edc9fdef086e4741495a1
Reviewed-on: https://go-review.googlesource.com/3571
Reviewed-by: Austin Clements <austin@google.com>
10 years agocmd/9a: fix GLOBL instruction
Russ Cox [Thu, 29 Jan 2015 18:50:19 +0000 (13:50 -0500)]
cmd/9a: fix GLOBL instruction

Because it was lumped in with the TEXT instruction,
the high 32 bits of the 64-bit constant holding the size
were always set to 0x80000000 (ArgsSizeUnknown).
This only worked because cmd/9l was reading the 64-bit
value into an int32.

While we're here, fix 5a.
It wasn't as much of a problem there because
the two values were being stored in two different fields.
But it was still wrong.

Change-Id: I69a2214c7be939530d499e29cfdc3b26720ac05a
Reviewed-on: https://go-review.googlesource.com/3570
Reviewed-by: Austin Clements <austin@google.com>
10 years agocmd/gc: fix capturing by value for range statements
Dmitry Vyukov [Thu, 29 Jan 2015 15:33:19 +0000 (18:33 +0300)]
cmd/gc: fix capturing by value for range statements

Kindly detected by race builders by failing TestRaceRange.
ORANGE typecheck does not increment decldepth around body.

Change-Id: I0df5f310cb3370a904c94d9647a9cf0f15729075
Reviewed-on: https://go-review.googlesource.com/3507
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/gc: typecheck type switch variables
Dmitry Vyukov [Fri, 30 Jan 2015 08:23:22 +0000 (11:23 +0300)]
cmd/gc: typecheck type switch variables

Type switch variables was not typechecked.
Previously it lead only to a minor consequence:

switch unsafe.Sizeof = x.(type) {

generated an inconsistent error message.
But capturing by value functionality now requries typechecking of all ONAMEs.

Fixes #9731

Change-Id: If037883cba53d85028fb97b1328696091b3b7ddd
Reviewed-on: https://go-review.googlesource.com/3600
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: fix nosplit stack overflow
Dmitry Vyukov [Thu, 29 Jan 2015 09:47:30 +0000 (12:47 +0300)]
runtime: fix nosplit stack overflow

The overflow happens only with -gcflags="-N -l"
and can be reproduced with:

$ go test -gcflags="-N -l" -a -run=none net

runtime.cgocall: nosplit stack overflow
504 assumed on entry to runtime.cgocall
480 after runtime.cgocall uses 24
472 on entry to runtime.cgocall_errno
408 after runtime.cgocall_errno uses 64
400 on entry to runtime.exitsyscall
288 after runtime.exitsyscall uses 112
280 on entry to runtime.exitsyscallfast
152 after runtime.exitsyscallfast uses 128
144 on entry to runtime.writebarrierptr
88 after runtime.writebarrierptr uses 56
80 on entry to runtime.writebarrierptr_nostore1
24 after runtime.writebarrierptr_nostore1 uses 56
16 on entry to runtime.acquirem
-24 after runtime.acquirem uses 40

Move closure creation into separate function so that
frames of writebarrierptr_shadow and writebarrierptr_nostore1
are overlapped.

Fixes #9721

Change-Id: I40851f0786763ee964af34814edbc3e3d73cf4e7
Reviewed-on: https://go-review.googlesource.com/3418
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: fix false race report during tracing
Dmitry Vyukov [Tue, 3 Feb 2015 10:01:09 +0000 (13:01 +0300)]
runtime: fix false race report during tracing

Currently race detector produces the following reports on pprof tests:

WARNING: DATA RACE
Read by goroutine 4:
  runtime/pprof_test.TestTraceStartStop()
      src/runtime/pprof/trace_test.go:38 +0x1da
  testing.tRunner()
      src/testing/testing.go:448 +0x13a

Previous write by goroutine 5:
  bytes.(*Buffer).grow()
      src/bytes/buffer.go:102 +0x190
  bytes.(*Buffer).Write()
      src/bytes/buffer.go:127 +0x75
  runtime/pprof.func·002()
      src/runtime/pprof/pprof.go:633 +0xae

Trace writer goroutine synchronizes with StopTrace
using trace.shutdownSema runtime semaphore.
But race detector does not see that synchronization
and so produces false reports.
Teach race detector about the synchronization.

Change-Id: I1219817325d4e16b423f29a0cbee94c929793881
Reviewed-on: https://go-review.googlesource.com/3746
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: rearrange framepointer check condition
Austin Clements [Tue, 3 Feb 2015 14:18:15 +0000 (09:18 -0500)]
runtime: rearrange framepointer check condition

The test for the framepointer experiment flag is cheaper and more
branch-predictable than the other parts of this conditional, so move
it first.  This is also more readable.

(Originally, the flag check required parsing the experiments string,
which is why it was done last.  Now that flag is cached.)

Change-Id: I84e00fa7e939e9064f0fa0a4a6fe00576dd61457
Reviewed-on: https://go-review.googlesource.com/3782
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agoruntime: use 2*regSize for saved frame pointer check
Austin Clements [Tue, 3 Feb 2015 14:09:56 +0000 (09:09 -0500)]
runtime: use 2*regSize for saved frame pointer check

Previously, we checked for a saved frame pointer by looking for a
2*ptrSize gap between the argument pointer and the locals pointer.
The intent of this check was to look for a two stack slot gap (caller
IP and saved frame pointer), but stack slots are regSize, not ptrSize.

Correct this by checking instead for a 2*regSize gap.

On most platforms, this made no difference because ptrSize==regSize.
However, on amd64p32 (nacl), the saved frame pointer check incorrectly
fired when there was no saved frame pointer because the one stack slot
for the caller IP left an 8 byte gap, which is 2*ptrSize (but not
2*regSize) on amd64p32.

Fixes #9760.

Change-Id: I6eedcf681fe5bf2bf924dde8a8f2d9860a4d758e
Reviewed-on: https://go-review.googlesource.com/3781
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agoruntime: add missing \n to error message
Austin Clements [Tue, 3 Feb 2015 13:35:38 +0000 (08:35 -0500)]
runtime: add missing \n to error message

Change-Id: Ife7d30f4191e6a8aaf3a442340d277989f7a062d
Reviewed-on: https://go-review.googlesource.com/3780
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agonet: case insensitivity of DNS labels in built-in stub resolver
Mikio Hara [Mon, 2 Feb 2015 12:09:23 +0000 (21:09 +0900)]
net: case insensitivity of DNS labels in built-in stub resolver

This change adds support for case insensitivity of DNS labels to
built-in DNS stub resolver as described in RFC 4343.

Fixes #9215.

Change-Id: Ia752fe71866a3bfa3ea08371985b799d419ddea3
Reviewed-on: https://go-review.googlesource.com/3685
Reviewed-by: Ian Lance Taylor <iant@golang.org>
10 years agonet/http: remove redundant strings.TrimPrefix
Erik Aigner [Mon, 2 Feb 2015 07:52:41 +0000 (08:52 +0100)]
net/http: remove redundant strings.TrimPrefix

We already checked for the prefix with strings.HasPrefix

Change-Id: I33852fd19ffa92aa33b75b94b4bb505f4043a54a
Reviewed-on: https://go-review.googlesource.com/3691
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agoinclude: fix arm build one more time
Dave Cheney [Fri, 30 Jan 2015 15:19:50 +0000 (02:19 +1100)]
include: fix arm build one more time

Fourth time's the charm.

Actually this doesn't fix the build, there is a
crash after go_bootstrap is compiled which looks
like it is related to auxv parsing.

Change-Id: Id00e2dfbe7bae42856f996065d3fb90b820e29a8
Reviewed-on: https://go-review.googlesource.com/3610
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agoruntime: Add memprofrate value to GODEBUG
Lynn Boger [Wed, 28 Jan 2015 18:28:59 +0000 (12:28 -0600)]
runtime: Add memprofrate value to GODEBUG

Add memprofrate as a value recognized in GODEBUG.  The
value provided is used as the new setting for
runtime.MemProfileRate, allowing the user to
adjust memory profiling.

Change-Id: If129a247683263b11e2dd42473cf9b31280543d5
Reviewed-on: https://go-review.googlesource.com/3450
Reviewed-by: Ian Lance Taylor <iant@golang.org>
10 years agocmd/6g, liblink, runtime: support saving base pointers
Austin Clements [Wed, 14 Jan 2015 16:09:50 +0000 (11:09 -0500)]
cmd/6g, liblink, runtime: support saving base pointers

This adds a "framepointer" GOEXPERIMENT that that makes the amd64
toolchain maintain base pointer chains in the same way that gcc
-fno-omit-frame-pointer does.  Go doesn't use these saved base
pointers, but this does enable external tools like Linux perf and
VTune to unwind Go stacks when collecting system-wide profiles.

This requires support in the compilers to not clobber BP, support in
liblink for generating the BP-saving function prologue and unwinding
epilogue, and support in the runtime to save BPs across preemption, to
skip saved BPs during stack unwinding and, and to adjust saved BPs
during stack moving.

As with other GOEXPERIMENTs, everything from the toolchain to the
runtime must be compiled with this experiment enabled.  To do this,
run make.bash (or all.bash) with GOEXPERIMENT=framepointer.

Change-Id: I4024853beefb9539949e5ca381adfdd9cfada544
Reviewed-on: https://go-review.googlesource.com/2992
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: eliminate uses of BP on amd64
Austin Clements [Tue, 27 Jan 2015 23:29:02 +0000 (18:29 -0500)]
runtime: eliminate uses of BP on amd64

Any place that clobbers BP in the runtime can potentially interfere
with frame pointer unwinding with GOEXPERIMENT=framepointer.  This
change eliminates uses of BP in the runtime to address this problem.
We have spare registers everywhere this occurs, so there's no downside
to eliminating BP.  Where possible, this uses the same new register as
the amd64p32 runtime, which doesn't use BP due to restrictions placed
on it by NaCL.

One nice side effect of this is that it will let perf/VTune unwind the
call stack even through a call to systemstack, which will let us get
really good call graphs from the garbage collector.

Change-Id: I0ffa14cb4dd2b613a7049b8ec59df37c52286212
Reviewed-on: https://go-review.googlesource.com/3390
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: rename m.gcing to m.preemptoff and make it a string
Austin Clements [Fri, 30 Jan 2015 20:30:41 +0000 (15:30 -0500)]
runtime: rename m.gcing to m.preemptoff and make it a string

m.gcing has become overloaded to mean "don't preempt this g" in
general.  Once the garbage collector is preemptible, the one thing it
*won't* mean is that we're in the garbage collector.

So, rename gcing to "preemptoff" and make it a string giving a reason
that preemption is disabled.  gcing was never set to anything but 0 or
1, so we don't have to worry about there being a stack of reasons.

Change-Id: I4337c29e8e942e7aa4f106fc29597e1b5de4ef46
Reviewed-on: https://go-review.googlesource.com/3660
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: update a few "onM"s in comments to say "systemstack"
Austin Clements [Wed, 28 Jan 2015 16:51:04 +0000 (11:51 -0500)]
runtime: update a few "onM"s in comments to say "systemstack"

Commit 656be31 replaced onM with systemstack, but missed updating a
few comments that still referred to onM.  Update these.

Change-Id: I0efb017e9a66ea0adebb6e1da6e518ee11263f69
Reviewed-on: https://go-review.googlesource.com/3664
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/9g: note suboptimal copy code
Austin Clements [Fri, 30 Jan 2015 16:18:24 +0000 (11:18 -0500)]
cmd/9g: note suboptimal copy code

9g generates needlessly complex code for small copies.  There are a
few other things that need to be improved about the copy code, so for
now just note the problem.

Change-Id: I0f1de4b2f9197a2635e27cc4b91ecf7a6c11f457
Reviewed-on: https://go-review.googlesource.com/3665
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agogo/printer: clearer logic (clenaup)
Robert Griesemer [Mon, 2 Feb 2015 19:02:09 +0000 (11:02 -0800)]
go/printer: clearer logic (clenaup)

Change-Id: I278ce47b38ec5732d981aec06b71f9ee5747c3bb
Reviewed-on: https://go-review.googlesource.com/3730
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agogo/printer: set prefix correctly when all comment lines blank
Dmitri Shuralyov [Mon, 2 Feb 2015 09:28:10 +0000 (01:28 -0800)]
go/printer: set prefix correctly when all comment lines blank

In stripCommonPrefix, the prefix was correctly calculated in all cases,
except one. That unhandled case is when there are more than 2 lines,
but all lines are blank (other than the first and last lines,
which contain /* and */ respectively).
This change detects that case and correctly sets the prefix calculated
from the last line. This is consistent with the (correct) behavior
that happens when there's at least one non-blank line.
That fixes issue #9751 that occurs for problematic input,
where cmd/gofmt and go/source would insert extra indentation on
every format operation. It also allows go/printer itself to print
such parsed files in an expected way.

Fixes #9751.

Change-Id: Id3dfb945beb59ffad3705085a3c285fca30a5f87
Reviewed-on: https://go-review.googlesource.com/3684
Reviewed-by: Robert Griesemer <gri@golang.org>
10 years agoos: fix TestMkdirAllAtSlash on Plan 9
David du Colombier [Mon, 2 Feb 2015 16:40:47 +0000 (17:40 +0100)]
os: fix TestMkdirAllAtSlash on Plan 9

Since CL 3676, the TestMkdirAllAtSlash test
depends on syscall.EROFS, which isn't defined
on Plan 9.

This change works around this issue by
defining a system dependent isReadonlyError
function.

Change-Id: If972fd2fe4828ee3bcb8537ea7f4ba29f7a87619
Reviewed-on: https://go-review.googlesource.com/3696
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agocmd/gc: always treat the output parameters as having been assigned in capturevars.
Shenghou Ma [Sat, 31 Jan 2015 07:50:56 +0000 (02:50 -0500)]
cmd/gc: always treat the output parameters as having been assigned in capturevars.

Fixes #9738.

Change-Id: Iab75de2d78335d4e31c3dce6a0e1826d8cddf5f3
Reviewed-on: https://go-review.googlesource.com/3690
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
10 years agonet: failed not faild
David Crawshaw [Mon, 2 Feb 2015 11:33:06 +0000 (11:33 +0000)]
net: failed not faild

Change-Id: Iea4221186325783db2029b07af1409015ddeda99
Reviewed-on: https://go-review.googlesource.com/3695
Reviewed-by: Dave Cheney <dave@cheney.net>
10 years agoos: don't silently skip test
Dave Cheney [Sat, 31 Jan 2015 03:48:14 +0000 (14:48 +1100)]
os: don't silently skip test

This is a followup to CL 3676.

Rather than silently returning from the test, a pass,
use the Skip facility to mark the test as skipped.

Change-Id: I90d237e770150bf8d69f14fb09874e70894a7f86
Reviewed-on: https://go-review.googlesource.com/3682
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agoos: allow EROFS in TestMkdirAllAtSlash
Rahul Chaudhry [Fri, 30 Jan 2015 23:07:11 +0000 (15:07 -0800)]
os: allow EROFS in TestMkdirAllAtSlash

On some systems (e.g. ChromeOS), / is mounted read-only.
This results in error code syscall.EROFS, which I guess
is just as valid as syscall.EACCES for this test.

Change-Id: I9188d5437a1b5ac1daa9c68b95b8dcb447666ca3
Reviewed-on: https://go-review.googlesource.com/3676
Reviewed-by: Ian Lance Taylor <iant@golang.org>
10 years agomath/big: split float conversion routines and tests into separate files
Robert Griesemer [Fri, 30 Jan 2015 22:53:53 +0000 (14:53 -0800)]
math/big: split float conversion routines and tests into separate files

No other functional changes.

Change-Id: I7e0bb7452c6a265535297ec7ce6a629f1aff695c
Reviewed-on: https://go-review.googlesource.com/3674
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agomath/big: split rat conversion routines and tests into separate files
Robert Griesemer [Fri, 30 Jan 2015 22:20:04 +0000 (14:20 -0800)]
math/big: split rat conversion routines and tests into separate files

No other functional changes.

Change-Id: I8be1fc488caa4f3d4c00afcb8c00475bfcd10709
Reviewed-on: https://go-review.googlesource.com/3673
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agomath/big: split int conversion routines and tests into separate files
Robert Griesemer [Fri, 30 Jan 2015 22:25:55 +0000 (14:25 -0800)]
math/big: split int conversion routines and tests into separate files

No other functional changes.

Change-Id: If0d9e6208d53478e70d991b6926ea196b2cccf2e
Reviewed-on: https://go-review.googlesource.com/3672
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agomath/big: split nat conversion routines and tests into separate files
Robert Griesemer [Fri, 30 Jan 2015 22:12:21 +0000 (14:12 -0800)]
math/big: split nat conversion routines and tests into separate files

No functional changes.

Change-Id: Ibbb705b167603d30467f3ebb83a3bb39845306a5
Reviewed-on: https://go-review.googlesource.com/3671
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agomath/big: parsing of fractions and floats in mantissa bases other than 10
Robert Griesemer [Thu, 29 Jan 2015 01:11:15 +0000 (17:11 -0800)]
math/big: parsing of fractions and floats in mantissa bases other than 10

Change-Id: I1eaebf956a69e0958201cc5e0a9beefa062c71e1
Reviewed-on: https://go-review.googlesource.com/3454
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agodoc: add log.SetOutput to go1.5.txt
Andrew Gerrand [Fri, 30 Jan 2015 16:01:14 +0000 (16:01 +0000)]
doc: add log.SetOutput to go1.5.txt

Change-Id: I257211f10b334eb4828be96cd434d588bfb1a378
Reviewed-on: https://go-review.googlesource.com/3605
Reviewed-by: Rob Pike <r@golang.org>
10 years agolog: add SetOutput method on Logger
Andrew Gerrand [Mon, 19 Jan 2015 03:54:53 +0000 (14:54 +1100)]
log: add SetOutput method on Logger

Fixes #9629

Change-Id: I66091003b97742ca6d857fe51d609833ab727216
Reviewed-on: https://go-review.googlesource.com/3023
Reviewed-by: Rob Pike <r@golang.org>
10 years agocmd/pack: make a test less disk-intensive in short mode
Brad Fitzpatrick [Thu, 29 Jan 2015 12:45:56 +0000 (13:45 +0100)]
cmd/pack: make a test less disk-intensive in short mode

Fixes #9656

Change-Id: I1158636683492ef12eeafb12e257d205026adc3f
Reviewed-on: https://go-review.googlesource.com/3175
Reviewed-by: Minux Ma <minux@golang.org>
10 years agodoc: remove redundant images
Andrew Gerrand [Tue, 27 Jan 2015 08:50:00 +0000 (19:50 +1100)]
doc: remove redundant images

These are no longer used by anything.

Change-Id: I50c971418b07cafc983242833a196ba2028a2723
Reviewed-on: https://go-review.googlesource.com/3603
Reviewed-by: Rob Pike <r@golang.org>
10 years agoliblink: fix arm build again
Dave Cheney [Fri, 30 Jan 2015 05:20:46 +0000 (16:20 +1100)]
liblink: fix arm build again

Another attempt to fix the arm build by moving the include of signal.h
to cmd/lex.c, unless we are building on plan9.

Obviously if we had a plan9/arm builder this would probably not work, but
this is only a temporary measure until the c2go transition is complete.

Change-Id: I7f8ae27349b2e7a09c55db03e02a01939159a268
Reviewed-on: https://go-review.googlesource.com/3566
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: fix system memory allocator on plan9
Dmitry Vyukov [Fri, 30 Jan 2015 11:36:12 +0000 (14:36 +0300)]
runtime: fix system memory allocator on plan9

The following line in sysFree:
n += (n + memRound) &^ memRound
doubles value of n (n += n).
Which is wrong and can lead to memory corruption.

Fixes #9712

Change-Id: I3c141b71da11e38837c09408cf4f1d22e8f7f36e
Reviewed-on: https://go-review.googlesource.com/3602
Reviewed-by: David du Colombier <0intro@gmail.com>
10 years agoruntime: fix trace ticks frequency on windows
Dmitry Vyukov [Thu, 29 Jan 2015 12:26:15 +0000 (15:26 +0300)]
runtime: fix trace ticks frequency on windows

Change-Id: I8c7fcc7705070bc9979e39d08a4c9b2870087a08
Reviewed-on: https://go-review.googlesource.com/3500
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
10 years agocmd/5l, cmd/9l: more ucontext.h fixes
Russ Cox [Fri, 30 Jan 2015 04:57:48 +0000 (23:57 -0500)]
cmd/5l, cmd/9l: more ucontext.h fixes

Change-Id: I32cad7358f5bfd8e107179653bdc55a69fbe772a
Reviewed-on: https://go-review.googlesource.com/3579
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/5l, cmd/8g: fix build failures
Russ Cox [Fri, 30 Jan 2015 04:49:27 +0000 (23:49 -0500)]
cmd/5l, cmd/8g: fix build failures

REG_R0 etc are defined in <ucontext.h> on ARM systems.
Possible use of uninitialized n in 8g/reg.c.

Change-Id: I6e8ce83a6515ca2b779ed8a344a25432db629cc2
Reviewed-on: https://go-review.googlesource.com/3578
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/dist: update for portable Prog, Addr
Russ Cox [Mon, 26 Jan 2015 20:16:24 +0000 (15:16 -0500)]
cmd/dist: update for portable Prog, Addr

There are no D_ names anymore.

Change-Id: Id3f1ce5efafb93818e5fd16c47ff48bbf61b5339
Reviewed-on: https://go-review.googlesource.com/3520
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
10 years agocmd/9a, cmd/9g, cmd/9l, liblink: update for portable Prog, Addr
Russ Cox [Mon, 26 Jan 2015 20:16:03 +0000 (15:16 -0500)]
cmd/9a, cmd/9g, cmd/9l, liblink: update for portable Prog, Addr

Change-Id: I55afed0eabf3c38e72ff105294782ac36446b66b
Reviewed-on: https://go-review.googlesource.com/3519
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
10 years agocmd/8a, cmd/8g, cmd/8l, liblink: update for portable Prog, Addr
Russ Cox [Mon, 26 Jan 2015 20:15:43 +0000 (15:15 -0500)]
cmd/8a, cmd/8g, cmd/8l, liblink: update for portable Prog, Addr

Change-Id: I19ed283962aa0221cf806307bde9ea0773a1bfd4
Reviewed-on: https://go-review.googlesource.com/3518
Reviewed-by: Austin Clements <austin@google.com>
10 years agocmd/6a, cmd/6g, cmd/6l, liblink: update for portable Prog, Addr
Russ Cox [Mon, 26 Jan 2015 20:15:25 +0000 (15:15 -0500)]
cmd/6a, cmd/6g, cmd/6l, liblink: update for portable Prog, Addr

Change-Id: I5535582660da3504663c6cba2637da132c65a400
Reviewed-on: https://go-review.googlesource.com/3517
Reviewed-by: Austin Clements <austin@google.com>
10 years agocmd/5a, cmd/5g, cmd/5l, liblink: update for portable Prog, Addr
Russ Cox [Mon, 26 Jan 2015 20:15:05 +0000 (15:15 -0500)]
cmd/5a, cmd/5g, cmd/5l, liblink: update for portable Prog, Addr

Change-Id: I06762d4fb3bb2616087339b6ae1eb5267a39c46a
Reviewed-on: https://go-review.googlesource.com/3516
Reviewed-by: Austin Clements <austin@google.com>
10 years agocmd/gc, cmd/ld, liblink: update for portable Prog, Addr changes
Russ Cox [Mon, 26 Jan 2015 20:14:23 +0000 (15:14 -0500)]
cmd/gc, cmd/ld, liblink: update for portable Prog, Addr changes

Change-Id: Ia6f8badca56565b9df80c8dbe28c47f6cf7e653f
Reviewed-on: https://go-review.googlesource.com/3515
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
10 years agoliblink: make Prog, Addr more portable and document
Russ Cox [Mon, 26 Jan 2015 20:13:05 +0000 (15:13 -0500)]
liblink: make Prog, Addr more portable and document

Change-Id: Idda476b71ae23f7b73fe63f062cf3531c1268eb3
Reviewed-on: https://go-review.googlesource.com/3514
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Dave Cheney <dave@cheney.net>
10 years agoliblink: fix error message on linux for unknown TLS base
Russ Cox [Thu, 29 Jan 2015 03:39:57 +0000 (22:39 -0500)]
liblink: fix error message on linux for unknown TLS base

headstr(Hlinux) was reporting "android",
making for some confusing error messages.

Change-Id: I437095bee7cb2143aa37c91cf786f3a3581ae7b9
Reviewed-on: https://go-review.googlesource.com/3513
Reviewed-by: Austin Clements <austin@google.com>
10 years agocmd/9g: use nopout in excise
Russ Cox [Thu, 29 Jan 2015 01:44:55 +0000 (20:44 -0500)]
cmd/9g: use nopout in excise

In addition to duplicating the logic, the old code was
clearing the line number, which led to missing source line
information in the -S output.

Also fix nopout, which was incomplete.

Change-Id: Ic2b596a2f9ec2fe85642ebe125cca8ef38c83085
Reviewed-on: https://go-review.googlesource.com/3512
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Dave Cheney <dave@cheney.net>
10 years agoliblink: bug fixes for ppc64 %P format
Russ Cox [Wed, 28 Jan 2015 02:07:35 +0000 (21:07 -0500)]
liblink: bug fixes for ppc64 %P format

- certain code paths were appending to the string without first clearing it.
- some prints were using spaces instead of tabs

Change-Id: I7a3d38289c8206682baf8942abf5a9950a56b449
Reviewed-on: https://go-review.googlesource.com/3511
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Dave Cheney <dave@cheney.net>
10 years agotest/closure2.go: correctly "use" tmp
Robert Griesemer [Thu, 29 Jan 2015 22:18:52 +0000 (14:18 -0800)]
test/closure2.go: correctly "use" tmp

cmd/go doesn't complain (this is an open issue), but go/types does

Change-Id: I2caec1f7aec991a9500d2c3504c29e4ab718c138
Reviewed-on: https://go-review.googlesource.com/3541
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agoruntime: scanvalid race Fixes #9727
Rick Hudson [Thu, 29 Jan 2015 15:37:32 +0000 (10:37 -0500)]
runtime: scanvalid race Fixes #9727

Set gcscanvalid=false after you have cased to _Grunning.
If you do it before the cas and the atomicstatus races to a scan state,
the scan will set gcscanvalid=true and we will be _Grunning
with gcscanvalid==true which is not a good thing.

Change-Id: Ie53ea744a5600392b47da91159d985fe6fe75961
Reviewed-on: https://go-review.googlesource.com/3510
Reviewed-by: Austin Clements <austin@google.com>
10 years agoruntime: use func value for parfor body
Austin Clements [Wed, 28 Jan 2015 20:55:23 +0000 (15:55 -0500)]
runtime: use func value for parfor body

Yet another leftover from C: parfor took a func value for the
callback, casted it to an unsafe.Pointer for storage, and then casted
it back to a func value to call it.  This is unnecessary, so just
store the body as a func value.  Beyond general cleanup, this also
eliminates the last use of unsafe in parfor.

Change-Id: Ia904af7c6c443ba75e2699835aee8e9a39b26dd8
Reviewed-on: https://go-review.googlesource.com/3396
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
10 years agoruntime: eliminate parfor ctx field
Austin Clements [Wed, 28 Jan 2015 20:49:26 +0000 (15:49 -0500)]
runtime: eliminate parfor ctx field

Prior to the conversion of the runtime to Go, this void* was
necessary to get closure information in to C callbacks.  There
are no more C callbacks and parfor is perfectly capable of
invoking a Go closure now, so eliminate ctx and all of its
unsafe-ness.  (Plus, the runtime currently doesn't use ctx for
anything.)

Change-Id: I39fc53b7dd3d7f660710abc76b0d831bfc6296d8
Reviewed-on: https://go-review.googlesource.com/3395
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
10 years agoruntime: use threads slice in parfor instead of unsafe pointer math
Austin Clements [Wed, 28 Jan 2015 20:25:05 +0000 (15:25 -0500)]
runtime: use threads slice in parfor instead of unsafe pointer math

parfor originally used a tail array for its thread array.  This got
replaced with a slice allocation in the conversion to Go, but many of
its gnarlier effects remained.  Instead of keeping track of the
pointer to the first element of the slice and using unsafe pointer
math to get at the ith element, just keep the slice around and use
regular slice indexing.  There is no longer any need for padding to
64-bit align the tail array (there hasn't been since the Go
conversion), so remove this unnecessary padding from the parfor
struct.  Finally, since the slice tracks its own length, replace the
nthrmax field with len(thr).

Change-Id: I0020a1815849bca53e3613a8fa46ae4fbae67576
Reviewed-on: https://go-review.googlesource.com/3394
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: move all parfor-related code to parfor.go
Austin Clements [Wed, 28 Jan 2015 19:51:49 +0000 (14:51 -0500)]
runtime: move all parfor-related code to parfor.go

This cleanup was slated for after the conversion of the runtime to Go.
Also improve type and function documentation.

Change-Id: I55a16b09e00cf701f246deb69e7ce7e3e04b26e7
Reviewed-on: https://go-review.googlesource.com/3393
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
10 years agoruntime: check alignment of 8-byte atomic loads and stores on 386
Austin Clements [Thu, 29 Jan 2015 16:54:45 +0000 (11:54 -0500)]
runtime: check alignment of 8-byte atomic loads and stores on 386

Currently, if we do an atomic{load,store}64 of an unaligned address on
386, we'll simply get a non-atomic load/store.  This has been the
source of myriad bugs, so add alignment checks to these two
operations.  These checks parallel the equivalent checks in
sync/atomic.

The alignment check is not necessary in cas64 because it uses a locked
instruction.  The CPU will either execute this atomically or raise an
alignment fault (#AC)---depending on the alignment check flag---either
of which is fine.

This also fixes the two places in the runtime that trip the new
checks.  One is in the runtime self-test and shouldn't have caused
real problems.  The other is in tickspersecond and could, in
principle, have caused a misread of the ticks per second during
initialization.

Change-Id: If1796667012a6154f64f5e71d043c7f5fb3dd050
Reviewed-on: https://go-review.googlesource.com/3521
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/go: add build flag -toolexec
Russ Cox [Tue, 27 Jan 2015 01:58:17 +0000 (20:58 -0500)]
cmd/go: add build flag -toolexec

Like the -exec flag, which specifies a program to use to run a built executable,
the -toolexec flag specifies a program to use to run a tool like 5a, 5g, or 5l.

This flag enables running the toolchain under common testing environments,
such as valgrind.

This flag also enables the use of custom testing environments or the substitution
of alternate tools. See https://godoc.org/rsc.io/toolstash for one possibility.

Change-Id: I256aa7af2d96a4bc7911dc58151cc2155dbd4121
Reviewed-on: https://go-review.googlesource.com/3351
Reviewed-by: Rob Pike <r@golang.org>
10 years agocmd/gc: capture variables by value
Dmitry Vyukov [Mon, 19 Jan 2015 19:59:58 +0000 (22:59 +0300)]
cmd/gc: capture variables by value

Language specification says that variables are captured by reference.
And that is what gc compiler does. However, in lots of cases it is
possible to capture variables by value under the hood without
affecting visible behavior of programs. For example, consider
the following typical pattern:

func (o *Obj) requestMany(urls []string) []Result {
wg := new(sync.WaitGroup)
wg.Add(len(urls))
res := make([]Result, len(urls))
for i := range urls {
i := i
go func() {
res[i] = o.requestOne(urls[i])
wg.Done()
}()
}
wg.Wait()
return res
}

Currently o, wg, res, and i are captured by reference causing 3+len(urls)
allocations (e.g. PPARAM o is promoted to PPARAMREF and moved to heap).
But all of them can be captured by value without changing behavior.

This change implements simple strategy for capturing by value:
if a captured variable is not addrtaken and never assigned to,
then it is captured by value (it is effectively const).
This simple strategy turned out to be very effective:
~80% of all captures in std lib are turned into value captures.
The remaining 20% are mostly in defers and non-escaping closures,
that is, they do not cause allocations anyway.

benchmark                                    old allocs     new allocs     delta
BenchmarkCompressedZipGarbage                153            126            -17.65%
BenchmarkEncodeDigitsSpeed1e4                91             69             -24.18%
BenchmarkEncodeDigitsSpeed1e5                178            129            -27.53%
BenchmarkEncodeDigitsSpeed1e6                1510           1051           -30.40%
BenchmarkEncodeDigitsDefault1e4              100            75             -25.00%
BenchmarkEncodeDigitsDefault1e5              193            139            -27.98%
BenchmarkEncodeDigitsDefault1e6              1420           985            -30.63%
BenchmarkEncodeDigitsCompress1e4             100            75             -25.00%
BenchmarkEncodeDigitsCompress1e5             193            139            -27.98%
BenchmarkEncodeDigitsCompress1e6             1420           985            -30.63%
BenchmarkEncodeTwainSpeed1e4                 109            81             -25.69%
BenchmarkEncodeTwainSpeed1e5                 211            151            -28.44%
BenchmarkEncodeTwainSpeed1e6                 1588           1097           -30.92%
BenchmarkEncodeTwainDefault1e4               103            77             -25.24%
BenchmarkEncodeTwainDefault1e5               199            143            -28.14%
BenchmarkEncodeTwainDefault1e6               1324           917            -30.74%
BenchmarkEncodeTwainCompress1e4              103            77             -25.24%
BenchmarkEncodeTwainCompress1e5              190            137            -27.89%
BenchmarkEncodeTwainCompress1e6              1327           919            -30.75%
BenchmarkConcurrentDBExec                    16223          16220          -0.02%
BenchmarkConcurrentStmtQuery                 17687          16182          -8.51%
BenchmarkConcurrentStmtExec                  5191           5186           -0.10%
BenchmarkConcurrentTxQuery                   17665          17661          -0.02%
BenchmarkConcurrentTxExec                    15154          15150          -0.03%
BenchmarkConcurrentTxStmtQuery               17661          16157          -8.52%
BenchmarkConcurrentTxStmtExec                3677           3673           -0.11%
BenchmarkConcurrentRandom                    14000          13614          -2.76%
BenchmarkManyConcurrentQueries               25             22             -12.00%
BenchmarkDecodeComplex128Slice               318            252            -20.75%
BenchmarkDecodeFloat64Slice                  318            252            -20.75%
BenchmarkDecodeInt32Slice                    318            252            -20.75%
BenchmarkDecodeStringSlice                   2318           2252           -2.85%
BenchmarkDecode                              11             8              -27.27%
BenchmarkEncodeGray                          64             56             -12.50%
BenchmarkEncodeNRGBOpaque                    64             56             -12.50%
BenchmarkEncodeNRGBA                         67             58             -13.43%
BenchmarkEncodePaletted                      68             60             -11.76%
BenchmarkEncodeRGBOpaque                     64             56             -12.50%
BenchmarkGoLookupIP                          153            139            -9.15%
BenchmarkGoLookupIPNoSuchHost                508            466            -8.27%
BenchmarkGoLookupIPWithBrokenNameServer      245            226            -7.76%
BenchmarkClientServer                        62             59             -4.84%
BenchmarkClientServerParallel4               62             59             -4.84%
BenchmarkClientServerParallel64              62             59             -4.84%
BenchmarkClientServerParallelTLS4            79             76             -3.80%
BenchmarkClientServerParallelTLS64           112            109            -2.68%
BenchmarkCreateGoroutinesCapture             10             6              -40.00%
BenchmarkAfterFunc                           1006           1005           -0.10%

Fixes #6632.

Change-Id: I0cd51e4d356331d7f3c5f447669080cd19b0d2ca
Reviewed-on: https://go-review.googlesource.com/3166
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agonet: remove full stack test cases for IPConn
Mikio Hara [Wed, 28 Jan 2015 02:38:05 +0000 (11:38 +0900)]
net: remove full stack test cases for IPConn

A few packages that handle net.IPConn in golang.org/x/net sub repository
already implement full stack test cases with more coverage than the net
package. There is no need to keep duplicate code around here.

This change removes full stack test cases for IPConn that require
knowing how to speak with each of protocol stack implementation of
supported platforms.

Change-Id: I871119a9746fc6a2b997b69cfd733463558f5816
Reviewed-on: https://go-review.googlesource.com/3404
Reviewed-by: Ian Lance Taylor <iant@golang.org>
10 years agonet: remove solaris tag from cgo
Mikio Hara [Mon, 26 Jan 2015 11:52:02 +0000 (20:52 +0900)]
net: remove solaris tag from cgo

For now solaris port does not support cgo. Moreover, its system calls
and library interfaces are different from BSD.

Change-Id: Idb4fed889973368b35d38b361b23581abacfdeab
Reviewed-on: https://go-review.googlesource.com/3306
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
10 years agoencoding/json: add UnmarshalTypeError.Offset
Alex Plugaru [Mon, 26 Jan 2015 10:51:43 +0000 (11:51 +0100)]
encoding/json: add UnmarshalTypeError.Offset

Fixes #9693

Change-Id: Ibf07199729bfc883b2a7e051cafd98185f912acd
Reviewed-on: https://go-review.googlesource.com/3283
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agoexpvar: Use sync/atomic to manipulate Int for better perf
Evan Phoenix [Wed, 28 Jan 2015 17:16:44 +0000 (09:16 -0800)]
expvar: Use sync/atomic to manipulate Int for better perf

Using a mutex to protect a single int operation is quite heavyweight.
Using sync/atomic provides much better performance. This change was
benchmarked as such:

BenchmarkSync   10000000       139 ns/op
BenchmarkAtomic 200000000      9.90 ns/op

package blah

import (
        "sync"
        "sync/atomic"
        "testing"
)

type Int struct {
        mu sync.RWMutex
        i  int64
}

func (v *Int) Add(delta int64) {
        v.mu.Lock()
        defer v.mu.Unlock()
        v.i += delta
}

type AtomicInt struct {
        i int64
}

func (v *AtomicInt) Add(delta int64) {
        atomic.AddInt64(&v.i, delta)
}

func BenchmarkSync(b *testing.B) {
        s := new(Int)

        for i := 0; i < b.N; i++ {
                s.Add(1)
        }
}

func BenchmarkAtomic(b *testing.B) {
        s := new(AtomicInt)

        for i := 0; i < b.N; i++ {
                s.Add(1)
        }
}

Change-Id: I6998239c785967647351bbfe8533c38e4894543b
Reviewed-on: https://go-review.googlesource.com/3430
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
10 years agocmd/cgo: add support for s390 and s390x
Dominik Vogt [Tue, 13 Jan 2015 11:36:44 +0000 (12:36 +0100)]
cmd/cgo: add support for s390 and s390x

This patch was previously sent for review using hg:
golang.org/cl/173930043

Change-Id: I559a2f2ee07990d0c23d2580381e32f8e23077a5
Reviewed-on: https://go-review.googlesource.com/3033
Reviewed-by: Ian Lance Taylor <iant@golang.org>
10 years agomath/big: sketched out complete set of Float/string conversion functions
Robert Griesemer [Wed, 28 Jan 2015 00:51:59 +0000 (16:51 -0800)]
math/big: sketched out complete set of Float/string conversion functions

Also:
- use io.ByteScanner rather than io.RuneScanner internally
- minor simplifications in Float.Add/Sub

Change-Id: Iae0e99384128dba9eccf68592c4fd389e2bd3b4f
Reviewed-on: https://go-review.googlesource.com/3380
Reviewed-by: Rob Pike <r@golang.org>
10 years agoruntime: set minimum heap size to 4Mbytes
Rick Hudson [Wed, 28 Jan 2015 20:57:46 +0000 (15:57 -0500)]
runtime: set minimum heap size to 4Mbytes

Set the minimum heap size to 4Mbytes except when the hash
table code wants to force a GC. In an unrelated change when a
mutator is asked to assist the GC by marking pointer workbufs
it will keep working until the requested number of pointers
are processed even if it means asking for additional workbufs.

Change-Id: I661cfc0a7f2efcf6286b5d37d73e593d9ecd04d5
Reviewed-on: https://go-review.googlesource.com/3392
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
10 years agocmd/gc: allocate stack buffer for ORUNESTR
Dmitry Vyukov [Wed, 28 Jan 2015 05:42:20 +0000 (08:42 +0300)]
cmd/gc: allocate stack buffer for ORUNESTR

If result of string(i) does not escape,
allocate a [4]byte temp on stack for it.

Change-Id: If31ce9447982929d5b3b963fd0830efae4247c37
Reviewed-on: https://go-review.googlesource.com/3411
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/gc: allocate buffers for non-escaped strings on stack
Dmitry Vyukov [Wed, 21 Jan 2015 14:37:59 +0000 (17:37 +0300)]
cmd/gc: allocate buffers for non-escaped strings on stack

Currently we always allocate string buffers in heap.
For example, in the following code we allocate a temp string
just for comparison:

if string(byteSlice) == "abc" { ... }

This change extends escape analysis to cover []byte->string
conversions and string concatenation. If the result of operations
does not escape, compiler allocates a small buffer
on stack and passes it to slicebytetostring and concatstrings.
Then runtime uses the buffer if the result fits into it.

Size of the buffer is 32 bytes. There is no fundamental theory
behind this number. Just an observation that on std lib
tests/benchmarks frequency of string allocation is inversely
proportional to string length; and there is significant number
of allocations up to length 32.

benchmark                                    old allocs     new allocs     delta
BenchmarkFprintfBytes                        2              1              -50.00%
BenchmarkDecodeComplex128Slice               318            316            -0.63%
BenchmarkDecodeFloat64Slice                  318            316            -0.63%
BenchmarkDecodeInt32Slice                    318            316            -0.63%
BenchmarkDecodeStringSlice                   2318           2316           -0.09%
BenchmarkStripTags                           11             5              -54.55%
BenchmarkDecodeGray                          111            102            -8.11%
BenchmarkDecodeNRGBAGradient                 200            188            -6.00%
BenchmarkDecodeNRGBAOpaque                   165            152            -7.88%
BenchmarkDecodePaletted                      319            309            -3.13%
BenchmarkDecodeRGB                           166            157            -5.42%
BenchmarkDecodeInterlacing                   279            268            -3.94%
BenchmarkGoLookupIP                          153            135            -11.76%
BenchmarkGoLookupIPNoSuchHost                508            466            -8.27%
BenchmarkGoLookupIPWithBrokenNameServer      245            226            -7.76%
BenchmarkClientServerParallel4               62             61             -1.61%
BenchmarkClientServerParallel64              62             61             -1.61%
BenchmarkClientServerParallelTLS4            79             78             -1.27%
BenchmarkClientServerParallelTLS64           112            111            -0.89%

benchmark                                    old ns/op      new ns/op      delta
BenchmarkFprintfBytes                        381            311            -18.37%
BenchmarkStripTags                           2615           2351           -10.10%
BenchmarkDecodeNRGBAGradient                 3715887        3635096        -2.17%
BenchmarkDecodeNRGBAOpaque                   3047645        2928644        -3.90%
BenchmarkGoLookupIP                          153            135            -11.76%
BenchmarkGoLookupIPNoSuchHost                508            466            -8.27%

Change-Id: I9ec01da816945c3329d7be3c7794b520418c3f99
Reviewed-on: https://go-review.googlesource.com/3120
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: avoid redundant scans
Rick Hudson [Mon, 26 Jan 2015 18:51:39 +0000 (13:51 -0500)]
runtime: avoid redundant scans

During a concurrent GC stacks are scanned in
an initial scan phase informing the GC of all
pointers on the stack. The GC only needs to rescan
the stack if it potentially changes which can only
happen if the goroutine runs.
This CL tracks whether the Goroutine has run
since it was last scanned and thus may have changed
its stack. If necessary the stack is rescanned.

Change-Id: I5fb1c4338d42e3f61ab56c9beb63b7b2da25f4f1
Reviewed-on: https://go-review.googlesource.com/3275
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agounsafe: minor doc string improvements
Robert Griesemer [Wed, 28 Jan 2015 19:40:32 +0000 (11:40 -0800)]
unsafe: minor doc string improvements

Change-Id: I369723c7a65f9a72c60b55704cebf40d78cf4f75
Reviewed-on: https://go-review.googlesource.com/3444
Reviewed-by: Alan Donovan <adonovan@google.com>
10 years agonet/http: close HTTP response bodies in benchmark
Brad Fitzpatrick [Wed, 28 Jan 2015 18:44:54 +0000 (12:44 -0600)]
net/http: close HTTP response bodies in benchmark

This should fix the race builders.

Change-Id: I9c9e7393d5e29d64ab797e346b34b1fa1dfe6d96
Reviewed-on: https://go-review.googlesource.com/3441
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
10 years agonet/http/pprof: add tracing support
Dmitry Vyukov [Fri, 12 Dec 2014 17:58:09 +0000 (18:58 +0100)]
net/http/pprof: add tracing support

net/http/pprof part of tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: I9092028fcbd5e8f97a56f2c155889ccdfb494afb
Reviewed-on: https://go-review.googlesource.com/1453
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/gc: don't copy []byte during string comparison
Dmitry Vyukov [Tue, 27 Jan 2015 20:57:12 +0000 (23:57 +0300)]
cmd/gc: don't copy []byte during string comparison

Currently we allocate a new string during []byte->string conversion
in string comparison expressions. String allocation is unnecessary in
this case, because comparison does memorize the strings for later use.
This change uses slicebytetostringtmp to construct temp string directly
from []byte buffer and passes it to runtime.eqstring.

Change-Id: If00f1faaee2076baa6f6724d245d5b5e0f59b563
Reviewed-on: https://go-review.googlesource.com/3410
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime/pprof: skip trace tests on solaris and windows
Dmitry Vyukov [Wed, 28 Jan 2015 17:08:54 +0000 (20:08 +0300)]
runtime/pprof: skip trace tests on solaris and windows

Coarse-grained test skips to fix bots.
Need to look closer at windows and nacl failures.

Change-Id: I767ef1707232918636b33f715459ee3c0349b45e
Reviewed-on: https://go-review.googlesource.com/3416
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agocmd/gc: ignore re-slicing in escape analysis
Dmitry Vyukov [Fri, 16 Jan 2015 20:30:35 +0000 (23:30 +0300)]
cmd/gc: ignore re-slicing in escape analysis

Escape analysis treats everything assigned to OIND/ODOTPTR as escaping.
As the result b escapes in the following code:

func (b *Buffer) Foo() {
n, m := ...
b.buf = b.buf[n:m]
}

This change recognizes such assignments and ignores them.

Update issue #9043.
Update issue #7921.

There are two similar cases in std lib that benefit from this optimization.
First is in archive/zip:

type readBuf []byte
func (b *readBuf) uint32() uint32 {
v := binary.LittleEndian.Uint32(*b)
*b = (*b)[4:]
return v
}

Second is in time:

type data struct {
p     []byte
error bool
}

func (d *data) read(n int) []byte {
if len(d.p) < n {
d.p = nil
d.error = true
return nil
}
p := d.p[0:n]
d.p = d.p[n:]
return p
}

benchmark                         old ns/op     new ns/op     delta
BenchmarkCompressedZipGarbage     32431724      32217851      -0.66%

benchmark                         old allocs     new allocs     delta
BenchmarkCompressedZipGarbage     153            143            -6.54%

Change-Id: Ia6cd32744e02e36d6d8c19f402f8451101711626
Reviewed-on: https://go-review.googlesource.com/3162
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/gc: improve escape analysis for &T{...}
Dmitry Vyukov [Mon, 19 Jan 2015 20:46:22 +0000 (23:46 +0300)]
cmd/gc: improve escape analysis for &T{...}

Currently all PTRLIT element initializers escape. There is no reason for that.
This change links STRUCTLIT to PTRLIT; STRUCTLIT element initializers are
already linked to the STRUCTLIT. As the result, PTRLIT element initializers
escape when PTRLIT itself escapes.

Change-Id: I89ecd8677cbf81addcfd469cd2fd461c0e9bf7dd
Reviewed-on: https://go-review.googlesource.com/3031
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime/pprof: add tests for tracer
Dmitry Vyukov [Tue, 23 Dec 2014 19:22:56 +0000 (22:22 +0300)]
runtime/pprof: add tests for tracer

Change-Id: I832a433f0f2fc10b0a2fea0bfb003a988fc2c81b
Reviewed-on: https://go-review.googlesource.com/2039
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/go: add tracing support
Dmitry Vyukov [Fri, 12 Dec 2014 18:41:18 +0000 (19:41 +0100)]
cmd/go: add tracing support

cmd/go part of tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: If346e11b8029c475b01fbf7172ce1c88171fb1b2
Reviewed-on: https://go-review.googlesource.com/1460
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agotesting: add tracing support
Dmitry Vyukov [Fri, 12 Dec 2014 18:43:23 +0000 (19:43 +0100)]
testing: add tracing support

testing part of tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: Ia3c2c4417106937d5775b0e7064db92c1fc36679
Reviewed-on: https://go-review.googlesource.com/1461
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime/pprof: add tracing support
Dmitry Vyukov [Fri, 12 Dec 2014 17:56:36 +0000 (18:56 +0100)]
runtime/pprof: add tracing support

runtime/pprof part of tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: I3143a569cbd33576f19ca47308d1ff5200d8c955
Reviewed-on: https://go-review.googlesource.com/1452
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: add tracing of runtime events
Dmitry Vyukov [Fri, 12 Dec 2014 17:41:57 +0000 (18:41 +0100)]
runtime: add tracing of runtime events

Add actual tracing of interesting runtime events.
Part of a larger tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: Icccf54aea54e09350bb698ba6bf11532f9fbe6d3
Reviewed-on: https://go-review.googlesource.com/1451
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agoruntime: add execution tracing functionality
Dmitry Vyukov [Fri, 12 Dec 2014 17:11:27 +0000 (18:11 +0100)]
runtime: add execution tracing functionality

This is first patch of series of patches that implement tracing functionality.
Design doc:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: I84588348bb05a6f6a102c230f3bca6380a3419fe
Reviewed-on: https://go-review.googlesource.com/1450
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/gc: fix condition for fast pathed interface conversions
Dmitry Vyukov [Wed, 28 Jan 2015 14:28:50 +0000 (17:28 +0300)]
cmd/gc: fix condition for fast pathed interface conversions

For some reason the current conditions require the type to be "uintptr-shaped".
This cuts off structs and arrays with a pointer.
isdirectiface and width==widthptr is sufficient condition to enable the fast paths.

Change-Id: I11842531e7941365413606cfd6c34c202aa14786
Reviewed-on: https://go-review.googlesource.com/3414
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agocmd/gc: allow map index expressions in for range statements
Dmitry Vyukov [Mon, 26 Jan 2015 08:26:55 +0000 (11:26 +0300)]
cmd/gc: allow map index expressions in for range statements

Fixes #9691.

Change-Id: I22bfc82e05497e91a7b18a668913aed6c723365d
Reviewed-on: https://go-review.googlesource.com/3282
Reviewed-by: Russ Cox <rsc@golang.org>
10 years agonet/http: fix goroutine leak in benchmark
Dmitry Vyukov [Wed, 28 Jan 2015 13:17:36 +0000 (16:17 +0300)]
net/http: fix goroutine leak in benchmark

Race builders report goroutine leaks after addition of this benchmark:
http://build.golang.org/log/18e47f4cbc18ee8db125e1f1157573dd1e333c41
Close idle connection in default transport.

Change-Id: I86ff7b2e0972ed47c5ebcb9fce19e7f39d3ff530
Reviewed-on: https://go-review.googlesource.com/3412
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
10 years agoreflect: cache call frames
Dmitry Vyukov [Mon, 22 Dec 2014 19:31:55 +0000 (22:31 +0300)]
reflect: cache call frames

Call frame allocations can account for significant portion
of all allocations in a program, if call is executed
in an inner loop (e.g. to process every line in a log).
On the other hand, the allocation is easy to remove
using sync.Pool since the allocation is strictly scoped.

benchmark           old ns/op     new ns/op     delta
BenchmarkCall       634           338           -46.69%
BenchmarkCall-4     496           167           -66.33%

benchmark           old allocs     new allocs     delta
BenchmarkCall       1              0              -100.00%
BenchmarkCall-4     1              0              -100.00%

Update #7818

Change-Id: Icf60cce0a9be82e6171f0c0bd80dee2393db54a7
Reviewed-on: https://go-review.googlesource.com/1954
Reviewed-by: Keith Randall <khr@golang.org>
10 years agonet: update test cases for network interface API
Mikio Hara [Mon, 26 Jan 2015 09:04:44 +0000 (18:04 +0900)]
net: update test cases for network interface API

This change extends existing test case to Windows for helping to fix
golang.org/issue/5395.

Change-Id: Iff077fa98ede511981df513f48d84c19375b3e04
Reviewed-on: https://go-review.googlesource.com/3304
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
10 years agoliblink: do not print pointers in debug output
Russ Cox [Tue, 27 Jan 2015 19:53:14 +0000 (14:53 -0500)]
liblink: do not print pointers in debug output

Pointers change from run to run, making it hard to use
the debug output to identify the reason for a changed
object file.

Change-Id: I0c954da0943092c48686afc99ecf75eba516de6a
Reviewed-on: https://go-review.googlesource.com/3352
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Rob Pike <r@golang.org>
10 years agocrypto/ecdsa: make Sign safe with broken entropy sources
David Leon Gil [Tue, 27 Jan 2015 07:00:21 +0000 (23:00 -0800)]
crypto/ecdsa: make Sign safe with broken entropy sources

ECDSA is unsafe to use if an entropy source produces predictable
output for the ephemeral nonces. E.g., [Nguyen]. A simple
countermeasure is to hash the secret key, the message, and
entropy together to seed a CSPRNG, from which the ephemeral key
is derived.

Fixes #9452

--

This is a minimalist (in terms of patch size) solution, though
not the most parsimonious in its use of primitives:

   - csprng_key = ChopMD-256(SHA2-512(priv.D||entropy||hash))
   - reader = AES-256-CTR(k=csprng_key)

This, however, provides at most 128-bit collision-resistance,
so that Adv will have a term related to the number of messages
signed that is significantly worse than plain ECDSA. This does
not seem to be of any practical importance.

ChopMD-256(SHA2-512(x)) is used, rather than SHA2-256(x), for
two sets of reasons:

*Practical:* SHA2-512 has a larger state and 16 more rounds; it
is likely non-generically stronger than SHA2-256. And, AFAIK,
cryptanalysis backs this up. (E.g., [Biryukov] gives a
distinguisher on 47-round SHA2-256 with cost < 2^85.) This is
well below a reasonable security-strength target.

*Theoretical:* [Coron] and [Chang] show that Chop-MD(F(x)) is
indifferentiable from a random oracle for slightly beyond the
birthday barrier. It seems likely that this makes a generic
security proof that this construction remains UF-CMA is
possible in the indifferentiability framework.

--

Many thanks to Payman Mohassel for reviewing this construction;
any mistakes are mine, however. And, as he notes, reusing the
private key in this way means that the generic-group (non-RO)
proof of ECDSA's security given in [Brown] no longer directly
applies.

--

[Brown]: http://www.cacr.math.uwaterloo.ca/techreports/2000/corr2000-54.ps
"Brown. The exact security of ECDSA. 2000"

[Coron]: https://www.cs.nyu.edu/~puniya/papers/merkle.pdf
"Coron et al. Merkle-Damgard revisited. 2005"

[Chang]: https://www.iacr.org/archive/fse2008/50860436/50860436.pdf
"Chang and Nandi. Improved indifferentiability security analysis
of chopMD hash function. 2008"

[Biryukov]: http://www.iacr.org/archive/asiacrypt2011/70730269/70730269.pdf
"Biryukov et al. Second-order differential collisions for reduced
SHA-256. 2011"

[Nguyen]: ftp://ftp.di.ens.fr/pub/users/pnguyen/PubECDSA.ps
"Nguyen and Shparlinski. The insecurity of the elliptic curve
digital signature algorithm with partially known nonces. 2003"

New tests:

  TestNonceSafety: Check that signatures are safe even with a
    broken entropy source.

  TestINDCCA: Check that signatures remain non-deterministic
    with a functional entropy source.

Updated "golden" KATs in crypto/tls/testdata that use ECDSA suites.

Change-Id: I55337a2fbec2e42a36ce719bd2184793682d678a
Reviewed-on: https://go-review.googlesource.com/3340
Reviewed-by: Adam Langley <agl@golang.org>
10 years agomath/big: various fixes, enable tests for 32bit platforms
Robert Griesemer [Tue, 27 Jan 2015 00:08:51 +0000 (16:08 -0800)]
math/big: various fixes, enable tests for 32bit platforms

- fixed Float.Add, Float.Sub
- fixed Float.PString to be platform independent
- fixed Float.Uint64
- fixed various test outputs

TBR: adonovan

Change-Id: I9d273b344d4786f1fed18862198b23285c358a39
Reviewed-on: https://go-review.googlesource.com/3321
Reviewed-by: Robert Griesemer <gri@golang.org>
10 years agoruntime: simplify code
Dmitry Vyukov [Tue, 27 Jan 2015 19:55:03 +0000 (22:55 +0300)]
runtime: simplify code

The %61 hack was added when runtime was is in C.
Now the Go compiler does the optimization.

Change-Id: I79c3302ec4b931eaaaaffe75e7101c92bf287fc7
Reviewed-on: https://go-review.googlesource.com/3289
Reviewed-by: Keith Randall <khr@golang.org>