Commit cd2f8356 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: remove mal/malloc/FlagNoGC/FlagNoInvokeGC

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