Changeset ea57077 for src/libcfa/heap.c


Ignore:
Timestamp:
Jul 27, 2018, 1:35:35 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:
8f50da0, c2ea058
Parents:
303c61d (diff), a92bd63 (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
  • src/libcfa/heap.c

    r303c61d rea57077  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 25 16:42:02 2018
    13 // Update Count     : 438
     12// Last Modified On : Thu Jul 26 22:28:23 2018
     13// Update Count     : 449
    1414//
    1515
     
    111111//      return temp;
    112112// } // prtHeapTermOff
     113
     114
     115#ifdef __CFA_DEBUG__
     116static unsigned int allocfree;                                                  // running total of allocations minus frees
     117static unsigned int appStart;                                                   // storage allocation when application starts
     118
     119static void checkUnfreed() {
     120        unsigned int total = allocfree - appStart;
     121    if ( total != 0 ) {
     122                // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
     123                // char helpText[512];
     124                // int len = snprintf( helpText, 512, "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
     125                //                                      "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
     126                //                                      (long int)getpid(), total, total ); // always print the UNIX pid
     127                // __cfaabi_dbg_bits_write( helpText, len );
     128    } // if
     129} // checkUnfreed
     130
     131extern "C" {
     132void heapAppStart() {                                                                   // called by __cfaabi_appready_startup
     133        appStart = allocfree;
     134} // heapAppStart
     135
     136void heapAppStop() {                                                                    // called by __cfaabi_appready_startdown
     137        checkUnfreed();
     138} // heapAppStop
     139} // extern "C"
     140#endif // __CFA_DEBUG__
    113141
    114142
     
    139167static int mmapFd = -1;                                                                 // fake or actual fd for anonymous file
    140168
    141 static unsigned int allocfree;                                                  // running total of allocations minus frees
    142 static unsigned int appStart;                                                   // storage allocation when application starts
    143 
    144 static void checkUnfreed() {
    145         #ifdef __CFA_DEBUG__
    146         unsigned int total = allocfree - appStart;
    147     if ( total != 0 ) {
    148                 // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
    149                 // char helpText[512];
    150                 // int len = snprintf( helpText, 512, "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
    151                 //                                      "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
    152                 //                                      (long int)getpid(), total, total ); // always print the UNIX pid
    153                 // __cfaabi_dbg_bits_write( helpText, len );
    154     } // if
    155         #endif // __CFA_DEBUG__
    156 } // checkUnfreed
    157 
    158 #ifdef __CFA_DEBUG__
    159 extern "C" {
    160 void heapAppStart() {                                                                   // called by __cfaabi_appready_startup
    161         appStart = allocfree;
    162 } // heapAppStart
    163 
    164 void heapAppStop() {                                                                    // called by __cfaabi_appready_startdown
    165         checkUnfreed();
    166 } // heapAppStop
    167 } // extern "C"
    168 #endif // __CFA_DEBUG__
    169 
    170169
    171170struct HeapManager {
     
    178177                                        union {
    179178                                                struct {                                                // 32-bit word => 64-bit header, 64-bit word => 128-bit header
    180                                                         #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __U_WORDSIZE__ == 32
     179                                                        #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_POINTER__ == 4
    181180                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    182                                                         #endif // __U_WORDSIZE__ == 32 && __U_WORDSIZE__ == 32
     181                                                        #endif // __ORDER_BIG_ENDIAN__ && __U_WORDSIZE__ == 32
    183182
    184183                                                        union {
     
    191190                                                        };
    192191
    193                                                         #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __U_WORDSIZE__ == 32
     192                                                        #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_POINTER__ == 4
    194193                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    195                                                         #endif // __U_WORDSIZE__ == 32 && __U_WORDSIZE__ == 32
     194                                                        #endif // __ORDER_LITTLE_ENDIAN__ && __U_WORDSIZE__ == 32
    196195
    197196                                                };
     
    204203                                        #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
    205204                                        uint32_t alignment;                                     // low-order bits of home/blockSize used for tricks
    206                                         #endif // __BYTE_ORDER__
     205                                        #endif // __ORDER_LITTLE_ENDIAN__
    207206
    208207                                        uint32_t offset;
     
    210209                                        #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
    211210                                        uint32_t alignment;                                     // low-order bits of home/blockSize used for tricks
    212                                         #endif // __BYTE_ORDER__
     211                                        #endif // __ORDER_BIG_ENDIAN__
    213212                                } fake;
    214213                        } kind;
     
    305304        #endif // __CFA_DEBUG__
    306305
     306        assert( heapManager.heapBegin == 0 );
    307307        heapManager{};
    308308} // memory_startup
     
    672672
    673673static inline void * malloc2( size_t size ) {                   // necessary for malloc statistics
    674     assert( heapManager.heapBegin != 0 ) ;                              // heap started
     674        assert( heapManager.heapBegin != 0 );
    675675    void * area = doMalloc( size );
    676676    if ( unlikely( area == 0 ) ) errno = ENOMEM;                // POSIX
Note: See TracChangeset for help on using the changeset viewer.