]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: init GC later
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Aug 2014 07:55:05 +0000 (11:55 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Aug 2014 07:55:05 +0000 (11:55 +0400)
Init GC later as it needs to read GOGC env var.
Fixes #8562.

LGTM=daniel.morsing, rsc
R=golang-codereviews, daniel.morsing, rsc
CC=golang-codereviews, khr, rlh
https://golang.org/cl/130990043

src/pkg/runtime/env_posix.c
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.c

index edd1d3568d893883af6f42f4e124e89f1f0fdae7..8bc3ffb0a29ca5a310cc34ee00a2eab31462b872 100644 (file)
@@ -22,6 +22,8 @@ runtime·getenv(int8 *s)
        bs = (byte*)s;
        len = runtime·findnull(bs);
        envv = (String*)syscall·envs.array;
+       if(envv == nil)
+               runtime·throw("getenv before env init");
        envc = syscall·envs.len;
        for(i=0; i<envc; i++){
                if(envv[i].len <= len)
index 8584cb6f6a9d974fe646a7ca9aa93104b266ba04..1e0cd38a0603aa70d04bd97cb9cd36c6d4396087 100644 (file)
@@ -158,7 +158,6 @@ runtime·schedinit(void)
        runtime·symtabinit();
        runtime·stackinit();
        runtime·mallocinit();
-       runtime·gcinit();
        runtime·chaninit();
        mcommoninit(g->m);
        
@@ -168,13 +167,10 @@ runtime·schedinit(void)
        // need to allocated memory.
        runtime·newErrorCString(0, &i);
        
-       // Initialize the cached gotraceback value, since
-       // gotraceback calls getenv, which mallocs on Plan 9.
-       runtime·gotraceback(nil);
-
        runtime·goargs();
        runtime·goenvs();
        runtime·parsedebugvars();
+       runtime·gcinit();
 
        runtime·sched.lastpoll = runtime·nanotime();
        procs = 1;
index 98c9edda41b350cf8a5c1886894a6c630a7c2fc1..275fffb347d81b01d8c00f58a4cf11b01a62db13 100644 (file)
@@ -12,7 +12,7 @@
 // The cached value is a uint32 in which the low bit
 // is the "crash" setting and the top 31 bits are the
 // gotraceback value.
-static uint32 traceback_cache = ~(uint32)0;
+static uint32 traceback_cache = 2<<1;
 
 // The GOTRACEBACK environment variable controls the
 // behavior of a Go program that is crashing and exiting.
@@ -23,29 +23,13 @@ static uint32 traceback_cache = ~(uint32)0;
 int32
 runtime·gotraceback(bool *crash)
 {
-       byte *p;
-       uint32 x;
-
        if(crash != nil)
                *crash = false;
        if(g->m->traceback != 0)
                return g->m->traceback;
-       x = runtime·atomicload(&traceback_cache);
-       if(x == ~(uint32)0) {
-               p = runtime·getenv("GOTRACEBACK");
-               if(p == nil)
-                       p = (byte*)"";
-               if(p[0] == '\0')
-                       x = 1<<1;
-               else if(runtime·strcmp(p, (byte*)"crash") == 0)
-                       x = (2<<1) | 1;
-               else
-                       x = runtime·atoi(p)<<1;        
-               runtime·atomicstore(&traceback_cache, x);
-       }
        if(crash != nil)
-               *crash = x&1;
-       return x>>1;
+               *crash = traceback_cache&1;
+       return traceback_cache>>1;
 }
 
 int32
@@ -134,8 +118,6 @@ runtime·goenvs_unix(void)
        syscall·envs.array = (byte*)s;
        syscall·envs.len = n;
        syscall·envs.cap = n;
-
-       traceback_cache = ~(uint32)0;
 }
 
 int32
@@ -354,6 +336,16 @@ runtime·parsedebugvars(void)
                        break;
                p++;
        }
+
+       p = runtime·getenv("GOTRACEBACK");
+       if(p == nil)
+               p = (byte*)"";
+       if(p[0] == '\0')
+               traceback_cache = 1<<1;
+       else if(runtime·strcmp(p, (byte*)"crash") == 0)
+               traceback_cache = (2<<1) | 1;
+       else
+               traceback_cache = runtime·atoi(p)<<1;  
 }
 
 // Poor mans 64-bit division.