]> Cypherpunks repositories - gostls13.git/commitdiff
runtime,runtime/debug: Converted some functions from goc to Go.
authorSanjay Menakuru <balasanjay@gmail.com>
Mon, 25 Aug 2014 03:27:00 +0000 (20:27 -0700)
committerKeith Randall <khr@golang.org>
Mon, 25 Aug 2014 03:27:00 +0000 (20:27 -0700)
LGTM=khr
R=golang-codereviews, khr
CC=dvyukov, golang-codereviews
https://golang.org/cl/131010044

src/pkg/runtime/debug/garbage.go
src/pkg/runtime/debug/stubs.go [new file with mode: 0644]
src/pkg/runtime/debug/stubs.s [new file with mode: 0644]
src/pkg/runtime/malloc.h
src/pkg/runtime/mgc0.c
src/pkg/runtime/proc.c
src/pkg/runtime/rdebug.go [new file with mode: 0644]
src/pkg/runtime/rdebug.goc [deleted file]
src/pkg/runtime/runtime.h
src/pkg/runtime/stubs.go

index edb3643871e67368d0b7cd11c135d170c1e0f18e..30994f21962ad7fb08b99988d5dee0f059ae4b99 100644 (file)
@@ -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 (file)
index 0000000..8fba6cf
--- /dev/null
@@ -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 (file)
index 0000000..d56274f
--- /dev/null
@@ -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)
index 48ec0260051676b8159bc5aa495f7d76f83fbf6d..fb51a9e5dd2498a347eed759ce5ede9c41e23833 100644 (file)
@@ -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)
index 2a476fae4d99bbcccd562cdc5809a30070b0171c..ded41510c4b5d6e339091d3ca8347a0ed3b9d9ad 100644 (file)
@@ -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
index 722f44bb1b0ddd260020869f2c1ac5a1a58b1dd1..44757a8afd28e170255476671dbad1b0ebd58101 100644 (file)
@@ -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 (file)
index 0000000..3df73ce
--- /dev/null
@@ -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 (file)
index 042b30a..0000000
+++ /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;
-}
index f12e50cbfb165f740df21634eb68408f6d4ef8e0..c96fc8141704140daea245e1f5011b33c8c8b511 100644 (file)
@@ -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*));
index 76f6faf53a3f658cbe3750dc550b5c62921ec2f9..37e768a4ec9587a0fb603801745d5459b3516d3f 100644 (file)
@@ -84,6 +84,8 @@ var (
        unrollgcprog_m,
        unrollgcproginplace_m,
        gosched_m,
+       setgcpercent_m,
+       setmaxthreads_m,
        ready_m,
        park_m,
        blockevent_m,