LEFT | RIGHT |
(no file at all) | |
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 if(s == nil) | 65 if(s == nil) |
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 |
| 76 if (sizeof(void*) == 4 && c->local_total_alloc >= (1<<30)) { |
| 77 // purge cache stats to prevent overflow |
| 78 runtime·lock(&runtime·mheap); |
| 79 runtime·purgecachedstats(m); |
| 80 runtime·unlock(&runtime·mheap); |
| 81 } |
| 82 |
75 if(!(flag & FlagNoGC)) | 83 if(!(flag & FlagNoGC)) |
76 runtime·markallocated(v, size, (flag&FlagNoPointers) != 0); | 84 runtime·markallocated(v, size, (flag&FlagNoPointers) != 0); |
77 | 85 |
78 m->mallocing = 0; | 86 m->mallocing = 0; |
79 | 87 |
80 if(!(flag & FlagNoProfiling) && (rate = runtime·MemProfileRate) > 0) { | 88 if(!(flag & FlagNoProfiling) && (rate = runtime·MemProfileRate) > 0) { |
81 if(size >= rate) | 89 if(size >= rate) |
82 goto profile; | 90 goto profile; |
83 if(m->mcache->next_sample > size) | 91 if(m->mcache->next_sample > size) |
84 m->mcache->next_sample -= size; | 92 m->mcache->next_sample -= size; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 171 } |
164 | 172 |
165 int32 | 173 int32 |
166 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp) | 174 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp) |
167 { | 175 { |
168 uintptr n, i; | 176 uintptr n, i; |
169 byte *p; | 177 byte *p; |
170 MSpan *s; | 178 MSpan *s; |
171 | 179 |
172 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 |
173 s = runtime·MHeap_LookupMaybe(&runtime·mheap, v); | 188 s = runtime·MHeap_LookupMaybe(&runtime·mheap, v); |
174 if(sp) | 189 if(sp) |
175 *sp = s; | 190 *sp = s; |
176 if(s == nil) { | 191 if(s == nil) { |
177 runtime·checkfreed(v, 1); | 192 runtime·checkfreed(v, 1); |
178 if(base) | 193 if(base) |
179 *base = nil; | 194 *base = nil; |
180 if(size) | 195 if(size) |
181 *size = 0; | 196 *size = 0; |
182 return 0; | 197 return 0; |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 runtime·printf("runtime.SetFinalizer: finalizer already set\n"); | 535 runtime·printf("runtime.SetFinalizer: finalizer already set\n"); |
521 goto throw; | 536 goto throw; |
522 } | 537 } |
523 return; | 538 return; |
524 | 539 |
525 badfunc: | 540 badfunc: |
526 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); |
527 throw: | 542 throw: |
528 runtime·throw("runtime.SetFinalizer"); | 543 runtime·throw("runtime.SetFinalizer"); |
529 } | 544 } |
LEFT | RIGHT |