Changeset a5da6a3
- Timestamp:
- Aug 1, 2018, 12:02:00 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- e614d73, fde66c2
- Parents:
- 5f08ac2f (diff), 5d4fa18 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
r5f08ac2f ra5da6a3 203 203 The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from hobby projects to commercial operating-systems. 204 204 This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more. 205 Nevertheless, C, first standardized almost forty years ago, lacks many features that make programming in more modern languages safer and more productive.205 Nevertheless, C, first standardized almost thirty years ago, lacks many features that make programming in more modern languages safer and more productive. 206 206 207 207 The goal of the \CFA project (pronounced ``C-for-all'') is to create an extension of C that provides modern safety and productivity features while still ensuring strong backwards compatibility with C and its programmers. -
doc/user/user.tex
r5f08ac2f ra5da6a3 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon Jul 9 10:49:52201814 %% Update Count : 336 113 %% Last Modified On : Thu Jul 26 17:29:05 2018 14 %% Update Count : 3366 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 5967 5967 void * memalign( size_t align, size_t size );§\indexc{memalign}§ 5968 5968 int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§ 5969 }5970 5971 // §\CFA§ safe equivalents, i.e., implicit size specification5972 forall( dtype T | sized(T) ) T * malloc( void );5973 forall( dtype T | sized(T) ) T * calloc( size_t dim );5974 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );5975 forall( dtype T | sized(T) ) T * memalign( size_t align );5976 forall( dtype T | sized(T) ) T * aligned_alloc( size_t align );5977 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align );5978 5979 // §\CFA§ safe general allocation, fill, resize, array5980 forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§5981 forall( dtype T | sized(T) ) T * alloc( char fill );5982 forall( dtype T | sized(T) ) T * alloc( size_t dim );5983 forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill );5984 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim );5985 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );5986 5987 // §\CFA§ safe general allocation, align, fill, array5988 forall( dtype T | sized(T) ) T * align_alloc( size_t align );5989 forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill );5990 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim );5991 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill );5992 5969 5993 5970 // C unsafe initialization/copy 5994 extern "C" {5995 5971 void * memset( void * dest, int c, size_t size ); 5996 5972 void * memcpy( void * dest, const void * src, size_t size ); 5997 5973 } 5998 5974 5975 forall( dtype T | sized(T) ) { 5976 // §\CFA§ safe equivalents, i.e., implicit size specification 5977 T * malloc( void ); 5978 T * calloc( size_t dim ); 5979 T * realloc( T * ptr, size_t size ); 5980 T * memalign( size_t align ); 5981 T * aligned_alloc( size_t align ); 5982 int posix_memalign( T ** ptr, size_t align ); 5983 5984 // §\CFA§ safe general allocation, fill, resize, array 5985 T * alloc( void );§\indexc{alloc}§ 5986 T * alloc( char fill ); 5987 T * alloc( size_t dim ); 5988 T * alloc( size_t dim, char fill ); 5989 T * alloc( T ptr[], size_t dim ); 5990 T * alloc( T ptr[], size_t dim, char fill ); 5991 5992 // §\CFA§ safe general allocation, align, fill, array 5993 T * align_alloc( size_t align ); 5994 T * align_alloc( size_t align, char fill ); 5995 T * align_alloc( size_t align, size_t dim ); 5996 T * align_alloc( size_t align, size_t dim, char fill ); 5997 5999 5998 // §\CFA§ safe initialization/copy, i.e., implicit size specification 6000 forall( dtype T | sized(T) )T * memset( T * dest, char c );§\indexc{memset}§6001 forall( dtype T | sized(T) )T * memcpy( T * dest, const T * src );§\indexc{memcpy}§5999 T * memset( T * dest, char c );§\indexc{memset}§ 6000 T * memcpy( T * dest, const T * src );§\indexc{memcpy}§ 6002 6001 6003 6002 // §\CFA§ safe initialization/copy array 6004 forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ); 6005 forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ); 6003 T * amemset( T dest[], char c, size_t dim ); 6004 T * amemcpy( T dest[], const T src[], size_t dim ); 6005 } 6006 6006 6007 6007 // §\CFA§ allocation/deallocation and constructor/destructor … … 6063 6063 forall( otype T | { int ?<?( T, T ); } ) 6064 6064 void qsort( const T * arr, size_t dim );§\indexc{qsort}§ 6065 6066 forall( otype E | { int ?<?( E, E ); } ) { 6067 E * bsearch( E key, const E * vals, size_t dim );§\indexc{bsearch}§ §\C{// location}§ 6068 size_t bsearch( E key, const E * vals, size_t dim );§\C{// position}§ 6069 E * bsearchl( E key, const E * vals, size_t dim );§\indexc{bsearchl}§ 6070 size_t bsearchl( E key, const E * vals, size_t dim ); 6071 E * bsearchu( E key, const E * vals, size_t dim );§\indexc{bsearchu}§ 6072 size_t bsearchu( E key, const E * vals, size_t dim ); 6073 } 6074 6075 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) { 6076 E * bsearch( K key, const E * vals, size_t dim ); 6077 size_t bsearch( K key, const E * vals, size_t dim ); 6078 E * bsearchl( K key, const E * vals, size_t dim ); 6079 size_t bsearchl( K key, const E * vals, size_t dim ); 6080 E * bsearchu( K key, const E * vals, size_t dim ); 6081 size_t bsearchu( K key, const E * vals, size_t dim ); 6082 } 6083 6084 forall( otype E | { int ?<?( E, E ); } ) { 6085 void qsort( E * vals, size_t dim );§\indexc{qsort}§ 6086 } 6065 6087 \end{cfa} 6066 6088 -
src/libcfa/heap.c
r5f08ac2f ra5da6a3 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jul 26 22:28:23201813 // Update Count : 4 4912 // Last Modified On : Tue Jul 31 18:08:50 2018 13 // Update Count : 470 14 14 // 15 15 … … 94 94 95 95 96 // static _Bool prtHeapTerm = false; 97 98 // inline _Bool prtHeapTerm() { 99 // return prtHeapTerm; 100 // } // prtHeapTerm 101 102 // _Bool prtHeapTermOn() { 103 // _Bool temp = traceHeap; 104 // traceHeap = true; 96 static _Bool checkFree = false; 97 98 inline _Bool checkFree() { 99 return checkFree; 100 } // checkFree 101 102 _Bool checkFreeOn() { 103 _Bool temp = checkFree; 104 checkFree = true; 105 return temp; 106 } // checkFreeOn 107 108 _Bool checkFreeOff() { 109 _Bool temp = checkFree; 110 checkFree = false; 111 return temp; 112 } // checkFreeOff 113 114 115 // static _Bool traceHeapTerm = false; 116 117 // inline _Bool traceHeapTerm() { 118 // return traceHeapTerm; 119 // } // traceHeapTerm 120 121 // _Bool traceHeapTermOn() { 122 // _Bool temp = traceHeapTerm; 123 // traceHeapTerm = true; 105 124 // return temp; 106 // } // prtHeapTermOn107 108 // _Bool prtHeapTermOff() {109 // _Bool temp = traceHeap ;110 // traceHeap = false;125 // } // traceHeapTermOn 126 127 // _Bool traceHeapTermOff() { 128 // _Bool temp = traceHeapTerm; 129 // traceHeapTerm = false; 111 130 // return temp; 112 // } // prtHeapTermOff131 // } // traceHeapTermOff 113 132 114 133 … … 139 158 } // extern "C" 140 159 #endif // __CFA_DEBUG__ 141 142 143 // statically allocated variables => zero filled.144 145 static size_t pageSize; // architecture pagesize146 static size_t heapExpand; // sbrk advance147 static size_t mmapStart; // cross over point for mmap148 static unsigned int maxBucketsUsed; // maximum number of buckets in use149 static unsigned int bucketSizes[NoBucketSizes] = { // different bucket sizes150 16, 32, 48, 64,151 80, 96, 112, 128, 144, 160, 192, 224,152 256, 320, 384, 448, 512, 640, 768, 896,153 1024, 1536, 2048, 2560, 3072, 3584, 4096, 6144,154 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360,155 16384, 18432, 20480, 22528, 24576, 26624, 28672, 30720,156 32768, 36864, 40960, 45056, 49152, 53248, 57344, 61440,157 65536, 73728, 81920, 90112, 98304, 106496, 114688, 122880,158 131072, 147456, 163840, 180224, 196608, 212992, 229376, 245760,159 262144, 294912, 327680, 360448, 393216, 425984, 458752, 491520,160 524288, 655360, 786432, 917504, 1048576, 1179648, 1310720, 1441792,161 1572864, 1703936, 1835008, 1966080, 2097152, 2621440, 3145728, 3670016,162 4194304163 };164 #ifdef FASTLOOKUP165 static unsigned char lookup[LookupSizes]; // O(1) lookup for small sizes166 #endif // FASTLOOKUP167 static int mmapFd = -1; // fake or actual fd for anonymous file168 160 169 161 … … 240 232 }; // HeapManager 241 233 234 static inline size_t getKey( const HeapManager.FreeHeader & freeheader ) { return freeheader.blockSize; } 235 // statically allocated variables => zero filled. 236 237 238 static size_t pageSize; // architecture pagesize 239 static size_t heapExpand; // sbrk advance 240 static size_t mmapStart; // cross over point for mmap 241 static unsigned int maxBucketsUsed; // maximum number of buckets in use 242 243 // Powers of 2 are common allocation sizes, so make powers of 2 generate the minimum required size. 244 static unsigned int bucketSizes[NoBucketSizes] @= { // different bucket sizes 245 16, 32, 48, 64, 246 64 + sizeof(HeapManager.Storage), 96, 112, 128, 128 + sizeof(HeapManager.Storage), 160, 192, 224, 247 256 + sizeof(HeapManager.Storage), 320, 384, 448, 512 + sizeof(HeapManager.Storage), 640, 768, 896, 248 1_024 + sizeof(HeapManager.Storage), 1_536, 2_048 + sizeof(HeapManager.Storage), 2_560, 3_072, 3_584, 4_096 + sizeof(HeapManager.Storage), 6_144, 249 8_192 + sizeof(HeapManager.Storage), 9_216, 10_240, 11_264, 12_288, 13_312, 14_336, 15_360, 250 16_384 + sizeof(HeapManager.Storage), 18_432, 20_480, 22_528, 24_576, 26_624, 28_672, 30_720, 251 32_768 + sizeof(HeapManager.Storage), 36_864, 40_960, 45_056, 49_152, 53_248, 57_344, 61_440, 252 65_536 + sizeof(HeapManager.Storage), 73_728, 81_920, 90_112, 98_304, 106_496, 114_688, 122_880, 253 131_072 + sizeof(HeapManager.Storage), 147_456, 163_840, 180_224, 196_608, 212_992, 229_376, 245_760, 254 262_144 + sizeof(HeapManager.Storage), 294_912, 327_680, 360_448, 393_216, 425_984, 458_752, 491_520, 255 524_288 + sizeof(HeapManager.Storage), 655_360, 786_432, 917_504, 1_048_576 + sizeof(HeapManager.Storage), 1_179_648, 1_310_720, 1_441_792, 256 1_572_864, 1_703_936, 1_835_008, 1_966_080, 2_097_152 + sizeof(HeapManager.Storage), 2_621_440, 3_145_728, 3_670_016, 257 4_194_304 + sizeof(HeapManager.Storage) 258 }; 259 #ifdef FASTLOOKUP 260 static unsigned char lookup[LookupSizes]; // O(1) lookup for small sizes 261 #endif // FASTLOOKUP 262 static int mmapFd = -1; // fake or actual fd for anonymous file 263 264 265 #ifdef __CFA_DEBUG__ 266 static _Bool heapBoot = 0; // detect recursion during boot 267 #endif // __CFA_DEBUG__ 268 static HeapManager heapManager __attribute__(( aligned (128) )) @= {}; // size of cache line to prevent false sharing 269 242 270 243 271 static inline _Bool setMmapStart( size_t value ) { … … 281 309 static void ^?{}( HeapManager & ) { 282 310 #ifdef __STATISTICS__ 283 // if ( prtHeapTerm() ) {311 // if ( traceHeapTerm() ) { 284 312 // printStats(); 285 // checkFree( heapManager, true );313 // if ( checkfree() ) checkFree( heapManager, true ); 286 314 // } // if 287 315 #endif // __STATISTICS__ 288 316 } // ~HeapManager 289 317 290 291 #ifdef __CFA_DEBUG__292 static _Bool heapBoot = 0; // detect recursion during boot293 #endif // __CFA_DEBUG__294 static HeapManager heapManager __attribute__(( aligned (128) )) @= {}; // size of cache line to prevent false sharing295 318 296 319 static void memory_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_MEMORY ) )); … … 312 335 ^heapManager{}; 313 336 } // memory_shutdown 314 315 static inline size_t getKey( const HeapManager.FreeHeader & freeheader ) { return freeheader.blockSize; }316 337 317 338 … … 342 363 static void printStats() { 343 364 char helpText[512]; 344 int len = snprintf( helpText, 512,345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 365 __cfaabi_dbg_bits_print_buffer( helpText, 512, 366 "\nHeap statistics:\n" 367 " malloc: calls %u / storage %llu\n" 368 " calloc: calls %u / storage %llu\n" 369 " memalign: calls %u / storage %llu\n" 370 " cmemalign: calls %u / storage %llu\n" 371 " realloc: calls %u / storage %llu\n" 372 " free: calls %u / storage %llu\n" 373 " mmap: calls %u / storage %llu\n" 374 " munmap: calls %u / storage %llu\n" 375 " sbrk: calls %u / storage %llu\n", 376 malloc_calls, malloc_storage, 377 calloc_calls, calloc_storage, 378 memalign_calls, memalign_storage, 379 cmemalign_calls, cmemalign_storage, 380 realloc_calls, realloc_storage, 381 free_calls, free_storage, 382 mmap_calls, mmap_storage, 383 munmap_calls, munmap_storage, 384 sbrk_calls, sbrk_storage 364 385 ); 365 write( statfd, helpText, len );366 386 } // printStats 367 387 … … 637 657 638 658 639 size_t checkFree( HeapManager & manager , _Bool prt) with ( manager ) {659 size_t checkFree( HeapManager & manager ) with ( manager ) { 640 660 size_t total = 0; 641 661 #ifdef __STATISTICS__ 642 662 __cfaabi_dbg_bits_acquire(); 643 if ( prt )__cfaabi_dbg_bits_print_nolock( "\nBin lists (bin size : free blocks on list)\n" );663 __cfaabi_dbg_bits_print_nolock( "\nBin lists (bin size : free blocks on list)\n" ); 644 664 #endif // __STATISTICS__ 645 665 for ( unsigned int i = 0; i < maxBucketsUsed; i += 1 ) { … … 659 679 } // for 660 680 #ifdef __STATISTICS__ 661 if ( prt )__cfaabi_dbg_bits_print_nolock( "%7zu, %-7u ", size, N );681 __cfaabi_dbg_bits_print_nolock( "%7zu, %-7u ", size, N ); 662 682 if ( (i + 1) % 8 == 0 ) __cfaabi_dbg_bits_print_nolock( "\n" ); 663 683 #endif // __STATISTICS__ 664 684 } // for 665 685 #ifdef __STATISTICS__ 666 if ( prt )__cfaabi_dbg_bits_print_nolock( "\ntotal free blocks:%zu\n", total );686 __cfaabi_dbg_bits_print_nolock( "\ntotal free blocks:%zu\n", total ); 667 687 __cfaabi_dbg_bits_release(); 668 688 #endif // __STATISTICS__ … … 922 942 #ifdef __STATISTICS__ 923 943 printStats(); 924 checkFree( heapManager, true);944 if ( checkFree() ) checkFree( heapManager ); 925 945 #endif // __STATISTICS__ 926 946 } // malloc_stats -
src/libcfa/stdhdr/malloc.h
r5f08ac2f ra5da6a3 10 10 // Created On : Thu Jul 20 15:58:16 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 23 18:20:32201813 // Update Count : 812 // Last Modified On : Tue Jul 31 10:01:10 2018 13 // Update Count : 9 14 14 // 15 15 … … 17 17 size_t default_mmap_start(); // CFA extras 18 18 size_t default_heap_expansion(); 19 20 _Bool traceHeap(); 21 _Bool traceHeapOn(); 22 _Bool traceHeapOff(); 23 24 _Bool traceHeapTerm(); 25 _Bool traceHeapTermOn(); 26 _Bool traceHeapTermOff(); 27 28 _Bool checkFree(); 29 _Bool checkFreeOn(); 30 _Bool checkFreeOff(); 31 19 32 extern "C" { 20 33 size_t malloc_alignment( void * );
Note: See TracChangeset
for help on using the changeset viewer.