Skip to content

cmd/compile: extra allocations in race mode #36516

@lni

Description

@lni

What version of Go are you using (go version)?

go 1.14 beta1

Does this issue reproduce with the latest release?

no

What operating system and processor architecture are you using (go env)?

GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/lni/gobin"
GOCACHE="/Users/lni/Library/Caches/go-build"
GOENV="/Users/lni/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/lni/go"
GOPRIVATE=""
GOPROXY="https://mirrors.aliyun.com/goproxy"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b5/ndb6rntd4ys0451zchd64p_m0000gn/T/go-build700408697=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run the following test with and without -race

package alloctest

import (
  "sync"
  "testing"
)

type rs struct {
  complete chan struct{}
  pool     *sync.Pool
}

func (rs *rs) release() {
  rs.pool.Put(rs)
}

func getrs(p *sync.Pool) *rs {
  return p.Get().(*rs)
}

func TestAlloc(t *testing.T) {
  p := &sync.Pool{}
  p.New = func() interface{} {
    v := &rs{
      complete: make(chan struct{}, 1),
      pool:     p,
    }
    return v
  }
  ac := testing.AllocsPerRun(1000, func() {
    v := getrs(p)
    v.release()
  })
  if ac > 1 {
    t.Fatalf("ac: %f, want <= 1", ac)
  }
}

What did you expect to see?

The test should pass with or without -race on 1.14 beta1

What did you see instead?

On 1.14 beta 1, it fails when -race is enabled, it passes when -race is not enabled. On 1.13.x, it passes with or without -race.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions