]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove mal/malloc/FlagNoGC/FlagNoInvokeGC
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 7 Aug 2014 09:04:04 +0000 (13:04 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 7 Aug 2014 09:04:04 +0000 (13:04 +0400)
FlagNoGC is unused now.
FlagNoInvokeGC is unneeded as we don't invoke GC
on g0 and when holding locks anyway.
mal/malloc have very few uses and you never remember
the exact set of flags they use and the difference between them.
Moreover, eventually we need to give exact types to all allocations,
something what mal/malloc do not support.

LGTM=khr
R=golang-codereviews, khr
CC=golang-codereviews, rsc
https://golang.org/cl/117580043

13 files changed:
src/pkg/runtime/cgo/callbacks.c
src/pkg/runtime/env_posix.c
src/pkg/runtime/heapdump.c
src/pkg/runtime/malloc.c
src/pkg/runtime/malloc.go
src/pkg/runtime/malloc.h
src/pkg/runtime/mgc0.c
src/pkg/runtime/panic.c
src/pkg/runtime/parfor.c
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.c
src/pkg/runtime/runtime.h
src/pkg/runtime/time.goc

index 5a4889c9b3f9c25b3aa745524198beb181a3ee44..954a1cdcc300122ea318d447d356c83e2eddce37 100644 (file)
@@ -38,8 +38,8 @@ _cgo_allocate_internal(uintptr len, byte *ret)
 {
        CgoMal *c;
 
-       ret = runtime·mal(len);
-       c = runtime·mal(sizeof(*c));
+       ret = runtime·mallocgc(len, nil, 0);
+       c = runtime·mallocgc(sizeof(*c), nil, 0);
        c->next = g->m->cgomal;
        c->alloc = ret;
        g->m->cgomal = c;
index 9b3583ce8b4ae8c79524fd0aec615506d240886b..edd1d3568d893883af6f42f4e124e89f1f0fdae7 100644 (file)
@@ -50,11 +50,11 @@ syscall·setenv_c(String k, String v)
        if(_cgo_setenv == nil)
                return;
 
-       arg[0] = runtime·malloc(k.len + 1);
+       arg[0] = runtime·mallocgc(k.len + 1, nil, 0);
        runtime·memmove(arg[0], k.str, k.len);
        arg[0][k.len] = 0;
 
-       arg[1] = runtime·malloc(v.len + 1);
+       arg[1] = runtime·mallocgc(v.len + 1, nil, 0);
        runtime·memmove(arg[1], v.str, v.len);
        arg[1][v.len] = 0;
 
index eec34f2cb7a471b933bec6e5caa3f34a97e7eaee..9e968a250e2d7b4e11271c3d234a0265ea566980 100644 (file)
@@ -544,8 +544,6 @@ dumpobjs(void)
                        bitp = (uintptr*)runtime·mheap.arena_start - off/wordsPerBitmapWord - 1;
                        shift = (off % wordsPerBitmapWord) * gcBits;
                        bits = (*bitp >> shift) & bitMask;
-
-                       // Skip FlagNoGC allocations (stacks)
                        if(bits != bitAllocated)
                                continue;
                        dumpobj(p, size, makeheapobjbv(p, size));
index 951117622f0f0f2894247925e4790d53f0e9fd8e..be3280e0f1ffe5c18cacf57c40d22a8a48238de6 100644 (file)
@@ -35,12 +35,6 @@ runtime·mallocgc(uintptr size, Type *typ, uint32 flag)
        return ret;
 }
 
-void*
-runtime·malloc(uintptr size)
-{
-       return runtime·mallocgc(size, nil, FlagNoInvokeGC);
-}
-
 int32
 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp)
 {
@@ -399,12 +393,6 @@ runtime·persistentalloc(uintptr size, uintptr align, uint64 *stat)
 
 // Runtime stubs.
 
-void*
-runtime·mal(uintptr n)
-{
-       return runtime·mallocgc(n, nil, 0);
-}
-
 static void*
 cnew(Type *typ, intgo n)
 {
index 81769573c98a03ff6f4a99f3ef47cdea73b8d490..e7f23889af1ea3e470b9e48e69d433640af098aa 100644 (file)
@@ -11,8 +11,7 @@ import (
 const (
        flagNoScan      = 1 << 0 // GC doesn't have to scan object
        flagNoProfiling = 1 << 1 // must not profile
-       flagNoZero      = 1 << 3 // don't zero memory
-       flagNoInvokeGC  = 1 << 4 // don't invoke GC
+       flagNoZero      = 1 << 2 // don't zero memory
 
        kindArray      = 17
        kindFunc       = 19
@@ -198,7 +197,7 @@ func gomallocgc(size uintptr, typ *_type, flags int) unsafe.Pointer {
 
        releasem(mp)
 
-       if flags&flagNoInvokeGC == 0 && memstats.heap_alloc >= memstats.next_gc {
+       if memstats.heap_alloc >= memstats.next_gc {
                gogc(0)
        }
 
index 1e26509bd9570119bc723e4ae4d3ffded1d8dc66..43feef79ed4aa05d86e58b96bd17c809552742f6 100644 (file)
@@ -513,7 +513,6 @@ void        runtime·MHeap_MapBits(MHeap *h);
 void   runtime·MHeap_MapSpans(MHeap *h);
 void   runtime·MHeap_Scavenger(void);
 
-void*  runtime·mallocgc(uintptr size, Type* typ, uint32 flag);
 void*  runtime·persistentalloc(uintptr size, uintptr align, uint64 *stat);
 int32  runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **s);
 void   runtime·gc(int32 force);
@@ -537,9 +536,7 @@ enum
        // flags to malloc
        FlagNoScan      = 1<<0, // GC doesn't have to scan object
        FlagNoProfiling = 1<<1, // must not profile
-       FlagNoGC        = 1<<2, // must not free or scan for pointers
-       FlagNoZero      = 1<<3, // don't zero memory
-       FlagNoInvokeGC  = 1<<4, // don't invoke GC
+       FlagNoZero      = 1<<2, // don't zero memory
 };
 
 void   runtime·MProf_Malloc(void*, uintptr);
index 16d616b3f6e0a521cc2d968056bdde31530efacb..4637d68bce7bba36d45295012f9e7893058e4200 100644 (file)
@@ -966,7 +966,7 @@ runtime·MSpan_Sweep(MSpan *s)
                xbits = *bitp;
                bits = (xbits>>shift) & bitMask;
 
-               // Non-allocated or FlagNoGC object, ignore.
+               // Non-allocated object, ignore.
                if(bits == bitBoundary)
                        continue;
                // Allocated and marked object, reset bits to allocated.
@@ -1659,7 +1659,7 @@ runfinq(void)
                                        // all not yet finalized objects are stored in finq.
                                        // If we do not mark it as FlagNoScan,
                                        // the last finalized object is not collected.
-                                       frame = runtime·mallocgc(framesz, 0, FlagNoScan|FlagNoInvokeGC);
+                                       frame = runtime·mallocgc(framesz, 0, FlagNoScan);
                                        framecap = framesz;
                                }
                                if(f->fint == nil)
index af8bb1bc0e5924952c3c0e6e9c1e73c7279a08b4..bc685398a6e4c7605259c826bf91143f0ee092ec 100644 (file)
@@ -42,7 +42,7 @@ newdefer(int32 siz)
        if(d == nil) {
                // deferpool is empty or just a big defer
                total = runtime·roundupsize(TOTALSIZE(siz));
-               d = runtime·malloc(total);
+               d = runtime·mallocgc(total, nil, 0);
        }
        d->siz = siz;
        d->special = 0;
index 4706e0a43a2dd4ba3aa8482d4201538320399f50..1073dfa39451784172fecf1f0d5db142cb5c58f2 100644 (file)
@@ -27,7 +27,7 @@ runtime·parforalloc(uint32 nthrmax)
 
        // The ParFor object is followed by CacheLineSize padding
        // and then nthrmax ParForThread.
-       desc = (ParFor*)runtime·malloc(sizeof(ParFor) + CacheLineSize + nthrmax * sizeof(ParForThread));
+       desc = (ParFor*)runtime·mallocgc(sizeof(ParFor) + CacheLineSize + nthrmax * sizeof(ParForThread), nil, 0);
        desc->thr = (ParForThread*)((byte*)(desc+1) + CacheLineSize);
        desc->nthrmax = nthrmax;
        return desc;
index 26e687e3b430f58a413c9f37aaa0625bef11d165..137f49f5f02b312a25ed336d152f76ecaa6ced5a 100644 (file)
@@ -183,7 +183,7 @@ runtime·schedinit(void)
                        n = MaxGomaxprocs;
                procs = n;
        }
-       runtime·allp = runtime·malloc((MaxGomaxprocs+1)*sizeof(runtime·allp[0]));
+       runtime·allp = runtime·mallocgc((MaxGomaxprocs+1)*sizeof(runtime·allp[0]), nil, 0);
        procresize(procs);
 
        runtime·copystack = runtime·precisestack;
@@ -1926,7 +1926,7 @@ allgadd(G *gp)
                cap = 4096/sizeof(new[0]);
                if(cap < 2*allgcap)
                        cap = 2*allgcap;
-               new = runtime·malloc(cap*sizeof(new[0]));
+               new = runtime·mallocgc(cap*sizeof(new[0]), nil, 0);
                if(new == nil)
                        runtime·throw("runtime: cannot allocate memory");
                if(runtime·allg != nil)
@@ -2396,7 +2396,7 @@ procresize(int32 new)
        for(i = 0; i < new; i++) {
                p = runtime·allp[i];
                if(p == nil) {
-                       p = (P*)runtime·mallocgc(sizeof(*p), 0, FlagNoInvokeGC);
+                       p = (P*)runtime·mallocgc(sizeof(*p), 0, 0);
                        p->id = i;
                        p->status = Pgcstop;
                        runtime·atomicstorep(&runtime·allp[i], p);
index 31b853c87a2acc09b598053693fc862ddd76ea1c..98c9edda41b350cf8a5c1886894a6c630a7c2fc1 100644 (file)
@@ -111,7 +111,7 @@ runtime·goargs(void)
        if(Windows)
                return;
 
-       s = runtime·malloc(argc*sizeof s[0]);
+       s = runtime·mallocgc(argc*sizeof s[0], nil, 0);
        for(i=0; i<argc; i++)
                s[i] = runtime·gostringnocopy(argv[i]);
        os·Args.array = (byte*)s;
@@ -128,7 +128,7 @@ runtime·goenvs_unix(void)
        for(n=0; argv[argc+1+n] != 0; n++)
                ;
 
-       s = runtime·malloc(n*sizeof s[0]);
+       s = runtime·mallocgc(n*sizeof s[0], nil, 0);
        for(i=0; i<n; i++)
                s[i] = runtime·gostringnocopy(argv[argc+1+i]);
        syscall·envs.array = (byte*)s;
index 1d1618b0d6e9538c785ba5cf9c46fe0ae90f22c0..1687b85c4470aa9b50b1f2ba2cc018cf125c212a 100644 (file)
@@ -829,7 +829,6 @@ int32       runtime·snprintf(byte*, int32, int8*, ...);
 byte*  runtime·mchr(byte*, byte, byte*);
 int32  runtime·mcmp(byte*, byte*, uintptr);
 void   runtime·memmove(void*, void*, uintptr);
-void*  runtime·mal(uintptr);
 String runtime·catstring(String, String);
 String runtime·gostring(byte*);
 String  runtime·gostringn(byte*, intgo);
@@ -876,7 +875,7 @@ void        runtime·mallocinit(void);
 void   runtime·chaninit(void);
 bool   runtime·ifaceeq_c(Iface, Iface);
 bool   runtime·efaceeq_c(Eface, Eface);
-void*  runtime·malloc(uintptr size);
+void*  runtime·mallocgc(uintptr size, Type* typ, uint32 flag);
 void   runtime·runpanic(Panic*);
 uintptr        runtime·getcallersp(void*);
 int32  runtime·mcount(void);
index 791e4eb02b3a554ecb9555b3d2dec4428d534a5e..10b8cea0abc761e5b9009b10ac86006e4d15af88 100644 (file)
@@ -125,7 +125,7 @@ addtimer(Timer *t)
                n = 16;
                if(n <= timers.cap)
                        n = timers.cap*3 / 2;
-               nt = runtime·malloc(n*sizeof nt[0]);
+               nt = runtime·mallocgc(n*sizeof nt[0], nil, 0);
                runtime·memmove(nt, timers.t, timers.len*sizeof nt[0]);
                timers.t = nt;
                timers.cap = n;