From: Dmitriy Vyukov Date: Thu, 21 Aug 2014 07:55:05 +0000 (+0400) Subject: runtime: init GC later X-Git-Tag: go1.4beta1~772 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=99e9bac8c42ccc950315dff1ee6933d7de180026;p=gostls13.git runtime: init GC later 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 --- diff --git a/src/pkg/runtime/env_posix.c b/src/pkg/runtime/env_posix.c index edd1d3568d..8bc3ffb0a2 100644 --- a/src/pkg/runtime/env_posix.c +++ b/src/pkg/runtime/env_posix.c @@ -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; im); @@ -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; diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index 98c9edda41..275fffb347 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -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.