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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 static void putempty(Workbuf*); | 181 static void putempty(Workbuf*); |
182 static Workbuf* handoff(Workbuf*); | 182 static Workbuf* handoff(Workbuf*); |
183 static void gchelperstart(void); | 183 static void gchelperstart(void); |
184 static void scanstack(G* gp, void *scanbuf); | 184 static void scanstack(G* gp, void *scanbuf); |
185 | 185 |
186 static struct { | 186 static struct { |
187 uint64 full; // lock-free list of full blocks | 187 uint64 full; // lock-free list of full blocks |
188 uint64 empty; // lock-free list of empty blocks | 188 uint64 empty; // lock-free list of empty blocks |
189 byte pad0[CacheLineSize]; // prevents false-sharing between full/empt
y and nproc/nwait | 189 byte pad0[CacheLineSize]; // prevents false-sharing between full/empt
y and nproc/nwait |
190 uint32 nproc; | 190 uint32 nproc; |
| 191 int64 tstart; |
191 volatile uint32 nwait; | 192 volatile uint32 nwait; |
192 volatile uint32 ndone; | 193 volatile uint32 ndone; |
193 volatile uint32 debugmarkdone; | 194 volatile uint32 debugmarkdone; |
194 Note alldone; | 195 Note alldone; |
195 ParFor *markfor; | 196 ParFor *markfor; |
196 ParFor *sweepfor; | 197 ParFor *sweepfor; |
197 | 198 |
198 Lock; | 199 Lock; |
199 byte *chunk; | 200 byte *chunk; |
200 uintptr nchunk; | 201 uintptr nchunk; |
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 case Gdead: | 1669 case Gdead: |
1669 break; | 1670 break; |
1670 case Grunning: | 1671 case Grunning: |
1671 runtime·throw("mark - world not stopped"); | 1672 runtime·throw("mark - world not stopped"); |
1672 case Grunnable: | 1673 case Grunnable: |
1673 case Gsyscall: | 1674 case Gsyscall: |
1674 case Gwaiting: | 1675 case Gwaiting: |
1675 addstackroots(gp); | 1676 addstackroots(gp); |
1676 break; | 1677 break; |
1677 } | 1678 } |
| 1679 |
| 1680 // remember when we've first observed the G blocked |
| 1681 // needed only to output in traceback |
| 1682 if((gp->status == Gwaiting || gp->status == Gsyscall) && gp->wai
tsince == 0) |
| 1683 gp->waitsince = work.tstart; |
1678 } | 1684 } |
1679 | 1685 |
1680 for(fb=allfin; fb; fb=fb->alllink) | 1686 for(fb=allfin; fb; fb=fb->alllink) |
1681 addroot((Obj){(byte*)fb->fin, fb->cnt*sizeof(fb->fin[0]), 0}); | 1687 addroot((Obj){(byte*)fb->fin, fb->cnt*sizeof(fb->fin[0]), 0}); |
1682 } | 1688 } |
1683 | 1689 |
1684 static void | 1690 static void |
1685 addfreelists(void) | 1691 addfreelists(void) |
1686 { | 1692 { |
1687 int32 i; | 1693 int32 i; |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 gc(struct gc_args *args) | 2229 gc(struct gc_args *args) |
2224 { | 2230 { |
2225 int64 t0, t1, t2, t3, t4; | 2231 int64 t0, t1, t2, t3, t4; |
2226 uint64 heap0, heap1, obj0, obj1, ninstr; | 2232 uint64 heap0, heap1, obj0, obj1, ninstr; |
2227 GCStats stats; | 2233 GCStats stats; |
2228 M *mp; | 2234 M *mp; |
2229 uint32 i; | 2235 uint32 i; |
2230 Eface eface; | 2236 Eface eface; |
2231 | 2237 |
2232 t0 = args->start_time; | 2238 t0 = args->start_time; |
| 2239 work.tstart = args->start_time;· |
2233 | 2240 |
2234 if(CollectStats) | 2241 if(CollectStats) |
2235 runtime·memclr((byte*)&gcstats, sizeof(gcstats)); | 2242 runtime·memclr((byte*)&gcstats, sizeof(gcstats)); |
2236 | 2243 |
2237 for(mp=runtime·allm; mp; mp=mp->alllink) | 2244 for(mp=runtime·allm; mp; mp=mp->alllink) |
2238 runtime·settype_flush(mp); | 2245 runtime·settype_flush(mp); |
2239 | 2246 |
2240 heap0 = 0; | 2247 heap0 = 0; |
2241 obj0 = 0; | 2248 obj0 = 0; |
2242 if(runtime·debug.gctrace) { | 2249 if(runtime·debug.gctrace) { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2671 uintptr n; | 2678 uintptr n; |
2672 | 2679 |
2673 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; | 2680 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; |
2674 n = ROUND(n, bitmapChunk); | 2681 n = ROUND(n, bitmapChunk); |
2675 if(h->bitmap_mapped >= n) | 2682 if(h->bitmap_mapped >= n) |
2676 return; | 2683 return; |
2677 | 2684 |
2678 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped, &mstats.gc_sys)
; | 2685 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped, &mstats.gc_sys)
; |
2679 h->bitmap_mapped = n; | 2686 h->bitmap_mapped = n; |
2680 } | 2687 } |
OLD | NEW |