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

runtime,runtime/debug: Converted some functions from goc to Go.

LGTM=khr
R=golang-codereviews, khr
CC=dvyukov, golang-codereviews
https://golang.org/cl/131010044
This commit is contained in:
Sanjay Menakuru 2014-08-24 20:27:00 -07:00 committed by Keith Randall
parent be2ad1d7f5
commit ef50462378
10 changed files with 106 additions and 46 deletions

View File

@ -19,14 +19,6 @@ type GCStats struct {
PauseQuantiles []time.Duration 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. // ReadGCStats reads statistics about garbage collection into stats.
// The number of entries in the pause history is system-dependent; // The number of entries in the pause history is system-dependent;
// stats.Pause slice will be reused if large enough, reallocated otherwise. // 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. // at startup, or 100 if the variable is not set.
// A negative percentage disables garbage collection. // A negative percentage disables garbage collection.
func SetGCPercent(percent int) int { func SetGCPercent(percent int) int {
old := setGCPercent(percent) old := setGCPercent(int32(percent))
runtime.GC() runtime.GC()
return old return int(old)
} }
// FreeOSMemory forces a garbage collection followed by an // 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. // that the runtime trigger only a panic, not a crash.
// SetPanicOnFault applies only to the current goroutine. // SetPanicOnFault applies only to the current goroutine.
// It returns the previous setting. // 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 // WriteHeapDump writes a description of the heap and the objects in
// it to the given file descriptor. // it to the given file descriptor.

View File

@ -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()

View File

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

View File

@ -586,7 +586,7 @@ void runtime·gc_m_ptr(Eface*);
void runtime·gc_g_ptr(Eface*); void runtime·gc_g_ptr(Eface*);
void runtime·gc_itab_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. // Value we use to mark dead pointers when GODEBUG=gcdead=1.
#define PoisonGC ((uintptr)0xf969696969696969ULL) #define PoisonGC ((uintptr)0xf969696969696969ULL)

View File

@ -1621,17 +1621,21 @@ runtimedebug·readGCStats(Slice *pauses)
pauses->len = n+3; pauses->len = n+3;
} }
int32 void
runtime·setgcpercent(int32 in) { runtime·setgcpercent_m(void) {
int32 in;
int32 out; int32 out;
in = (int32)(intptr)g->m->scalararg[0];
runtime·lock(&runtime·mheap.lock); runtime·lock(&runtime·mheap.lock);
out = runtime·gcpercent; out = runtime·gcpercent;
if(in < 0) if(in < 0)
in = -1; in = -1;
runtime·gcpercent = in; runtime·gcpercent = in;
runtime·unlock(&runtime·mheap.lock); runtime·unlock(&runtime·mheap.lock);
return out;
g->m->scalararg[0] = (uintptr)(intptr)out;
} }
static void static void

View File

@ -3199,17 +3199,21 @@ runtime·topofstack(Func *f)
(runtime·externalthreadhandlerp != 0 && f->entry == runtime·externalthreadhandlerp); (runtime·externalthreadhandlerp != 0 && f->entry == runtime·externalthreadhandlerp);
} }
int32 void
runtime·setmaxthreads(int32 in) runtime·setmaxthreads_m(void)
{ {
int32 in;
int32 out; int32 out;
in = g->m->scalararg[0];
runtime·lock(&runtime·sched.lock); runtime·lock(&runtime·sched.lock);
out = runtime·sched.maxmcount; out = runtime·sched.maxmcount;
runtime·sched.maxmcount = in; runtime·sched.maxmcount = in;
checkmcount(); checkmcount();
runtime·unlock(&runtime·sched.lock); runtime·unlock(&runtime·sched.lock);
return out;
g->m->scalararg[0] = out;
} }
static int8 experiment[] = GOEXPERIMENT; // defined in zaexperiment.h static int8 experiment[] = GOEXPERIMENT; // defined in zaexperiment.h

42
src/pkg/runtime/rdebug.go Normal file
View File

@ -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
}

View File

@ -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 runtimedebug
#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;
}

View File

@ -981,7 +981,7 @@ void runtime·crash(void);
void runtime·parsedebugvars(void); void runtime·parsedebugvars(void);
void _rt0_go(void); void _rt0_go(void);
void* runtime·funcdata(Func*, int32); void* runtime·funcdata(Func*, int32);
int32 runtime·setmaxthreads(int32); void runtime·setmaxthreads_m(void);
G* runtime·timejump(void); G* runtime·timejump(void);
void runtime·iterate_itabs(void (*callback)(Itab*)); void runtime·iterate_itabs(void (*callback)(Itab*));
void runtime·iterate_finq(void (*callback)(FuncVal*, byte*, uintptr, Type*, PtrType*)); void runtime·iterate_finq(void (*callback)(FuncVal*, byte*, uintptr, Type*, PtrType*));

View File

@ -84,6 +84,8 @@ var (
unrollgcprog_m, unrollgcprog_m,
unrollgcproginplace_m, unrollgcproginplace_m,
gosched_m, gosched_m,
setgcpercent_m,
setmaxthreads_m,
ready_m, ready_m,
park_m, park_m,
blockevent_m, blockevent_m,