LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 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 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "arch_GOARCH.h" | 6 #include "arch_GOARCH.h" |
7 #include "stack.h" | 7 #include "stack.h" |
8 #include "malloc.h" | 8 #include "malloc.h" |
9 #include "../../cmd/ld/textflag.h" | 9 #include "../../cmd/ld/textflag.h" |
10 | 10 |
11 // Code related to defer, panic and recover. | 11 // Code related to defer, panic and recover. |
12 | 12 |
13 uint32 runtime·panicking; | 13 uint32 runtime·panicking; |
14 static Lock paniclk; | 14 static Lock paniclk; |
15 | 15 |
16 // Each P holds pool for defers with arg sizes 8, 24, 40, 56 and 72 bytes. | 16 // Each P holds pool for defers with arg sizes 8, 24, 40, 56 and 72 bytes. |
17 // Memory block is 40 (24 for 32 bits) bytes larger due to Defer header. | 17 // Memory block is 40 (24 for 32 bits) bytes larger due to Defer header. |
18 // This maps exactly to malloc size classes. | 18 // This maps exactly to malloc size classes. |
19 | 19 |
20 // defer size class for arg size sz | 20 // defer size class for arg size sz |
21 #define DEFERCLASS(sz) (((sz)+7)>>4) | 21 #define DEFERCLASS(sz) (((sz)+7)>>4) |
22 // total size of memory block for defer with arg size sz | 22 // total size of memory block for defer with arg size sz |
23 #define TOTALSIZE(sz) (sizeof(Defer) - sizeof(((Defer*)nil)->args) + ROUND(sz, s
izeof(uintptr))) | 23 #define TOTALSIZE(sz) (sizeof(Defer) - sizeof(((Defer*)nil)->args) + ROUND((sz)+
((sz)==0), sizeof(uintptr))) |
24 | 24 |
25 // Allocate a Defer, usually using per-P pool. | 25 // Allocate a Defer, usually using per-P pool. |
26 // Each defer must be released with freedefer. | 26 // Each defer must be released with freedefer. |
27 static Defer* | 27 static Defer* |
28 newdefer(int32 siz) | 28 newdefer(int32 siz) |
29 { | 29 { |
30 int32 total, sc; | 30 int32 total, sc; |
31 Defer *d; | 31 Defer *d; |
32 P *p; | 32 P *p; |
33 | 33 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 for(i=0; i<nelem(p->deferpool); i++) | 156 for(i=0; i<nelem(p->deferpool); i++) |
157 map[i] = -1; | 157 map[i] = -1; |
158 for(i=0;; i++) { | 158 for(i=0;; i++) { |
159 defersc = DEFERCLASS(i); | 159 defersc = DEFERCLASS(i); |
160 if(defersc >= nelem(p->deferpool)) | 160 if(defersc >= nelem(p->deferpool)) |
161 break; | 161 break; |
162 siz = TOTALSIZE(i); | 162 siz = TOTALSIZE(i); |
163 mallocsc = runtime·SizeToClass(siz); | 163 mallocsc = runtime·SizeToClass(siz); |
164 siz = runtime·class_to_size[mallocsc]; | 164 siz = runtime·class_to_size[mallocsc]; |
165 » » // runtime·printf("defer class %d: arg size %d, block size %d(%d
)\n", defersc, i, siz, mallocsc); | 165 » » //runtime·printf("defer class %d: arg size %d, block size %d(%d)
\n", defersc, i, siz, mallocsc); |
166 if(map[defersc] < 0) { | 166 if(map[defersc] < 0) { |
167 map[defersc] = mallocsc; | 167 map[defersc] = mallocsc; |
168 continue; | 168 continue; |
169 } | 169 } |
170 if(map[defersc] != mallocsc) { | 170 if(map[defersc] != mallocsc) { |
171 runtime·printf("bad defer size class: i=%d siz=%d malloc
sc=%d/%d\n", | 171 runtime·printf("bad defer size class: i=%d siz=%d malloc
sc=%d/%d\n", |
172 i, siz, map[defersc], mallocsc); | 172 i, siz, map[defersc], mallocsc); |
173 runtime·throw("bad defer size class"); | 173 runtime·throw("bad defer size class"); |
174 } | 174 } |
175 } | 175 } |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 { | 571 { |
572 rundefer(); | 572 rundefer(); |
573 runtime·goexit(); | 573 runtime·goexit(); |
574 } | 574 } |
575 | 575 |
576 void | 576 void |
577 runtime·panicdivide(void) | 577 runtime·panicdivide(void) |
578 { | 578 { |
579 runtime·panicstring("integer divide by zero"); | 579 runtime·panicstring("integer divide by zero"); |
580 } | 580 } |
LEFT | RIGHT |