LEFT | RIGHT |
(no file at all) | |
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. | 5 // Garbage collector. |
6 | 6 |
7 #include "runtime.h" | 7 #include "runtime.h" |
8 #include "arch_GOARCH.h" | 8 #include "arch_GOARCH.h" |
9 #include "malloc.h" | 9 #include "malloc.h" |
10 #include "stack.h" | 10 #include "stack.h" |
(...skipping 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 | 2012 |
2013 if(gcpercent == GcpercentUnknown) { // first time through | 2013 if(gcpercent == GcpercentUnknown) { // first time through |
2014 runtime·lock(&runtime·mheap); | 2014 runtime·lock(&runtime·mheap); |
2015 if(gcpercent == GcpercentUnknown) | 2015 if(gcpercent == GcpercentUnknown) |
2016 gcpercent = readgogc(); | 2016 gcpercent = readgogc(); |
2017 runtime·unlock(&runtime·mheap); | 2017 runtime·unlock(&runtime·mheap); |
2018 } | 2018 } |
2019 if(gcpercent < 0) | 2019 if(gcpercent < 0) |
2020 return; | 2020 return; |
2021 | 2021 |
2022 » runtime·semacquire(&runtime·worldsema); | 2022 » runtime·semacquire(&runtime·worldsema, false); |
2023 if(!force && mstats.heap_alloc < mstats.next_gc) { | 2023 if(!force && mstats.heap_alloc < mstats.next_gc) { |
2024 // typically threads which lost the race to grab | 2024 // typically threads which lost the race to grab |
2025 // worldsema exit here when gc is done. | 2025 // worldsema exit here when gc is done. |
2026 runtime·semrelease(&runtime·worldsema); | 2026 runtime·semrelease(&runtime·worldsema); |
2027 return; | 2027 return; |
2028 } | 2028 } |
2029 | 2029 |
2030 // Ok, we're doing it! Stop everybody else | 2030 // Ok, we're doing it! Stop everybody else |
2031 a.start_time = runtime·nanotime(); | 2031 a.start_time = runtime·nanotime(); |
2032 m->gcing = 1; | 2032 m->gcing = 1; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2211 runtime·MProf_GC(); | 2211 runtime·MProf_GC(); |
2212 } | 2212 } |
2213 | 2213 |
2214 void | 2214 void |
2215 runtime·ReadMemStats(MStats *stats) | 2215 runtime·ReadMemStats(MStats *stats) |
2216 { | 2216 { |
2217 // Have to acquire worldsema to stop the world, | 2217 // Have to acquire worldsema to stop the world, |
2218 // because stoptheworld can only be used by | 2218 // because stoptheworld can only be used by |
2219 // one goroutine at a time, and there might be | 2219 // one goroutine at a time, and there might be |
2220 // a pending garbage collection already calling it. | 2220 // a pending garbage collection already calling it. |
2221 » runtime·semacquire(&runtime·worldsema); | 2221 » runtime·semacquire(&runtime·worldsema, false); |
2222 m->gcing = 1; | 2222 m->gcing = 1; |
2223 runtime·stoptheworld(); | 2223 runtime·stoptheworld(); |
2224 updatememstats(nil); | 2224 updatememstats(nil); |
2225 *stats = mstats; | 2225 *stats = mstats; |
2226 m->gcing = 0; | 2226 m->gcing = 0; |
2227 m->locks++; | 2227 m->locks++; |
2228 runtime·semrelease(&runtime·worldsema); | 2228 runtime·semrelease(&runtime·worldsema); |
2229 runtime·starttheworld(); | 2229 runtime·starttheworld(); |
2230 m->locks--; | 2230 m->locks--; |
2231 } | 2231 } |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2538 uintptr n; | 2538 uintptr n; |
2539 | 2539 |
2540 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; | 2540 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; |
2541 n = ROUND(n, bitmapChunk); | 2541 n = ROUND(n, bitmapChunk); |
2542 if(h->bitmap_mapped >= n) | 2542 if(h->bitmap_mapped >= n) |
2543 return; | 2543 return; |
2544 | 2544 |
2545 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped); | 2545 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped); |
2546 h->bitmap_mapped = n; | 2546 h->bitmap_mapped = n; |
2547 } | 2547 } |
LEFT | RIGHT |