Changes in / [692e6f1:64cf022]
- Files:
-
- 6 edited
-
doc/bibliography/pl.bib (modified) (2 diffs)
-
libcfa/src/bitmanip.hfa (modified) (2 diffs)
-
libcfa/src/heap.cfa (modified) (21 diffs)
-
libcfa/src/stdhdr/malloc.h (modified) (2 diffs)
-
libcfa/src/stdlib.cfa (modified) (2 diffs)
-
libcfa/src/stdlib.hfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/bibliography/pl.bib
r692e6f1 r64cf022 4566 4566 } 4567 4567 4568 @inproceedings{Fang06,4569 author = {Fang, Yi and McMillan, Kenneth L. and Pnueli, Amir and Zuck, Lenore D.},4570 editor = {Najm, Elie and Pradat-Peyre, Jean-Fran{\c{c}}ois and Donzeau-Gouge, V{\'e}ronique Vigui{\'e}},4571 title = {Liveness by Invisible Invariants},4572 booktitle = {Formal Techniques for Networked and Distributed Systems - FORTE 2006},4573 year = 2006,4574 publisher = {Springer Berlin Heidelberg},4575 address = {Berlin, Heidelberg},4576 pages = {356--371},4577 }4578 4579 4568 @article{Pierce00, 4580 4569 keywords = {Scala, polymorphism, subtyping, type inference}, … … 6667 6656 } 6668 6657 6669 @article{Aravind09,6670 author = {Alex A. Aravind and Wim H. Hesselink},6671 title = {A Queue Based Mutual Exclusion Algorithm},6672 journal = acta,6673 volume = 46,6674 pages = {73--86},6675 year = 2009,6676 }6677 6678 6658 % R 6679 6659 -
libcfa/src/bitmanip.hfa
r692e6f1 r64cf022 11 11 // Created On : Sat Mar 14 18:12:27 2020 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Thu Apr 16 18:09:34202014 // Update Count : 1 2013 // Last Modified On : Wed Apr 15 10:51:01 2020 14 // Update Count : 119 15 15 // 16 16 … … 21 21 // Bits are numbered 1-N. 22 22 23 //#include <assert.h>23 #include <assert.h> 24 24 25 25 #define __bitsizeof( n ) (sizeof(n) * __CHAR_BIT__) -
libcfa/src/heap.cfa
r692e6f1 r64cf022 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 18 08:17:53 202013 // Update Count : 71612 // Last Modified On : Wed Apr 1 15:59:53 2020 13 // Update Count : 692 14 14 // 15 15 … … 181 181 } fake; // FakeHeader 182 182 } kind; // Kind 183 size_t size; // allocation size in bytes183 uint32_t dimension; // used by calloc-like to remember number of array elements 184 184 } header; // Header 185 185 char pad[libAlign() - sizeof( Header )]; … … 265 265 static unsigned long long int free_storage; 266 266 static unsigned int free_calls; 267 static unsigned long long int aalloc_storage;268 static unsigned int aalloc_calls;269 267 static unsigned long long int calloc_storage; 270 268 static unsigned int calloc_calls; 271 269 static unsigned long long int memalign_storage; 272 270 static unsigned int memalign_calls; 273 static unsigned long long int amemalign_storage;274 static unsigned int amemalign_calls;275 271 static unsigned long long int cmemalign_storage; 276 272 static unsigned int cmemalign_calls; … … 284 280 // Use "write" because streams may be shutdown when calls are made. 285 281 static void printStats() { 286 char helpText[ 1024];282 char helpText[512]; 287 283 __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText), 288 284 "\nHeap statistics:\n" 289 285 " malloc: calls %u / storage %llu\n" 290 " aalloc: calls %u / storage %llu\n"291 286 " calloc: calls %u / storage %llu\n" 292 287 " memalign: calls %u / storage %llu\n" 293 " amemalign: calls %u / storage %llu\n"294 288 " cmemalign: calls %u / storage %llu\n" 295 289 " resize: calls %u / storage %llu\n" … … 300 294 " sbrk: calls %u / storage %llu\n", 301 295 malloc_calls, malloc_storage, 302 aalloc_calls, calloc_storage,303 296 calloc_calls, calloc_storage, 304 297 memalign_calls, memalign_storage, 305 amemalign_calls, amemalign_storage,306 298 cmemalign_calls, cmemalign_storage, 307 299 resize_calls, resize_storage, … … 315 307 316 308 static int printStatsXML( FILE * stream ) { // see malloc_info 317 char helpText[ 1024];309 char helpText[512]; 318 310 int len = snprintf( helpText, sizeof(helpText), 319 311 "<malloc version=\"1\">\n" … … 322 314 "</sizes>\n" 323 315 "<total type=\"malloc\" count=\"%u\" size=\"%llu\"/>\n" 324 "<total type=\"aalloc\" count=\"%u\" size=\"%llu\"/>\n"325 316 "<total type=\"calloc\" count=\"%u\" size=\"%llu\"/>\n" 326 317 "<total type=\"memalign\" count=\"%u\" size=\"%llu\"/>\n" 327 "<total type=\"amemalign\" count=\"%u\" size=\"%llu\"/>\n"328 318 "<total type=\"cmemalign\" count=\"%u\" size=\"%llu\"/>\n" 329 319 "<total type=\"resize\" count=\"%u\" size=\"%llu\"/>\n" … … 335 325 "</malloc>", 336 326 malloc_calls, malloc_storage, 337 aalloc_calls, aalloc_storage,338 327 calloc_calls, calloc_storage, 339 328 memalign_calls, memalign_storage, 340 amemalign_calls, amemalign_storage,341 329 cmemalign_calls, cmemalign_storage, 342 330 resize_calls, resize_storage, … … 578 566 } // if 579 567 580 block->header.size = size; // store allocation size581 568 void * addr = &(block->data); // adjust off header to user bytes 582 569 … … 747 734 //assert( heapManager.heapBegin != 0 ); 748 735 if ( unlikely( heapManager.heapBegin == 0p ) ) heapManager{}; // called before memory_startup ? 749 #if __SIZEOF_POINTER__ == 8750 verify( size < ((typeof(size_t))1 << 48) );751 #endif // __SIZEOF_POINTER__ == 8752 736 void * addr = doMalloc( size ); 753 737 if ( unlikely( addr == 0p ) ) errno = ENOMEM; // POSIX … … 756 740 757 741 758 static inline void * callocNoStats( size_t dim, size_t elemSize ) {759 size_t size = dim* elemSize;742 static inline void * callocNoStats( size_t noOfElems, size_t elemSize ) { 743 size_t size = noOfElems * elemSize; 760 744 char * addr = (char *)mallocNoStats( size ); 761 745 if ( unlikely( addr == 0p ) ) return 0p; … … 774 758 memset( addr, '\0', bsize - sizeof(HeapManager.Storage) ); // set to zeros 775 759 760 assert( noOfElems <= UINT32_MAX ); 761 header->dimension = noOfElems; // store number of array elements 776 762 header->kind.real.blockSize |= 2; // mark as zero filled 777 763 return addr; … … 815 801 816 802 817 static inline void * cmemalignNoStats( size_t alignment, size_t dim, size_t elemSize ) {818 size_t size = dim* elemSize;803 static inline void * cmemalignNoStats( size_t alignment, size_t noOfElems, size_t elemSize ) { 804 size_t size = noOfElems * elemSize; 819 805 char * addr = (char *)memalignNoStats( alignment, size ); 820 806 if ( unlikely( addr == 0p ) ) return 0p; … … 829 815 memset( addr, '\0', dataStorage( bsize, addr, header ) ); // set to zeros 830 816 817 assert( noOfElems <= UINT32_MAX ); 818 header->dimension = noOfElems; // store initial array size 831 819 header->kind.real.blockSize |= 2; // mark as zero filled 832 820 return addr; … … 855 843 } // malloc 856 844 857 858 // Allocate memory for an array of dim elements of size bytes each and returns a pointer to the allocated memory. If 859 // dim or size is 0, then calloc() returns either 0p, or a unique pointer value that can later be successfully 860 // passed to free(). 861 void * aalloc( size_t dim, size_t elemSize ) { 862 #ifdef __STATISTICS__ 863 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST ); 864 __atomic_add_fetch( &aalloc_storage, dim * elemSize, __ATOMIC_SEQ_CST ); 865 #endif // __STATISTICS__ 866 867 size_t size = dim * elemSize; 868 char * addr = (char *)mallocNoStats( size ); 869 if ( unlikely( addr == 0p ) ) return 0p; 870 871 HeapManager.Storage.Header * header; 872 HeapManager.FreeHeader * freeElem; 873 size_t bsize, alignment; 874 headers( "aalloc", addr, header, freeElem, bsize, alignment ); 875 876 header->kind.real.blockSize |= 2; // mark as zero filled 877 return addr; 878 } // aalloc 879 880 881 // Same as aalloc() with memory is set to zero. 882 void * calloc( size_t dim, size_t elemSize ) { 845 // Allocate memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated 846 // memory. The memory is set to zero. If nmemb or size is 0, then calloc() returns either 0p, or a unique pointer 847 // value that can later be successfully passed to free(). 848 void * calloc( size_t noOfElems, size_t elemSize ) { 883 849 #ifdef __STATISTICS__ 884 850 __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST ); 885 __atomic_add_fetch( &calloc_storage, dim* elemSize, __ATOMIC_SEQ_CST );886 #endif // __STATISTICS__ 887 888 return callocNoStats( dim, elemSize );851 __atomic_add_fetch( &calloc_storage, noOfElems * elemSize, __ATOMIC_SEQ_CST ); 852 #endif // __STATISTICS__ 853 854 return callocNoStats( noOfElems, elemSize ); 889 855 } // calloc 890 856 … … 908 874 size_t bsize, oalign = 0; 909 875 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 910 911 876 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 877 912 878 // same size, DO NOT preserve STICKY PROPERTIES. 913 if ( oalign == 0 && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size879 if ( oalign == 0 && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size 914 880 header->kind.real.blockSize &= -2; // no alignment and turn off 0 fill 915 881 return oaddr; … … 985 951 986 952 987 // Same as aalloc() with memory alignment.988 void * amemalign( size_t alignment, size_t dim, size_t elemSize ) {953 // Same as calloc() with memory alignment. 954 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ) { 989 955 #ifdef __STATISTICS__ 990 956 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 991 __atomic_add_fetch( &cmemalign_storage, dim * elemSize, __ATOMIC_SEQ_CST ); 992 #endif // __STATISTICS__ 993 994 size_t size = dim * elemSize; 995 char * addr = (char *)memalignNoStats( alignment, size ); 996 if ( unlikely( addr == 0p ) ) return 0p; 997 HeapManager.Storage.Header * header; 998 HeapManager.FreeHeader * freeElem; 999 size_t bsize; 1000 headers( "amemalign", addr, header, freeElem, bsize, alignment ); 1001 1002 header->kind.real.blockSize |= 2; // mark as zero filled 1003 return addr; 1004 } // amemalign 1005 1006 1007 // Same as calloc() with memory alignment. 1008 void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) { 1009 #ifdef __STATISTICS__ 1010 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1011 __atomic_add_fetch( &cmemalign_storage, dim * elemSize, __ATOMIC_SEQ_CST ); 1012 #endif // __STATISTICS__ 1013 1014 return cmemalignNoStats( alignment, dim, elemSize ); 957 __atomic_add_fetch( &cmemalign_storage, noOfElems * elemSize, __ATOMIC_SEQ_CST ); 958 #endif // __STATISTICS__ 959 960 return cmemalignNoStats( alignment, noOfElems, elemSize ); 1015 961 } // cmemalign 1016 962 … … 1069 1015 1070 1016 1071 // Returns the alignment of anallocation.1017 // Returns the alignment of the allocation. 1072 1018 size_t malloc_alignment( void * addr ) { 1073 1019 if ( unlikely( addr == 0p ) ) return libAlign(); // minimum alignment … … 1080 1026 } // malloc_alignment 1081 1027 1082 // Set the alignment for an the allocation and return previous alignment or 0 if no alignment. 1083 size_t $malloc_alignment_set( void * addr, size_t alignment ) { 1084 if ( unlikely( addr == 0p ) ) return libAlign(); // minimum alignment 1085 size_t ret; 1086 HeapManager.Storage.Header * header = headerAddr( addr ); 1087 if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ? 1088 ret = header->kind.fake.alignment & -2; // remove flag from old value 1089 header->kind.fake.alignment = alignment | 1; // add flag to new value 1090 } else { 1091 ret = 0; // => no alignment to change 1092 } // if 1093 return ret; 1094 } // $malloc_alignment_set 1095 1096 1097 // Returns true if the allocation is zero filled, e.g., allocated by calloc(). 1028 1029 // Returns true if the allocation is zero filled, i.e., initially allocated by calloc(). 1098 1030 bool malloc_zero_fill( void * addr ) { 1099 1031 if ( unlikely( addr == 0p ) ) return false; // null allocation is not zero fill … … 1102 1034 header = realHeader( header ); // backup from fake to real header 1103 1035 } // if 1104 return (header->kind.real.blockSize & 2) != 0; // zero filled ?1036 return (header->kind.real.blockSize & 2) != 0; // zero filled (calloc/cmemalign) ? 1105 1037 } // malloc_zero_fill 1106 1038 1107 // Set allocation is zero filled and return previous zero filled. 1108 bool $malloc_zero_fill_set( void * addr ) { 1039 1040 // Returns number of elements if the allocation is for an array, i.e., by calloc(). 1041 size_t malloc_dimension( void * addr ) { 1109 1042 if ( unlikely( addr == 0p ) ) return false; // null allocation is not zero fill 1110 1043 HeapManager.Storage.Header * header = headerAddr( addr ); … … 1112 1045 header = realHeader( header ); // backup from fake to real header 1113 1046 } // if 1114 bool ret = (header->kind.real.blockSize & 2) != 0; // zero filled ? 1115 header->kind.real.blockSize |= 2; // mark as zero filled 1116 return ret; 1117 } // $malloc_zero_fill_set 1118 1119 1120 // Returns original total allocation size (not bucket size) => array size is dimension * sizeif(T). 1121 size_t malloc_size( void * addr ) { 1122 if ( unlikely( addr == 0p ) ) return false; // null allocation is not zero fill 1123 HeapManager.Storage.Header * header = headerAddr( addr ); 1124 if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ? 1125 header = realHeader( header ); // backup from fake to real header 1126 } // if 1127 return header->size; 1128 } // malloc_size 1129 1130 // Set allocation size and return previous size. 1131 size_t $malloc_size_set( void * addr, size_t size ) { 1132 if ( unlikely( addr == 0p ) ) return false; // null allocation is not zero fill 1133 HeapManager.Storage.Header * header = headerAddr( addr ); 1134 if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ? 1135 header = realHeader( header ); // backup from fake to real header 1136 } // if 1137 size_t ret = header->size; 1138 header->size = size; 1139 return ret; 1140 } // $malloc_size_set 1047 return header->dimension; // array (calloc/cmemalign) 1048 } // malloc_zero_fill 1141 1049 1142 1050 -
libcfa/src/stdhdr/malloc.h
r692e6f1 r64cf022 10 10 // Created On : Thu Jul 20 15:58:16 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 16 22:44:06202013 // Update Count : 1 312 // Last Modified On : Sun Mar 8 10:01:20 2020 13 // Update Count : 11 14 14 // 15 15 … … 31 31 32 32 extern "C" { 33 void * aalloc( size_t noOfElems, size_t elemSize );34 void * amemalign( size_t alignment, size_t noOfElems, size_t elemSize );35 33 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); 36 34 size_t malloc_alignment( void * ); 37 35 bool malloc_zero_fill( void * ); 38 size_t malloc_ size( void * );36 size_t malloc_dimension( void * ); 39 37 int malloc_stats_fd( int fd ); 40 38 } // extern "C" -
libcfa/src/stdlib.cfa
r692e6f1 r64cf022 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Apr 16 22:43:33202013 // Update Count : 49 812 // Last Modified On : Tue Mar 31 13:26:46 2020 13 // Update Count : 495 14 14 // 15 15 … … 37 37 } // alloc_set 38 38 39 T * alloc_set( T ptr[], size_t dim, T fill ) { // realloc array with fill39 T * alloc_set( T ptr[], size_t dim, T fill ) { // realloc array with fill 40 40 size_t olen = malloc_usable_size( ptr ); // current allocation 41 41 void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc 42 42 size_t nlen = malloc_usable_size( nptr ); // new allocation 43 43 if ( nlen > olen ) { // larger ? 44 for ( i; malloc_size( ptr ) / sizeof(T) ~ dim ) { 45 memcpy( &ptr[i], &fill, sizeof(T) ); // initialize with fill value 46 } // for 44 for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value 47 45 } // if 48 46 return (T *)nptr; -
libcfa/src/stdlib.hfa
r692e6f1 r64cf022 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 16 22:44:05202013 // Update Count : 4 3212 // Last Modified On : Wed Apr 1 18:38:41 2020 13 // Update Count : 429 14 14 // 15 15 … … 25 25 void * memalign( size_t align, size_t size ); // malloc.h 26 26 size_t malloc_usable_size( void * ptr ); // malloc.h 27 size_t malloc_size( void * addr ); // CFA heap28 27 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA heap 29 28 void * memset( void * dest, int fill, size_t size ); // string.h
Note:
See TracChangeset
for help on using the changeset viewer.