Home | History | Annotate | Download | only in alloc

Lines Matching defs:heapSource

25 #include "alloc/HeapSource.h"
143 static void enqueueBlock(HeapSource *heapSource, size_t block);
178 struct HeapSource {
246 static void describeBlocks(const HeapSource *heapSource)
248 for (size_t i = 0; i < heapSource->totalBlocks; ++i) {
250 printf("%d ", heapSource->blockSpace[i]);
282 static int isValidAddress(const HeapSource *heapSource, const u1 *addr)
287 return heapSource->baseBlock <= block &&
288 heapSource->limitBlock > block;
296 static void *allocateBlocks(HeapSource *heapSource, size_t blocks)
298 size_t allocBlocks = heapSource->allocBlocks;
299 size_t totalBlocks = heapSource->totalBlocks;
310 if (heapSource->blockSpace[i+j] != BLOCK_FREE) {
320 heapSource->blockSpace[i] = BLOCK_TO_SPACE; /* why to-space? */
322 heapSource->blockSpace[i+j] = BLOCK_CONTINUED;
324 heapSource->allocBlocks += blocks;
325 void *addr = &heapSource->blockBase[i*BLOCK_SIZE];
328 if (heapSource->queueHead != QUEUE_TAIL) {
329 LOG_ALLOC("allocateBlocks allocBlocks=%zu,block#=%zu", heapSource->allocBlocks, i);
335 enqueueBlock(heapSource, i);
342 heapSource->totalBlocks,
343 heapSource->allocBlocks,
344 heapSource->bytesAllocated);
349 static size_t addressToBlock(const HeapSource *heapSource, const void *addr)
351 assert(heapSource != NULL);
352 assert(isValidAddress(heapSource, addr));
353 return (((uintptr_t)addr) >> BLOCK_SHIFT) - heapSource->baseBlock;
357 static u1 *blockToAddress(const HeapSource *heapSource, size_t block)
361 addr = (u1 *) (((uintptr_t) heapSource->baseBlock + block) * BLOCK_SIZE);
362 assert(isValidAddress(heapSource, addr));
366 static void clearBlock(HeapSource *heapSource, size_t block)
368 assert(heapSource != NULL);
369 assert(block < heapSource->totalBlocks);
370 u1 *addr = heapSource->blockBase + block*BLOCK_SIZE;
373 dvmHeapBitmapClearObjectBit(&heapSource->allocBits, addr + i);
377 static void clearFromSpace(HeapSource *heapSource)
379 assert(heapSource != NULL);
382 while (i < heapSource->totalBlocks) {
383 if (heapSource->blockSpace[i] != BLOCK_FROM_SPACE) {
387 heapSource->blockSpace[i] = BLOCK_FREE;
388 clearBlock(heapSource, i);
391 while (i < heapSource->totalBlocks &&
392 heapSource->blockSpace[i] == BLOCK_CONTINUED) {
393 heapSource->blockSpace[i] = BLOCK_FREE;
394 clearBlock(heapSource, i);
406 static void enqueueBlock(HeapSource *heapSource, size_t block)
408 assert(heapSource != NULL);
409 assert(block < heapSource->totalBlocks);
410 if (heapSource->queueHead != QUEUE_TAIL) {
411 heapSource->blockQueue[heapSource->queueTail] = block;
413 heapSource->queueHead = block;
415 heapSource->blockQueue[block] = QUEUE_TAIL;
416 heapSource->queueTail = block;
417 ++heapSource->queueSize;
424 static void promoteBlockByAddr(HeapSource *heapSource, const void *addr)
428 block = addressToBlock(heapSource, (const u1 *)addr);
429 if (heapSource->blockSpace[block] != BLOCK_TO_SPACE) {
430 // LOG_PROM("promoting block %zu %d @ %p", block, heapSource->blockSpace[block], obj);
431 heapSource->blockSpace[block] = BLOCK_TO_SPACE;
432 enqueueBlock(heapSource, block);
434 heapSource->allocBlocks += 1;
436 // LOG_PROM("NOT promoting block %zu %d @ %p", block, heapSource->blockSpace[block], obj);
443 HeapSource *heapSource;
447 heapSource = calloc(1, sizeof(*heapSource));
448 assert(heapSource != NULL);
450 heapSource->minimumSize = alignUp(startSize, BLOCK_SIZE);
451 heapSource->maximumSize = alignUp(absoluteMaxSize, BLOCK_SIZE);
453 heapSource->currentSize = heapSource->maximumSize;
456 heapSource->blockBase = virtualAlloc(heapSource->maximumSize);
457 assert(heapSource->blockBase != NULL);
458 heapSource->baseBlock = (uintptr_t) heapSource->blockBase >> BLOCK_SHIFT;
459 heapSource->limitBlock = ((uintptr_t) heapSource->blockBase + heapSource->maximumSize) >> BLOCK_SHIFT;
461 heapSource->allocBlocks = 0;
462 heapSource->totalBlocks = (heapSource->limitBlock - heapSource->baseBlock);
464 assert(heapSource->totalBlocks = heapSource->maximumSize / BLOCK_SIZE);
467 size_t size = sizeof(heapSource->blockQueue[0]);
468 heapSource->blockQueue = malloc(heapSource->totalBlocks*size);
469 assert(heapSource->blockQueue != NULL);
470 memset(heapSource->blockQueue, 0xCC, heapSource->totalBlocks*size);
471 heapSource->queueHead = QUEUE_TAIL;
476 size_t size = sizeof(heapSource->blockSpace[0]);
477 heapSource->blockSpace = calloc(1, heapSource->totalBlocks*size);
478 assert(heapSource->blockSpace != NULL);
481 dvmHeapBitmapInit(&heapSource->allocBits,
482 heapSource->blockBase,
483 heapSource->maximumSize,
487 heapSource->allocPtr = allocateBlocks(heapSource, 1);
488 heapSource->allocLimit = heapSource->allocPtr + BLOCK_SIZE;
492 gcHeap->heapSource = heapSource;
515 if (*gcHeap == NULL || (*gcHeap)->heapSource == NULL)
517 free((*gcHeap)->heapSource->blockQueue);
518 free((*gcHeap)->heapSource->blockSpace);
519 virtualFree((*gcHeap)->heapSource->blockBase,
520 (*gcHeap)->heapSource
521 free((*gcHeap)->heapSource);
522 (*gcHeap)->heapSource = NULL;
531 HeapSource *heapSource;
534 heapSource = gDvm.gcHeap->heapSource;
537 value = heapSource->maximumSize;
540 value = heapSource->maximumSize;
543 value = heapSource->bytesAllocated;
546 value = sumHeapBitmap(&heapSource->allocBits);
570 return &gDvm.gcHeap->heapSource->allocBits;
585 HeapSource *heapSource;
589 heapSource = gDvm.gcHeap->heapSource;
590 assert(heapSource != NULL);
591 assert(heapSource->allocPtr != NULL);
592 assert(heapSource->allocLimit != NULL);
595 available = heapSource->allocLimit - heapSource->allocPtr;
599 addr = heapSource->allocPtr;
600 heapSource->allocPtr += aligned;
601 heapSource->bytesAllocated += aligned;
602 dvmHeapBitmapSetObjectBit(&heapSource->allocBits, addr);
608 addr = allocateBlocks(heapSource, 1);
610 heapSource->allocLimit = addr + BLOCK_SIZE;
611 heapSource->allocPtr = addr + aligned;
612 heapSource->bytesAllocated += aligned;
613 dvmHeapBitmapSetObjectBit(&heapSource->allocBits, addr);
622 addr = allocateBlocks(heapSource, blocks);
625 heapSource->bytesAllocated += aligned;
626 dvmHeapBitmapSetObjectBit(&heapSource->allocBits, addr);
640 HeapSource *heapSource;
645 heapSource = gDvm.gcHeap->heapSource;
648 block = addressToBlock(heapSource, (const u1 *)addr);
649 if (heapSource->queueHead == QUEUE_TAIL) {
655 enqueueBlock(heapSource, block);
656 LOG_PROM("forced promoting block %zu %d @ %p", block, heapSource->blockSpace[block], addr);
663 HeapSource *heapSource = gDvm.gcHeap->heapSource;
664 return dvmHeapBitmapCoversAddress(&heapSource->allocBits, ptr);
673 HeapSource *heapSource;
676 heapSource = gDvm.gcHeap->heapSource;
677 bitmap = &heapSource->allocBits;
710 return gDvm.gcHeap->heapSource->currentSize;
765 HeapSource *heapSource = gDvm.gcHeap->heapSource;
768 heapSource->allocBlocks = 0;
769 heapSource->queueSize = 0;
770 heapSource->queueHead = QUEUE_TAIL;
774 heapSource->allocPtr = NULL;
775 heapSource->allocLimit = NULL;
778 for (size_t i = 0; i < heapSource->totalBlocks; ++i) {
779 if (heapSource->blockSpace[i] == BLOCK_TO_SPACE) {
780 heapSource->blockSpace[i] = BLOCK_FROM_SPACE;
787 HeapSource *heapSource = gDvm.gcHeap->heapSource;
788 *total = heapSource->totalBlocks*BLOCK_SIZE;
789 *alloc = heapSource->allocBlocks*BLOCK_SIZE;
795 HeapSource *heapSource;
800 heapSource = gDvm.gcHeap->heapSource;
801 base = heapSource->blockBase;
803 limit = heapSource->blockBase + heapSource->maximumSize;
806 space2 = heapSource->blockSpace[offset >> BLOCK_SHIFT];
826 promoteBlockByAddr(gDvm.gcHeap->heapSource, obj);
1285 gDvm.gcHeap->heapSource->allocBlocks);
1318 fromObj, addressToBlock(gDvm.gcHeap->heapSource,fromObj),
1319 toObj, addressToBlock(gDvm.gcHeap->heapSource,toObj),
1881 static void scavengeBlock(HeapSource *heapSource, size_t block)
1887 LOG_SCAV("scavengeBlock(heapSource=%p,block=%zu)", heapSource, block);
1889 assert(heapSource != NULL);
1890 assert(block < heapSource->totalBlocks);
1891 assert(heapSource->blockSpace[block] == BLOCK_TO_SPACE);
1893 cursor = blockToAddress(heapSource, block);
1938 static void verifyBlock(HeapSource *heapSource, size_t block)
1944 // LOG_VER("verifyBlock(heapSource=%p,block=%zu)", heapSource, block);
1946 assert(heapSource != NULL);
1947 assert(block < heapSource->totalBlocks);
1948 assert(heapSource->blockSpace[block] == BLOCK_TO_SPACE);
1950 cursor = blockToAddress(heapSource, block);
1975 static void describeBlockQueue(const HeapSource *heapSource)
1980 block = heapSource->queueHead;
1982 LOG_SCAV(">>> describeBlockQueue(heapSource=%p)", heapSource);
1985 block = heapSource->blockQueue[block];
1989 count, heapSource->queueSize);
1990 block = heapSource->queueHead;
1992 space = heapSource->blockSpace[block];
1993 LOG_SCAV("block=%zu@%p,space=%zu", block, blockToAddress(heapSource,block), space);
1994 block = heapSource->blockQueue[block];
1997 LOG_SCAV("<<< describeBlockQueue(heapSource=%p)", heapSource);
2005 HeapSource *heapSource;
2009 heapSource = gDvm.gcHeap->heapSource;
2010 describeBlockQueue(heapSource);
2011 while (heapSource->queueHead != QUEUE_TAIL) {
2012 block = heapSource->queueHead;
2014 scavengeBlock(heapSource, block);
2015 heapSource->queueHead = heapSource->blockQueue[block];
2016 LOG_SCAV("New queue head is %zu", heapSource->queueHead);
2028 HeapSource *heapSource = gDvm.gcHeap->heapSource;
2030 for (size_t i = 0; i < heapSource->totalBlocks; ++i) {
2031 switch (heapSource->blockSpace[i]) {
2042 for (size_t i = 0; i < heapSource->totalBlocks; ++i) {
2043 if (heapSource->blockSpace[i] != BLOCK_TO_SPACE) {
2046 verifyBlock(heapSource, i);
2052 HeapSource *heapSource = gDvm.gcHeap->heapSource;
2053 describeBlocks(heapSource);
2090 // describeBlocks(gcHeap->heapSource);
2097 gDvm.gcHeap->heapSource->allocPtr = allocateBlocks(gDvm.gcHeap->heapSource, 1);
2098 gDvm.gcHeap->heapSource->allocLimit = gDvm.gcHeap->heapSource->allocPtr + BLOCK_SIZE;
2105 promoteBlockByAddr(gDvm.gcHeap->heapSource, gDvm.gcHeap->heapSource->allocPtr);
2166 //describeBlocks(gcHeap->heapSource);
2168 clearFromSpace(gcHeap->heapSource);