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. | 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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 ········ | 578 ········ |
579 precise_type = false; | 579 precise_type = false; |
580 nominal_size = 0; | 580 nominal_size = 0; |
581 | 581 |
582 // Allocate ptrbuf, bitbuf | 582 // Allocate ptrbuf, bitbuf |
583 { | 583 { |
584 runtime·lock(&lock); | 584 runtime·lock(&lock); |
585 | 585 |
586 if(bufferList == nil) { | 586 if(bufferList == nil) { |
587 bufferList = runtime·SysAlloc(sizeof(*bufferList)); | 587 bufferList = runtime·SysAlloc(sizeof(*bufferList)); |
| 588 if(bufferList == nil) |
| 589 runtime·throw("runtime: cannot allocate memory")
; |
588 bufferList->next = nil; | 590 bufferList->next = nil; |
589 } | 591 } |
590 scanbuffers = bufferList; | 592 scanbuffers = bufferList; |
591 bufferList = bufferList->next; | 593 bufferList = bufferList->next; |
592 | 594 |
593 ptrbuf = &scanbuffers->ptrtarget[0]; | 595 ptrbuf = &scanbuffers->ptrtarget[0]; |
594 ptrbuf_end = &scanbuffers->ptrtarget[0] + nelem(scanbuffers->ptr
target); | 596 ptrbuf_end = &scanbuffers->ptrtarget[0] + nelem(scanbuffers->ptr
target); |
595 bitbuf = &scanbuffers->bittarget[0]; | 597 bitbuf = &scanbuffers->bittarget[0]; |
596 objbuf = &scanbuffers->obj[0]; | 598 objbuf = &scanbuffers->obj[0]; |
597 objbuf_end = &scanbuffers->obj[0] + nelem(scanbuffers->obj); | 599 objbuf_end = &scanbuffers->obj[0] + nelem(scanbuffers->obj); |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 { | 1142 { |
1141 if(b != nil) | 1143 if(b != nil) |
1142 runtime·lfstackpush(&work.full, &b->node); | 1144 runtime·lfstackpush(&work.full, &b->node); |
1143 b = (Workbuf*)runtime·lfstackpop(&work.empty); | 1145 b = (Workbuf*)runtime·lfstackpop(&work.empty); |
1144 if(b == nil) { | 1146 if(b == nil) { |
1145 // Need to allocate. | 1147 // Need to allocate. |
1146 runtime·lock(&work); | 1148 runtime·lock(&work); |
1147 if(work.nchunk < sizeof *b) { | 1149 if(work.nchunk < sizeof *b) { |
1148 work.nchunk = 1<<20; | 1150 work.nchunk = 1<<20; |
1149 work.chunk = runtime·SysAlloc(work.nchunk); | 1151 work.chunk = runtime·SysAlloc(work.nchunk); |
| 1152 if(work.chunk == nil) |
| 1153 runtime·throw("runtime: cannot allocate memory")
; |
1150 } | 1154 } |
1151 b = (Workbuf*)work.chunk; | 1155 b = (Workbuf*)work.chunk; |
1152 work.chunk += sizeof *b; | 1156 work.chunk += sizeof *b; |
1153 work.nchunk -= sizeof *b; | 1157 work.nchunk -= sizeof *b; |
1154 runtime·unlock(&work); | 1158 runtime·unlock(&work); |
1155 } | 1159 } |
1156 b->nobj = 0; | 1160 b->nobj = 0; |
1157 return b; | 1161 return b; |
1158 } | 1162 } |
1159 | 1163 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 addroot(Obj obj) | 1227 addroot(Obj obj) |
1224 { | 1228 { |
1225 uint32 cap; | 1229 uint32 cap; |
1226 Obj *new; | 1230 Obj *new; |
1227 | 1231 |
1228 if(work.nroot >= work.rootcap) { | 1232 if(work.nroot >= work.rootcap) { |
1229 cap = PageSize/sizeof(Obj); | 1233 cap = PageSize/sizeof(Obj); |
1230 if(cap < 2*work.rootcap) | 1234 if(cap < 2*work.rootcap) |
1231 cap = 2*work.rootcap; | 1235 cap = 2*work.rootcap; |
1232 new = (Obj*)runtime·SysAlloc(cap*sizeof(Obj)); | 1236 new = (Obj*)runtime·SysAlloc(cap*sizeof(Obj)); |
| 1237 if(new == nil) |
| 1238 runtime·throw("runtime: cannot allocate memory"); |
1233 if(work.roots != nil) { | 1239 if(work.roots != nil) { |
1234 runtime·memmove(new, work.roots, work.rootcap*sizeof(Obj
)); | 1240 runtime·memmove(new, work.roots, work.rootcap*sizeof(Obj
)); |
1235 runtime·SysFree(work.roots, work.rootcap*sizeof(Obj)); | 1241 runtime·SysFree(work.roots, work.rootcap*sizeof(Obj)); |
1236 } | 1242 } |
1237 work.roots = new; | 1243 work.roots = new; |
1238 work.rootcap = cap; | 1244 work.rootcap = cap; |
1239 } | 1245 } |
1240 work.roots[work.nroot] = obj; | 1246 work.roots[work.nroot] = obj; |
1241 work.nroot++; | 1247 work.nroot++; |
1242 } | 1248 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 if(!runtime·getfinalizer(p, true, &fn, &nret)) { | 1380 if(!runtime·getfinalizer(p, true, &fn, &nret)) { |
1375 runtime·setblockspecial(p, false); | 1381 runtime·setblockspecial(p, false); |
1376 runtime·MProf_Free(p, size); | 1382 runtime·MProf_Free(p, size); |
1377 return false; | 1383 return false; |
1378 } | 1384 } |
1379 | 1385 |
1380 runtime·lock(&finlock); | 1386 runtime·lock(&finlock); |
1381 if(finq == nil || finq->cnt == finq->cap) { | 1387 if(finq == nil || finq->cnt == finq->cap) { |
1382 if(finc == nil) { | 1388 if(finc == nil) { |
1383 finc = runtime·SysAlloc(PageSize); | 1389 finc = runtime·SysAlloc(PageSize); |
| 1390 if(finc == nil) |
| 1391 runtime·throw("runtime: cannot allocate memory")
; |
1384 finc->cap = (PageSize - sizeof(FinBlock)) / sizeof(Final
izer) + 1; | 1392 finc->cap = (PageSize - sizeof(FinBlock)) / sizeof(Final
izer) + 1; |
1385 finc->alllink = allfin; | 1393 finc->alllink = allfin; |
1386 allfin = finc; | 1394 allfin = finc; |
1387 } | 1395 } |
1388 block = finc; | 1396 block = finc; |
1389 finc = block->next; | 1397 finc = block->next; |
1390 block->next = finq; | 1398 block->next = finq; |
1391 finq = block; | 1399 finq = block; |
1392 } | 1400 } |
1393 f = &finq->fin[finq->cnt]; | 1401 f = &finq->fin[finq->cnt]; |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 uintptr n; | 2176 uintptr n; |
2169 | 2177 |
2170 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; | 2178 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; |
2171 n = (n+bitmapChunk-1) & ~(bitmapChunk-1); | 2179 n = (n+bitmapChunk-1) & ~(bitmapChunk-1); |
2172 if(h->bitmap_mapped >= n) | 2180 if(h->bitmap_mapped >= n) |
2173 return; | 2181 return; |
2174 | 2182 |
2175 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped); | 2183 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped); |
2176 h->bitmap_mapped = n; | 2184 h->bitmap_mapped = n; |
2177 } | 2185 } |
LEFT | RIGHT |