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

75 Commits

Author SHA1 Message Date
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
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
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
Keith Randall
7c1e33033d reflect: Fix reflect.funcLayout. The GC bitmap has two bits per
pointer, not one.

Fixes #9179

LGTM=iant, rsc
R=golang-codereviews, iant, rsc
CC=golang-codereviews
https://golang.org/cl/182160043
2014-12-01 07:52:09 -08:00
Russ Cox
3e804631d9 [dev.cc] all: merge dev.power64 (7667e41f3ced) into dev.cc
This is to reduce the delta between dev.cc and dev.garbage to just garbage collector changes.

These are the files that had merge conflicts and have been edited by hand:
        malloc.go
        mem_linux.go
        mgc.go
        os1_linux.go
        proc1.go
        panic1.go
        runtime1.go

LGTM=austin
R=austin
CC=golang-codereviews
https://golang.org/cl/174180043
2014-11-14 12:10:52 -05:00
Russ Cox
33e910296e [dev.cc] reflect: interfaces contain only pointers
[This CL is part of the removal of C code from package runtime.
See golang.org/s/dev.cc for an overview.]

Adjustments for changes made in CL 169360043.
This change is already present in the dev.garbage branch.

LGTM=r
R=r
CC=austin, golang-codereviews, iant, khr
https://golang.org/cl/167520044
2014-11-11 01:23:01 -05:00
Austin Clements
700ab16daf [dev.power64] reflect: fix asm on power64x
reflect/asm_power64x.s was missing changes made to other
platforms for stack maps.  This CL ports those changes.  With
this fix, the reflect test passes on power64x.

LGTM=rsc
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/170870043
2014-10-31 15:29:03 -04:00
Austin Clements
f0bd539c59 [dev.power64] all: merge default into dev.power64
This brings dev.power64 up-to-date with the current tip of
default.  go_bootstrap is still panicking with a bad defer
when initializing the runtime (even on amd64).

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/152570049
2014-10-22 15:51:54 -04:00
Austin Clements
2bd616b1a7 build: merge the great pkg/ rename into dev.power64
This also removes pkg/runtime/traceback_lr.c, which was ported
to Go in an earlier commit and then moved to
runtime/traceback.go.

Reviewer: rsc@golang.org
          rsc: LGTM
2014-10-22 13:25:37 -04:00
Ian Lance Taylor
82a0188c88 reflect: fix TestAllocations now that interfaces hold only pointers
This test was failing but did not break the build because it
was not run when -test.short was used.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/157150043
2014-10-20 11:10:03 -07:00
Ian Lance Taylor
7b9c5ec24b reflect: allocate correct type in assignTo and cvtT2I
I came across this while debugging a GC problem in gccgo.
There is code in assignTo and cvtT2I that handles assignment
to all interface values.  It allocates an empty interface even
if the real type is a non-empty interface.  The fields are
then set for a non-empty interface, but the memory is recorded
as holding an empty interface.  This means that the GC has
incorrect information.

This is extremely unlikely to fail, because the code in the GC
that handles empty interfaces looks like this:

