diff --git a/src/pkg/runtime/debug/garbage.go b/src/pkg/runtime/debug/garbage.go index edb3643871e..30994f21962 100644 --- a/src/pkg/runtime/debug/garbage.go +++ b/src/pkg/runtime/debug/garbage.go @@ -19,14 +19,6 @@ type GCStats struct { PauseQuantiles []time.Duration } -// Implemented in package runtime. -func readGCStats(*[]time.Duration) -func enableGC(bool) bool -func setGCPercent(int) int -func freeOSMemory() -func setMaxStack(int) int -func setMaxThreads(int) int - // ReadGCStats reads statistics about garbage collection into stats. // The number of entries in the pause history is system-dependent; // stats.Pause slice will be reused if large enough, reallocated otherwise. @@ -91,9 +83,9 @@ func (x byDuration) Less(i, j int) bool { return x[i] < x[j] } // at startup, or 100 if the variable is not set. // A negative percentage disables garbage collection. func SetGCPercent(percent int) int { - old := setGCPercent(percent) + old := setGCPercent(int32(percent)) runtime.GC() - return old + return int(old) } // FreeOSMemory forces a garbage collection followed by an @@ -145,7 +137,9 @@ func SetMaxThreads(threads int) int { // that the runtime trigger only a panic, not a crash. // SetPanicOnFault applies only to the current goroutine. // It returns the previous setting. -func SetPanicOnFault(enabled bool) bool +func SetPanicOnFault(enabled bool) bool { + return setPanicOnFault(enabled) +} // WriteHeapDump writes a description of the heap and the objects in // it to the given file descriptor. diff --git a/src/pkg/runtime/debug/stubs.go b/src/pkg/runtime/debug/stubs.go new file mode 100644 index 00000000000..8fba6cf34b7 --- /dev/null +++ b/src/pkg/runtime/debug/stubs.go @@ -0,0 +1,20 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package debug + +import ( + "time" +) + +// Uses assembly to call corresponding runtime-internal functions. +func setMaxStack(int) int +func setGCPercent(int32) int32 +func setPanicOnFault(bool) bool +func setMaxThreads(int) int + +// Implemented in package runtime. +func readGCStats(*[]time.Duration) +func enableGC(bool) bool +func freeOSMemory() diff --git a/src/pkg/runtime/debug/stubs.s b/src/pkg/runtime/debug/stubs.s new file mode 100644 index 00000000000..d56274f2dc7 --- /dev/null +++ b/src/pkg/runtime/debug/stubs.s @@ -0,0 +1,21 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +#ifdef GOARCH_arm +#define JMP B +#endif + +TEXT ·setMaxStack(SB),NOSPLIT,$0-0 + JMP runtime·setMaxStack(SB) + +TEXT ·setGCPercent(SB),NOSPLIT,$0-0 + JMP runtime·setGCPercent(SB) + +TEXT ·setPanicOnFault(SB),NOSPLIT,$0-0 + JMP runtime·setPanicOnFault(SB) + +TEXT ·setMaxThreads(SB),NOSPLIT,$0-0 + JMP runtime·setMaxThreads(SB) diff --git a/src/pkg/runtime/malloc.h b/src/pkg/runtime/malloc.h index 48ec0260051..fb51a9e5dd2 100644 --- a/src/pkg/runtime/malloc.h +++ b/src/pkg/runtime/malloc.h @@ -586,7 +586,7 @@ void runtime·gc_m_ptr(Eface*); void runtime·gc_g_ptr(Eface*); void runtime·gc_itab_ptr(Eface*); -int32 runtime·setgcpercent(int32); +void runtime·setgcpercent_m(void); // Value we use to mark dead pointers when GODEBUG=gcdead=1. #define PoisonGC ((uintptr)0xf969696969696969ULL) diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index 2a476fae4d9..ded41510c4b 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -1621,17 +1621,21 @@ runtime∕debug·readGCStats(Slice *pauses) pauses->len = n+3; } -int32 -runtime·setgcpercent(int32 in) { +void +runtime·setgcpercent_m(void) { + int32 in; int32 out; + in = (int32)(intptr)g->m->scalararg[0]; + runtime·lock(&runtime·mheap.lock); out = runtime·gcpercent; if(in < 0) in = -1; runtime·gcpercent = in; runtime·unlock(&runtime·mheap.lock); - return out; + + g->m->scalararg[0] = (uintptr)(intptr)out; } static void diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 722f44bb1b0..44757a8afd2 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -3199,17 +3199,21 @@ runtime·topofstack(Func *f) (runtime·externalthreadhandlerp != 0 && f->entry == runtime·externalthreadhandlerp); } -int32 -runtime·setmaxthreads(int32 in) +void +runtime·setmaxthreads_m(void) { + int32 in; int32 out; + in = g->m->scalararg[0]; + runtime·lock(&runtime·sched.lock); out = runtime·sched.maxmcount; runtime·sched.maxmcount = in; checkmcount(); runtime·unlock(&runtime·sched.lock); - return out; + + g->m->scalararg[0] = out; } static int8 experiment[] = GOEXPERIMENT; // defined in zaexperiment.h diff --git a/src/pkg/runtime/rdebug.go b/src/pkg/runtime/rdebug.go new file mode 100644 index 00000000000..3df73ce660f --- /dev/null +++ b/src/pkg/runtime/rdebug.go @@ -0,0 +1,42 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package runtime + +func setMaxStack(in int) (out int) { + out = int(maxstacksize) + maxstacksize = uint(in) + return out +} + +func setGCPercent(in int32) (out int32) { + mp := acquirem() + mp.scalararg[0] = uint(int(in)) + onM(&setgcpercent_m) + out = int32(int(mp.scalararg[0])) + releasem(mp) + return out +} + +func setPanicOnFault(newb bool) (old bool) { + new := uint8(0) + if newb { + new = 1 + } + + mp := acquirem() + old = mp.curg.paniconfault == 1 + mp.curg.paniconfault = new + releasem(mp) + return old +} + +func setMaxThreads(in int) (out int) { + mp := acquirem() + mp.scalararg[0] = uint(in) + onM(&setmaxthreads_m) + out = int(mp.scalararg[0]) + releasem(mp) + return out +} diff --git a/src/pkg/runtime/rdebug.goc b/src/pkg/runtime/rdebug.goc deleted file mode 100644 index 042b30ace9b..00000000000 --- a/src/pkg/runtime/rdebug.goc +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package runtime∕debug -#include "runtime.h" -#include "arch_GOARCH.h" -#include "malloc.h" -#include "stack.h" - -func setMaxStack(in int) (out int) { - out = runtime·maxstacksize; - runtime·maxstacksize = in; -} - -func setGCPercent(in int) (out int) { - out = runtime·setgcpercent(in); -} - -func setMaxThreads(in int) (out int) { - out = runtime·setmaxthreads(in); -} - -func SetPanicOnFault(enabled bool) (old bool) { - old = g->paniconfault; - g->paniconfault = enabled; -} diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index f12e50cbfb1..c96fc814170 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -981,7 +981,7 @@ void runtime·crash(void); void runtime·parsedebugvars(void); void _rt0_go(void); void* runtime·funcdata(Func*, int32); -int32 runtime·setmaxthreads(int32); +void runtime·setmaxthreads_m(void); G* runtime·timejump(void); void runtime·iterate_itabs(void (*callback)(Itab*)); void runtime·iterate_finq(void (*callback)(FuncVal*, byte*, uintptr, Type*, PtrType*)); diff --git a/src/pkg/runtime/stubs.go b/src/pkg/runtime/stubs.go index 76f6faf53a3..37e768a4ec9 100644 --- a/src/pkg/runtime/stubs.go +++ b/src/pkg/runtime/stubs.go @@ -84,6 +84,8 @@ var ( unrollgcprog_m, unrollgcproginplace_m, gosched_m, + setgcpercent_m, + setmaxthreads_m, ready_m, park_m, blockevent_m,