1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:54:42 -07:00

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
This commit is contained in:
Dmitriy Vyukov 2014-08-21 11:55:05 +04:00
parent a0dbbeae67
commit 99e9bac8c4
3 changed files with 16 additions and 26 deletions

View 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)

View 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;

View 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.