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 // Page heap. | 5 // Page heap. |
6 // | 6 // |
7 // See malloc.h for overview. | 7 // See malloc.h for overview. |
8 // | 8 // |
9 // When a MSpan is in the heap free list, state == MSpanFree | 9 // When a MSpan is in the heap free list, state == MSpanFree |
10 // and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span. | 10 // and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 static bool | 159 static bool |
160 MHeap_Grow(MHeap *h, uintptr npage) | 160 MHeap_Grow(MHeap *h, uintptr npage) |
161 { | 161 { |
162 uintptr ask; | 162 uintptr ask; |
163 void *v; | 163 void *v; |
164 MSpan *s; | 164 MSpan *s; |
165 | 165 |
166 // Ask for a big chunk, to reduce the number of mappings | 166 // Ask for a big chunk, to reduce the number of mappings |
167 // the operating system needs to track; also amortizes | 167 // the operating system needs to track; also amortizes |
168 // the overhead of an operating system mapping. | 168 // the overhead of an operating system mapping. |
169 » // For Native Client, allocate a multiple of 64kB (16 pages). | 169 » // Allocate a multiple of 64kB (16 pages). |
170 npage = (npage+15)&~15; | 170 npage = (npage+15)&~15; |
171 ask = npage<<PageShift; | 171 ask = npage<<PageShift; |
172 if(ask < HeapAllocChunk) | 172 if(ask < HeapAllocChunk) |
173 ask = HeapAllocChunk; | 173 ask = HeapAllocChunk; |
174 | 174 |
175 v = runtime_SysAlloc(ask); | 175 v = runtime_SysAlloc(ask); |
176 if(v == nil) { | 176 if(v == nil) { |
177 if(ask > (npage<<PageShift)) { | 177 if(ask > (npage<<PageShift)) { |
178 ask = npage<<PageShift; | 178 ask = npage<<PageShift; |
179 v = runtime_SysAlloc(ask); | 179 v = runtime_SysAlloc(ask); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 void | 341 void |
342 runtime_MSpanList_Insert(MSpan *list, MSpan *span) | 342 runtime_MSpanList_Insert(MSpan *list, MSpan *span) |
343 { | 343 { |
344 if(span->next != nil || span->prev != nil) | 344 if(span->next != nil || span->prev != nil) |
345 runtime_throw("MSpanList_Insert"); | 345 runtime_throw("MSpanList_Insert"); |
346 span->next = list->next; | 346 span->next = list->next; |
347 span->prev = list; | 347 span->prev = list; |
348 span->next->prev = span; | 348 span->next->prev = span; |
349 span->prev->next = span; | 349 span->prev->next = span; |
350 } | 350 } |
OLD | NEW |