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 // See malloc.h for overview. | 5 // See malloc.h for overview. |
6 // | 6 // |
7 // TODO(rsc): double-check stats. | 7 // TODO(rsc): double-check stats. |
8 | 8 |
9 package runtime | 9 package runtime |
10 #include "runtime.h" | 10 #include "runtime.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 runtime·throw("out of memory"); | 66 runtime·throw("out of memory"); |
67 size = npages<<PageShift; | 67 size = npages<<PageShift; |
68 c->local_alloc += size; | 68 c->local_alloc += size; |
69 c->local_total_alloc += size; | 69 c->local_total_alloc += size; |
70 v = (void*)(s->start << PageShift); | 70 v = (void*)(s->start << PageShift); |
71 | 71 |
72 // setup for mark sweep | 72 // setup for mark sweep |
73 runtime·markspan(v, 0, 0, true); | 73 runtime·markspan(v, 0, 0, true); |
74 } | 74 } |
75 | 75 |
76 » if (sizeof(void*) == 4 && c->local_total_alloc >(1<<30)) { | 76 » if (sizeof(void*) == 4 && c->local_total_alloc >= (1<<30)) { |
77 // purge cache stats to prevent overflow | 77 // purge cache stats to prevent overflow |
78 runtime·lock(&runtime·mheap); | 78 runtime·lock(&runtime·mheap); |
79 runtime·purgecachedstats(m); | 79 runtime·purgecachedstats(m); |
80 runtime·unlock(&runtime·mheap); | 80 runtime·unlock(&runtime·mheap); |
81 } | 81 } |
82 | 82 |
83 if(!(flag & FlagNoGC)) | 83 if(!(flag & FlagNoGC)) |
84 runtime·markallocated(v, size, (flag&FlagNoPointers) != 0); | 84 runtime·markallocated(v, size, (flag&FlagNoPointers) != 0); |
85 | 85 |
86 m->mallocing = 0; | 86 m->mallocing = 0; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 | 172 |
173 int32 | 173 int32 |
174 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp) | 174 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp) |
175 { | 175 { |
176 uintptr n, i; | 176 uintptr n, i; |
177 byte *p; | 177 byte *p; |
178 MSpan *s; | 178 MSpan *s; |
179 | 179 |
180 m->mcache->local_nlookup++; | 180 m->mcache->local_nlookup++; |
| 181 if (sizeof(void*) == 4 && m->mcache->local_nlookup >= (1<<30)) { |
| 182 // purge cache stats to prevent overflow |
| 183 runtime·lock(&runtime·mheap); |
| 184 runtime·purgecachedstats(m); |
| 185 runtime·unlock(&runtime·mheap); |
| 186 } |
| 187 |
181 s = runtime·MHeap_LookupMaybe(&runtime·mheap, v); | 188 s = runtime·MHeap_LookupMaybe(&runtime·mheap, v); |
182 if(sp) | 189 if(sp) |
183 *sp = s; | 190 *sp = s; |
184 if(s == nil) { | 191 if(s == nil) { |
185 runtime·checkfreed(v, 1); | 192 runtime·checkfreed(v, 1); |
186 if(base) | 193 if(base) |
187 *base = nil; | 194 *base = nil; |
188 if(size) | 195 if(size) |
189 *size = 0; | 196 *size = 0; |
190 return 0; | 197 return 0; |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 runtime·printf("runtime.SetFinalizer: finalizer already set\n"); | 535 runtime·printf("runtime.SetFinalizer: finalizer already set\n"); |
529 goto throw; | 536 goto throw; |
530 } | 537 } |
531 return; | 538 return; |
532 | 539 |
533 badfunc: | 540 badfunc: |
534 runtime·printf("runtime.SetFinalizer: second argument is %S, not func(%S
)\n", *finalizer.type->string, *obj.type->string); | 541 runtime·printf("runtime.SetFinalizer: second argument is %S, not func(%S
)\n", *finalizer.type->string, *obj.type->string); |
535 throw: | 542 throw: |
536 runtime·throw("runtime.SetFinalizer"); | 543 runtime·throw("runtime.SetFinalizer"); |
537 } | 544 } |
LEFT | RIGHT |