OLD | NEW |
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 #include "runtime.h" | 9 #include "runtime.h" |
10 #include "arch_GOARCH.h" | 10 #include "arch_GOARCH.h" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 if(!runtime·mlookup(obj.data, &base, &size, nil) || obj.data != base) { | 452 if(!runtime·mlookup(obj.data, &base, &size, nil) || obj.data != base) { |
453 // As an implementation detail we allow to set finalizers for an
inner byte | 453 // As an implementation detail we allow to set finalizers for an
inner byte |
454 // of an object if it could come from tiny alloc (see mallocgc f
or details). | 454 // of an object if it could come from tiny alloc (see mallocgc f
or details). |
455 if(ot->elem == nil || (ot->elem->kind&KindNoPointers) == 0 || ot
->elem->size >= TinySize) { | 455 if(ot->elem == nil || (ot->elem->kind&KindNoPointers) == 0 || ot
->elem->size >= TinySize) { |
456 runtime·printf("runtime.SetFinalizer: pointer not at beg
inning of allocated block (%p)\n", obj.data); | 456 runtime·printf("runtime.SetFinalizer: pointer not at beg
inning of allocated block (%p)\n", obj.data); |
457 goto throw; | 457 goto throw; |
458 } | 458 } |
459 } | 459 } |
460 if(finalizer.type != nil) { | 460 if(finalizer.type != nil) { |
461 runtime·createfing(); | 461 runtime·createfing(); |
462 » » if(finalizer.type->kind != KindFunc) | 462 » » if((finalizer.type->kind&KindMask) != KindFunc) |
463 goto badfunc; | 463 goto badfunc; |
464 ft = (FuncType*)finalizer.type; | 464 ft = (FuncType*)finalizer.type; |
465 if(ft->dotdotdot || ft->in.len != 1) | 465 if(ft->dotdotdot || ft->in.len != 1) |
466 goto badfunc; | 466 goto badfunc; |
467 fint = *(Type**)ft->in.array; | 467 fint = *(Type**)ft->in.array; |
468 if(fint == obj.type) { | 468 if(fint == obj.type) { |
469 // ok - same type | 469 // ok - same type |
470 » » } else if(fint->kind == KindPtr && (fint->x == nil || fint->x->n
ame == nil || obj.type->x == nil || obj.type->x->name == nil) && ((PtrType*)fint
)->elem == ((PtrType*)obj.type)->elem) { | 470 » » } else if((fint->kind&KindMask) == KindPtr && (fint->x == nil ||
fint->x->name == nil || obj.type->x == nil || obj.type->x->name == nil) && ((Pt
rType*)fint)->elem == ((PtrType*)obj.type)->elem) { |
471 // ok - not same type, but both pointers, | 471 // ok - not same type, but both pointers, |
472 // one or the other is unnamed, and same element type, s
o assignable. | 472 // one or the other is unnamed, and same element type, s
o assignable. |
473 » » } else if(fint->kind == KindInterface && ((InterfaceType*)fint)-
>mhdr.len == 0) { | 473 » » } else if((fint->kind&KindMask) == KindInterface && ((InterfaceT
ype*)fint)->mhdr.len == 0) { |
474 // ok - satisfies empty interface | 474 // ok - satisfies empty interface |
475 » » } else if(fint->kind == KindInterface && runtime·ifaceE2I2((Inte
rfaceType*)fint, obj, &iface)) { | 475 » » } else if((fint->kind&KindMask) == KindInterface && runtime·ifac
eE2I2((InterfaceType*)fint, obj, &iface)) { |
476 // ok - satisfies non-empty interface | 476 // ok - satisfies non-empty interface |
477 } else | 477 } else |
478 goto badfunc; | 478 goto badfunc; |
479 | 479 |
480 // compute size needed for return parameters | 480 // compute size needed for return parameters |
481 nret = 0; | 481 nret = 0; |
482 for(i=0; i<ft->out.len; i++) { | 482 for(i=0; i<ft->out.len; i++) { |
483 t = ((Type**)ft->out.array)[i]; | 483 t = ((Type**)ft->out.array)[i]; |
484 nret = ROUND(nret, t->align) + t->size; | 484 nret = ROUND(nret, t->align) + t->size; |
485 } | 485 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 npages++; | 543 npages++; |
544 s = runtime·MHeap_Alloc(&runtime·mheap, npages, 0, 1, !(flag & FlagNoZer
o)); | 544 s = runtime·MHeap_Alloc(&runtime·mheap, npages, 0, 1, !(flag & FlagNoZer
o)); |
545 if(s == nil) | 545 if(s == nil) |
546 runtime·throw("out of memory"); | 546 runtime·throw("out of memory"); |
547 s->limit = (byte*)(s->start<<PageShift) + size; | 547 s->limit = (byte*)(s->start<<PageShift) + size; |
548 v = (void*)(s->start << PageShift); | 548 v = (void*)(s->start << PageShift); |
549 // setup for mark sweep | 549 // setup for mark sweep |
550 runtime·markspan(v, 0, 0, true); | 550 runtime·markspan(v, 0, 0, true); |
551 g->m->ptrarg[0] = s; | 551 g->m->ptrarg[0] = s; |
552 } | 552 } |
OLD | NEW |