]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix dump of data/bss
authorDmitriy Vyukov <dvyukov@google.com>
Mon, 18 Aug 2014 12:42:24 +0000 (16:42 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Mon, 18 Aug 2014 12:42:24 +0000 (16:42 +0400)
Fixes #8530.

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

src/pkg/runtime/heapdump.c
src/pkg/runtime/mgc0.c
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.h

index e5032783a8faddc83ce40a8a2a3f147b7d18e412..aa817fceec7dcbb28e946689ae8b628775182320 100644 (file)
@@ -23,8 +23,6 @@ extern byte data[];
 extern byte edata[];
 extern byte bss[];
 extern byte ebss[];
-extern byte gcdata[];
-extern byte gcbss[];
 
 enum {
        FieldKindEol = 0,
@@ -497,13 +495,13 @@ dumproots(void)
        dumpint(TagData);
        dumpint((uintptr)data);
        dumpmemrange(data, edata - data);
-       dumpfields((BitVector){(edata - data)*8, (uint32*)gcdata});
+       dumpfields((BitVector){(edata - data)*8, (uint32*)runtime·gcdatamask});
 
        // bss segment
        dumpint(TagBss);
        dumpint((uintptr)bss);
        dumpmemrange(bss, ebss - bss);
-       dumpfields((BitVector){(ebss - bss)*8, (uint32*)gcbss});
+       dumpfields((BitVector){(ebss - bss)*8, (uint32*)runtime·gcbssmask});
 
        // MSpan.types
        allspans = runtime·mheap.allspans;
index f46d329017f973c5e243ea61776d61a689564598..5389538eae7fa49d66ea436377ac8ba161b164cc 100644 (file)
@@ -78,10 +78,9 @@ enum {
 };
 
 #define ScanConservatively ((byte*)1)
-#define GcpercentUnknown (-2)
 
 // Initialized from $GOGC.  GOGC=off means no gc.
-extern int32 runtime·gcpercent = GcpercentUnknown;
+extern int32 runtime·gcpercent;
 
 static FuncVal* poolcleanup;
 
@@ -172,6 +171,8 @@ static FinBlock     *finc;          // cache of free blocks
 static FinBlock        *allfin;        // list of all blocks
 bool   runtime·fingwait;
 bool   runtime·fingwake;
+byte*  runtime·gcdatamask;
+byte*  runtime·gcbssmask;
 
 static Lock    gclock;
 
@@ -200,8 +201,6 @@ static struct {
        volatile uint32 ndone;
        Note    alldone;
        ParFor* markfor;
-       byte*   gcdata;
-       byte*   gcbss;
 } work;
 
 // scanblock scans a block of n bytes starting at pointer b for references
@@ -517,11 +516,11 @@ markroot(ParFor *desc, uint32 i)
        // Note: if you add a case here, please also update heapdump.c:dumproots.
        switch(i) {
        case RootData:
-               scanblock(data, edata - data, work.gcdata);
+               scanblock(data, edata - data, runtime·gcdatamask);
                break;
 
        case RootBss:
-               scanblock(bss, ebss - bss, work.gcbss);
+               scanblock(bss, ebss - bss, runtime·gcbssmask);
                break;
 
        case RootFinalizers:
@@ -1300,6 +1299,18 @@ runtime·readgogc(void)
        return runtime·atoi(p);
 }
 
+void
+runtime·gcinit(void)
+{
+       if(sizeof(Workbuf) != WorkbufSize)
+               runtime·throw("runtime: size of Workbuf is suboptimal");
+
+       work.markfor = runtime·parforalloc(MaxGcproc);
+       runtime·gcpercent = runtime·readgogc();
+       runtime·gcdatamask = unrollglobgcprog(gcdata, edata - data);
+       runtime·gcbssmask = unrollglobgcprog(gcbss, ebss - bss);
+}
+
 // force = 1 - do GC regardless of current heap usage
 // force = 2 - go GC and eager sweep
 void
@@ -1308,8 +1319,6 @@ runtime·gc(int32 force)
        struct gc_args a;
        int32 i;
 
-       if(sizeof(Workbuf) != WorkbufSize)
-               runtime·throw("runtime: size of Workbuf is suboptimal");
        // The gc is turned off (via enablegc) until
        // the bootstrap has completed.
        // Also, malloc gets called in the guts
@@ -1321,12 +1330,6 @@ runtime·gc(int32 force)
        if(!mstats.enablegc || g == g->m->g0 || g->m->locks > 0 || runtime·panicking)
                return;
 
-       if(runtime·gcpercent == GcpercentUnknown) {    // first time through
-               runtime·lock(&runtime·mheap.lock);
-               if(runtime·gcpercent == GcpercentUnknown)
-                       runtime·gcpercent = runtime·readgogc();
-               runtime·unlock(&runtime·mheap.lock);
-       }
        if(runtime·gcpercent < 0)
                return;
 
@@ -1415,14 +1418,6 @@ gc(struct gc_args *args)
        t0 = args->start_time;
        work.tstart = args->start_time; 
 
-       if(work.gcdata == nil) {
-               work.gcdata = unrollglobgcprog(gcdata, edata - data);
-               work.gcbss = unrollglobgcprog(gcbss, ebss - bss);
-       }
-
-       if(work.markfor == nil)
-               work.markfor = runtime·parforalloc(MaxGcproc);
-
        t1 = 0;
        if(runtime·debug.gctrace)
                t1 = runtime·nanotime();
@@ -1598,8 +1593,6 @@ runtime·setgcpercent(int32 in) {
        int32 out;
 
        runtime·lock(&runtime·mheap.lock);
-       if(runtime·gcpercent == GcpercentUnknown)
-               runtime·gcpercent = runtime·readgogc();
        out = runtime·gcpercent;
        if(in < 0)
                in = -1;
@@ -2027,7 +2020,7 @@ runtime·getgcmask(byte *p, Type *t, byte **mask, uintptr *len)
                *mask = runtime·mallocgc(*len, nil, 0);
                for(i = 0; i < n; i += PtrSize) {
                        off = (p+i-data)/PtrSize;
-                       bits = (work.gcdata[off/PointersPerByte] >> ((off%PointersPerByte)*BitsPerPointer))&BitsMask;
+                       bits = (runtime·gcdatamask[off/PointersPerByte] >> ((off%PointersPerByte)*BitsPerPointer))&BitsMask;
                        (*mask)[i/PtrSize] = bits;
                }
                return;
@@ -2039,7 +2032,7 @@ runtime·getgcmask(byte *p, Type *t, byte **mask, uintptr *len)
                *mask = runtime·mallocgc(*len, nil, 0);
                for(i = 0; i < n; i += PtrSize) {
                        off = (p+i-bss)/PtrSize;
-                       bits = (work.gcbss[off/PointersPerByte] >> ((off%PointersPerByte)*BitsPerPointer))&BitsMask;
+                       bits = (runtime·gcbssmask[off/PointersPerByte] >> ((off%PointersPerByte)*BitsPerPointer))&BitsMask;
                        (*mask)[i/PtrSize] = bits;
                }
                return;
index 443bdda100d9cd1a23bb1c1900321d13e951451c..a3e0f4bc52bd661e62b6f9ad203a3d6e44f15e5c 100644 (file)
@@ -158,6 +158,7 @@ runtime·schedinit(void)
        runtime·symtabinit();
        runtime·stackinit();
        runtime·mallocinit();
+       runtime·gcinit();
        runtime·chaninit();
        mcommoninit(g->m);
        
index 62100a783ae95936802549254a4dbb7d8a02df3f..0aeba39da8c7721694b8bbee5a6ace8d7d03f917 100644 (file)
@@ -779,6 +779,8 @@ extern      uint32  runtime·cpuid_ecx;
 extern uint32  runtime·cpuid_edx;
 extern DebugVars       runtime·debug;
 extern uintptr runtime·maxstacksize;
+extern byte*   runtime·gcdatamask;
+extern byte*   runtime·gcbssmask;
 
 /*
  * common functions and data
@@ -880,6 +882,7 @@ void        runtime·shrinkstack(G*);
 MCache*        runtime·allocmcache(void);
 void   runtime·freemcache(MCache*);
 void   runtime·mallocinit(void);
+void   runtime·gcinit(void);
 void   runtime·chaninit(void);
 void*  runtime·mallocgc(uintptr size, Type* typ, uint32 flag);
 void   runtime·runpanic(Panic*);