Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(42)

Side by Side Diff: src/pkg/runtime/malloc.cgo

Issue 257041: code review 257041: runtime: clock garbage collection on bytes allocated, n... (Closed)
Patch Set: code review 257041: runtime: clock garbage collection on bytes allocated, n... Created 15 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/runtime/malloc.h ('k') | src/pkg/runtime/mcache.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 throw("malloc mlookup"); 54 throw("malloc mlookup");
55 } 55 }
56 *ref = RefNone | refflag; 56 *ref = RefNone | refflag;
57 } else { 57 } else {
58 // TODO(rsc): Report tracebacks for very large allocations. 58 // TODO(rsc): Report tracebacks for very large allocations.
59 59
60 // Allocate directly from heap. 60 // Allocate directly from heap.
61 npages = size >> PageShift; 61 npages = size >> PageShift;
62 if((size & PageMask) != 0) 62 if((size & PageMask) != 0)
63 npages++; 63 npages++;
64 » » s = MHeap_Alloc(&mheap, npages, 0); 64 » » s = MHeap_Alloc(&mheap, npages, 0, 1);
65 if(s == nil) 65 if(s == nil)
66 throw("out of memory"); 66 throw("out of memory");
67 mstats.alloc += npages<<PageShift; 67 mstats.alloc += npages<<PageShift;
68 mstats.total_alloc += npages<<PageShift; 68 mstats.total_alloc += npages<<PageShift;
69 v = (void*)(s->start << PageShift); 69 v = (void*)(s->start << PageShift);
70 70
71 // setup for mark sweep 71 // setup for mark sweep
72 s->gcref0 = RefNone | refflag; 72 s->gcref0 = RefNone | refflag;
73 } 73 }
74 74
75 m->mallocing = 0; 75 m->mallocing = 0;
76 76
77 » if(dogc && mstats.inuse_pages > mstats.next_gc) 77 » if(dogc && mstats.heap_alloc >= mstats.next_gc)
78 gc(0); 78 gc(0);
79 return v; 79 return v;
80 } 80 }
81 81
82 void* 82 void*
83 malloc(uintptr size) 83 malloc(uintptr size)
84 { 84 {
85 return mallocgc(size, 0, 0, 1); 85 return mallocgc(size, 0, 0, 1);
86 } 86 }
87 87
(...skipping 18 matching lines...) Expand all
106 throw("free mlookup"); 106 throw("free mlookup");
107 } 107 }
108 *ref = RefFree; 108 *ref = RefFree;
109 109
110 // Find size class for v. 110 // Find size class for v.
111 sizeclass = s->sizeclass; 111 sizeclass = s->sizeclass;
112 if(sizeclass == 0) { 112 if(sizeclass == 0) {
113 // Large object. 113 // Large object.
114 mstats.alloc -= s->npages<<PageShift; 114 mstats.alloc -= s->npages<<PageShift;
115 runtime_memclr(v, s->npages<<PageShift); 115 runtime_memclr(v, s->npages<<PageShift);
116 » » MHeap_Free(&mheap, s); 116 » » MHeap_Free(&mheap, s, 1);
117 } else { 117 } else {
118 // Small object. 118 // Small object.
119 c = m->mcache; 119 c = m->mcache;
120 size = class_to_size[sizeclass]; 120 size = class_to_size[sizeclass];
121 if(size > sizeof(uintptr)) 121 if(size > sizeof(uintptr))
122 ((uintptr*)v)[1] = 1; // mark as "needs to be zeroed" 122 ((uintptr*)v)[1] = 1; // mark as "needs to be zeroed"
123 mstats.alloc -= size; 123 mstats.alloc -= size;
124 mstats.by_size[sizeclass].nfree++; 124 mstats.by_size[sizeclass].nfree++;
125 MCache_Free(c, v, sizeclass, size); 125 MCache_Free(c, v, sizeclass, size);
126 } 126 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 320 }
321 nret = (nret + sizeof(void*)-1) & ~(sizeof(void*)-1); 321 nret = (nret + sizeof(void*)-1) & ~(sizeof(void*)-1);
322 322
323 if(getfinalizer(obj.data, 0, nil)) { 323 if(getfinalizer(obj.data, 0, nil)) {
324 printf("runtime.SetFinalizer: finalizer already set"); 324 printf("runtime.SetFinalizer: finalizer already set");
325 goto throw; 325 goto throw;
326 } 326 }
327 } 327 }
328 addfinalizer(obj.data, finalizer.data, nret); 328 addfinalizer(obj.data, finalizer.data, nret);
329 } 329 }
OLDNEW
« no previous file with comments | « src/pkg/runtime/malloc.h ('k') | src/pkg/runtime/mcache.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b