1. 04 Apr, 2016 8 commits
    • Alexandru Moșoi's avatar
      cmd/compile: fold IsInBounds of modulo. · 68325b56
      Alexandru Moșoi authored
      In b we only need the division by 0 check.
      
      func b(i uint, v []byte) byte {
          return v[i%uint(len(v))]
      }
      
      Updates #15079.
      
      Change-Id: Ic7491e677dd57cd6ba577efbce576dbb6e023cbd
      Reviewed-on: https://go-review.googlesource.com/21502
      Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro>
      Reviewed-by: 's avatarDavid Chase <drchase@google.com>
      Reviewed-by: 's avatarAhmed Waheed <oneofone@gmail.com>
      68325b56
    • Austin Clements's avatar
      runtime: fix pagesInUse accounting · 61f56e92
      Austin Clements authored
      When we grow the heap, we create a temporary "in use" span for the
      memory acquired from the OS and then free that span to link it into
      the heap. Hence, we (1) increase pagesInUse when we make the temporary
      span so that (2) freeing the span will correctly decrease it.
      
      However, currently step (1) increases pagesInUse by the number of
      pages requested from the heap, while step (2) decreases it by the
      number of pages requested from the OS (the size of the temporary
      span). These aren't necessarily the same, since we round up the number
      of pages we request from the OS, so steps 1 and 2 don't necessarily
      cancel out like they're supposed to. Over time, this can add up and
      cause pagesInUse to underflow and wrap around to 2^64. The garbage
      collector computes the sweep ratio from this, so if this happens, the
      sweep ratio becomes effectively infinite, causing the first allocation
      on each P in a sweep cycle to sweep the entire heap. This makes
      sweeping effectively STW.
      
      Fix this by increasing pagesInUse in step 1 by the number of pages
      requested from the OS, so that the two steps correctly cancel out. We
      add a test that checks that the running total matches the actual state
      of the heap.
      
      Fixes #15022. For 1.6.x.
      
      Change-Id: Iefd9d6abe37d0d447cbdbdf9941662e4f18eeffc
      Reviewed-on: https://go-review.googlesource.com/21280
      Run-TryBot: Austin Clements <austin@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      61f56e92
    • David Crawshaw's avatar
      cmd/link: keep types together when dynamic linking · 2d568895
      David Crawshaw authored
      To refer to types and names by offsets, we want to keep the symbols in
      the same sections. Do this by making all types .relro for now.
      
      Once name offsets are further along, name data can move out of relro.
      
      Change-Id: I1cbd2e914bd180cdf25c4aeb13d9c1c734febe69
      Reviewed-on: https://go-review.googlesource.com/21394Reviewed-by: 's avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
      Run-TryBot: David Crawshaw <crawshaw@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      2d568895
    • Caio Marcelo de Oliveira Filho's avatar
      go/types: better error when assigning to struct field in map · 74c0fea9
      Caio Marcelo de Oliveira Filho authored
      Identify this assignment case and instead of the more general error
      
          prog.go:6: cannot assign to students["sally"].age (value of type int)
      
      produce
      
          prog.go:6: cannot directly assign to struct field students["sally"].age in map
      
      that explains why the assignment is not possible. Used ExprString
      instead of String of operand since the type of the field is not relevant
      to the error.
      
      Updates #13779.
      
      Change-Id: I581251145ae6336ddd181b9ddd77f657c51b5aff
      Reviewed-on: https://go-review.googlesource.com/21463Reviewed-by: 's avatarDavid Chase <drchase@google.com>
      Run-TryBot: David Chase <drchase@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      74c0fea9
    • Caio Marcelo de Oliveira Filho's avatar
      cmd/compile: better error when assigning to struct field in map · f229e467
      Caio Marcelo de Oliveira Filho authored
      Identify this assignment case and instead of the more general error
      
          prog.go:6: cannot assign to students["sally"].age
      
      produce
      
          prog.go:6: cannot directly assign to struct field students["sally"].age in map
      
      that explains why the assignment is not possible.
      
      Fixes #13779.
      
      Change-Id: I90c10b445f907834fc1735aa66e44a0f447aa74f
      Reviewed-on: https://go-review.googlesource.com/21462Reviewed-by: 's avatarDavid Chase <drchase@google.com>
      f229e467
    • Alex Brainman's avatar
      runtime: change osyield to use Windows SwitchToThread · 1f5b1b2b
      Alex Brainman authored
      It appears that windows osyield is just 15ms sleep on my computer
      (see benchmarks below). Replace NtWaitForSingleObject in osyield
      with SwitchToThread (as suggested by Dmitry).
      
      Also add issue #14790 related benchmarks, so we can track perfomance
      changes in CL 20834 and CL 20835 and beyond.
      
      Update #14790
      
      benchmark                             old ns/op     new ns/op     delta
      BenchmarkChanToSyscallPing1ms         1953200       1953000       -0.01%
      BenchmarkChanToSyscallPing15ms        31562904      31248400      -1.00%
      BenchmarkSyscallToSyscallPing1ms      5247          4202          -19.92%
      BenchmarkSyscallToSyscallPing15ms     5260          4374          -16.84%
      BenchmarkChanToChanPing1ms            474           494           +4.22%
      BenchmarkChanToChanPing15ms           468           489           +4.49%
      BenchmarkOsYield1ms                   980018        75.5          -99.99%
      BenchmarkOsYield15ms                  15625200      75.8          -100.00%
      
      Change-Id: I1b4cc7caca784e2548ee3c846ca07ef152ebedce
      Reviewed-on: https://go-review.googlesource.com/21294
      Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
      Reviewed-by: 's avatarDmitry Vyukov <dvyukov@google.com>
      Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      1f5b1b2b
    • Rob Pike's avatar
      html/template: prefix the internally-used FuncMap values with an underscore · 02adfa0b
      Rob Pike authored
      This makes these names even less likely to collide with a real user-defined function.
      
      Fixes #13852.
      
      Change-Id: If5a8562c6797ced19c355c7ab2c86fc4401a8674
      Reviewed-on: https://go-review.googlesource.com/21490
      Run-TryBot: Rob Pike <r@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
      02adfa0b
    • Christopher Nelson's avatar
      cmd/go: fix -buildmode=c-archive should work on windows · ed8f0e5c
      Christopher Nelson authored
      Add supporting code for runtime initialization, including both
      32- and 64-bit x86 architectures.
      
      Add .ctors section on Windows to PE .o files, and INITENTRY to .ctors
      section to plug in to the GCC C/C++ startup initialization mechanism.
      This allows the Go runtime to initialize itself. Add .text section
      symbol for .ctor relocations. Note: This is unlikely to be useful for
      MSVC-based toolchains.
      
      Fixes #13494
      
      Change-Id: I4286a96f70e5f5228acae88eef46e2bed95813f3
      Reviewed-on: https://go-review.googlesource.com/18057Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      ed8f0e5c
  2. 03 Apr, 2016 12 commits
  3. 02 Apr, 2016 7 commits
  4. 01 Apr, 2016 13 commits
    • Brad Fitzpatrick's avatar
      runtime, syscall: only search for Windows DLLs in the System32 directory · 683448a3
      Brad Fitzpatrick authored
      Make sure that for any DLL that Go uses itself, we only look for the
      DLL in the Windows System32 directory, guarding against DLL preloading
      attacks.
      
      (Unless the Windows version is ancient and LoadLibraryEx is
      unavailable, in which case the user probably has bigger security
      problems anyway.)
      
      This does not change the behavior of syscall.LoadLibrary or NewLazyDLL
      if the DLL name is something unused by Go itself.
      
      This change also intentionally does not add any new API surface. Instead,
      x/sys is updated with a LoadLibraryEx function and LazyDLL.Flags in:
          https://golang.org/cl/21388
      
      Updates #14959
      
      Change-Id: I8d29200559cc19edf8dcf41dbdd39a389cd6aeb9
      Reviewed-on: https://go-review.googlesource.com/21140Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      683448a3
    • Ian Lance Taylor's avatar
      runtime: allocate mp.cgocallers earlier · 59fc42b2
      Ian Lance Taylor authored
      Fixes #15061.
      
      Change-Id: I71f69f398d1c5f3a884bbd044786f1a5600d0fae
      Reviewed-on: https://go-review.googlesource.com/21398
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      59fc42b2
    • Josh Bleecher Snyder's avatar
      cmd/compile: rename Node.Int to Node.Int64 · 5cab0169
      Josh Bleecher Snyder authored
      gorename -from '"cmd/compile/internal/gc".Node.Int' -to 'Int64'
      
      Change-Id: I2fe3bf9a26ae6b0600d990d0c981e4b8b53020a4
      Reviewed-on: https://go-review.googlesource.com/21426Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      5cab0169
    • Matthew Dempsky's avatar
      cmd/compile: more Isfoo Type cleanups · 00e5a68c
      Matthew Dempsky authored
      Replace isideal(t) with t.IsUntyped().
      Replace Istype(t, k) with t.IsKind(k).
      Replace isnilinter(t) with t.IsEmptyInterface().
      
      Also replace a lot of t.IsKind(TFOO) with t.IsFoo().
      
      Replacements prepared mechanically with gofmt -w -r.
      
      Passes toolstash -cmp.
      
      Change-Id: Iba48058f3cc863e15af14277b5ff5e729e67e043
      Reviewed-on: https://go-review.googlesource.com/21424Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      00e5a68c
    • Josh Bleecher Snyder's avatar
      cmd/compile: add Type.SetNumElem · 5dd129bc
      Josh Bleecher Snyder authored
      This removes all access to Type.Bound
      from outside type.go.
      
      Update sinit to make a new type rather than
      copy and mutate.
      
      Update bimport to create a new slice type
      instead of mutating TDDDFIELD.
      These are rare, so the extra allocs are nominal.
      
      I’m not happy about having a setter,
      but it appears the most practical route
      forward at the moment, and it only has a few uses.
      
      Passes toolstash -cmp.
      
      Change-Id: I174f07c8f336afc656904bde4bdbde4f3ef0db96
      Reviewed-on: https://go-review.googlesource.com/21423
      Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      5dd129bc
    • Josh Bleecher Snyder's avatar
      cmd/compile: use Node.Int more · e504055e
      Josh Bleecher Snyder authored
      Generated by eg.
      
      Passes toolstash -cmp.
      
      Change-Id: I7516c211ca9aacf824f74894671dc62d31763b01
      Reviewed-on: https://go-review.googlesource.com/21422
      Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
      Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      e504055e
    • Josh Bleecher Snyder's avatar
      cmd/compile: use NumElem instead of Type.Bound · 3a0783c5
      Josh Bleecher Snyder authored
      This eliminates all direct reads of Type.Bound
      outside type.go.
      
      Change-Id: I0a9a72539f8f4c0de7f5e05e1821936bf7db5eb7
      Reviewed-on: https://go-review.googlesource.com/21421
      Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
      Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      3a0783c5
    • Matthew Dempsky's avatar
      cmd/compile: cleanup algtype code · 077902d1
      Matthew Dempsky authored
      Add AlgKind enum type to represent AFOO values.
      
      Add IsComparable, IsRegularMemory, IncomparableField helper methods to
      codify common higher-level idioms.
      
      Passes toolstash -cmp.
      
      Change-Id: I54c544953997a8ccc72396b3058897edcbbea392
      Reviewed-on: https://go-review.googlesource.com/21420
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      077902d1
    • Ian Lance Taylor's avatar
      runtime/cgo: only build _cgo_callers if x_cgo_callers is defined · 58394fd7
      Ian Lance Taylor authored
      Fixes a problem when using the external linker on Solaris.  The Solaris
      external linker still doesn't work due to issue #14957.
      
      The problem is, for example, with `go test cmd/objdump`:
      
              objdump_test.go:71: go build fmthello.go: exit status 2
                      # command-line-arguments
                      /var/gcc/iant/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
                      Undefined                       first referenced
                       symbol                             in file
                      x_cgo_callers                       /tmp/go-link-355600608/go.o
                      ld: fatal: symbol referencing errors
                      collect2: error: ld returned 1 exit status
      
      Change-Id: I54917cfd5c288ee77ea25c439489bd2c9124fe73
      Reviewed-on: https://go-review.googlesource.com/21392
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
      58394fd7
    • Sebastien Binet's avatar
      reflect: implement StructOf · 633ab742
      Sebastien Binet authored
      This change exposes a facility to create new struct types from a slice of
      reflect.StructFields.
      
      - reflect: first stab at implementing StructOf
      - reflect: tests for StructOf
      
      StructOf creates new struct types in the form of structTypeWithMethods
      to accomodate the GC (especially the uncommonType.methods slice field.)
      
      Creating struct types with embedded interfaces with unexported methods
      is not supported yet and will panic.
      Creating struct types with non-ASCII field names or types is not yet
      supported (see #15064.)
      
      Binaries' sizes for linux_amd64:
      
      old=tip (0104a31b)
      
                  old bytes     new bytes     delta
      bin/go      9911336       9915456       +0.04%
      reflect     781704        830048        +6.18%
      
      Updates #5748.
      Updates #15064.
      
      Change-Id: I3b8fd4fadd6ce3b1b922e284f0ae72a3a8e3ce44
      Reviewed-on: https://go-review.googlesource.com/9251Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
      Run-TryBot: David Crawshaw <crawshaw@golang.org>
      633ab742
    • Shahar Kohanim's avatar
      cmd/internal/obj: more idiomatic object writer · 014f3e1e
      Shahar Kohanim authored
      Change-Id: I41722ee605ea76a6b52e8a7e1e10f2293cef1a7a
      Reviewed-on: https://go-review.googlesource.com/21371Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
      014f3e1e
    • Alexandru Moșoi's avatar
      cmd/compile/internal/ssa: BCE for induction variables · b91cc530
      Alexandru Moșoi authored
      There are 5293 loop in the main go repository.
      A survey of the top most common for loops:
      
           18 for __k__ := 0; i < len(sa.Addr); i++ {
           19 for __k__ := 0; ; i++ {
           19 for __k__ := 0; i < 16; i++ {
           25 for __k__ := 0; i < length; i++ {
           30 for __k__ := 0; i < 8; i++ {
           49 for __k__ := 0; i < len(s); i++ {
           67 for __k__ := 0; i < n; i++ {
          376 for __k__ := range __slice__ {
          685 for __k__, __v__ := range __slice__ {
         2074 for __, __v__ := range __slice__ {
      
      The algorithm to find induction variables handles all cases
      with an upper limit. It currently doesn't find related induction
      variables such as c * ind or c + ind.
      
      842 out of 22954 bound checks are removed for src/make.bash.
      1957 out of 42952 bounds checks are removed for src/all.bash.
      
      Things to do in follow-up CLs:
      * Find the associated pointer for `for _, v := range a {}`
      * Drop the NilChecks on the pointer.
      * Replace the implicit induction variable by a loop over the pointer
      
      Generated garbage can be reduced if we share the sdom between passes.
      
      % benchstat old.txt new.txt
      name       old time/op     new time/op     delta
      Template       337ms ± 3%      333ms ± 3%    ~             (p=0.258 n=9+9)
      GoTypes        1.11s ± 2%      1.10s ± 2%    ~           (p=0.912 n=10+10)
      Compiler       5.25s ± 1%      5.29s ± 2%    ~             (p=0.077 n=9+9)
      MakeBash       33.5s ± 1%      34.1s ± 2%  +1.85%          (p=0.011 n=9+9)
      
      name       old alloc/op    new alloc/op    delta
      Template      63.6MB ± 0%     63.9MB ± 0%  +0.52%         (p=0.000 n=10+9)
      GoTypes        218MB ± 0%      219MB ± 0%  +0.59%         (p=0.000 n=10+9)
      Compiler       978MB ± 0%      985MB ± 0%  +0.69%        (p=0.000 n=10+10)
      
      name       old allocs/op   new allocs/op   delta
      Template        582k ± 0%       583k ± 0%  +0.10%        (p=0.000 n=10+10)
      GoTypes        1.78M ± 0%      1.78M ± 0%  +0.12%        (p=0.000 n=10+10)
      Compiler       7.68M ± 0%      7.69M ± 0%  +0.05%        (p=0.000 n=10+10)
      
      name       old text-bytes  new text-bytes  delta
      HelloSize       581k ± 0%       581k ± 0%  -0.08%        (p=0.000 n=10+10)
      CmdGoSize      6.40M ± 0%      6.39M ± 0%  -0.08%        (p=0.000 n=10+10)
      
      name       old data-bytes  new data-bytes  delta
      HelloSize      3.66k ± 0%      3.66k ± 0%    ~     (all samples are equal)
      CmdGoSize       134k ± 0%       134k ± 0%    ~     (all samples are equal)
      
      name       old bss-bytes   new bss-bytes   delta
      HelloSize       126k ± 0%       126k ± 0%    ~     (all samples are equal)
      CmdGoSize       149k ± 0%       149k ± 0%    ~     (all samples are equal)
      
      name       old exe-bytes   new exe-bytes   delta
      HelloSize       947k ± 0%       946k ± 0%  -0.01%        (p=0.000 n=10+10)
      CmdGoSize      9.92M ± 0%      9.91M ± 0%  -0.06%        (p=0.000 n=10+10)
      
      Change-Id: Ie74bdff46fd602db41bb457333d3a762a0c3dc4d
      Reviewed-on: https://go-review.googlesource.com/20517Reviewed-by: 's avatarDavid Chase <drchase@google.com>
      Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro>
      b91cc530
    • Ian Lance Taylor's avatar
      runtime: support symbolic backtrace of C code in a cgo crash · ea306ae6
      Ian Lance Taylor authored
      The new function runtime.SetCgoTraceback may be used to register stack
      traceback and symbolizer functions, written in C, to do a stack
      traceback from cgo code.
      
      There is a sample implementation of runtime.SetCgoSymbolizer at
      github.com/ianlancetaylor/cgosymbolizer.  Just importing that package is
      sufficient to get symbolic C backtraces.
      
      Currently only supported on linux/amd64.
      
      Change-Id: If96ee2eb41c6c7379d407b9561b87557bfe47341
      Reviewed-on: https://go-review.googlesource.com/17761Reviewed-by: 's avatarAustin Clements <austin@google.com>
      ea306ae6