Changes in / [692e6f1:64cf022]


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • doc/bibliography/pl.bib

    r692e6f1 r64cf022  
    45664566}
    45674567
    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 
    45794568@article{Pierce00,
    45804569    keywords    = {Scala, polymorphism, subtyping, type inference},
     
    66676656}
    66686657
    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 
    66786658% R
    66796659
  • libcfa/src/bitmanip.hfa

    r692e6f1 r64cf022  
    1111// Created On       : Sat Mar 14 18:12:27 2020
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Thu Apr 16 18:09:34 2020
    14 // Update Count     : 120
     13// Last Modified On : Wed Apr 15 10:51:01 2020
     14// Update Count     : 119
    1515//
    1616
     
    2121// Bits are numbered 1-N.
    2222
    23 //#include <assert.h>
     23#include <assert.h>
    2424
    2525#define __bitsizeof( n ) (sizeof(n) * __CHAR_BIT__)
  • libcfa/src/heap.cfa

    r692e6f1 r64cf022  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 18 08:17:53 2020
    13 // Update Count     : 716
     12// Last Modified On : Wed Apr  1 15:59:53 2020
     13// Update Count     : 692
    1414//
    1515
     
    181181                                } fake; // FakeHeader
    182182                        } kind; // Kind
    183                         size_t size;                                                            // allocation size in bytes
     183                        uint32_t dimension;                                                     // used by calloc-like to remember number of array elements
    184184                } header; // Header
    185185                char pad[libAlign() - sizeof( Header )];
     
    265265static unsigned long long int free_storage;
    266266static unsigned int free_calls;
    267 static unsigned long long int aalloc_storage;
    268 static unsigned int aalloc_calls;
    269267static unsigned long long int calloc_storage;
    270268static unsigned int calloc_calls;
    271269static unsigned long long int memalign_storage;
    272270static unsigned int memalign_calls;
    273 static unsigned long long int amemalign_storage;
    274 static unsigned int amemalign_calls;
    275271static unsigned long long int cmemalign_storage;
    276272static unsigned int cmemalign_calls;
     
    284280// Use "write" because streams may be shutdown when calls are made.
    285281static void printStats() {
    286         char helpText[1024];
     282        char helpText[512];
    287283        __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText),
    288284                                                                        "\nHeap statistics:\n"
    289285                                                                        "  malloc: calls %u / storage %llu\n"
    290                                                                         "  aalloc: calls %u / storage %llu\n"
    291286                                                                        "  calloc: calls %u / storage %llu\n"
    292287                                                                        "  memalign: calls %u / storage %llu\n"
    293                                                                         "  amemalign: calls %u / storage %llu\n"
    294288                                                                        "  cmemalign: calls %u / storage %llu\n"
    295289                                                                        "  resize: calls %u / storage %llu\n"
     
    300294                                                                        "  sbrk: calls %u / storage %llu\n",
    301295                                                                        malloc_calls, malloc_storage,
    302                                                                         aalloc_calls, calloc_storage,
    303296                                                                        calloc_calls, calloc_storage,
    304297                                                                        memalign_calls, memalign_storage,
    305                                                                         amemalign_calls, amemalign_storage,
    306298                                                                        cmemalign_calls, cmemalign_storage,
    307299                                                                        resize_calls, resize_storage,
     
    315307
    316308static int printStatsXML( FILE * stream ) {                             // see malloc_info
    317         char helpText[1024];
     309        char helpText[512];
    318310        int len = snprintf( helpText, sizeof(helpText),
    319311                                                "<malloc version=\"1\">\n"
     
    322314                                                "</sizes>\n"
    323315                                                "<total type=\"malloc\" count=\"%u\" size=\"%llu\"/>\n"
    324                                                 "<total type=\"aalloc\" count=\"%u\" size=\"%llu\"/>\n"
    325316                                                "<total type=\"calloc\" count=\"%u\" size=\"%llu\"/>\n"
    326317                                                "<total type=\"memalign\" count=\"%u\" size=\"%llu\"/>\n"
    327                                                 "<total type=\"amemalign\" count=\"%u\" size=\"%llu\"/>\n"
    328318                                                "<total type=\"cmemalign\" count=\"%u\" size=\"%llu\"/>\n"
    329319                                                "<total type=\"resize\" count=\"%u\" size=\"%llu\"/>\n"
     
    335325                                                "</malloc>",
    336326                                                malloc_calls, malloc_storage,
    337                                                 aalloc_calls, aalloc_storage,
    338327                                                calloc_calls, calloc_storage,
    339328                                                memalign_calls, memalign_storage,
    340                                                 amemalign_calls, amemalign_storage,
    341329                                                cmemalign_calls, cmemalign_storage,
    342330                                                resize_calls, resize_storage,
     
    578566        } // if
    579567
    580         block->header.size = size;                                                      // store allocation size
    581568        void * addr = &(block->data);                                           // adjust off header to user bytes
    582569
     
    747734        //assert( heapManager.heapBegin != 0 );
    748735        if ( unlikely( heapManager.heapBegin == 0p ) ) heapManager{}; // called before memory_startup ?
    749 #if __SIZEOF_POINTER__ == 8
    750         verify( size < ((typeof(size_t))1 << 48) );
    751 #endif // __SIZEOF_POINTER__ == 8
    752736        void * addr = doMalloc( size );
    753737        if ( unlikely( addr == 0p ) ) errno = ENOMEM;           // POSIX
     
    756740
    757741
    758 static inline void * callocNoStats( size_t dim, size_t elemSize ) {
    759         size_t size = dim * elemSize;
     742static inline void * callocNoStats( size_t noOfElems, size_t elemSize ) {
     743        size_t size = noOfElems * elemSize;
    760744        char * addr = (char *)mallocNoStats( size );
    761745  if ( unlikely( addr == 0p ) ) return 0p;
     
    774758                memset( addr, '\0', bsize - sizeof(HeapManager.Storage) ); // set to zeros
    775759
     760        assert( noOfElems <= UINT32_MAX );
     761        header->dimension = noOfElems;                                          // store number of array elements
    776762        header->kind.real.blockSize |= 2;                                       // mark as zero filled
    777763        return addr;
     
    815801
    816802
    817 static inline void * cmemalignNoStats( size_t alignment, size_t dim, size_t elemSize ) {
    818         size_t size = dim * elemSize;
     803static inline void * cmemalignNoStats( size_t alignment, size_t noOfElems, size_t elemSize ) {
     804        size_t size = noOfElems * elemSize;
    819805        char * addr = (char *)memalignNoStats( alignment, size );
    820806  if ( unlikely( addr == 0p ) ) return 0p;
     
    829815                memset( addr, '\0', dataStorage( bsize, addr, header ) ); // set to zeros
    830816
     817        assert( noOfElems <= UINT32_MAX );
     818        header->dimension = noOfElems;                                          // store initial array size
    831819        header->kind.real.blockSize |= 2;                                       // mark as zero filled
    832820        return addr;
     
    855843        } // malloc
    856844
    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 ) {
    883849                #ifdef __STATISTICS__
    884850                __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 );
    889855        } // calloc
    890856
     
    908874                size_t bsize, oalign = 0;
    909875                headers( "resize", oaddr, header, freeElem, bsize, oalign );
    910 
    911876                size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket
     877
    912878                // same size, DO NOT preserve STICKY PROPERTIES.
    913           if ( oalign == 0 && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size
     879                if ( oalign == 0 && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size
    914880                        header->kind.real.blockSize &= -2;                      // no alignment and turn off 0 fill
    915881                        return oaddr;
     
    985951
    986952
    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 ) {
    989955                #ifdef __STATISTICS__
    990956                __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 );
    1015961        } // cmemalign
    1016962
     
    10691015
    10701016
    1071         // Returns the alignment of an allocation.
     1017        // Returns the alignment of the allocation.
    10721018        size_t malloc_alignment( void * addr ) {
    10731019          if ( unlikely( addr == 0p ) ) return libAlign();      // minimum alignment
     
    10801026        } // malloc_alignment
    10811027
    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().
    10981030        bool malloc_zero_fill( void * addr ) {
    10991031          if ( unlikely( addr == 0p ) ) return false;           // null allocation is not zero fill
     
    11021034                        header = realHeader( header );                          // backup from fake to real header
    11031035                } // if
    1104                 return (header->kind.real.blockSize & 2) != 0;  // zero filled ?
     1036                return (header->kind.real.blockSize & 2) != 0;  // zero filled (calloc/cmemalign) ?
    11051037        } // malloc_zero_fill
    11061038
    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 ) {
    11091042          if ( unlikely( addr == 0p ) ) return false;           // null allocation is not zero fill
    11101043                HeapManager.Storage.Header * header = headerAddr( addr );
     
    11121045                        header = realHeader( header );                          // backup from fake to real header
    11131046                } // 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
    11411049
    11421050
  • libcfa/src/stdhdr/malloc.h

    r692e6f1 r64cf022  
    1010// Created On       : Thu Jul 20 15:58:16 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 16 22:44:06 2020
    13 // Update Count     : 13
     12// Last Modified On : Sun Mar  8 10:01:20 2020
     13// Update Count     : 11
    1414//
    1515
     
    3131
    3232extern "C" {
    33 void * aalloc( size_t noOfElems, size_t elemSize );
    34 void * amemalign( size_t alignment, size_t noOfElems, size_t elemSize );
    3533void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );
    3634size_t malloc_alignment( void * );
    3735bool malloc_zero_fill( void * );
    38 size_t malloc_size( void * );
     36size_t malloc_dimension( void * );
    3937int malloc_stats_fd( int fd );
    4038} // extern "C"
  • libcfa/src/stdlib.cfa

    r692e6f1 r64cf022  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 16 22:43:33 2020
    13 // Update Count     : 498
     12// Last Modified On : Tue Mar 31 13:26:46 2020
     13// Update Count     : 495
    1414//
    1515
     
    3737        } // alloc_set
    3838
    39         T * alloc_set( T ptr[], size_t dim, T fill ) {          // realloc array with fill
     39        T * alloc_set( T ptr[], size_t dim, T fill ) { // realloc array with fill
    4040                size_t olen = malloc_usable_size( ptr );                // current allocation
    4141                void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
    4242                size_t nlen = malloc_usable_size( nptr );               // new allocation
    4343                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
    4745                } // if
    4846                return (T *)nptr;
  • libcfa/src/stdlib.hfa

    r692e6f1 r64cf022  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 16 22:44:05 2020
    13 // Update Count     : 432
     12// Last Modified On : Wed Apr  1 18:38:41 2020
     13// Update Count     : 429
    1414//
    1515
     
    2525        void * memalign( size_t align, size_t size );           // malloc.h
    2626        size_t malloc_usable_size( void * ptr );                        // malloc.h
    27         size_t malloc_size( void * addr );                                      // CFA heap
    2827        void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA heap
    2928        void * memset( void * dest, int fill, size_t size ); // string.h
Note: See TracChangeset for help on using the changeset viewer.