github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/runtime/extern.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package runtime contains operations that interact with Go's runtime system, 7 such as functions to control goroutines. It also includes the low-level type information 8 used by the reflect package; see reflect's documentation for the programmable 9 interface to the run-time type system. 10 11 Environment Variables 12 13 The following environment variables ($name or %name%, depending on the host 14 operating system) control the run-time behavior of Go programs. The meanings 15 and use may change from release to release. 16 17 The GOGC variable sets the initial garbage collection target percentage. 18 A collection is triggered when the ratio of freshly allocated data to live data 19 remaining after the previous collection reaches this percentage. The default 20 is GOGC=100. Setting GOGC=off disables the garbage collector entirely. 21 The runtime/debug package's SetGCPercent function allows changing this 22 percentage at run time. See https://golang.org/pkg/runtime/debug/#SetGCPercent. 23 24 The GODEBUG variable controls debugging variables within the runtime. 25 It is a comma-separated list of name=val pairs setting these named variables: 26 27 allocfreetrace: setting allocfreetrace=1 causes every allocation to be 28 profiled and a stack trace printed on each object's allocation and free. 29 30 efence: setting efence=1 causes the allocator to run in a mode 31 where each object is allocated on a unique page and addresses are 32 never recycled. 33 34 gccheckmark: setting gccheckmark=1 enables verification of the 35 garbage collector's concurrent mark phase by performing a 36 second mark pass while the world is stopped. If the second 37 pass finds a reachable object that was not found by concurrent 38 mark, the garbage collector will panic. 39 40 gcpacertrace: setting gcpacertrace=1 causes the garbage collector to 41 print information about the internal state of the concurrent pacer. 42 43 gcshrinkstackoff: setting gcshrinkstackoff=1 disables moving goroutines 44 onto smaller stacks. In this mode, a goroutine's stack can only grow. 45 46 gcstackbarrieroff: setting gcstackbarrieroff=1 disables the use of stack barriers 47 that allow the garbage collector to avoid repeating a stack scan during the 48 mark termination phase. 49 50 gcstackbarrierall: setting gcstackbarrierall=1 installs stack barriers 51 in every stack frame, rather than in exponentially-spaced frames. 52 53 gcstoptheworld: setting gcstoptheworld=1 disables concurrent garbage collection, 54 making every garbage collection a stop-the-world event. Setting gcstoptheworld=2 55 also disables concurrent sweeping after the garbage collection finishes. 56 57 gctrace: setting gctrace=1 causes the garbage collector to emit a single line to standard 58 error at each collection, summarizing the amount of memory collected and the 59 length of the pause. Setting gctrace=2 emits the same summary but also 60 repeats each collection. The format of this line is subject to change. 61 Currently, it is: 62 gc # @#s #%: #+...+# ms clock, #+...+# ms cpu, #->#-># MB, # MB goal, # P 63 where the fields are as follows: 64 gc # the GC number, incremented at each GC 65 @#s time in seconds since program start 66 #% percentage of time spent in GC since program start 67 #+...+# wall-clock/CPU times for the phases of the GC 68 #->#-># MB heap size at GC start, at GC end, and live heap 69 # MB goal goal heap size 70 # P number of processors used 71 The phases are stop-the-world (STW) sweep termination, scan, 72 synchronize Ps, mark, and STW mark termination. The CPU times 73 for mark are broken down in to assist time (GC performed in 74 line with allocation), background GC time, and idle GC time. 75 If the line ends with "(forced)", this GC was forced by a 76 runtime.GC() call and all phases are STW. 77 78 memprofilerate: setting memprofilerate=X will update the value of runtime.MemProfileRate. 79 When set to 0 memory profiling is disabled. Refer to the description of 80 MemProfileRate for the default value. 81 82 memprofilerate: setting memprofilerate=X changes the setting for 83 runtime.MemProfileRate. Refer to the description of this variable for how 84 it is used and its default value. 85 86 sbrk: setting sbrk=1 replaces the memory allocator and garbage collector 87 with a trivial allocator that obtains memory from the operating system and 88 never reclaims any memory. 89 90 scavenge: scavenge=1 enables debugging mode of heap scavenger. 91 92 scheddetail: setting schedtrace=X and scheddetail=1 causes the scheduler to emit 93 detailed multiline info every X milliseconds, describing state of the scheduler, 94 processors, threads and goroutines. 95 96 schedtrace: setting schedtrace=X causes the scheduler to emit a single line to standard 97 error every X milliseconds, summarizing the scheduler state. 98 99 The GOMAXPROCS variable limits the number of operating system threads that 100 can execute user-level Go code simultaneously. There is no limit to the number of threads 101 that can be blocked in system calls on behalf of Go code; those do not count against 102 the GOMAXPROCS limit. This package's GOMAXPROCS function queries and changes 103 the limit. 104 105 The GOTRACEBACK variable controls the amount of output generated when a Go 106 program fails due to an unrecovered panic or an unexpected runtime condition. 107 By default, a failure prints a stack trace for every extant goroutine, eliding functions 108 internal to the run-time system, and then exits with exit code 2. 109 If GOTRACEBACK=0, the per-goroutine stack traces are omitted entirely. 110 If GOTRACEBACK=1, the default behavior is used. 111 If GOTRACEBACK=2, the per-goroutine stack traces include run-time functions. 112 If GOTRACEBACK=crash, the per-goroutine stack traces include run-time functions, 113 and if possible the program crashes in an operating-specific manner instead of 114 exiting. For example, on Unix systems, the program raises SIGABRT to trigger a 115 core dump. 116 117 The GOARCH, GOOS, GOPATH, and GOROOT environment variables complete 118 the set of Go environment variables. They influence the building of Go programs 119 (see https://golang.org/cmd/go and https://golang.org/pkg/go/build). 120 GOARCH, GOOS, and GOROOT are recorded at compile time and made available by 121 constants or functions in this package, but they do not influence the execution 122 of the run-time system. 123 */ 124 package runtime 125 126 // Gosched yields the processor, allowing other goroutines to run. It does not 127 // suspend the current goroutine, so execution resumes automatically. 128 func Gosched() 129 130 // Goexit terminates the goroutine that calls it. No other goroutine is affected. 131 // Goexit runs all deferred calls before terminating the goroutine. 132 // 133 // Calling Goexit from the main goroutine terminates that goroutine 134 // without func main returning. Since func main has not returned, 135 // the program continues execution of other goroutines. 136 // If all other goroutines exit, the program crashes. 137 func Goexit() 138 139 // Caller reports file and line number information about function invocations on 140 // the calling goroutine's stack. The argument skip is the number of stack frames 141 // to ascend, with 0 identifying the caller of Caller. (For historical reasons the 142 // meaning of skip differs between Caller and Callers.) The return values report the 143 // program counter, file name, and line number within the file of the corresponding 144 // call. The boolean ok is false if it was not possible to recover the information. 145 func Caller(skip int) (pc uintptr, file string, line int, ok bool) 146 147 // Callers fills the slice pc with the program counters of function invocations 148 // on the calling goroutine's stack. The argument skip is the number of stack frames 149 // to skip before recording in pc, with 0 identifying the frame for Callers itself and 150 // 1 identifying the caller of Callers. 151 // It returns the number of entries written to pc. 152 func Callers(skip int, pc []uintptr) int 153 154 type Func struct { 155 opaque struct{} // unexported field to disallow conversions 156 } 157 158 // FuncForPC returns a *Func describing the function that contains the 159 // given program counter address, or else nil. 160 func FuncForPC(pc uintptr) *Func 161 162 // Name returns the name of the function. 163 func (f *Func) Name() string { 164 return funcname_go(f) 165 } 166 167 // Entry returns the entry address of the function. 168 func (f *Func) Entry() uintptr { 169 return funcentry_go(f) 170 } 171 172 // FileLine returns the file name and line number of the 173 // source code corresponding to the program counter pc. 174 // The result will not be accurate if pc is not a program 175 // counter within f. 176 func (f *Func) FileLine(pc uintptr) (file string, line int) { 177 return funcline_go(f, pc) 178 } 179 180 // implemented in symtab.c 181 func funcline_go(*Func, uintptr) (string, int) 182 func funcname_go(*Func) string 183 func funcentry_go(*Func) uintptr 184 185 // SetFinalizer sets the finalizer associated with x to f. 186 // When the garbage collector finds an unreachable block 187 // with an associated finalizer, it clears the association and runs 188 // f(x) in a separate goroutine. This makes x reachable again, but 189 // now without an associated finalizer. Assuming that SetFinalizer 190 // is not called again, the next time the garbage collector sees 191 // that x is unreachable, it will free x. 192 // 193 // SetFinalizer(x, nil) clears any finalizer associated with x. 194 // 195 // The argument x must be a pointer to an object allocated by 196 // calling new or by taking the address of a composite literal. 197 // The argument f must be a function that takes a single argument 198 // to which x's type can be assigned, and can have arbitrary ignored return 199 // values. If either of these is not true, SetFinalizer aborts the 200 // program. 201 // 202 // Finalizers are run in dependency order: if A points at B, both have 203 // finalizers, and they are otherwise unreachable, only the finalizer 204 // for A runs; once A is freed, the finalizer for B can run. 205 // If a cyclic structure includes a block with a finalizer, that 206 // cycle is not guaranteed to be garbage collected and the finalizer 207 // is not guaranteed to run, because there is no ordering that 208 // respects the dependencies. 209 // 210 // The finalizer for x is scheduled to run at some arbitrary time after 211 // x becomes unreachable. 212 // There is no guarantee that finalizers will run before a program exits, 213 // so typically they are useful only for releasing non-memory resources 214 // associated with an object during a long-running program. 215 // For example, an os.File object could use a finalizer to close the 216 // associated operating system file descriptor when a program discards 217 // an os.File without calling Close, but it would be a mistake 218 // to depend on a finalizer to flush an in-memory I/O buffer such as a 219 // bufio.Writer, because the buffer would not be flushed at program exit. 220 // 221 // It is not guaranteed that a finalizer will run if the size of *x is 222 // zero bytes. 223 // 224 // A single goroutine runs all finalizers for a program, sequentially. 225 // If a finalizer must run for a long time, it should do so by starting 226 // a new goroutine. 227 func SetFinalizer(x, f interface{}) 228 229 func getgoroot() string 230 231 // GOROOT returns the root of the Go tree. 232 // It uses the GOROOT environment variable, if set, 233 // or else the root used during the Go build. 234 func GOROOT() string { 235 s := getgoroot() 236 if s != "" { 237 return s 238 } 239 return defaultGoroot 240 } 241 242 // Version returns the Go tree's version string. 243 // It is either the commit hash and date at the time of the build or, 244 // when possible, a release tag like "go1.3". 245 func Version() string { 246 return theVersion 247 } 248 249 // GOOS is the running program's operating system target: 250 // one of darwin, freebsd, linux, and so on. 251 const GOOS string = theGoos 252 253 // GOARCH is the running program's architecture target: 254 // 386, amd64, arm, arm64, ppc64, ppc64le. 255 const GOARCH string = theGoarch 256 257 // GCCGOTOOLDIR is the Tool Dir for the gccgo build 258 const GCCGOTOOLDIR string = theGccgoToolDir