Ignore:
Timestamp:
Jan 14, 2021, 12:23:14 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8e4aa05
Parents:
4468a70 (diff), ec19b21 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r4468a70 r342af53  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 16 12:28:25 2020
    13 // Update Count     : 1023
     12// Last Modified On : Sun Jan 10 11:20:49 2021
     13// Update Count     : 1031
    1414//
    1515
     
    262262#ifdef __STATISTICS__
    263263// Heap statistics counters.
    264 static unsigned int malloc_calls;
     264static unsigned int malloc_zero_calls, malloc_calls;
    265265static unsigned long long int malloc_storage;
    266 static unsigned int aalloc_calls;
     266static unsigned int aalloc_zero_calls, aalloc_calls;
    267267static unsigned long long int aalloc_storage;
    268 static unsigned int calloc_calls;
     268static unsigned int calloc_zero_calls, calloc_calls;
    269269static unsigned long long int calloc_storage;
    270 static unsigned int memalign_calls;
     270static unsigned int memalign_zero_calls, memalign_calls;
    271271static unsigned long long int memalign_storage;
    272 static unsigned int amemalign_calls;
     272static unsigned int amemalign_zero_calls, amemalign_calls;
    273273static unsigned long long int amemalign_storage;
    274 static unsigned int cmemalign_calls;
     274static unsigned int cmemalign_zero_calls, cmemalign_calls;
    275275static unsigned long long int cmemalign_storage;
    276 static unsigned int resize_calls;
     276static unsigned int resize_zero_calls, resize_calls;
    277277static unsigned long long int resize_storage;
    278 static unsigned int realloc_calls;
     278static unsigned int realloc_zero_calls, realloc_calls;
    279279static unsigned long long int realloc_storage;
    280 static unsigned int free_calls;
     280static unsigned int free_zero_calls, free_calls;
    281281static unsigned long long int free_storage;
    282282static unsigned int mmap_calls;
     
    287287static unsigned long long int sbrk_storage;
    288288// Statistics file descriptor (changed by malloc_stats_fd).
    289 static int stat_fd = STDERR_FILENO;                                             // default stderr
     289static int stats_fd = STDERR_FILENO;                                    // default stderr
    290290
    291291// Use "write" because streams may be shutdown when calls are made.
     
    293293        char helpText[1024];
    294294        __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText),
    295                                                                         "\nHeap statistics:\n"
    296                                                                         "  malloc: calls %u / storage %llu\n"
    297                                                                         "  aalloc: calls %u / storage %llu\n"
    298                                                                         "  calloc: calls %u / storage %llu\n"
    299                                                                         "  memalign: calls %u / storage %llu\n"
    300                                                                         "  amemalign: calls %u / storage %llu\n"
    301                                                                         "  cmemalign: calls %u / storage %llu\n"
    302                                                                         "  resize: calls %u / storage %llu\n"
    303                                                                         "  realloc: calls %u / storage %llu\n"
    304                                                                         "  free: calls %u / storage %llu\n"
    305                                                                         "  mmap: calls %u / storage %llu\n"
    306                                                                         "  munmap: calls %u / storage %llu\n"
    307                                                                         "  sbrk: calls %u / storage %llu\n",
    308                                                                         malloc_calls, malloc_storage,
    309                                                                         aalloc_calls, aalloc_storage,
    310                                                                         calloc_calls, calloc_storage,
    311                                                                         memalign_calls, memalign_storage,
    312                                                                         amemalign_calls, amemalign_storage,
    313                                                                         cmemalign_calls, cmemalign_storage,
    314                                                                         resize_calls, resize_storage,
    315                                                                         realloc_calls, realloc_storage,
    316                                                                         free_calls, free_storage,
    317                                                                         mmap_calls, mmap_storage,
    318                                                                         munmap_calls, munmap_storage,
    319                                                                         sbrk_calls, sbrk_storage
     295                                                                "\nHeap statistics:\n"
     296                                                                "  malloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     297                                                                "  aalloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     298                                                                "  calloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     299                                                                "  memalign  0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     300                                                                "  amemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     301                                                                "  cmemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     302                                                                "  resize    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     303                                                                "  realloc   0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     304                                                                "  free      0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     305                                                                "  mmap      calls %'u; storage %'llu bytes\n"
     306                                                                "  munmap    calls %'u; storage %'llu bytes\n"
     307                                                                "  sbrk      calls %'u; storage %'llu bytes\n",
     308                                                                malloc_zero_calls, malloc_calls, malloc_storage,
     309                                                                aalloc_zero_calls, aalloc_calls, aalloc_storage,
     310                                                                calloc_zero_calls, calloc_calls, calloc_storage,
     311                                                                memalign_zero_calls, memalign_calls, memalign_storage,
     312                                                                amemalign_zero_calls, amemalign_calls, amemalign_storage,
     313                                                                cmemalign_zero_calls, cmemalign_calls, cmemalign_storage,
     314                                                                resize_zero_calls, resize_calls, resize_storage,
     315                                                                realloc_zero_calls, realloc_calls, realloc_storage,
     316                                                                free_zero_calls, free_calls, free_storage,
     317                                                                mmap_calls, mmap_storage,
     318                                                                munmap_calls, munmap_storage,
     319                                                                sbrk_calls, sbrk_storage
    320320                );
    321321} // printStats
     
    328328                                                "<sizes>\n"
    329329                                                "</sizes>\n"
    330                                                 "<total type=\"malloc\" count=\"%u\" size=\"%llu\"/>\n"
    331                                                 "<total type=\"aalloc\" count=\"%u\" size=\"%llu\"/>\n"
    332                                                 "<total type=\"calloc\" count=\"%u\" size=\"%llu\"/>\n"
    333                                                 "<total type=\"memalign\" count=\"%u\" size=\"%llu\"/>\n"
    334                                                 "<total type=\"amemalign\" count=\"%u\" size=\"%llu\"/>\n"
    335                                                 "<total type=\"cmemalign\" count=\"%u\" size=\"%llu\"/>\n"
    336                                                 "<total type=\"resize\" count=\"%u\" size=\"%llu\"/>\n"
    337                                                 "<total type=\"realloc\" count=\"%u\" size=\"%llu\"/>\n"
    338                                                 "<total type=\"free\" count=\"%u\" size=\"%llu\"/>\n"
    339                                                 "<total type=\"mmap\" count=\"%u\" size=\"%llu\"/>\n"
    340                                                 "<total type=\"munmap\" count=\"%u\" size=\"%llu\"/>\n"
    341                                                 "<total type=\"sbrk\" count=\"%u\" size=\"%llu\"/>\n"
     330                                                "<total type=\"malloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     331                                                "<total type=\"aalloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     332                                                "<total type=\"calloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     333                                                "<total type=\"memalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     334                                                "<total type=\"amemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     335                                                "<total type=\"cmemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     336                                                "<total type=\"resize\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     337                                                "<total type=\"realloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     338                                                "<total type=\"free\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     339                                                "<total type=\"mmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     340                                                "<total type=\"munmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     341                                                "<total type=\"sbrk\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    342342                                                "</malloc>",
    343                                                 malloc_calls, malloc_storage,
    344                                                 aalloc_calls, aalloc_storage,
    345                                                 calloc_calls, calloc_storage,
    346                                                 memalign_calls, memalign_storage,
    347                                                 amemalign_calls, amemalign_storage,
    348                                                 cmemalign_calls, cmemalign_storage,
    349                                                 resize_calls, resize_storage,
    350                                                 realloc_calls, realloc_storage,
    351                                                 free_calls, free_storage,
     343                                                malloc_zero_calls, malloc_calls, malloc_storage,
     344                                                aalloc_zero_calls, aalloc_calls, aalloc_storage,
     345                                                calloc_zero_calls, calloc_calls, calloc_storage,
     346                                                memalign_zero_calls, memalign_calls, memalign_storage,
     347                                                amemalign_zero_calls, amemalign_calls, amemalign_storage,
     348                                                cmemalign_zero_calls, cmemalign_calls, cmemalign_storage,
     349                                                resize_zero_calls, resize_calls, resize_storage,
     350                                                realloc_zero_calls, realloc_calls, realloc_storage,
     351                                                free_zero_calls, free_calls, free_storage,
    352352                                                mmap_calls, mmap_storage,
    353353                                                munmap_calls, munmap_storage,
     
    466466} // headers
    467467
    468 #ifdef __CFA_DEBUG__
    469 #if __SIZEOF_POINTER__ == 4
    470 #define MASK 0xdeadbeef
    471 #else
    472 #define MASK 0xdeadbeefdeadbeef
    473 #endif
    474 #define STRIDE size_t
    475 
    476 static void * Memset( void * addr, STRIDE size ) {              // debug only
    477         if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );
    478         if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );
    479 
    480         STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);
    481         for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;
    482         return addr;
    483 } // Memset
    484 #endif // __CFA_DEBUG__
     468// #ifdef __CFA_DEBUG__
     469// #if __SIZEOF_POINTER__ == 4
     470// #define MASK 0xdeadbeef
     471// #else
     472// #define MASK 0xdeadbeefdeadbeef
     473// #endif
     474// #define STRIDE size_t
     475
     476// static void * Memset( void * addr, STRIDE size ) {           // debug only
     477//      if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );
     478//      if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );
     479
     480//      STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);
     481//      for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;
     482//      return addr;
     483// } // Memset
     484// #endif // __CFA_DEBUG__
    485485
    486486
     
    498498                        unlock( extlock );
    499499                        __cfaabi_bits_print_nolock( STDERR_FILENO, NO_MEMORY_MSG, size );
    500                         _exit( EXIT_FAILURE );
    501                 } // if
     500                        _exit( EXIT_FAILURE );                                          // give up
     501                } // if
     502                // Make storage executable for thunks.
    502503                if ( mprotect( (char *)heapEnd + heapRemaining, increase, __map_prot ) ) {
    503504                        unlock( extlock );
     
    770771
    771772
    772 static inline void * callocNoStats( size_t dim, size_t elemSize ) {
    773         size_t size = dim * elemSize;
    774   if ( unlikely( size ) == 0 ) return 0p;                               // 0 BYTE ALLOCATION RETURNS NULL POINTER
    775         char * addr = (char *)mallocNoStats( size );
    776 
    777         HeapManager.Storage.Header * header;
    778         HeapManager.FreeHeader * freeElem;
    779         size_t bsize, alignment;
    780         #ifndef __CFA_DEBUG__
    781         bool mapped =
    782         #endif // __CFA_DEBUG__
    783                 headers( "calloc", addr, header, freeElem, bsize, alignment );
    784         #ifndef __CFA_DEBUG__
    785 
    786         // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
    787         if ( ! mapped )
    788         #endif // __CFA_DEBUG__
    789                 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
    790                 // `-header`-addr                      `-size
    791                 memset( addr, '\0', size );                                             // set to zeros
    792 
    793         header->kind.real.blockSize |= 2;                                       // mark as zero filled
    794         return addr;
    795 } // callocNoStats
    796 
    797 
    798773static inline void * memalignNoStats( size_t alignment, size_t size ) {
    799774  if ( unlikely( size ) == 0 ) return 0p;                               // 0 BYTE ALLOCATION RETURNS NULL POINTER
     
    834809
    835810
    836 static inline void * cmemalignNoStats( size_t alignment, size_t dim, size_t elemSize ) {
    837         size_t size = dim * elemSize;
    838   if ( unlikely( size ) == 0 ) return 0p;                               // 0 BYTE ALLOCATION RETURNS NULL POINTER
    839         char * addr = (char *)memalignNoStats( alignment, size );
    840 
    841         HeapManager.Storage.Header * header;
    842         HeapManager.FreeHeader * freeElem;
    843         size_t bsize;
    844         #ifndef __CFA_DEBUG__
    845         bool mapped =
    846         #endif // __CFA_DEBUG__
    847                 headers( "cmemalign", addr, header, freeElem, bsize, alignment );
    848 
    849         // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
    850         #ifndef __CFA_DEBUG__
    851         if ( ! mapped )
    852         #endif // __CFA_DEBUG__
    853                 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
    854                 // `-header`-addr                      `-size
    855                 memset( addr, '\0', size );                                             // set to zeros
    856 
    857         header->kind.real.blockSize |= 2;                                       // mark as zero filled
    858         return addr;
    859 } // cmemalignNoStats
    860 
    861 
    862811extern "C" {
    863812        // Allocates size bytes and returns a pointer to the allocated memory.  The contents are undefined. If size is 0,
     
    865814        void * malloc( size_t size ) {
    866815                #ifdef __STATISTICS__
    867                 __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
    868                 __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
     816                if ( likely( size > 0 ) ) {
     817                        __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
     818                        __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
     819                } else {
     820                        __atomic_add_fetch( &malloc_zero_calls, 1, __ATOMIC_SEQ_CST );
     821                } // if
    869822                #endif // __STATISTICS__
    870823
     
    877830                size_t size = dim * elemSize;
    878831                #ifdef __STATISTICS__
    879                 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST );
    880                 __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST );
     832                if ( likely( size > 0 ) ) {
     833                        __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST );
     834                        __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST );
     835                } else {
     836                        __atomic_add_fetch( &aalloc_zero_calls, 1, __ATOMIC_SEQ_CST );
     837                } // if
    881838                #endif // __STATISTICS__
    882839
     
    887844        // Same as aalloc() with memory set to zero.
    888845        void * calloc( size_t dim, size_t elemSize ) {
     846                size_t size = dim * elemSize;
     847          if ( unlikely( size ) == 0 ) {                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
     848                        #ifdef __STATISTICS__
     849                        __atomic_add_fetch( &calloc_zero_calls, 1, __ATOMIC_SEQ_CST );
     850                        #endif // __STATISTICS__
     851                        return 0p;
     852                } // if
    889853                #ifdef __STATISTICS__
    890854                __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST );
     
    892856                #endif // __STATISTICS__
    893857
    894                 return callocNoStats( dim, elemSize );
     858                char * addr = (char *)mallocNoStats( size );
     859
     860                HeapManager.Storage.Header * header;
     861                HeapManager.FreeHeader * freeElem;
     862                size_t bsize, alignment;
     863
     864                #ifndef __CFA_DEBUG__
     865                bool mapped =
     866                        #endif // __CFA_DEBUG__
     867                        headers( "calloc", addr, header, freeElem, bsize, alignment );
     868
     869                #ifndef __CFA_DEBUG__
     870                // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
     871                if ( ! mapped )
     872                #endif // __CFA_DEBUG__
     873                        // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
     874                        // `-header`-addr                      `-size
     875                        memset( addr, '\0', size );                                     // set to zeros
     876
     877                header->kind.real.blockSize |= 2;                               // mark as zero filled
     878                return addr;
    895879        } // calloc
    896880
     
    901885        // call to malloc(), alloc(), calloc() or realloc(). If the area pointed to was moved, a free(oaddr) is done.
    902886        void * resize( void * oaddr, size_t size ) {
     887                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     888          if ( unlikely( size == 0 ) ) {                                        // special cases
     889                        #ifdef __STATISTICS__
     890                        __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST );
     891                        #endif // __STATISTICS__
     892                        free( oaddr );
     893                        return 0p;
     894                } // if
    903895                #ifdef __STATISTICS__
    904896                __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    905897                #endif // __STATISTICS__
    906898
    907                 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    908           if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    909899          if ( unlikely( oaddr == 0p ) ) {
    910900                        #ifdef __STATISTICS__
     
    918908                size_t bsize, oalign;
    919909                headers( "resize", oaddr, header, freeElem, bsize, oalign );
     910
    920911                size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket
    921 
    922912                // same size, DO NOT preserve STICKY PROPERTIES.
    923913                if ( oalign == libAlign() && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size
     
    940930        // the old and new sizes.
    941931        void * realloc( void * oaddr, size_t size ) {
     932                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     933          if ( unlikely( size == 0 ) ) {                                        // special cases
     934                        #ifdef __STATISTICS__
     935                        __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST );
     936                        #endif // __STATISTICS__
     937                        free( oaddr );
     938                        return 0p;
     939                } // if
    942940                #ifdef __STATISTICS__
    943941                __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
    944942                #endif // __STATISTICS__
    945943
    946                 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    947           if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    948944          if ( unlikely( oaddr == 0p ) ) {
    949945                        #ifdef __STATISTICS__
     
    999995        void * memalign( size_t alignment, size_t size ) {
    1000996                #ifdef __STATISTICS__
    1001                 __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST );
    1002                 __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST );
     997                if ( likely( size > 0 ) ) {
     998                        __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST );
     999                        __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST );
     1000                } else {
     1001                        __atomic_add_fetch( &memalign_zero_calls, 1, __ATOMIC_SEQ_CST );
     1002                } // if
    10031003                #endif // __STATISTICS__
    10041004
     
    10111011                size_t size = dim * elemSize;
    10121012                #ifdef __STATISTICS__
    1013                 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
    1014                 __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
     1013                if ( likely( size > 0 ) ) {
     1014                        __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
     1015                        __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
     1016                } else {
     1017                        __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST );
     1018                } // if
    10151019                #endif // __STATISTICS__
    10161020
     
    10211025        // Same as calloc() with memory alignment.
    10221026        void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) {
     1027                size_t size = dim * elemSize;
     1028          if ( unlikely( size ) == 0 ) {                                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
     1029                        #ifdef __STATISTICS__
     1030                        __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST );
     1031                        #endif // __STATISTICS__
     1032                        return 0p;
     1033                } // if
    10231034                #ifdef __STATISTICS__
    10241035                __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
     
    10261037                #endif // __STATISTICS__
    10271038
    1028                 return cmemalignNoStats( alignment, dim, elemSize );
     1039                char * addr = (char *)memalignNoStats( alignment, size );
     1040
     1041                HeapManager.Storage.Header * header;
     1042                HeapManager.FreeHeader * freeElem;
     1043                size_t bsize;
     1044
     1045                #ifndef __CFA_DEBUG__
     1046                bool mapped =
     1047                        #endif // __CFA_DEBUG__
     1048                        headers( "cmemalign", addr, header, freeElem, bsize, alignment );
     1049
     1050                // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
     1051                #ifndef __CFA_DEBUG__
     1052                if ( ! mapped )
     1053                #endif // __CFA_DEBUG__
     1054                        // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
     1055                        // `-header`-addr                      `-size
     1056                        memset( addr, '\0', size );                                     // set to zeros
     1057
     1058                header->kind.real.blockSize |= 2;                               // mark as zero filled
     1059                return addr;
    10291060        } // cmemalign
    10301061
     
    10651096        // 0p, no operation is performed.
    10661097        void free( void * addr ) {
    1067                 #ifdef __STATISTICS__
    1068                 __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST );
    1069                 #endif // __STATISTICS__
    1070 
    10711098          if ( unlikely( addr == 0p ) ) {                                       // special case
     1099                        #ifdef __STATISTICS__
     1100                        __atomic_add_fetch( &free_zero_calls, 1, __ATOMIC_SEQ_CST );
     1101                        #endif // __STATISTICS__
     1102
    10721103                        // #ifdef __CFA_DEBUG__
    10731104                        // if ( traceHeap() ) {
     
    11821213        int malloc_stats_fd( int fd __attribute__(( unused )) ) {
    11831214                #ifdef __STATISTICS__
    1184                 int temp = stat_fd;
    1185                 stat_fd = fd;
     1215                int temp = stats_fd;
     1216                stats_fd = fd;
    11861217                return temp;
    11871218                #else
     
    12141245        // The string is printed on the file stream stream.  The exported string includes information about all arenas (see
    12151246        // malloc).
    1216         int malloc_info( int options, FILE * stream ) {
     1247        int malloc_info( int options, FILE * stream __attribute__(( unused )) ) {
    12171248          if ( options != 0 ) { errno = EINVAL; return -1; }
    12181249                #ifdef __STATISTICS__
     
    12431274// Must have CFA linkage to overload with C linkage realloc.
    12441275void * resize( void * oaddr, size_t nalign, size_t size ) {
    1245         #ifdef __STATISTICS__
    1246         __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    1247         #endif // __STATISTICS__
     1276        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     1277  if ( unlikely( size == 0 ) ) {                                                // special cases
     1278                #ifdef __STATISTICS__
     1279                __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST );
     1280                #endif // __STATISTICS__
     1281                free( oaddr );
     1282                return 0p;
     1283        } // if
    12481284
    12491285        if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
    12501286        #ifdef __CFA_DEBUG__
    1251         else
    1252                 checkAlign( nalign );                                                   // check alignment
     1287        else checkAlign( nalign );                                                      // check alignment
    12531288        #endif // __CFA_DEBUG__
    12541289
    1255         // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1256   if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    12571290  if ( unlikely( oaddr == 0p ) ) {
    12581291                #ifdef __STATISTICS__
     1292                __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    12591293                __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    12601294                #endif // __STATISTICS__
     
    13021336
    13031337void * realloc( void * oaddr, size_t nalign, size_t size ) {
     1338        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     1339  if ( unlikely( size == 0 ) ) {                                                // special cases
     1340                #ifdef __STATISTICS__
     1341                __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST );
     1342                #endif // __STATISTICS__
     1343                free( oaddr );
     1344                return 0p;
     1345        } // if
     1346
    13041347        if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
    13051348        #ifdef __CFA_DEBUG__
    1306         else
    1307                 checkAlign( nalign );                                                   // check alignment
     1349        else checkAlign( nalign );                                                      // check alignment
    13081350        #endif // __CFA_DEBUG__
    13091351
    1310         // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1311   if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    13121352  if ( unlikely( oaddr == 0p ) ) {
    13131353                #ifdef __STATISTICS__
Note: See TracChangeset for help on using the changeset viewer.