obj = nil;
typ = eface->type;
if(typ != nil) {
        if(!(typ->kind&KindDirectIface) || !(typ->kind&KindNoPointers))
                obj = eface->data;

In the current runtime the condition is always true--if
KindDirectIface is set, then KindNoPointers is clear--and we
always want to set obj = eface->data.  So the question is what
happens when we incorrectly store a non-empty interface value
in memory marked as an empty interface.  In that case
eface->type will not be a *rtype as we expect, but will
instead be a pointer to an Itab.  We are going to use this
pointer to look at a *rtype kind field.  The *rtype struct
starts out like this:

type rtype struct {
        size          uintptr
        hash          uint32            // hash of type; avoids computation in hash tables
        _             uint8             // unused/padding
        align         uint8             // alignment of variable with this type
        fieldAlign    uint8             // alignment of struct field with this type
        kind          uint8             // enumeration for C

An Itab always has at least two pointers, so on a
little-endian 64-bit system the kind field will be the high
byte of the second pointer.  This will normally be zero, so
the test of typ->kind will succeed, which is what we want.

On a 32-bit system it might be possible to construct a failing
case by somehow getting the Itab for an interface with one
method to be immediately followed by a word that is all ones.
The effect would be that the test would sometimes fail and the
GC would not mark obj, leading to an invalid dangling
pointer.  I have not tried to construct this test.

I noticed this in gccgo, where this error is much more likely
to cause trouble for a rather random reason: gccgo uses a
different layout of rtype, and in gccgo the kind field happens
to be the low byte of a pointer, not the high byte.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/155450044
2014-10-20 10:43:43 -07:00
Russ Cox
0d81b72e1b reflect: a few microoptimizations
Replace i < 0 || i >= x with uint(i) >= uint(x).
Shorten a few other code sequences.
Move the kind bits to the bottom of the flag word, to avoid shifts.

LGTM=r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/159020043
2014-10-17 12:54:31 -04:00
Damien Neil
4e1d196543 reflect: fix struct size calculation to include terminal padding
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/160920045
2014-10-16 13:58:32 -07:00
Russ Cox
a1616d4a32 reflect: shorten value to 3 words
scalar is no longer needed, now that
interfaces always hold pointers.

Comparing best of 5 with TurboBoost turned off,
on a 2012 Retina MacBook Pro Core i5.
Still not completely confident in these numbers,
but the gob and template improvements seem real.

benchmark                       old ns/op   new ns/op   delta
BenchmarkBinaryTree17           3819892491  3803008185  -0.44%
BenchmarkFannkuch11             3623876405  3611776426  -0.33%
BenchmarkFmtFprintfEmpty        119         118         -0.84%
BenchmarkFmtFprintfString       294         292         -0.68%
BenchmarkFmtFprintfInt          310         304         -1.94%
BenchmarkFmtFprintfIntInt       513         507         -1.17%
BenchmarkFmtFprintfPrefixedInt  427         426         -0.23%
BenchmarkFmtFprintfFloat        562         554         -1.42%
BenchmarkFmtManyArgs            1873        1832        -2.19%
BenchmarkGobDecode              15824504    14746565    -6.81%
BenchmarkGobEncode              14347378    14208743    -0.97%
BenchmarkGzip                   537229271   537973492   +0.14%
BenchmarkGunzip                 134996775   135406149   +0.30%
BenchmarkHTTPClientServer       119065      116937      -1.79%
BenchmarkJSONEncode             29134359    28928099    -0.71%
BenchmarkJSONDecode             106867289   105770161   -1.03%
BenchmarkMandelbrot200          5798475     5791433     -0.12%
BenchmarkGoParse                5299169     5379201     +1.51%
BenchmarkRegexpMatchEasy0_32    195         195         +0.00%
BenchmarkRegexpMatchEasy0_1K    477         477         +0.00%
BenchmarkRegexpMatchEasy1_32    170         170         +0.00%
BenchmarkRegexpMatchEasy1_1K    1412        1397        -1.06%
BenchmarkRegexpMatchMedium_32   336         337         +0.30%
BenchmarkRegexpMatchMedium_1K   109025      108977      -0.04%
BenchmarkRegexpMatchHard_32     5854        5856        +0.03%
BenchmarkRegexpMatchHard_1K     184914      184748      -0.09%
BenchmarkRevcomp                829233526   836598734   +0.89%
BenchmarkTemplate               142055312   137016166   -3.55%
BenchmarkTimeParse              598         597         -0.17%
BenchmarkTimeFormat             564         568         +0.71%

Fixes #7425.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant, khr
https://golang.org/cl/158890043
2014-10-15 14:24:18 -04:00
Russ Cox
94950afdf8 reflect: add fast path for FieldByIndex with len(index) = 1
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/152640043
2014-10-15 13:33:00 -04:00
Ian Lance Taylor
3cf9acccae reflect: generated unrolled GC bitmask directly
The code for a generated type is already generating an
unrolled GC bitmask.  Rather than unrolling the the source
type bitmasks and copying them, just generate the required
bitmask directly.  Don't mark it as an unrolled GC program,
since there is no need to do so.

Fixes #8917.

LGTM=rsc
R=dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/156930044
2014-10-13 10:01:34 -07:00
Michael Hudson-Doyle
14cd40d912 reflect: add direct call tests to TestMakeFuncVariadic
TestMakeFuncVariadic only called the variadic function via Call and
CallSlice, not via a direct function call.

I thought these tests would fail under gccgo tip, but they don't.  Still seems worth having though.

LGTM=iant
R=golang-codereviews, gobot, iant
CC=golang-codereviews
https://golang.org/cl/152060043
2014-10-08 15:58:56 -07:00
Ian Lance Taylor
6920b2a1f9 reflect: add tests for variadic method calls
These tests fail when using gccgo.  In gccgo using Interface
on the value of a method function is implemented using a
variant of MakeFunc.  That approach did not correctly handle
variadic functions.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/151280043
2014-10-08 15:48:46 -07:00
Russ Cox
18172c42ff runtime: remove type-punning for Type.gc[0], gc[1]
Depending on flags&KindGCProg,
gc[0] and gc[1] are either pointers or inlined bitmap bits.
That's not compatible with a precise garbage collector:
it needs to be always pointers or never pointers.

Change the inlined bitmap case to store a pointer to an
out-of-line bitmap in gc[0]. The out-of-line bitmaps are
dedup'ed, so that for example all pointer types share the
same out-of-line bitmap.

Fixes #8864.

LGTM=r
R=golang-codereviews, dvyukov, r
CC=golang-codereviews, iant, khr, rlh
https://golang.org/cl/155820043
2014-10-07 11:06:51 -04:00
Russ Cox
62d3202aaa reflect: fix IsValid vs Kind mismatch after Elem of nil interface
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/151960044
2014-10-01 16:51:32 -04:00
Russ Cox
dd8f29e3fe reflect: adjust Value.String to give correct answer for methods
Fixes #7859.

LGTM=r
R=adonovan, r
CC=golang-codereviews
https://golang.org/cl/136710043
2014-09-18 21:19:18 -04:00
Russ Cox
a325f4f2b3 reflect: add Type.Comparable
Like most of the Type methods, the definition of Comparable
is what the Go spec says it is.

Fixes #7911.

LGTM=gri
R=gri, r
CC=golang-codereviews
https://golang.org/cl/144020043
2014-09-16 17:40:10 -04:00
Russ Cox
f0d44dbeaf runtime: look up arg stackmap for makeFuncStub/methodValueStub during traceback
makeFuncStub and methodValueStub are used by reflect as
generic function implementations. Each call might have
different arguments. Extract those arguments from the
closure data instead of assuming it is the same each time.

Because the argument map is now being extracted from the
function itself, we don't need the special cases in reflect.Call
anymore, so delete those.

Fixes an occasional crash seen when stack copying does
not update makeFuncStub's arguments correctly.

Will also help make it safe to require stack maps in the
garbage collector.

Derived from CL 142000044 by khr.

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/143890044
2014-09-12 07:29:19 -04:00
Keith Randall
b78d7b75c7 reflect: use runtime's memmove instead of its own
They will both need write barriers at some point.
But until then, no reason why we shouldn't share.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/141330043
2014-09-10 12:37:28 -07:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00