runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct) { MSpan *s; runtime·lock(h); runtime·purgecachedstats(m); s = MHeap_AllocLocked(h, npage, sizeclass); if(s != nil) { mstats.heap_inuse += npage<<PageShift; if(acct) { mstats.heap_objects++; mstats.heap_alloc += npage<<PageShift; } } runtime·unlock(h); return s; }
int32 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp) { uintptr n, i; byte *p; MSpan *s; g->m->mcache->local_nlookup++; if (sizeof(void*) == 4 && g->m->mcache->local_nlookup >= (1<<30)) { // purge cache stats to prevent overflow runtime·lock(&runtime·mheap.lock); runtime·purgecachedstats(g->m->mcache); runtime·unlock(&runtime·mheap.lock); } s = runtime·MHeap_LookupMaybe(&runtime·mheap, v); if(sp) *sp = s; if(s == nil) { if(base) *base = nil; if(size) *size = 0; return 0; } p = (byte*)((uintptr)s->start<<PageShift); if(s->sizeclass == 0) { // Large object. if(base) *base = p; if(size) *size = s->npages<<PageShift; return 1; } n = s->elemsize; if(base) { i = ((byte*)v - p)/n; *base = p + i*n; } if(size) *size = n; return 1; }