LEFT | RIGHT |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime | 5 package runtime |
6 | 6 |
7 import "unsafe" | 7 import "unsafe" |
8 | 8 |
9 // Declarations for runtime services implemented in C or assembly. | 9 // Declarations for runtime services implemented in C or assembly. |
10 // C implementations of these functions are in stubs.goc. | 10 // C implementations of these functions are in stubs.goc. |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 // n must be a power of 2 | 38 // n must be a power of 2 |
39 func roundup(p unsafe.Pointer, n uintptr) unsafe.Pointer { | 39 func roundup(p unsafe.Pointer, n uintptr) unsafe.Pointer { |
40 return unsafe.Pointer((uintptr(p) + n - 1) &^ (n - 1)) | 40 return unsafe.Pointer((uintptr(p) + n - 1) &^ (n - 1)) |
41 } | 41 } |
42 | 42 |
43 // in stubs.goc | 43 // in stubs.goc |
44 func acquirem() *m | 44 func acquirem() *m |
45 func releasem(mp *m) | 45 func releasem(mp *m) |
46 | 46 |
| 47 // An mFunction represents a C function that runs on the M stack. It |
| 48 // can be called from Go using mcall or onM. Through the magic of |
| 49 // linking, an mFunction variable and the corresponding C code entry |
| 50 // point live at the same address. |
| 51 type mFunction byte |
| 52 |
47 // in asm_*.s | 53 // in asm_*.s |
48 func mcall(fn *byte) | 54 func mcall(fn *mFunction) |
49 func onM(fn *byte) | 55 func onM(fn *mFunction) |
50 | 56 |
51 // C routines that run on the M stack. Call these like | 57 // C functions that run on the M stack. Call these like |
52 // mcall(&mcacheRefill) | 58 // mcall(&mcacheRefill_m) |
53 // Arguments should be passed in m->scalararg[x] and | 59 // Arguments should be passed in m->scalararg[x] and |
54 // m->ptrarg[x]. Return values can be passed in those | 60 // m->ptrarg[x]. Return values can be passed in those |
55 // same slots. | 61 // same slots. |
56 var mcacheRefill byte | 62 var ( |
57 var largeAlloc byte | 63 » mcacheRefill_m, |
58 var mprofMalloc byte | 64 » largeAlloc_m, |
59 var mgc2 byte | 65 » mprofMalloc_m, |
60 var setFinalizer byte | 66 » gc_m, |
61 var unrollgcprog byte | 67 » setFinalizer_m, |
62 var unrollgcproginplace byte | 68 » markallocated_m, |
| 69 » unrollgcprog_m, |
| 70 » unrollgcproginplace_m mFunction |
| 71 ) |
63 | 72 |
64 // memclr clears n bytes starting at ptr. | 73 // memclr clears n bytes starting at ptr. |
65 // in memclr_*.s | 74 // in memclr_*.s |
66 func memclr(ptr unsafe.Pointer, n uintptr) | 75 func memclr(ptr unsafe.Pointer, n uintptr) |
67 | 76 |
68 func racemalloc(p unsafe.Pointer, size uintptr) | 77 func racemalloc(p unsafe.Pointer, size uintptr) |
69 func tracealloc(p unsafe.Pointer, size uintptr, typ *_type) | 78 func tracealloc(p unsafe.Pointer, size uintptr, typ *_type) |
70 | 79 |
71 // memmove copies n bytes from "from" to "to". | 80 // memmove copies n bytes from "from" to "to". |
72 // in memmove_*.s | 81 // in memmove_*.s |
73 func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr) | 82 func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr) |
74 | 83 |
75 // in asm_*.s | 84 // in asm_*.s |
76 func fastrand2() uint32 | 85 func fastrand2() uint32 |
77 | 86 |
78 const ( | 87 const ( |
79 gcpercentUnknown = -2 | 88 gcpercentUnknown = -2 |
80 concurrentSweep = true | 89 concurrentSweep = true |
81 ) | 90 ) |
82 | 91 |
83 // in asm_*.s | 92 // Atomic operations to read/write a pointer. |
| 93 // in stubs.goc |
| 94 func goatomicloadp(p unsafe.Pointer) unsafe.Pointer // return *p |
| 95 func goatomicstorep(p unsafe.Pointer, v unsafe.Pointer) // *p = v |
| 96 |
| 97 // in stubs.goc |
84 // if *p == x { *p = y; return true } else { return false }, atomically | 98 // if *p == x { *p = y; return true } else { return false }, atomically |
85 //go:noescape | 99 //go:noescape |
86 func gocas(p *uint32, x uint32, y uint32) bool | 100 func gocas(p *uint32, x uint32, y uint32) bool |
87 | 101 |
88 //go:noescape | 102 //go:noescape |
89 func gocasx(p *uintptr, x uintptr, y uintptr) bool | 103 func gocasx(p *uintptr, x uintptr, y uintptr) bool |
90 | 104 |
91 func goreadgogc() int32 | 105 func goreadgogc() int32 |
92 func gonanotime() int64 | 106 func gonanotime() int64 |
93 func gosched() | 107 func gosched() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 152 |
139 // noescape hides a pointer from escape analysis. noescape is | 153 // noescape hides a pointer from escape analysis. noescape is |
140 // the identity function but escape analysis doesn't think the | 154 // the identity function but escape analysis doesn't think the |
141 // output depends on the input. noescape is inlined and currently | 155 // output depends on the input. noescape is inlined and currently |
142 // compiles down to a single xor instruction. | 156 // compiles down to a single xor instruction. |
143 // USE CAREFULLY! | 157 // USE CAREFULLY! |
144 func noescape(p unsafe.Pointer) unsafe.Pointer { | 158 func noescape(p unsafe.Pointer) unsafe.Pointer { |
145 x := uintptr(p) | 159 x := uintptr(p) |
146 return unsafe.Pointer(x ^ 0) | 160 return unsafe.Pointer(x ^ 0) |
147 } | 161 } |
LEFT | RIGHT |