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" |
11 #include "arch_GOARCH.h" | 11 #include "arch_GOARCH.h" |
12 #include "malloc.h" | 12 #include "malloc.h" |
13 #include "type.h" | 13 #include "type.h" |
14 #include "typekind.h" | 14 #include "typekind.h" |
15 #include "race.h" | 15 #include "race.h" |
16 #include "stack.h" | 16 #include "stack.h" |
17 #include "../../cmd/ld/textflag.h" | 17 #include "../../cmd/ld/textflag.h" |
18 | 18 |
19 // Mark mheap as 'no pointers', it does not contain interesting pointers but occ
upies ~45K. | 19 // Mark mheap as 'no pointers', it does not contain interesting pointers but occ
upies ~45K. |
20 #pragma dataflag NOPTR | 20 #pragma dataflag NOPTR |
21 MHeap runtime·mheap; | 21 MHeap runtime·mheap; |
22 MStats mstats; | |
23 | 22 |
24 int32 runtime·checking; | 23 int32 runtime·checking; |
25 | 24 |
26 extern MStats mstats; // defined in zruntime_def_$GOOS_$GOARCH.go | 25 extern MStats mstats; // defined in zruntime_def_$GOOS_$GOARCH.go |
27 | 26 |
28 extern volatile intgo runtime·MemProfileRate; | 27 extern volatile intgo runtime·MemProfileRate; |
29 | 28 |
30 // Allocate an object of at least size bytes. | 29 // Allocate an object of at least size bytes. |
31 // Small objects are allocated from the per-thread cache's free lists. | 30 // Small objects are allocated from the per-thread cache's free lists. |
32 // Large objects (> 32 kB) are allocated straight from the heap. | 31 // Large objects (> 32 kB) are allocated straight from the heap. |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 h->largefree += c->local_largefree; | 313 h->largefree += c->local_largefree; |
315 c->local_largefree = 0; | 314 c->local_largefree = 0; |
316 h->nlargefree += c->local_nlargefree; | 315 h->nlargefree += c->local_nlargefree; |
317 c->local_nlargefree = 0; | 316 c->local_nlargefree = 0; |
318 for(i=0; i<nelem(c->local_nsmallfree); i++) { | 317 for(i=0; i<nelem(c->local_nsmallfree); i++) { |
319 h->nsmallfree[i] += c->local_nsmallfree[i]; | 318 h->nsmallfree[i] += c->local_nsmallfree[i]; |
320 c->local_nsmallfree[i] = 0; | 319 c->local_nsmallfree[i] = 0; |
321 } | 320 } |
322 } | 321 } |
323 | 322 |
324 // Size of the trailing by_size array differs between Go and C, | 323 uintptr runtime·sizeof_C_MStats = sizeof(MStats); |
325 // NumSizeClasses was changed, but we can not change Go struct because of backwa
rd compatibility. | |
326 // sizeof_C_MStats is what C thinks about size of Go struct. | |
327 uintptr runtime·sizeof_C_MStats = sizeof(MStats) - (NumSizeClasses - 61) * sizeo
f(mstats.by_size[0]); | |
328 | 324 |
329 #define MaxArena32 (2U<<30) | 325 #define MaxArena32 (2U<<30) |
330 | 326 |
331 void | 327 void |
332 runtime·mallocinit(void) | 328 runtime·mallocinit(void) |
333 { | 329 { |
334 byte *p; | 330 byte *p; |
335 uintptr arena_size, bitmap_size, spans_size; | 331 uintptr arena_size, bitmap_size, spans_size; |
336 extern byte end[]; | 332 extern byte end[]; |
337 byte *want; | 333 byte *want; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 // NOTE: asking to remove a finalizer when there currently isn't
one set is OK. | 802 // NOTE: asking to remove a finalizer when there currently isn't
one set is OK. |
807 runtime·removefinalizer(obj.data); | 803 runtime·removefinalizer(obj.data); |
808 } | 804 } |
809 return; | 805 return; |
810 | 806 |
811 badfunc: | 807 badfunc: |
812 runtime·printf("runtime.SetFinalizer: cannot pass %S to finalizer %S\n",
*obj.type->string, *finalizer.type->string); | 808 runtime·printf("runtime.SetFinalizer: cannot pass %S to finalizer %S\n",
*obj.type->string, *finalizer.type->string); |
813 throw: | 809 throw: |
814 runtime·throw("runtime.SetFinalizer"); | 810 runtime·throw("runtime.SetFinalizer"); |
815 } | 811 } |
LEFT | RIGHT |