LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 // Garbage collector (GC). | 5 // Garbage collector (GC). |
6 // | 6 // |
7 // GC is: | 7 // GC is: |
8 // - mark&sweep | 8 // - mark&sweep |
9 // - mostly precise (with the exception of some C-allocated objects, assembly fr
ames/arguments, etc) | 9 // - mostly precise (with the exception of some C-allocated objects, assembly fr
ames/arguments, etc) |
10 // - parallel (up to MaxGcproc threads) | 10 // - parallel (up to MaxGcproc threads) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 RootFinalizers = 2, | 74 RootFinalizers = 2, |
75 RootSpans = 3, | 75 RootSpans = 3, |
76 RootFlushCaches = 4, | 76 RootFlushCaches = 4, |
77 RootCount = 5, | 77 RootCount = 5, |
78 }; | 78 }; |
79 | 79 |
80 #define ScanConservatively ((byte*)1) | 80 #define ScanConservatively ((byte*)1) |
81 | 81 |
82 // Initialized from $GOGC. GOGC=off means no gc. | 82 // Initialized from $GOGC. GOGC=off means no gc. |
83 extern int32 runtime·gcpercent; | 83 extern int32 runtime·gcpercent; |
84 | |
85 static FuncVal* poolcleanup; | |
86 | |
87 void | |
88 sync·runtime_registerPoolCleanup(FuncVal *f) | |
89 { | |
90 poolcleanup = f; | |
91 } | |
92 | |
93 void | |
94 runtime·clearpools(void) | |
95 { | |
96 P *p, **pp; | |
97 MCache *c; | |
98 int32 i; | |
99 | |
100 // clear sync.Pool's | |
101 if(poolcleanup != nil) | |
102 reflect·call(poolcleanup, nil, 0, 0); | |
103 | |
104 for(pp=runtime·allp; p=*pp; pp++) { | |
105 // clear tinyalloc pool | |
106 c = p->mcache; | |
107 if(c != nil) { | |
108 c->tiny = nil; | |
109 c->tinysize = 0; | |
110 c->sudogcache = nil; | |
111 } | |
112 // clear defer pools | |
113 for(i=0; i<nelem(p->deferpool); i++) | |
114 p->deferpool[i] = nil; | |
115 } | |
116 } | |
117 | 84 |
118 // Holding worldsema grants an M the right to try to stop the world. | 85 // Holding worldsema grants an M the right to try to stop the world. |
119 // The procedure is: | 86 // The procedure is: |
120 // | 87 // |
121 // runtime·semacquire(&runtime·worldsema); | 88 // runtime·semacquire(&runtime·worldsema); |
122 // m->gcing = 1; | 89 // m->gcing = 1; |
123 // runtime·stoptheworld(); | 90 // runtime·stoptheworld(); |
124 // | 91 // |
125 // ... do stuff ... | 92 // ... do stuff ... |
126 // | 93 // |
(...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 | 1863 |
1897 void runtime·gc_unixnanotime(int64 *now); | 1864 void runtime·gc_unixnanotime(int64 *now); |
1898 | 1865 |
1899 int64 runtime·unixnanotime(void) | 1866 int64 runtime·unixnanotime(void) |
1900 { | 1867 { |
1901 int64 now; | 1868 int64 now; |
1902 | 1869 |
1903 runtime·gc_unixnanotime(&now); | 1870 runtime·gc_unixnanotime(&now); |
1904 return now; | 1871 return now; |
1905 } | 1872 } |
LEFT | RIGHT |