Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
diff vmalloc.c @ 141:79bb48d7d93b
changed free back to request to master and bugfixes
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 21 Sep 2011 11:51:29 +0200 |
| parents | 2c8f3cf6c058 |
| children | 98fc8f3761a2 |
line diff
1.1 --- a/vmalloc.c Mon Sep 19 18:43:08 2011 +0200 1.2 +++ b/vmalloc.c Wed Sep 21 11:51:29 2011 +0200 1.3 @@ -14,18 +14,25 @@ 1.4 #include <string.h> 1.5 #include <math.h> 1.6 1.7 +#define NDEBUG 1.8 +#include <assert.h> 1.9 + 1.10 #include "VMS.h" 1.11 #include "vmalloc.h" 1.12 #include "Histogram/Histogram.h" 1.13 1.14 #define MAX_UINT64 0xFFFFFFFFFFFFFFFF 1.15 1.16 + 1.17 + 1.18 inline void 1.19 sendFreeReqst_lib(int receiverID, void *ptrToFree, VirtProcr *animPr); 1.20 1.21 inline void 1.22 sendFreeReqst_master(int receiverID, void *ptrToFree); 1.23 1.24 +void VMS__check_free_list(MallocArrays *freeLists); 1.25 + 1.26 //A MallocProlog is a head element if the HigherInMem variable is NULL 1.27 //A Chunk is free if the prevChunkInFreeList variable is NULL 1.28 1.29 @@ -54,14 +61,21 @@ 1.30 removedChunk->nextChunkInFreeList->prevChunkInFreeList = 1.31 (MallocProlog*)container; 1.32 1.33 + assert((freeLists->bigChunksSearchVector[0] & ((uint64)1 << containerIdx)) != 0); 1.34 + 1.35 if(*container == NULL) 1.36 { 1.37 if(containerIdx < 64) 1.38 + { 1.39 + assert((freeLists->bigChunksSearchVector[0] & ((uint64)1 << containerIdx)) != 0); 1.40 freeLists->bigChunksSearchVector[0] &= ~((uint64)1 << containerIdx); 1.41 + } 1.42 else 1.43 + { 1.44 + assert((freeLists->bigChunksSearchVector[1] & ((uint64)1 << (containerIdx-64))) != 0); 1.45 freeLists->bigChunksSearchVector[1] &= ~((uint64)1 << (containerIdx-64)); 1.46 + } 1.47 } 1.48 - 1.49 return removedChunk; 1.50 } 1.51 1.52 @@ -103,14 +117,21 @@ 1.53 1.54 //The last element in the list points to the container. If the container points 1.55 //to NULL the container is empty 1.56 - if(*((void**)(chunk->prevChunkInFreeList)) == NULL && getChunkSize(chunk) >= BIG_LOWER_BOUND); 1.57 + if(((*((void**)(chunk->prevChunkInFreeList))) == NULL) && (getChunkSize(chunk) >= BIG_LOWER_BOUND)) 1.58 { 1.59 + assert((*((void**)(chunk->prevChunkInFreeList))) == NULL); 1.60 //Find the approppiate container because we do not know it 1.61 uint64 containerIdx = ((uintptr_t)chunk->prevChunkInFreeList - (uintptr_t)freeLists->bigChunks) >> 3; 1.62 if(containerIdx < (uint64)64) 1.63 + { 1.64 + assert((freeLists->bigChunksSearchVector[0] & ((uint64)1 << containerIdx)) != 0); 1.65 freeLists->bigChunksSearchVector[0] &= ~((uint64)1 << containerIdx); 1.66 + } 1.67 if(containerIdx < 128 && containerIdx >=64) 1.68 + { 1.69 + assert((freeLists->bigChunksSearchVector[1] & ((uint64)1 << (containerIdx-64))) != 0); 1.70 freeLists->bigChunksSearchVector[1] &= ~((uint64)1 << (containerIdx-64)); 1.71 + } 1.72 1.73 } 1.74 } 1.75 @@ -183,7 +204,7 @@ 1.76 } 1.77 containerIdx += 64; 1.78 } 1.79 - containerIdx--; 1.80 + containerIdx--; // ffsl index starts at 1 1.81 1.82 1.83 foundChunk = removeChunk(freeLists, containerIdx); 1.84 @@ -199,6 +220,8 @@ 1.85 freeLists->bigChunksSearchVector[0] |= ((uint64)1 << containerIdx); 1.86 else 1.87 freeLists->bigChunksSearchVector[1] |= ((uint64)1 << (containerIdx-64)); 1.88 + assert(freeLists->bigChunks[containerIdx] == foundChunk); 1.89 + assert((freeLists->bigChunksSearchVector[0] & ((uint64)1 << containerIdx)) != 0); 1.90 foundChunk = newChunk; 1.91 } 1.92 1.93 @@ -280,6 +303,7 @@ 1.94 addIntervalToHist( startStamp, endStamp, _VMSMasterEnv->mallocTimeHist ); 1.95 #endif 1.96 //======================================================================== 1.97 + assert(getChunkSize((MallocProlog*)returnChunk)>=sizeRequested); 1.98 1.99 //skip over the prolog by adding its size to the pointer return 1.100 return returnChunk + 1; 1.101 @@ -334,8 +358,8 @@ 1.102 InterVMSCoreReqst *freeReqst = VMS__malloc(sizeof(InterVMSCoreReqst)); 1.103 freeReqst->freePtr = ptrToFree; 1.104 freeReqst->secondReqType = transfer_free_ptr; 1.105 - 1.106 - sendInterMasterReqst(receiverID, (InterMasterReqst*)freeReqst); 1.107 + 1.108 + VMS__sendInterMasterReqst(receiverID, (InterMasterReqst*)freeReqst); 1.109 } 1.110 1.111 /* 1.112 @@ -357,6 +381,18 @@ 1.113 VMS__send_VMSSem_request( (void*)&reqData, animPr ); 1.114 } 1.115 1.116 +void VMS__check_free_list(MallocArrays *freeLists) 1.117 +{ 1.118 + int idx; 1.119 + for(idx=0; idx< freeLists->containerCount; idx++) 1.120 + { 1.121 + if(freeLists->bigChunks[idx]) 1.122 + assert((freeLists->bigChunksSearchVector[0] & ((uint64)1 << idx)) != 0); 1.123 + if((freeLists->bigChunksSearchVector[0] & ((uint64)1 << idx))) 1.124 + assert(freeLists->bigChunks[idx] != NULL); 1.125 + } 1.126 +} 1.127 + 1.128 /* 1.129 * This is sequential code, meant to only be called from the Master, not from 1.130 * any slave VPs. 1.131 @@ -411,7 +447,8 @@ 1.132 freeLists->bigChunksSearchVector[0] |= (uint64)1 << containerIdx; 1.133 else 1.134 freeLists->bigChunksSearchVector[1] |= (uint64)1 << (containerIdx-64); 1.135 - } 1.136 + assert((freeLists->bigChunksSearchVector[0] & (uint64)1 << containerIdx) != 0); 1.137 + } 1.138 1.139 //============================= MEASUREMENT STUFF ======================== 1.140 #ifdef MEAS__TIME_MALLOC 1.141 @@ -457,7 +494,7 @@ 1.142 1.143 firstChunk->nextLowerInMem = NULL; 1.144 firstChunk->nextHigherInMem = (MallocProlog*)((uintptr_t)firstChunk + 1.145 - MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE - sizeof(MallocProlog*)); 1.146 + MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE - sizeof(MallocProlog)); 1.147 firstChunk->nextChunkInFreeList = NULL; 1.148 //previous element in the queue is the container 1.149 firstChunk->prevChunkInFreeList = (MallocProlog*)&freeLists->bigChunks[container-2]; 1.150 @@ -465,9 +502,15 @@ 1.151 freeLists->bigChunks[container-2] = firstChunk; 1.152 //Insert into bit search list 1.153 if(container <= 65) 1.154 + { 1.155 freeLists->bigChunksSearchVector[0] = ((uint64)1 << (container-2)); 1.156 + freeLists->bigChunksSearchVector[1] = 0; 1.157 + } 1.158 else 1.159 + { 1.160 + freeLists->bigChunksSearchVector[0] = 0; 1.161 freeLists->bigChunksSearchVector[1] = ((uint64)1 << (container-66)); 1.162 + } 1.163 1.164 //Create dummy chunk to mark the top of stack this is of course 1.165 //never freed
