Changeset 578ec01c
- Timestamp:
- Jan 4, 2022, 1:36:04 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 6111f1f
- Parents:
- 15b05c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/heap.cfa
r15b05c8 r578ec01c 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 9 19:03:02 202113 // Update Count : 10 4012 // Last Modified On : Sun Jan 2 23:29:41 2022 13 // Update Count : 1058 14 14 // 15 15 … … 263 263 #ifdef __STATISTICS__ 264 264 // Heap statistics counters. 265 static unsigned int malloc_ zero_calls, malloc_calls;266 static unsigned long long int malloc_storage ;267 static unsigned int aalloc_ zero_calls, aalloc_calls;268 static unsigned long long int aalloc_storage ;269 static unsigned int calloc_ zero_calls, calloc_calls;270 static unsigned long long int calloc_storage ;271 static unsigned int memalign_ zero_calls, memalign_calls;272 static unsigned long long int memalign_storage ;273 static unsigned int amemalign_ zero_calls, amemalign_calls;274 static unsigned long long int amemalign_storage ;275 static unsigned int cmemalign_ zero_calls, cmemalign_calls;276 static unsigned long long int cmemalign_storage ;277 static unsigned int resize_ zero_calls, resize_calls;278 static unsigned long long int resize_storage ;279 static unsigned int realloc_ zero_calls, realloc_calls;280 static unsigned long long int realloc_storage ;281 static unsigned int free_ zero_calls, free_calls;282 static unsigned long long int free_storage ;265 static unsigned int malloc_calls, malloc_0_calls; 266 static unsigned long long int malloc_storage_request, malloc_storage_alloc; 267 static unsigned int aalloc_calls, aalloc_0_calls; 268 static unsigned long long int aalloc_storage_request, aalloc_storage_alloc; 269 static unsigned int calloc_calls, calloc_0_calls; 270 static unsigned long long int calloc_storage_request, calloc_storage_alloc; 271 static unsigned int memalign_calls, memalign_0_calls; 272 static unsigned long long int memalign_storage_request, memalign_storage_alloc; 273 static unsigned int amemalign_calls, amemalign_0_calls; 274 static unsigned long long int amemalign_storage_request, amemalign_storage_alloc; 275 static unsigned int cmemalign_calls, cmemalign_0_calls; 276 static unsigned long long int cmemalign_storage_request, cmemalign_storage_alloc; 277 static unsigned int resize_calls, resize_0_calls; 278 static unsigned long long int resize_storage_request, resize_storage_alloc; 279 static unsigned int realloc_calls, realloc_0_calls; 280 static unsigned long long int realloc_storage_request, realloc_storage_alloc; 281 static unsigned int free_calls, free_null_calls; 282 static unsigned long long int free_storage_request, free_storage_alloc; 283 283 static unsigned int mmap_calls; 284 static unsigned long long int mmap_storage ;284 static unsigned long long int mmap_storage_request, mmap_storage_alloc; 285 285 static unsigned int munmap_calls; 286 static unsigned long long int munmap_storage ;286 static unsigned long long int munmap_storage_request, munmap_storage_alloc; 287 287 static unsigned int sbrk_calls; 288 288 static unsigned long long int sbrk_storage; … … 294 294 char helpText[1024]; 295 295 __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText), 296 "\nHeap statistics: \n"297 " malloc 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"298 " aalloc 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"299 " calloc 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"300 " memalign 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"301 " amemalign 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"302 " cmemalign 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"303 " resize 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"304 " realloc 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"305 " free 0-calls %'u; >0-calls %'u; storage%'llu bytes\n"306 " mmapcalls %'u; storage %'llu bytes\n"307 " m unmap calls %'u; storage%'llu bytes\n"308 " sbrk calls %'u; storage%'llu bytes\n",309 malloc_ zero_calls, malloc_calls, malloc_storage,310 aalloc_ zero_calls, aalloc_calls, aalloc_storage,311 calloc_ zero_calls, calloc_calls, calloc_storage,312 memalign_ zero_calls, memalign_calls, memalign_storage,313 amemalign_ zero_calls, amemalign_calls, amemalign_storage,314 cmemalign_ zero_calls, cmemalign_calls, cmemalign_storage,315 resize_ zero_calls, resize_calls, resize_storage,316 realloc_ zero_calls, realloc_calls, realloc_storage,317 free_ zero_calls, free_calls, free_storage,318 mmap_calls, mmap_storage,319 m unmap_calls, munmap_storage,320 sbrk_calls, sbrk_storage296 "\nHeap statistics: (storage request / allocation + header)\n" 297 " malloc >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 298 " aalloc >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 299 " calloc >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 300 " memalign >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 301 " amemalign >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 302 " cmemalign >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 303 " resize >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 304 " realloc >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n" 305 " free !null calls %'u; null calls %'u; storage %'llu / %'llu bytes\n" 306 " sbrk calls %'u; storage %'llu bytes\n" 307 " mmap calls %'u; storage %'llu / %'llu bytes\n" 308 " munmap calls %'u; storage %'llu / %'llu bytes\n", 309 malloc_calls, malloc_0_calls, malloc_storage_request, malloc_storage_alloc, 310 aalloc_calls, aalloc_0_calls, aalloc_storage_request, aalloc_storage_alloc, 311 calloc_calls, calloc_0_calls, calloc_storage_request, calloc_storage_alloc, 312 memalign_calls, memalign_0_calls, memalign_storage_request, memalign_storage_alloc, 313 amemalign_calls, amemalign_0_calls, amemalign_storage_request, amemalign_storage_alloc, 314 cmemalign_calls, cmemalign_0_calls, cmemalign_storage_request, cmemalign_storage_alloc, 315 resize_calls, resize_0_calls, resize_storage_request, resize_storage_alloc, 316 realloc_calls, realloc_0_calls, realloc_storage_request, realloc_storage_alloc, 317 free_calls, free_null_calls, free_storage_request, free_storage_alloc, 318 sbrk_calls, sbrk_storage, 319 mmap_calls, mmap_storage_request, mmap_storage_alloc, 320 munmap_calls, munmap_storage_request, munmap_storage_alloc 321 321 ); 322 322 } // printStats … … 329 329 "<sizes>\n" 330 330 "</sizes>\n" 331 "<total type=\"malloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 332 "<total type=\"aalloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 333 "<total type=\"calloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 334 "<total type=\"memalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 335 "<total type=\"amemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 336 "<total type=\"cmemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 337 "<total type=\"resize\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 338 "<total type=\"realloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 339 "<total type=\"free\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 340 "<total type=\"mmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n" 341 "<total type=\"munmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n" 331 "<total type=\"malloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 332 "<total type=\"aalloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 333 "<total type=\"calloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 334 "<total type=\"memalign\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 335 "<total type=\"amemalign\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 336 "<total type=\"cmemalign\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 337 "<total type=\"resize\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 338 "<total type=\"realloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 339 "<total type=\"free\" !null=\"%'u;\" 0 null=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 342 340 "<total type=\"sbrk\" count=\"%'u;\" size=\"%'llu\"/> bytes\n" 341 "<total type=\"mmap\" count=\"%'u;\" size=\"%'llu / %'llu\" / > bytes\n" 342 "<total type=\"munmap\" count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n" 343 343 "</malloc>", 344 malloc_ zero_calls, malloc_calls, malloc_storage,345 aalloc_ zero_calls, aalloc_calls, aalloc_storage,346 calloc_ zero_calls, calloc_calls, calloc_storage,347 memalign_ zero_calls, memalign_calls, memalign_storage,348 amemalign_ zero_calls, amemalign_calls, amemalign_storage,349 cmemalign_ zero_calls, cmemalign_calls, cmemalign_storage,350 resize_ zero_calls, resize_calls, resize_storage,351 realloc_ zero_calls, realloc_calls, realloc_storage,352 free_ zero_calls, free_calls, free_storage,353 mmap_calls, mmap_storage,354 m unmap_calls, munmap_storage,355 sbrk_calls, sbrk_storage344 malloc_calls, malloc_0_calls, malloc_storage_request, malloc_storage_alloc, 345 aalloc_calls, aalloc_0_calls, aalloc_storage_request, aalloc_storage_alloc, 346 calloc_calls, calloc_0_calls, calloc_storage_request, calloc_storage_alloc, 347 memalign_calls, memalign_0_calls, memalign_storage_request, memalign_storage_alloc, 348 amemalign_calls, amemalign_0_calls, amemalign_storage_request, amemalign_storage_alloc, 349 cmemalign_calls, cmemalign_0_calls, cmemalign_storage_request, cmemalign_storage_alloc, 350 resize_calls, resize_0_calls, resize_storage_request, resize_storage_alloc, 351 realloc_calls, realloc_0_calls, realloc_storage_request, realloc_storage_alloc, 352 free_calls, free_null_calls, free_storage_request, free_storage_alloc, 353 sbrk_calls, sbrk_storage, 354 mmap_calls, mmap_storage_request, mmap_storage_alloc, 355 munmap_calls, munmap_storage_request, munmap_storage_alloc 356 356 ); 357 357 __cfaabi_bits_write( fileno( stream ), helpText, len ); // ensures all bytes written or exit … … 577 577 #ifdef __STATISTICS__ 578 578 __atomic_add_fetch( &mmap_calls, 1, __ATOMIC_SEQ_CST ); 579 __atomic_add_fetch( &mmap_storage, tsize, __ATOMIC_SEQ_CST ); 579 __atomic_add_fetch( &mmap_storage_request, size, __ATOMIC_SEQ_CST ); 580 __atomic_add_fetch( &mmap_storage_alloc, tsize, __ATOMIC_SEQ_CST ); 580 581 #endif // __STATISTICS__ 581 582 … … 626 627 #ifdef __STATISTICS__ 627 628 __atomic_add_fetch( &munmap_calls, 1, __ATOMIC_SEQ_CST ); 628 __atomic_add_fetch( &munmap_storage, size, __ATOMIC_SEQ_CST ); 629 __atomic_add_fetch( &munmap_storage_request, header->kind.real.size, __ATOMIC_SEQ_CST ); 630 __atomic_add_fetch( &munmap_storage_alloc, size, __ATOMIC_SEQ_CST ); 629 631 #endif // __STATISTICS__ 630 632 if ( munmap( header, size ) == -1 ) { … … 642 644 #ifdef __STATISTICS__ 643 645 __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST ); 644 __atomic_add_fetch( &free_storage, size, __ATOMIC_SEQ_CST ); 646 __atomic_add_fetch( &free_storage_request, header->kind.real.size, __ATOMIC_SEQ_CST ); 647 __atomic_add_fetch( &free_storage_alloc, size, __ATOMIC_SEQ_CST ); 645 648 #endif // __STATISTICS__ 646 649 … … 819 822 if ( likely( size > 0 ) ) { 820 823 __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST ); 821 __atomic_add_fetch( &malloc_storage , size, __ATOMIC_SEQ_CST );824 __atomic_add_fetch( &malloc_storage_request, size, __ATOMIC_SEQ_CST ); 822 825 } else { 823 __atomic_add_fetch( &malloc_ zero_calls, 1, __ATOMIC_SEQ_CST );826 __atomic_add_fetch( &malloc_0_calls, 1, __ATOMIC_SEQ_CST ); 824 827 } // if 825 828 #endif // __STATISTICS__ … … 835 838 if ( likely( size > 0 ) ) { 836 839 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST ); 837 __atomic_add_fetch( &aalloc_storage , size, __ATOMIC_SEQ_CST );840 __atomic_add_fetch( &aalloc_storage_request, size, __ATOMIC_SEQ_CST ); 838 841 } else { 839 __atomic_add_fetch( &aalloc_ zero_calls, 1, __ATOMIC_SEQ_CST );842 __atomic_add_fetch( &aalloc_0_calls, 1, __ATOMIC_SEQ_CST ); 840 843 } // if 841 844 #endif // __STATISTICS__ … … 850 853 if ( unlikely( size ) == 0 ) { // 0 BYTE ALLOCATION RETURNS NULL POINTER 851 854 #ifdef __STATISTICS__ 852 __atomic_add_fetch( &calloc_ zero_calls, 1, __ATOMIC_SEQ_CST );855 __atomic_add_fetch( &calloc_0_calls, 1, __ATOMIC_SEQ_CST ); 853 856 #endif // __STATISTICS__ 854 857 return 0p; … … 856 859 #ifdef __STATISTICS__ 857 860 __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST ); 858 __atomic_add_fetch( &calloc_storage , dim * elemSize, __ATOMIC_SEQ_CST );861 __atomic_add_fetch( &calloc_storage_request, dim * elemSize, __ATOMIC_SEQ_CST ); 859 862 #endif // __STATISTICS__ 860 863 … … 891 894 if ( unlikely( size == 0 ) ) { // special cases 892 895 #ifdef __STATISTICS__ 893 __atomic_add_fetch( &resize_ zero_calls, 1, __ATOMIC_SEQ_CST );896 __atomic_add_fetch( &resize_0_calls, 1, __ATOMIC_SEQ_CST ); 894 897 #endif // __STATISTICS__ 895 898 free( oaddr ); … … 902 905 if ( unlikely( oaddr == 0p ) ) { 903 906 #ifdef __STATISTICS__ 904 __atomic_add_fetch( &resize_storage , size, __ATOMIC_SEQ_CST );907 __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST ); 905 908 #endif // __STATISTICS__ 906 909 return mallocNoStats( size ); … … 921 924 922 925 #ifdef __STATISTICS__ 923 __atomic_add_fetch( &resize_storage , size, __ATOMIC_SEQ_CST );926 __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST ); 924 927 #endif // __STATISTICS__ 925 928 … … 936 939 if ( unlikely( size == 0 ) ) { // special cases 937 940 #ifdef __STATISTICS__ 938 __atomic_add_fetch( &realloc_ zero_calls, 1, __ATOMIC_SEQ_CST );941 __atomic_add_fetch( &realloc_0_calls, 1, __ATOMIC_SEQ_CST ); 939 942 #endif // __STATISTICS__ 940 943 free( oaddr ); … … 947 950 if ( unlikely( oaddr == 0p ) ) { 948 951 #ifdef __STATISTICS__ 949 __atomic_add_fetch( &realloc_storage , size, __ATOMIC_SEQ_CST );952 __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST ); 950 953 #endif // __STATISTICS__ 951 954 return mallocNoStats( size ); … … 969 972 970 973 #ifdef __STATISTICS__ 971 __atomic_add_fetch( &realloc_storage , size, __ATOMIC_SEQ_CST );974 __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST ); 972 975 #endif // __STATISTICS__ 973 976 … … 1000 1003 if ( likely( size > 0 ) ) { 1001 1004 __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST ); 1002 __atomic_add_fetch( &memalign_storage , size, __ATOMIC_SEQ_CST );1005 __atomic_add_fetch( &memalign_storage_request, size, __ATOMIC_SEQ_CST ); 1003 1006 } else { 1004 __atomic_add_fetch( &memalign_ zero_calls, 1, __ATOMIC_SEQ_CST );1007 __atomic_add_fetch( &memalign_0_calls, 1, __ATOMIC_SEQ_CST ); 1005 1008 } // if 1006 1009 #endif // __STATISTICS__ … … 1016 1019 if ( likely( size > 0 ) ) { 1017 1020 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1018 __atomic_add_fetch( &cmemalign_storage , size, __ATOMIC_SEQ_CST );1021 __atomic_add_fetch( &cmemalign_storage_request, size, __ATOMIC_SEQ_CST ); 1019 1022 } else { 1020 __atomic_add_fetch( &cmemalign_ zero_calls, 1, __ATOMIC_SEQ_CST );1023 __atomic_add_fetch( &cmemalign_0_calls, 1, __ATOMIC_SEQ_CST ); 1021 1024 } // if 1022 1025 #endif // __STATISTICS__ … … 1031 1034 if ( unlikely( size ) == 0 ) { // 0 BYTE ALLOCATION RETURNS NULL POINTER 1032 1035 #ifdef __STATISTICS__ 1033 __atomic_add_fetch( &cmemalign_ zero_calls, 1, __ATOMIC_SEQ_CST );1036 __atomic_add_fetch( &cmemalign_0_calls, 1, __ATOMIC_SEQ_CST ); 1034 1037 #endif // __STATISTICS__ 1035 1038 return 0p; … … 1037 1040 #ifdef __STATISTICS__ 1038 1041 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1039 __atomic_add_fetch( &cmemalign_storage , dim * elemSize, __ATOMIC_SEQ_CST );1042 __atomic_add_fetch( &cmemalign_storage_request, dim * elemSize, __ATOMIC_SEQ_CST ); 1040 1043 #endif // __STATISTICS__ 1041 1044 … … 1101 1104 if ( unlikely( addr == 0p ) ) { // special case 1102 1105 #ifdef __STATISTICS__ 1103 __atomic_add_fetch( &free_ zero_calls, 1, __ATOMIC_SEQ_CST );1106 __atomic_add_fetch( &free_null_calls, 1, __ATOMIC_SEQ_CST ); 1104 1107 #endif // __STATISTICS__ 1105 1108 … … 1280 1283 if ( unlikely( size == 0 ) ) { // special cases 1281 1284 #ifdef __STATISTICS__ 1282 __atomic_add_fetch( &resize_ zero_calls, 1, __ATOMIC_SEQ_CST );1285 __atomic_add_fetch( &resize_0_calls, 1, __ATOMIC_SEQ_CST ); 1283 1286 #endif // __STATISTICS__ 1284 1287 free( oaddr ); … … 1294 1297 #ifdef __STATISTICS__ 1295 1298 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 1296 __atomic_add_fetch( &resize_storage , size, __ATOMIC_SEQ_CST );1299 __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST ); 1297 1300 #endif // __STATISTICS__ 1298 1301 return memalignNoStats( nalign, size ); … … 1329 1332 1330 1333 #ifdef __STATISTICS__ 1331 __atomic_add_fetch( &resize_storage , size, __ATOMIC_SEQ_CST );1334 __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST ); 1332 1335 #endif // __STATISTICS__ 1333 1336 … … 1342 1345 if ( unlikely( size == 0 ) ) { // special cases 1343 1346 #ifdef __STATISTICS__ 1344 __atomic_add_fetch( &realloc_ zero_calls, 1, __ATOMIC_SEQ_CST );1347 __atomic_add_fetch( &realloc_0_calls, 1, __ATOMIC_SEQ_CST ); 1345 1348 #endif // __STATISTICS__ 1346 1349 free( oaddr ); … … 1356 1359 #ifdef __STATISTICS__ 1357 1360 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST ); 1358 __atomic_add_fetch( &realloc_storage , size, __ATOMIC_SEQ_CST );1361 __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST ); 1359 1362 #endif // __STATISTICS__ 1360 1363 return memalignNoStats( nalign, size ); … … 1380 1383 #ifdef __STATISTICS__ 1381 1384 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST ); 1382 __atomic_add_fetch( &realloc_storage , size, __ATOMIC_SEQ_CST );1385 __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST ); 1383 1386 #endif // __STATISTICS__ 1384 1387
Note: See TracChangeset
for help on using the changeset viewer.