Left: | ||
Right: |
OLD | NEW |
---|---|
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 24 matching lines...) Expand all Loading... | |
35 PC_BITS = PRECISE | LOOP, | 35 PC_BITS = PRECISE | LOOP, |
36 | 36 |
37 // Pointer map | 37 // Pointer map |
38 BitsPerPointer = 2, | 38 BitsPerPointer = 2, |
39 BitsNoPointer = 0, | 39 BitsNoPointer = 0, |
40 BitsPointer = 1, | 40 BitsPointer = 1, |
41 BitsIface = 2, | 41 BitsIface = 2, |
42 BitsEface = 3, | 42 BitsEface = 3, |
43 }; | 43 }; |
44 | 44 |
45 struct { | |
dvyukov
2013/12/18 12:09:38
static struct
dvyukov
2013/12/18 12:09:38
{ on next line
bradfitz
2013/12/18 17:31:25
Done.
bradfitz
2013/12/18 17:31:25
that is not consistent with the rest of this file
| |
46 Lock;·· | |
47 void *head; | |
dvyukov
2013/12/18 12:09:38
pin * to type in struct defs
bradfitz
2013/12/18 17:31:25
Done.
| |
48 } pools; | |
49 | |
50 void | |
51 sync·runtime_registerPool(void **p) | |
52 { | |
53 runtime·lock(&pools); | |
54 p[0] = pools.head; | |
55 pools.head = p; | |
56 runtime·unlock(&pools); | |
57 } | |
58 | |
59 void | |
60 clearpools(void) | |
61 { | |
62 void **p, **next; | |
63 | |
64 for(p = pools.head; p != nil; p = next) { | |
65 next = p[0]; | |
66 p[0] = nil; // next | |
67 p[1] = nil; // slice | |
68 p[2] = nil; | |
69 p[3] = nil; | |
70 } | |
71 pools.head = nil; | |
72 } | |
73 | |
45 // Bits in per-word bitmap. | 74 // Bits in per-word bitmap. |
46 // #defines because enum might not be able to hold the values. | 75 // #defines because enum might not be able to hold the values. |
47 // | 76 // |
48 // Each word in the bitmap describes wordsPerBitmapWord words | 77 // Each word in the bitmap describes wordsPerBitmapWord words |
49 // of heap memory. There are 4 bitmap bits dedicated to each heap word, | 78 // of heap memory. There are 4 bitmap bits dedicated to each heap word, |
50 // so on a 64-bit system there is one bitmap word per 16 heap words. | 79 // so on a 64-bit system there is one bitmap word per 16 heap words. |
51 // The bits in the word are packed together by type first, then by | 80 // The bits in the word are packed together by type first, then by |
52 // heap location, so each 64-bit bitmap word consists of, from top to bottom, | 81 // heap location, so each 64-bit bitmap word consists of, from top to bottom, |
53 // the 16 bitSpecial bits for the corresponding heap words, then the 16 bitMarke d bits, | 82 // the 16 bitSpecial bits for the corresponding heap words, then the 16 bitMarke d bits, |
54 // then the 16 bitNoScan/bitBlockBoundary bits, then the 16 bitAllocated bits. | 83 // then the 16 bitNoScan/bitBlockBoundary bits, then the 16 bitAllocated bits. |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2082 // typically threads which lost the race to grab | 2111 // typically threads which lost the race to grab |
2083 // worldsema exit here when gc is done. | 2112 // worldsema exit here when gc is done. |
2084 runtime·semrelease(&runtime·worldsema); | 2113 runtime·semrelease(&runtime·worldsema); |
2085 return; | 2114 return; |
2086 } | 2115 } |
2087 | 2116 |
2088 // Ok, we're doing it! Stop everybody else | 2117 // Ok, we're doing it! Stop everybody else |
2089 a.start_time = runtime·nanotime(); | 2118 a.start_time = runtime·nanotime(); |
2090 m->gcing = 1; | 2119 m->gcing = 1; |
2091 runtime·stoptheworld(); | 2120 runtime·stoptheworld(); |
2092 » | 2121 |
2122 » clearpools(); | |
2123 | |
2093 // Run gc on the g0 stack. We do this so that the g stack | 2124 // Run gc on the g0 stack. We do this so that the g stack |
2094 // we're currently running on will no longer change. Cuts | 2125 // we're currently running on will no longer change. Cuts |
2095 // the root set down a bit (g0 stacks are not scanned, and | 2126 // the root set down a bit (g0 stacks are not scanned, and |
2096 // we don't need to scan gc's internal state). Also an | 2127 // we don't need to scan gc's internal state). Also an |
2097 // enabler for copyable stacks. | 2128 // enabler for copyable stacks. |
2098 for(i = 0; i < (runtime·debug.gctrace > 1 ? 2 : 1); i++) { | 2129 for(i = 0; i < (runtime·debug.gctrace > 1 ? 2 : 1); i++) { |
2099 // switch to g0, call gc(&a), then switch back | 2130 // switch to g0, call gc(&a), then switch back |
2100 g->param = &a; | 2131 g->param = &a; |
2101 g->status = Gwaiting; | 2132 g->status = Gwaiting; |
2102 g->waitreason = "garbage collection"; | 2133 g->waitreason = "garbage collection"; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2602 uintptr n; | 2633 uintptr n; |
2603 | 2634 |
2604 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; | 2635 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; |
2605 n = ROUND(n, bitmapChunk); | 2636 n = ROUND(n, bitmapChunk); |
2606 if(h->bitmap_mapped >= n) | 2637 if(h->bitmap_mapped >= n) |
2607 return; | 2638 return; |
2608 | 2639 |
2609 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped, &mstats.gc_sys) ; | 2640 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped, &mstats.gc_sys) ; |
2610 h->bitmap_mapped = n; | 2641 h->bitmap_mapped = n; |
2611 } | 2642 } |
OLD | NEW |