Commit 99e9bac8 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent a0dbbeae
......@@ -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)
......
......@@ -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;
......
......@@ -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.
......
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