From d5a36cd6bb14a3bf00c58779848beeaeb87ade7d Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Tue, 21 Jan 2014 10:53:51 +0400 Subject: runtime: zero 2-word memory blocks in-place Currently for 2-word blocks we set the flag to clear the flag. Makes no sense. In particular on 32-bits we call memclr always. R=golang-codereviews, dave, iant CC=golang-codereviews, khr, rsc https://golang.org/cl/41170044 --- src/pkg/runtime/malloc.goc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/pkg/runtime/malloc.goc') diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc index f83e498293..739c61e4f4 100644 --- a/src/pkg/runtime/malloc.goc +++ b/src/pkg/runtime/malloc.goc @@ -75,7 +75,7 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag) if(!(flag & FlagNoZero)) { v->next = nil; // block is zeroed iff second word is zero ... - if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0) + if(size > 2*sizeof(uintptr) && ((uintptr*)v)[1] != 0) runtime·memclr((byte*)v, size); } c->local_cachealloc += size; @@ -205,8 +205,10 @@ runtime·free(void *v) c->local_largefree += size; } else { // Small object. - if(size > sizeof(uintptr)) + if(size > 2*sizeof(uintptr)) ((uintptr*)v)[1] = (uintptr)0xfeedfeedfeedfeedll; // mark as "needs to be zeroed" + else if(size > sizeof(uintptr)) + ((uintptr*)v)[1] = 0; // Must mark v freed before calling MCache_Free: // it might coalesce v and other blocks into a bigger span // and change the bitmap further. -- cgit v1.3