Ignore:
Timestamp:
Aug 14, 2018, 1:21:19 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
5a5d31a
Parents:
ef2eade (diff), 0e0f128c (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' into jenkins-sandbox

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    ref2eade r7b3a6e6  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 31 18:08:50 2018
    13 // Update Count     : 470
     12// Last Modified On : Sat Aug 11 08:22:16 2018
     13// Update Count     : 495
    1414//
    1515
     
    7575
    7676
    77 static _Bool traceHeap = false;
    78 
    79 inline _Bool traceHeap() {
     77static bool traceHeap = false;
     78
     79inline bool traceHeap() {
    8080        return traceHeap;
    8181} // traceHeap
    8282
    83 _Bool traceHeapOn() {
    84         _Bool temp = traceHeap;
     83bool traceHeapOn() {
     84        bool temp = traceHeap;
    8585        traceHeap = true;
    8686        return temp;
    8787} // traceHeapOn
    8888
    89 _Bool traceHeapOff() {
    90         _Bool temp = traceHeap;
     89bool traceHeapOff() {
     90        bool temp = traceHeap;
    9191        traceHeap = false;
    9292        return temp;
     
    9494
    9595
    96 static _Bool checkFree = false;
    97 
    98 inline _Bool checkFree() {
     96static bool checkFree = false;
     97
     98inline bool checkFree() {
    9999        return checkFree;
    100100} // checkFree
    101101
    102 _Bool checkFreeOn() {
    103         _Bool temp = checkFree;
     102bool checkFreeOn() {
     103        bool temp = checkFree;
    104104        checkFree = true;
    105105        return temp;
    106106} // checkFreeOn
    107107
    108 _Bool checkFreeOff() {
    109         _Bool temp = checkFree;
     108bool checkFreeOff() {
     109        bool temp = checkFree;
    110110        checkFree = false;
    111111        return temp;
     
    113113
    114114
    115 // static _Bool traceHeapTerm = false;
    116 
    117 // inline _Bool traceHeapTerm() {
     115// static bool traceHeapTerm = false;
     116
     117// inline bool traceHeapTerm() {
    118118//      return traceHeapTerm;
    119119// } // traceHeapTerm
    120120
    121 // _Bool traceHeapTermOn() {
    122 //      _Bool temp = traceHeapTerm;
     121// bool traceHeapTermOn() {
     122//      bool temp = traceHeapTerm;
    123123//      traceHeapTerm = true;
    124124//      return temp;
    125125// } // traceHeapTermOn
    126126
    127 // _Bool traceHeapTermOff() {
    128 //      _Bool temp = traceHeapTerm;
     127// bool traceHeapTermOff() {
     128//      bool temp = traceHeapTerm;
    129129//      traceHeapTerm = false;
    130130//      return temp;
     
    133133
    134134#ifdef __CFA_DEBUG__
    135 static unsigned int allocfree;                                                  // running total of allocations minus frees
    136 static unsigned int appStart;                                                   // storage allocation when application starts
     135static unsigned int allocFree;                                                  // running total of allocations minus frees
    137136
    138137static void checkUnfreed() {
    139         unsigned int total = allocfree - appStart;
    140     if ( total != 0 ) {
     138    if ( allocFree != 0 ) {
    141139                // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
    142140                // char helpText[512];
    143                 // int len = snprintf( helpText, 512, "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
     141                // int len = snprintf( helpText, sizeof(helpText), "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
    144142                //                                      "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
    145                 //                                      (long int)getpid(), total, total ); // always print the UNIX pid
     143                //                                      (long int)getpid(), allocFree, allocFree ); // always print the UNIX pid
    146144                // __cfaabi_dbg_bits_write( helpText, len );
    147145    } // if
     
    150148extern "C" {
    151149void heapAppStart() {                                                                   // called by __cfaabi_appready_startup
    152         appStart = allocfree;
     150        allocFree = 0;
    153151} // heapAppStart
    154152
    155153void heapAppStop() {                                                                    // called by __cfaabi_appready_startdown
     154        fclose( stdin ); fclose( stdout );
    156155        checkUnfreed();
    157156} // heapAppStop
     
    191190                                                #endif // LOCKFREE
    192191                                        };
    193                                 } real;
     192                                } real; // RealHeader
    194193                                struct FakeHeader {
    195194                                        #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
     
    202201                                        uint32_t alignment;                                     // low-order bits of home/blockSize used for tricks
    203202                                        #endif // __ORDER_BIG_ENDIAN__
    204                                 } fake;
    205                         } kind;
     203                                } fake; // FakeHeader
     204                        } kind; // Kind
    206205            } header; // Header
    207206            char pad[ALIGN - sizeof( Header )];
     
    264263
    265264#ifdef __CFA_DEBUG__
    266 static _Bool heapBoot = 0;                                                              // detect recursion during boot
     265static bool heapBoot = 0;                                                               // detect recursion during boot
    267266#endif // __CFA_DEBUG__
    268267static HeapManager heapManager __attribute__(( aligned (128) )) @= {}; // size of cache line to prevent false sharing
    269268
    270269
    271 static inline _Bool setMmapStart( size_t value ) {
     270static inline bool setMmapStart( size_t value ) {
    272271    if ( value < pageSize || bucketSizes[NoBucketSizes - 1] < value ) return true;
    273272    mmapStart = value;                                                                  // set global
     
    363362static void printStats() {
    364363    char helpText[512];
    365         __cfaabi_dbg_bits_print_buffer( helpText, 512,
     364        __cfaabi_dbg_bits_print_buffer( helpText, sizeof(helpText),
    366365                        "\nHeap statistics:\n"
    367366                        "  malloc: calls %u / storage %llu\n"
     
    389388static int printStatsXML( FILE * stream ) {
    390389    char helpText[512];
    391     int len = snprintf( helpText, 512,
     390    int len = snprintf( helpText, sizeof(helpText),
    392391                                                "<malloc version=\"1\">\n"
    393392                                                "<heap nr=\"0\">\n"
     
    433432
    434433
    435 static inline _Bool setHeapExpand( size_t value ) {
     434static inline bool setHeapExpand( size_t value ) {
    436435    if ( heapExpand < pageSize ) return true;
    437436    heapExpand = value;
     
    440439
    441440
    442 static inline void checkHeader( _Bool check, const char * name, void * addr ) {
     441static inline void checkHeader( bool check, const char * name, void * addr ) {
    443442    if ( unlikely( check ) ) {                                                  // bad address ?
    444443                abort( "Attempt to %s storage %p with address outside the heap.\n"
     
    463462#define headerAddr( addr ) ((HeapManager.Storage.Header *)( (char *)addr - sizeof(HeapManager.Storage) ))
    464463
    465 static inline _Bool headers( const char * name, void * addr, HeapManager.Storage.Header *& header, HeapManager.FreeHeader *& freeElem, size_t & size, size_t & alignment ) with ( heapManager ) {
     464static inline bool headers( const char * name, void * addr, HeapManager.Storage.Header *& header, HeapManager.FreeHeader *& freeElem, size_t & size, size_t & alignment ) with ( heapManager ) {
    466465    header = headerAddr( addr );
    467466
     
    589588        #ifdef __CFA_DEBUG__
    590589    assert( ((uintptr_t)area & (libAlign() - 1)) == 0 ); // minimum alignment ?
    591     __atomic_add_fetch( &allocfree, tsize, __ATOMIC_SEQ_CST );
     590    __atomic_add_fetch( &allocFree, tsize, __ATOMIC_SEQ_CST );
    592591        if ( traceHeap() ) {
    593592                enum { BufferSize = 64 };
     
    646645
    647646        #ifdef __CFA_DEBUG__
    648     __atomic_add_fetch( &allocfree, -size, __ATOMIC_SEQ_CST );
     647    __atomic_add_fetch( &allocFree, -size, __ATOMIC_SEQ_CST );
    649648    if ( traceHeap() ) {
    650                 enum { BufferSize = 64 };
    651                 char helpText[BufferSize];
    652                 int len = snprintf( helpText, BufferSize, "Free( %p ) size:%zu\n", addr, size );
     649                char helpText[64];
     650                int len = snprintf( helpText, sizeof(helpText), "Free( %p ) size:%zu\n", addr, size );
    653651                __cfaabi_dbg_bits_write( helpText, len );
    654652    } // if
     
    758756                HeapManager.FreeHeader * freeElem;
    759757                size_t asize, alignment;
    760                 _Bool mapped __attribute__(( unused )) = headers( "calloc", area, header, freeElem, asize, alignment );
     758                bool mapped __attribute__(( unused )) = headers( "calloc", area, header, freeElem, asize, alignment );
    761759                #ifndef __CFA_DEBUG__
    762760                // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
     
    781779                HeapManager.FreeHeader * freeElem;
    782780                size_t asize;
    783                 _Bool mapped __attribute__(( unused )) = headers( "cmemalign", area, header, freeElem, asize, alignment );
     781                bool mapped __attribute__(( unused )) = headers( "cmemalign", area, header, freeElem, asize, alignment );
    784782                #ifndef __CFA_DEBUG__
    785783                // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
     
    826824                if ( unlikely( header->kind.real.blockSize & 2 ) ) { // previous request zero fill (calloc/cmemalign) ?
    827825                        assert( (header->kind.real.blockSize & 1) == 0 );
    828                         _Bool mapped __attribute__(( unused )) = headers( "realloc", area, header, freeElem, asize, alignment );
     826                        bool mapped __attribute__(( unused )) = headers( "realloc", area, header, freeElem, asize, alignment );
    829827                        #ifndef __CFA_DEBUG__
    830828                        // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
     
    889887    } // free
    890888
     889
    891890    int mallopt( int option, int value ) {
    892891                choose( option ) {
     
    929928
    930929
    931     _Bool malloc_zero_fill( void * addr ) {
     930    bool malloc_zero_fill( void * addr ) {
    932931                if ( unlikely( addr == 0 ) ) return false;              // null allocation is not zero fill
    933932                HeapManager.Storage.Header * header = (HeapManager.Storage.Header *)( (char *)addr - sizeof(HeapManager.Storage) );
Note: See TracChangeset for help on using the changeset viewer.