aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc_test.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2015-10-26 12:38:47 -0700
committerMatthew Dempsky <mdempsky@google.com>2015-10-26 21:14:15 +0000
commitd18167fefea5e77388dbc1e323e8527b58494185 (patch)
treed7f7b1e5718ef3bc87d8cd02af06e90b02f1a482 /src/runtime/malloc_test.go
parente6ccfc1ad14d1078428fe5f408498f925ab69670 (diff)
downloadgo-d18167fefea5e77388dbc1e323e8527b58494185.tar.xz
runtime: fix tiny allocator
When a new tiny block is allocated because we're allocating an object that won't fit into the current block, mallocgc saves the new block if it has more space leftover than the old block. However, the logic for this was subtly broken in golang.org/cl/2814, resulting in never saving (or consequently reusing) a tiny block. Change-Id: Ib5f6769451fb82877ddeefe75dfe79ed4a04fd40 Reviewed-on: https://go-review.googlesource.com/16330 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/malloc_test.go')
-rw-r--r--src/runtime/malloc_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go
index f0e73baea5..b8278bb4bc 100644
--- a/src/runtime/malloc_test.go
+++ b/src/runtime/malloc_test.go
@@ -82,6 +82,23 @@ func TestStringConcatenationAllocs(t *testing.T) {
}
}
+func TestTinyAlloc(t *testing.T) {
+ const N = 16
+ var v [N]unsafe.Pointer
+ for i := range v {
+ v[i] = unsafe.Pointer(new(byte))
+ }
+
+ chunks := make(map[uintptr]bool, N)
+ for _, p := range v {
+ chunks[uintptr(p)&^7] = true
+ }
+
+ if len(chunks) == N {
+ t.Fatal("no bytes allocated within the same 8-byte chunk")
+ }
+}
+
var mallocSink uintptr
func BenchmarkMalloc8(b *testing.B) {