2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// The racewalk pass modifies the code tree for the function as follows:
|
|
|
|
|
//
|
|
|
|
|
// 1. It inserts a call to racefuncenter at the beginning of each function.
|
|
|
|
|
// 2. It inserts a call to racefuncexit at the end of each function.
|
|
|
|
|
// 3. It inserts a call to raceread before each memory read.
|
|
|
|
|
// 4. It inserts a call to racewrite before each memory write.
|
|
|
|
|
//
|
|
|
|
|
// The rewriting is not yet complete. Certain nodes are not rewritten
|
|
|
|
|
// but should be.
|
|
|
|
|
|
|
|
|
|
// TODO(dvyukov): do not instrument initialization as writes:
|
|
|
|
|
// a := make([]int, 10)
|
|
|
|
|
|
|
|
|
|
// Do not instrument the following packages at all,
|
|
|
|
|
// at best instrumentation would cause infinite recursion.
|
|
|
|
|
var omit_pkgs = []string{"runtime", "runtime/race"}
|
|
|
|
|
|
|
|
|
|
// Only insert racefuncenter/racefuncexit into the following packages.
|
|
|
|
|
// Memory accesses in the packages are either uninteresting or will cause false positives.
|
|
|
|
|
var noinst_pkgs = []string{"sync", "sync/atomic"}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func ispkgin(pkgs []string) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
if myimportpath != "" {
|
2015-02-23 16:07:24 -05:00
|
|
|
for i := 0; i < len(pkgs); i++ {
|
2015-02-13 14:40:36 -05:00
|
|
|
if myimportpath == pkgs[i] {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func isforkfunc(fn *Node) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
// Special case for syscall.forkAndExecInChild.
|
|
|
|
|
// In the child, this function must not acquire any locks, because
|
|
|
|
|
// they might have been locked at the time of the fork. This means
|
|
|
|
|
// no rescheduling, no malloc calls, and no new stack segments.
|
|
|
|
|
// Race instrumentation does all of the above.
|
2015-05-27 10:42:55 -04:00
|
|
|
return myimportpath != "" && myimportpath == "syscall" && fn.Func.Nname.Sym.Name == "forkAndExecInChild"
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func racewalk(fn *Node) {
|
2015-02-17 22:13:49 -05:00
|
|
|
if ispkgin(omit_pkgs) || isforkfunc(fn) {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
if !ispkgin(noinst_pkgs) {
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalklist(fn.Nbody, nil)
|
|
|
|
|
|
|
|
|
|
// nothing interesting for race detector in fn->enter
|
2015-03-25 19:33:01 -07:00
|
|
|
racewalklist(fn.Func.Exit, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// nodpc is the PC of the caller as extracted by
|
|
|
|
|
// getcallerpc. We use -widthptr(FP) for x86.
|
|
|
|
|
// BUG: this will not work on arm.
|
2015-02-23 16:07:24 -05:00
|
|
|
nodpc := Nod(OXXX, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
*nodpc = *nodfp
|
|
|
|
|
nodpc.Type = Types[TUINTPTR]
|
|
|
|
|
nodpc.Xoffset = int64(-Widthptr)
|
2015-02-23 16:07:24 -05:00
|
|
|
nd := mkcall("racefuncenter", nil, nil, nodpc)
|
2015-03-25 19:33:01 -07:00
|
|
|
fn.Func.Enter = concat(list1(nd), fn.Func.Enter)
|
2015-02-13 14:40:36 -05:00
|
|
|
nd = mkcall("racefuncexit", nil, nil)
|
2015-03-25 19:33:01 -07:00
|
|
|
fn.Func.Exit = list(fn.Func.Exit, nd)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if Debug['W'] != 0 {
|
2015-05-27 10:42:55 -04:00
|
|
|
s := fmt.Sprintf("after racewalk %v", fn.Func.Nname.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
dumplist(s, fn.Nbody)
|
2015-05-27 10:42:55 -04:00
|
|
|
s = fmt.Sprintf("enter %v", fn.Func.Nname.Sym)
|
2015-03-25 19:33:01 -07:00
|
|
|
dumplist(s, fn.Func.Enter)
|
2015-05-27 10:42:55 -04:00
|
|
|
s = fmt.Sprintf("exit %v", fn.Func.Nname.Sym)
|
2015-03-25 19:33:01 -07:00
|
|
|
dumplist(s, fn.Func.Exit)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func racewalklist(l *NodeList, init **NodeList) {
|
|
|
|
|
var instr *NodeList
|
|
|
|
|
|
|
|
|
|
for ; l != nil; l = l.Next {
|
|
|
|
|
instr = nil
|
|
|
|
|
racewalknode(&l.N, &instr, 0, 0)
|
|
|
|
|
if init == nil {
|
|
|
|
|
l.N.Ninit = concat(l.N.Ninit, instr)
|
|
|
|
|
} else {
|
|
|
|
|
*init = concat(*init, instr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// walkexpr and walkstmt combined
|
|
|
|
|
// walks the tree and adds calls to the
|
|
|
|
|
// instrumentation code to top-level (statement) nodes' init
|
|
|
|
|
func racewalknode(np **Node, init **NodeList, wr int, skip int) {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := *np
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if n == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Debug['w'] > 1 {
|
|
|
|
|
Dump("racewalk-before", n)
|
|
|
|
|
}
|
|
|
|
|
setlineno(n)
|
|
|
|
|
if init == nil {
|
|
|
|
|
Fatal("racewalk: bad init list")
|
|
|
|
|
}
|
|
|
|
|
if init == &n.Ninit {
|
|
|
|
|
// If init == &n->ninit and n->ninit is non-nil,
|
|
|
|
|
// racewalknode might append it to itself.
|
|
|
|
|
// nil it out and handle it separately before putting it back.
|
2015-02-23 16:07:24 -05:00
|
|
|
l := n.Ninit
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
n.Ninit = nil
|
|
|
|
|
racewalklist(l, nil)
|
|
|
|
|
racewalknode(&n, &l, wr, skip) // recurse with nil n->ninit
|
|
|
|
|
appendinit(&n, l)
|
|
|
|
|
*np = n
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
racewalklist(n.Ninit, nil)
|
|
|
|
|
|
|
|
|
|
switch n.Op {
|
|
|
|
|
default:
|
|
|
|
|
Fatal("racewalk: unknown node type %v", Oconv(int(n.Op), 0))
|
|
|
|
|
|
cmd/internal/gc: emit write barriers at lower level
This is primarily preparation for inlining, not an optimization by itself,
but it still helps some.
name old new delta
BenchmarkBinaryTree17 18.2s × (0.99,1.01) 17.9s × (0.99,1.01) -1.57%
BenchmarkFannkuch11 4.44s × (1.00,1.00) 4.42s × (1.00,1.00) -0.40%
BenchmarkFmtFprintfEmpty 119ns × (0.95,1.02) 118ns × (0.96,1.02) ~
BenchmarkFmtFprintfString 501ns × (0.99,1.02) 486ns × (0.99,1.01) -2.89%
BenchmarkFmtFprintfInt 474ns × (0.99,1.00) 457ns × (0.99,1.01) -3.59%
BenchmarkFmtFprintfIntInt 792ns × (1.00,1.00) 768ns × (1.00,1.01) -3.03%
BenchmarkFmtFprintfPrefixedInt 574ns × (1.00,1.01) 584ns × (0.99,1.03) +1.83%
BenchmarkFmtFprintfFloat 749ns × (1.00,1.00) 739ns × (0.99,1.00) -1.34%
BenchmarkFmtManyArgs 2.94µs × (1.00,1.01) 2.77µs × (1.00,1.00) -5.76%
BenchmarkGobDecode 39.5ms × (0.99,1.01) 39.3ms × (0.99,1.01) ~
BenchmarkGobEncode 39.4ms × (1.00,1.01) 39.4ms × (0.99,1.00) ~
BenchmarkGzip 658ms × (1.00,1.01) 661ms × (0.99,1.01) ~
BenchmarkGunzip 142ms × (1.00,1.00) 142ms × (1.00,1.00) +0.22%
BenchmarkHTTPClientServer 134µs × (0.99,1.01) 133µs × (0.98,1.01) ~
BenchmarkJSONEncode 57.1ms × (0.99,1.01) 56.5ms × (0.99,1.01) ~
BenchmarkJSONDecode 141ms × (1.00,1.00) 143ms × (1.00,1.00) +1.09%
BenchmarkMandelbrot200 6.01ms × (1.00,1.00) 6.01ms × (1.00,1.00) ~
BenchmarkGoParse 10.1ms × (0.91,1.09) 9.6ms × (0.94,1.07) ~
BenchmarkRegexpMatchEasy0_32 207ns × (1.00,1.01) 210ns × (1.00,1.00) +1.45%
BenchmarkRegexpMatchEasy0_1K 592ns × (0.99,1.00) 596ns × (0.99,1.01) +0.68%
BenchmarkRegexpMatchEasy1_32 184ns × (0.99,1.01) 184ns × (0.99,1.01) ~
BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.00) 1.01µs × (0.99,1.01) ~
BenchmarkRegexpMatchMedium_32 327ns × (0.99,1.00) 327ns × (1.00,1.01) ~
BenchmarkRegexpMatchMedium_1K 92.5µs × (1.00,1.00) 93.0µs × (1.00,1.02) +0.48%
BenchmarkRegexpMatchHard_32 4.79µs × (0.95,1.00) 4.76µs × (0.95,1.01) ~
BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.00) 136µs × (1.00,1.01) ~
BenchmarkRevcomp 900ms × (0.99,1.01) 892ms × (1.00,1.01) ~
BenchmarkTemplate 170ms × (0.99,1.01) 175ms × (0.99,1.00) +2.95%
BenchmarkTimeParse 645ns × (1.00,1.00) 638ns × (1.00,1.00) -1.16%
BenchmarkTimeFormat 740ns × (1.00,1.00) 772ns × (1.00,1.00) +4.39%
Change-Id: I0be905e32791e0cb70ff01f169c4b309a971d981
Reviewed-on: https://go-review.googlesource.com/9159
Reviewed-by: Rick Hudson <rlh@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-17 00:25:10 -04:00
|
|
|
case OAS, OASWB, OAS2FUNC:
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalknode(&n.Left, init, 1, 0)
|
|
|
|
|
racewalknode(&n.Right, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// can't matter
|
2015-04-01 09:38:44 -07:00
|
|
|
case OCFUNC, OVARKILL:
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OBLOCK:
|
|
|
|
|
if n.List == nil {
|
|
|
|
|
goto ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch n.List.N.Op {
|
|
|
|
|
// Blocks are used for multiple return function calls.
|
|
|
|
|
// x, y := f() becomes BLOCK{CALL f, AS x [SP+0], AS y [SP+n]}
|
|
|
|
|
// We don't want to instrument between the statements because it will
|
|
|
|
|
// smash the results.
|
2015-04-01 09:38:44 -07:00
|
|
|
case OCALLFUNC, OCALLMETH, OCALLINTER:
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalknode(&n.List.N, &n.List.N.Ninit, 0, 0)
|
|
|
|
|
|
2015-03-02 14:22:05 -05:00
|
|
|
var fini *NodeList
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalklist(n.List.Next, &fini)
|
|
|
|
|
n.List = concat(n.List, fini)
|
|
|
|
|
|
|
|
|
|
// Ordinary block, for loop initialization or inlined bodies.
|
|
|
|
|
default:
|
|
|
|
|
racewalklist(n.List, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODEFER:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OPROC:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OCALLINTER:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// Instrument dst argument of runtime.writebarrier* calls
|
|
|
|
|
// as we do not instrument runtime code.
|
|
|
|
|
// typedslicecopy is instrumented in runtime.
|
|
|
|
|
case OCALLFUNC:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ONOT,
|
|
|
|
|
OMINUS,
|
|
|
|
|
OPLUS,
|
|
|
|
|
OREAL,
|
|
|
|
|
OIMAG,
|
2015-04-03 15:58:18 -04:00
|
|
|
OCOM,
|
|
|
|
|
OSQRT:
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalknode(&n.Left, init, wr, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODOTINTER:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODOT:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 1)
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODOTPTR: // dst = (*x).f with implicit *; otherwise it's ODOT+OIND
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OIND: // *p
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OSPTR, OLEN, OCAP:
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
2015-02-17 22:13:49 -05:00
|
|
|
if Istype(n.Left.Type, TMAP) {
|
2015-02-23 16:07:24 -05:00
|
|
|
n1 := Nod(OCONVNOP, n.Left, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
n1.Type = Ptrto(Types[TUINT8])
|
|
|
|
|
n1 = Nod(OIND, n1, nil)
|
|
|
|
|
typecheck(&n1, Erv)
|
|
|
|
|
callinstr(&n1, init, 0, skip)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OLSH,
|
|
|
|
|
ORSH,
|
|
|
|
|
OLROT,
|
|
|
|
|
OAND,
|
|
|
|
|
OANDNOT,
|
|
|
|
|
OOR,
|
|
|
|
|
OXOR,
|
|
|
|
|
OSUB,
|
|
|
|
|
OMUL,
|
|
|
|
|
OHMUL,
|
|
|
|
|
OEQ,
|
|
|
|
|
ONE,
|
|
|
|
|
OLT,
|
|
|
|
|
OLE,
|
|
|
|
|
OGE,
|
|
|
|
|
OGT,
|
|
|
|
|
OADD,
|
|
|
|
|
OCOMPLEX:
|
|
|
|
|
racewalknode(&n.Left, init, wr, 0)
|
|
|
|
|
racewalknode(&n.Right, init, wr, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OANDAND, OOROR:
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalknode(&n.Left, init, wr, 0)
|
|
|
|
|
|
|
|
|
|
// walk has ensured the node has moved to a location where
|
|
|
|
|
// side effects are safe.
|
|
|
|
|
// n->right may not be executed,
|
|
|
|
|
// so instrumentation goes to n->right->ninit, not init.
|
|
|
|
|
racewalknode(&n.Right, &n.Right.Ninit, wr, 0)
|
|
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ONAME:
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OCONV:
|
|
|
|
|
racewalknode(&n.Left, init, wr, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OCONVNOP:
|
|
|
|
|
racewalknode(&n.Left, init, wr, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case ODIV, OMOD:
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalknode(&n.Left, init, wr, 0)
|
|
|
|
|
racewalknode(&n.Right, init, wr, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OINDEX:
|
2015-02-17 22:13:49 -05:00
|
|
|
if !Isfixedarray(n.Left.Type) {
|
2015-02-13 14:40:36 -05:00
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
2015-02-17 22:13:49 -05:00
|
|
|
} else if !islvalue(n.Left) {
|
2015-02-13 14:40:36 -05:00
|
|
|
// index of unaddressable array, like Map[k][i].
|
|
|
|
|
racewalknode(&n.Left, init, wr, 0)
|
|
|
|
|
|
|
|
|
|
racewalknode(&n.Right, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
racewalknode(&n.Right, init, 0, 0)
|
|
|
|
|
if n.Left.Type.Etype != TSTRING {
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
}
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR:
|
cmd/internal/gc: optimize slice + write barrier
The code generated for a slice x[i:j] or x[i:j:k] computes the entire
new slice (base, len, cap) and then uses it as the evaluation of the
slice expression.
If the slice is part of an update x = x[i:j] or x = x[i:j:k], there are
opportunities to avoid computing some of these fields.
For x = x[0:i], we know that only the len is changing;
base can be ignored completely, and cap can be left unmodified.
For x = x[0:i:j], we know that only len and cap are changing;
base can be ignored completely.
For x = x[i:i], we know that the resulting cap is zero, and we don't
adjust the base during a slice producing a zero-cap result,
so again base can be ignored completely.
No write to base, no write barrier.
The old slice code was trying to work at a Go syntax level, mainly
because that was how you wrote code just once instead of once
per architecture. Now the compiler is factored a bit better and we
can implement slice during code generation but still have one copy
of the code. So the new code is working at that lower level.
(It must, to update only parts of the result.)
This CL by itself:
name old mean new mean delta
BinaryTree17 5.81s × (0.98,1.03) 5.71s × (0.96,1.05) ~ (p=0.101)
Fannkuch11 4.35s × (1.00,1.00) 4.39s × (1.00,1.00) +0.79% (p=0.000)
FmtFprintfEmpty 86.0ns × (0.94,1.11) 82.6ns × (0.98,1.04) -3.86% (p=0.048)
FmtFprintfString 276ns × (0.98,1.04) 273ns × (0.98,1.02) ~ (p=0.235)
FmtFprintfInt 274ns × (0.98,1.06) 270ns × (0.99,1.01) ~ (p=0.119)
FmtFprintfIntInt 506ns × (0.99,1.01) 475ns × (0.99,1.01) -6.02% (p=0.000)
FmtFprintfPrefixedInt 391ns × (0.99,1.01) 393ns × (1.00,1.01) ~ (p=0.139)
FmtFprintfFloat 566ns × (0.99,1.01) 574ns × (1.00,1.01) +1.33% (p=0.001)
FmtManyArgs 1.91µs × (0.99,1.01) 1.87µs × (0.99,1.02) -1.83% (p=0.000)
GobDecode 15.3ms × (0.99,1.02) 15.0ms × (0.98,1.05) -1.84% (p=0.042)
GobEncode 11.5ms × (0.97,1.03) 11.4ms × (0.99,1.03) ~ (p=0.152)
Gzip 645ms × (0.99,1.01) 647ms × (0.99,1.01) ~ (p=0.265)
Gunzip 142ms × (1.00,1.00) 143ms × (1.00,1.01) +0.90% (p=0.000)
HTTPClientServer 90.5µs × (0.97,1.04) 88.5µs × (0.99,1.03) -2.27% (p=0.014)
JSONEncode 32.0ms × (0.98,1.03) 29.6ms × (0.98,1.01) -7.51% (p=0.000)
JSONDecode 114ms × (0.99,1.01) 104ms × (1.00,1.01) -8.60% (p=0.000)
Mandelbrot200 6.04ms × (1.00,1.01) 6.02ms × (1.00,1.00) ~ (p=0.057)
GoParse 6.47ms × (0.97,1.05) 6.37ms × (0.97,1.04) ~ (p=0.105)
RegexpMatchEasy0_32 171ns × (0.93,1.07) 152ns × (0.99,1.01) -11.09% (p=0.000)
RegexpMatchEasy0_1K 550ns × (0.98,1.01) 530ns × (1.00,1.00) -3.78% (p=0.000)
RegexpMatchEasy1_32 135ns × (0.99,1.02) 134ns × (0.99,1.01) -1.33% (p=0.002)
RegexpMatchEasy1_1K 879ns × (1.00,1.01) 865ns × (1.00,1.00) -1.58% (p=0.000)
RegexpMatchMedium_32 243ns × (1.00,1.00) 233ns × (1.00,1.00) -4.30% (p=0.000)
RegexpMatchMedium_1K 70.3µs × (1.00,1.00) 69.5µs × (1.00,1.00) -1.13% (p=0.000)
RegexpMatchHard_32 3.82µs × (1.00,1.01) 3.74µs × (1.00,1.00) -1.95% (p=0.000)
RegexpMatchHard_1K 117µs × (1.00,1.00) 115µs × (1.00,1.00) -1.69% (p=0.000)
Revcomp 917ms × (0.97,1.04) 920ms × (0.97,1.04) ~ (p=0.786)
Template 114ms × (0.99,1.01) 117ms × (0.99,1.01) +2.58% (p=0.000)
TimeParse 622ns × (0.99,1.01) 615ns × (0.99,1.00) -1.06% (p=0.000)
TimeFormat 665ns × (0.99,1.01) 654ns × (0.99,1.00) -1.70% (p=0.000)
This CL and previous CL (append) combined:
name old mean new mean delta
BinaryTree17 5.68s × (0.97,1.04) 5.71s × (0.96,1.05) ~ (p=0.638)
Fannkuch11 4.41s × (0.98,1.03) 4.39s × (1.00,1.00) ~ (p=0.474)
FmtFprintfEmpty 92.7ns × (0.91,1.16) 82.6ns × (0.98,1.04) -10.89% (p=0.004)
FmtFprintfString 281ns × (0.96,1.08) 273ns × (0.98,1.02) ~ (p=0.078)
FmtFprintfInt 288ns × (0.97,1.06) 270ns × (0.99,1.01) -6.37% (p=0.000)
FmtFprintfIntInt 493ns × (0.97,1.04) 475ns × (0.99,1.01) -3.53% (p=0.002)
FmtFprintfPrefixedInt 423ns × (0.97,1.04) 393ns × (1.00,1.01) -7.07% (p=0.000)
FmtFprintfFloat 598ns × (0.99,1.01) 574ns × (1.00,1.01) -4.02% (p=0.000)
FmtManyArgs 1.89µs × (0.98,1.05) 1.87µs × (0.99,1.02) ~ (p=0.305)
GobDecode 14.8ms × (0.98,1.03) 15.0ms × (0.98,1.05) ~ (p=0.237)
GobEncode 12.3ms × (0.98,1.01) 11.4ms × (0.99,1.03) -6.95% (p=0.000)
Gzip 656ms × (0.99,1.05) 647ms × (0.99,1.01) ~ (p=0.101)
Gunzip 142ms × (1.00,1.00) 143ms × (1.00,1.01) +0.58% (p=0.001)
HTTPClientServer 91.2µs × (0.97,1.04) 88.5µs × (0.99,1.03) -3.02% (p=0.003)
JSONEncode 32.6ms × (0.97,1.08) 29.6ms × (0.98,1.01) -9.10% (p=0.000)
JSONDecode 114ms × (0.97,1.05) 104ms × (1.00,1.01) -8.74% (p=0.000)
Mandelbrot200 6.11ms × (0.98,1.04) 6.02ms × (1.00,1.00) ~ (p=0.090)
GoParse 6.66ms × (0.97,1.04) 6.37ms × (0.97,1.04) -4.41% (p=0.000)
RegexpMatchEasy0_32 159ns × (0.99,1.00) 152ns × (0.99,1.01) -4.69% (p=0.000)
RegexpMatchEasy0_1K 538ns × (1.00,1.01) 530ns × (1.00,1.00) -1.57% (p=0.000)
RegexpMatchEasy1_32 138ns × (1.00,1.00) 134ns × (0.99,1.01) -2.91% (p=0.000)
RegexpMatchEasy1_1K 869ns × (0.99,1.01) 865ns × (1.00,1.00) -0.51% (p=0.012)
RegexpMatchMedium_32 252ns × (0.99,1.01) 233ns × (1.00,1.00) -7.85% (p=0.000)
RegexpMatchMedium_1K 72.7µs × (1.00,1.00) 69.5µs × (1.00,1.00) -4.43% (p=0.000)
RegexpMatchHard_32 3.85µs × (1.00,1.00) 3.74µs × (1.00,1.00) -2.74% (p=0.000)
RegexpMatchHard_1K 118µs × (1.00,1.00) 115µs × (1.00,1.00) -2.24% (p=0.000)
Revcomp 920ms × (0.97,1.07) 920ms × (0.97,1.04) ~ (p=0.998)
Template 129ms × (0.98,1.03) 117ms × (0.99,1.01) -9.79% (p=0.000)
TimeParse 619ns × (0.99,1.01) 615ns × (0.99,1.00) -0.57% (p=0.011)
TimeFormat 661ns × (0.98,1.04) 654ns × (0.99,1.00) ~ (p=0.223)
Change-Id: If054d81ab2c71d8d62cf54b5b1fac2af66b387fc
Reviewed-on: https://go-review.googlesource.com/9813
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-05-06 12:35:53 -04:00
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OADDR:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 1)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// n->left is Type* which is not interesting.
|
|
|
|
|
case OEFACE:
|
|
|
|
|
racewalknode(&n.Right, init, 0, 0)
|
|
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OITAB:
|
|
|
|
|
racewalknode(&n.Left, init, 0, 0)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// should not appear in AST by now
|
|
|
|
|
case OSEND,
|
|
|
|
|
ORECV,
|
|
|
|
|
OCLOSE,
|
|
|
|
|
ONEW,
|
|
|
|
|
OXCASE,
|
|
|
|
|
OXFALL,
|
|
|
|
|
OCASE,
|
|
|
|
|
OPANIC,
|
|
|
|
|
ORECOVER,
|
|
|
|
|
OCONVIFACE,
|
|
|
|
|
OCMPIFACE,
|
|
|
|
|
OMAKECHAN,
|
|
|
|
|
OMAKEMAP,
|
|
|
|
|
OMAKESLICE,
|
|
|
|
|
OCALL,
|
|
|
|
|
OCOPY,
|
|
|
|
|
OAPPEND,
|
|
|
|
|
ORUNESTR,
|
|
|
|
|
OARRAYBYTESTR,
|
|
|
|
|
OARRAYRUNESTR,
|
|
|
|
|
OSTRARRAYBYTE,
|
|
|
|
|
OSTRARRAYRUNE,
|
|
|
|
|
OINDEXMAP,
|
|
|
|
|
// lowered to call
|
|
|
|
|
OCMPSTR,
|
|
|
|
|
OADDSTR,
|
|
|
|
|
ODOTTYPE,
|
|
|
|
|
ODOTTYPE2,
|
|
|
|
|
OAS2DOTTYPE,
|
|
|
|
|
OCALLPART,
|
|
|
|
|
// lowered to PTRLIT
|
|
|
|
|
OCLOSURE, // lowered to PTRLIT
|
|
|
|
|
ORANGE, // lowered to ordinary for loop
|
|
|
|
|
OARRAYLIT, // lowered to assignments
|
|
|
|
|
OMAPLIT,
|
|
|
|
|
OSTRUCTLIT,
|
|
|
|
|
OAS2,
|
|
|
|
|
OAS2RECV,
|
|
|
|
|
OAS2MAPR,
|
|
|
|
|
OASOP:
|
|
|
|
|
Yyerror("racewalk: %v must be lowered by now", Oconv(int(n.Op), 0))
|
|
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// impossible nodes: only appear in backend.
|
2015-04-01 09:38:44 -07:00
|
|
|
case ORROTC, OEXTEND:
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("racewalk: %v cannot exist now", Oconv(int(n.Op), 0))
|
2015-04-09 10:08:29 +03:00
|
|
|
goto ret
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-04-09 10:08:29 +03:00
|
|
|
case OGETG:
|
|
|
|
|
Yyerror("racewalk: OGETG can happen only in runtime which we don't instrument")
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
2015-05-22 01:16:52 -04:00
|
|
|
case OFOR:
|
2015-05-26 21:30:20 -04:00
|
|
|
if n.Left != nil {
|
|
|
|
|
racewalknode(&n.Left, &n.Left.Ninit, 0, 0)
|
|
|
|
|
}
|
2015-05-22 01:16:52 -04:00
|
|
|
if n.Right != nil {
|
|
|
|
|
racewalknode(&n.Right, &n.Right.Ninit, 0, 0)
|
|
|
|
|
}
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
case OIF, OSWITCH:
|
|
|
|
|
if n.Left != nil {
|
|
|
|
|
racewalknode(&n.Left, &n.Left.Ninit, 0, 0)
|
|
|
|
|
}
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// just do generic traversal
|
|
|
|
|
case OCALLMETH,
|
2015-02-13 14:40:36 -05:00
|
|
|
ORETURN,
|
|
|
|
|
ORETJMP,
|
|
|
|
|
OSELECT,
|
|
|
|
|
OEMPTY,
|
|
|
|
|
OBREAK,
|
|
|
|
|
OCONTINUE,
|
|
|
|
|
OFALL,
|
|
|
|
|
OGOTO,
|
|
|
|
|
OLABEL:
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// does not require instrumentation
|
|
|
|
|
case OPRINT, // don't bother instrumenting it
|
|
|
|
|
OPRINTN, // don't bother instrumenting it
|
|
|
|
|
OCHECKNIL, // always followed by a read.
|
|
|
|
|
OPARAM, // it appears only in fn->exit to copy heap params back
|
|
|
|
|
OCLOSUREVAR, // immutable pointer to captured variable
|
|
|
|
|
ODOTMETH, // either part of CALLMETH or CALLPART (lowered to PTRLIT)
|
|
|
|
|
OINDREG, // at this stage, only n(SP) nodes from nodarg
|
|
|
|
|
ODCL, // declarations (without value) cannot be races
|
|
|
|
|
ODCLCONST,
|
|
|
|
|
ODCLTYPE,
|
|
|
|
|
OTYPE,
|
|
|
|
|
ONONAME,
|
|
|
|
|
OLITERAL,
|
2015-04-09 10:08:29 +03:00
|
|
|
OSLICESTR, // always preceded by bounds checking, avoid double instrumentation.
|
|
|
|
|
OTYPESW: // ignored by code generation, do not instrument.
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret:
|
|
|
|
|
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
|
|
|
|
|
racewalklist(n.List, init)
|
|
|
|
|
}
|
|
|
|
|
racewalklist(n.Nbody, nil)
|
|
|
|
|
racewalklist(n.Rlist, nil)
|
|
|
|
|
*np = n
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func isartificial(n *Node) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
// compiler-emitted artificial things that we do not want to instrument,
|
|
|
|
|
// cant' possibly participate in a data race.
|
|
|
|
|
if n.Op == ONAME && n.Sym != nil && n.Sym.Name != "" {
|
|
|
|
|
if n.Sym.Name == "_" {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// autotmp's are always local
|
|
|
|
|
if strings.HasPrefix(n.Sym.Name, "autotmp_") {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// statictmp's are read-only
|
|
|
|
|
if strings.HasPrefix(n.Sym.Name, "statictmp_") {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go.itab is accessed only by the compiler and runtime (assume safe)
|
|
|
|
|
if n.Sym.Pkg != nil && n.Sym.Pkg.Name != "" && n.Sym.Pkg.Name == "go.itab" {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func callinstr(np **Node, init **NodeList, wr int, skip int) bool {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := *np
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
//print("callinstr for %+N [ %O ] etype=%E class=%d\n",
|
|
|
|
|
// n, n->op, n->type ? n->type->etype : -1, n->class);
|
|
|
|
|
|
|
|
|
|
if skip != 0 || n.Type == nil || n.Type.Etype >= TIDEAL {
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
t := n.Type
|
2015-02-17 22:13:49 -05:00
|
|
|
if isartificial(n) {
|
|
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
b := outervalue(n)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// it skips e.g. stores to ... parameter array
|
2015-02-17 22:13:49 -05:00
|
|
|
if isartificial(b) {
|
|
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-03-27 12:00:07 -07:00
|
|
|
class := b.Class
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// BUG: we _may_ want to instrument PAUTO sometimes
|
|
|
|
|
// e.g. if we've got a local variable/method receiver
|
|
|
|
|
// that has got a pointer inside. Whether it points to
|
|
|
|
|
// the heap or not is impossible to know at compile time
|
|
|
|
|
if (class&PHEAP != 0) || class == PPARAMREF || class == PEXTERN || b.Op == OINDEX || b.Op == ODOTPTR || b.Op == OIND {
|
2015-02-23 16:07:24 -05:00
|
|
|
hascalls := 0
|
2015-02-13 14:40:36 -05:00
|
|
|
foreach(n, hascallspred, &hascalls)
|
|
|
|
|
if hascalls != 0 {
|
|
|
|
|
n = detachexpr(n, init)
|
|
|
|
|
*np = n
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 22:01:01 -04:00
|
|
|
n = treecopy(n, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
makeaddable(n)
|
2015-02-23 16:07:24 -05:00
|
|
|
var f *Node
|
2015-02-17 22:13:49 -05:00
|
|
|
if t.Etype == TSTRUCT || Isfixedarray(t) {
|
2015-02-23 16:07:24 -05:00
|
|
|
name := "racereadrange"
|
2015-02-13 14:40:36 -05:00
|
|
|
if wr != 0 {
|
|
|
|
|
name = "racewriterange"
|
|
|
|
|
}
|
|
|
|
|
f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(t.Width))
|
|
|
|
|
} else {
|
2015-02-23 16:07:24 -05:00
|
|
|
name := "raceread"
|
2015-02-13 14:40:36 -05:00
|
|
|
if wr != 0 {
|
|
|
|
|
name = "racewrite"
|
|
|
|
|
}
|
|
|
|
|
f = mkcall(name, nil, init, uintptraddr(n))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*init = list(*init, f)
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// makeaddable returns a node whose memory location is the
|
|
|
|
|
// same as n, but which is addressable in the Go language
|
|
|
|
|
// sense.
|
|
|
|
|
// This is different from functions like cheapexpr that may make
|
|
|
|
|
// a copy of their argument.
|
|
|
|
|
func makeaddable(n *Node) {
|
|
|
|
|
// The arguments to uintptraddr technically have an address but
|
|
|
|
|
// may not be addressable in the Go sense: for example, in the case
|
|
|
|
|
// of T(v).Field where T is a struct type and v is
|
|
|
|
|
// an addressable value.
|
|
|
|
|
switch n.Op {
|
|
|
|
|
case OINDEX:
|
2015-02-17 22:13:49 -05:00
|
|
|
if Isfixedarray(n.Left.Type) {
|
2015-02-13 14:40:36 -05:00
|
|
|
makeaddable(n.Left)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Turn T(v).Field into v.Field
|
2015-04-01 09:38:44 -07:00
|
|
|
case ODOT, OXDOT:
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Left.Op == OCONVNOP {
|
|
|
|
|
n.Left = n.Left.Left
|
|
|
|
|
}
|
|
|
|
|
makeaddable(n.Left)
|
|
|
|
|
|
|
|
|
|
// nothing to do
|
|
|
|
|
case ODOTPTR:
|
|
|
|
|
fallthrough
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func uintptraddr(n *Node) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
r := Nod(OADDR, n, nil)
|
2015-02-17 22:13:49 -05:00
|
|
|
r.Bounded = true
|
2015-02-13 14:40:36 -05:00
|
|
|
r = conv(r, Types[TUNSAFEPTR])
|
|
|
|
|
r = conv(r, Types[TUINTPTR])
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func detachexpr(n *Node, init **NodeList) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
addr := Nod(OADDR, n, nil)
|
|
|
|
|
l := temp(Ptrto(n.Type))
|
|
|
|
|
as := Nod(OAS, l, addr)
|
2015-02-13 14:40:36 -05:00
|
|
|
typecheck(&as, Etop)
|
|
|
|
|
walkexpr(&as, init)
|
|
|
|
|
*init = list(*init, as)
|
2015-02-23 16:07:24 -05:00
|
|
|
ind := Nod(OIND, l, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
typecheck(&ind, Erv)
|
|
|
|
|
walkexpr(&ind, init)
|
|
|
|
|
return ind
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func foreachnode(n *Node, f func(*Node, interface{}), c interface{}) {
|
|
|
|
|
if n != nil {
|
|
|
|
|
f(n, c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func foreachlist(l *NodeList, f func(*Node, interface{}), c interface{}) {
|
|
|
|
|
for ; l != nil; l = l.Next {
|
|
|
|
|
foreachnode(l.N, f, c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func foreach(n *Node, f func(*Node, interface{}), c interface{}) {
|
|
|
|
|
foreachlist(n.Ninit, f, c)
|
|
|
|
|
foreachnode(n.Left, f, c)
|
|
|
|
|
foreachnode(n.Right, f, c)
|
|
|
|
|
foreachlist(n.List, f, c)
|
|
|
|
|
foreachlist(n.Nbody, f, c)
|
|
|
|
|
foreachlist(n.Rlist, f, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func hascallspred(n *Node, c interface{}) {
|
|
|
|
|
switch n.Op {
|
2015-04-01 09:38:44 -07:00
|
|
|
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER:
|
2015-02-13 14:40:36 -05:00
|
|
|
(*c.(*int))++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 12:58:47 -07:00
|
|
|
// appendinit is like addinit in subr.go
|
2015-02-13 14:40:36 -05:00
|
|
|
// but appends rather than prepends.
|
|
|
|
|
func appendinit(np **Node, init *NodeList) {
|
|
|
|
|
if init == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
n := *np
|
2015-02-13 14:40:36 -05:00
|
|
|
switch n.Op {
|
|
|
|
|
// There may be multiple refs to this node;
|
|
|
|
|
// introduce OCONVNOP to hold init list.
|
2015-04-01 09:38:44 -07:00
|
|
|
case ONAME, OLITERAL:
|
2015-02-13 14:40:36 -05:00
|
|
|
n = Nod(OCONVNOP, n, nil)
|
|
|
|
|
|
|
|
|
|
n.Type = n.Left.Type
|
|
|
|
|
n.Typecheck = 1
|
|
|
|
|
*np = n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Ninit = concat(n.Ninit, init)
|
|
|
|
|
n.Ullman = UINF
|
|
|
|
|
}
|