Commit ef504623 authored by Sanjay Menakuru's avatar Sanjay Menakuru Committed by Keith Randall

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
parent be2ad1d7
......@@ -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.
......
// 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()
// 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)
......@@ -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)
......
......@@ -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
......
......@@ -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
......
// 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
}
// 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;
}
......@@ -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*));
......
......@@ -84,6 +84,8 @@ var (
unrollgcprog_m,
unrollgcproginplace_m,
gosched_m,
setgcpercent_m,
setmaxthreads_m,
ready_m,
park_m,
blockevent_m,
......
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