2 #include "multicoregc.h"
3 #include "multicoreruntime.h"
4 #include "pmc_garbage.h"
6 #include "runtime_arch.h"
7 #include "multicoremsg.h"
9 void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
10 unsigned int memcheck=minimumbytes>PMC_MINALLOC?minimumbytes:PMC_MINALLOC;
12 for(int i=0;i<NUMCORES4GC;i+=2) {
13 void *startptr=pmc_heapptr->regions[i].lastptr;
14 void *finishptr=(i+1)<NUMCORES4GC?pmc_heapptr->regions[i+1].lastptr:pmc_heapptr->regions[i].endptr;
16 if ((finishptr-startptr)>memcheck) {
17 struct pmc_region *region=&pmc_heapptr->regions[i];
18 tmc_spin_mutex_lock(®ion->lock);
19 startptr=region->lastptr;
21 //double check that we have the space
22 if ((finishptr-startptr)<memcheck)
24 unsigned int startindex=region->lowunit;
25 unsigned int endindex=pmc_heapptr->regions[i+1].highunit;
26 void * newstartptr=startptr+memcheck;
28 //update unit end points
29 for(unsigned int index=startindex;index<(endindex-1);index++) {
30 void *ptr=pmc_unitend(index);
31 if ((ptr>startptr)&&(ptr<=newstartptr)) {
32 //tprintf("Ch: %u -> %x\n", index, newstartptr);
33 pmc_heapptr->units[index].endptr=newstartptr;
39 region->lastptr=newstartptr;
41 *numbytesallocated=(unsigned int)(newstartptr-startptr);
42 tmc_spin_mutex_unlock(®ion->lock);
46 tmc_spin_mutex_unlock(®ion->lock);
49 if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
52 for(int i=0;i<NUMCORES4GC;i++) {
54 send_msg_1(i, GCSTARTPRE);
58 send_msg_1(STARTUPCORE,GCINVOKE);