Changeset 7a70fb2 for libcfa/src


Ignore:
Timestamp:
Dec 17, 2020, 10:34:27 AM (4 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:
852ae0ea
Parents:
72a3aff (diff), 28e88d7 (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

Location:
libcfa/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/collection.hfa

    r72a3aff r7a70fb2  
    11#pragma once
     2#include <stdio.h> // REMOVE THIS AFTER DEBUGGING
     3
    24
    35struct Colable {
    4         Colable * next;                                                                         // next node in the list
     6        struct Colable * next;                                                                          // next node in the list
    57        // invariant: (next != 0) <=> listed()
    68};
    7 
    8 inline {
     9#ifdef __cforall
     10static inline {
    911        // PUBLIC
    1012
     
    2830        }
    2931
    30         // wrappers to make Collection have T
    31         forall( dtype T ) {
    32                 T *& Next( T * n ) {
    33                         return (T *)Next( (Colable *)n );
    34                 }
     32        // // wrappers to make Collection have T
     33        // forall( dtype T ) {
     34        //      T *& Next( T * n ) {
     35        //              return (T *)Next( (Colable *)n );
     36        //      }
    3537
    36                 bool listed( T * n ) {
    37                         return Next( (Colable *)n ) != 0p;
    38                 }
    39         } // distribution
     38        //      bool listed( T * n ) {
     39        //              return Next( (Colable *)n ) != 0p;
     40        //      }
     41        // } // distribution
    4042} // distribution
    4143
     
    4547};
    4648
    47 inline {
     49static inline {
    4850        // class invariant: root == 0 & empty() | *root in *this
    4951        void ?{}( Collection &, const Collection & ) = void; // no copy
     
    6870};
    6971
    70 inline {
     72static inline {
    7173        void ?{}( ColIter & colIter ) with( colIter ) {
    7274                curr = 0p;
     
    7981        } // distribution
    8082} // distribution
     83#endif
  • libcfa/src/bits/containers.hfa

    r72a3aff r7a70fb2  
    3636        #define __small_array_t(T) __small_array(T)
    3737#else
    38         #define __small_array_t(T) struct __small_array
     38        #define __small_array_t(T) __small_array
    3939#endif
    4040
  • libcfa/src/bits/defs.hfa

    r72a3aff r7a70fb2  
    2929#define __cfa_anonymous_object(x) inline struct x
    3030#else
    31 #define __cfa_anonymous_object(x) x __cfa_anonymous_object
     31#define __cfa_anonymous_object(x) struct x __cfa_anonymous_object
    3232#endif
    3333
  • libcfa/src/bits/queue.hfa

    r72a3aff r7a70fb2  
    33#include "bits/collection.hfa"
    44
    5 forall( dtype T ) {
     5forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
    66        struct Queue {
    77                inline Collection;                                                              // Plan 9 inheritance
     
    6464                        T & t = head( q );
    6565                        if ( root ) {
    66                                 root = Next( root );
     66                                root = Next( (T *)root );
    6767                                if ( &head( q ) == &t ) {
    6868                                        root = last = 0p;                                       // only one element
     
    142142} // distribution
    143143
    144 forall( dtype T ) {
     144forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
    145145        struct QueueIter {
    146146                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/bits/sequence.hfa

    r72a3aff r7a70fb2  
    22
    33#include "bits/collection.hfa"
     4#include "bits/defs.hfa"
    45
    56struct Seqable {
    6         inline Colable;
    7         Seqable * back;                                                                         // pointer to previous node in the list
     7        __cfa_anonymous_object(Colable);
     8        struct Seqable * back;                                                                          // pointer to previous node in the list
    89};
    910
    10 inline {
     11#ifdef __cforall
     12static inline {
    1113        // PUBLIC
    1214
     
    2628        }
    2729
    28         // wrappers to make Collection have T
    29         forall( dtype T ) {
    30                 T *& Back( T * n ) {
    31                         return (T *)Back( (Seqable *)n );
    32                 }
    33         } // distribution
     30        // // wrappers to make Collection have T
     31        // forall( dtype T ) {
     32        //      T *& Back( T * n ) {
     33        //              return (T *)Back( (Seqable *)n );
     34        //      }
     35        // } // distribution
    3436} // distribution
    3537
    36 forall( dtype T ) {
     38forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); bool listed ( T * ); } ) {
    3739        struct Sequence {
    3840                inline Collection;                                                              // Plan 9 inheritance
    3941        };
    4042
    41         inline {
     43        static inline {
    4244                // wrappers to make Collection have T
    4345                T & head( Sequence(T) & s ) with( s ) {
     
    184186                                T * toEnd = Back( &head( s ) );
    185187                                T * fromEnd = Back( &head( from ) );
    186                                 Back( root ) = fromEnd;
     188                                Back( (T *)root ) = fromEnd;
    187189                                Next( fromEnd ) = &head( s );
    188                                 Back( from.root ) = toEnd;
     190                                Back( (T *)from.root ) = toEnd;
    189191                                Next( toEnd ) = &head( from );
    190192                        } // if
     
    214216} // distribution
    215217
    216 forall( dtype T ) {
     218forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); bool listed ( T * ); } ) {
    217219        // SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order.
    218220        struct SeqIter {
     
    224226        };
    225227
    226         inline {
     228        static inline {
    227229                void ?{}( SeqIter(T) & si ) with( si ) {
    228230                        ((ColIter &)si){};
     
    265267        };
    266268
    267         inline {
     269        static inline {
    268270                void ?{}( SeqIterRev(T) & si ) with( si ) {     
    269271                        ((ColIter &)si){};
     
    298300        } // distribution
    299301} // distribution
     302
     303#endif
  • libcfa/src/bits/stack.hfa

    r72a3aff r7a70fb2  
    33#include "bits/collection.hfa"
    44
    5 forall( dtype T ) {
     5forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
    66        struct Stack {
    77                inline Collection;                                                              // Plan 9 inheritance
     
    4444                        T & t = head( s );
    4545                        if ( root ) {
    46                                 root = ( T *)Next( root );
     46                                root = ( T *)Next( (T *)root );
    4747                                if ( &head( s ) == &t ) root = 0p;              // only one element ?
    4848                                Next( &t ) = 0p;
     
    5858
    5959
    60 forall( dtype T ) {
     60forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
    6161        struct StackIter {
    6262                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/concurrency/coroutine.cfa

    r72a3aff r7a70fb2  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Oct 23 23:05:24 2020
    13 // Update Count     : 22
     12// Last Modified On : Tue Dec 15 12:06:04 2020
     13// Update Count     : 23
    1414//
    1515
     
    8888static const size_t MinStackSize = 1000;
    8989extern size_t __page_size;                              // architecture pagesize HACK, should go in proper runtime singleton
     90extern int __map_prot;
    9091
    9192void __stack_prepare( __stack_info_t * this, size_t create_size );
     
    206207                __cfaabi_dbg_debug_do(
    207208                        storage = (char*)(storage) - __page_size;
    208                         if ( mprotect( storage, __page_size, PROT_READ | PROT_WRITE ) == -1 ) {
     209                        if ( mprotect( storage, __page_size, __map_prot ) == -1 ) {
    209210                                abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
    210211                        }
  • libcfa/src/concurrency/invoke.h

    r72a3aff r7a70fb2  
    189189                struct __monitor_group_t monitors;
    190190
     191                // used to put threads on user data structures
     192                struct {
     193                        struct $thread * next;
     194                        struct $thread * back;
     195                } seqable;
     196
    191197                struct {
    192198                        struct $thread * next;
     
    218224                }
    219225
     226                static inline $thread *& Back( $thread * this ) __attribute__((const)) {
     227                        return this->seqable.back;
     228                }
     229
     230                static inline $thread *& Next( $thread * this ) __attribute__((const)) {
     231                        return this->seqable.next;
     232                }
     233
     234                static inline bool listed( $thread * this ) {
     235                        return this->seqable.next != 0p;
     236                }
     237
    220238                static inline void ?{}(__monitor_group_t & this) {
    221239                        (this.data){0p};
  • libcfa/src/concurrency/kernel/startup.cfa

    r72a3aff r7a70fb2  
    117117}
    118118
    119 size_t __page_size = 0;
     119extern size_t __page_size;
    120120
    121121//-----------------------------------------------------------------------------
     
    161161        /* paranoid */ verify( ! __preemption_enabled() );
    162162        __cfadbg_print_safe(runtime_core, "Kernel : Starting\n");
    163 
    164         __page_size = sysconf( _SC_PAGESIZE );
    165163
    166164        __cfa_dbg_global_clusters.list{ __get };
     
    681679        #if CFA_PROCESSOR_USE_MMAP
    682680                stacksize = ceiling( stacksize, __page_size ) + __page_size;
    683                 stack = mmap(0p, stacksize, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
     681                stack = mmap(0p, stacksize, __map_prot, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
    684682                if(stack == ((void*)-1)) {
    685683                        abort( "pthread stack creation : internal error, mmap failure, error(%d) %s.", errno, strerror( errno ) );
  • libcfa/src/concurrency/locks.cfa

    r72a3aff r7a70fb2  
    2929
    3030        void ^?{}( info_thread(L) & this ){ }
     31
     32        info_thread(L) *& Back( info_thread(L) * this ) {
     33                return (info_thread(L) *)Back( (Seqable *)this );
     34        }
     35
     36        info_thread(L) *& Next( info_thread(L) * this ) {
     37                return (info_thread(L) *)Next( (Colable *)this );
     38        }
     39
     40        bool listed( info_thread(L) * this ) {
     41                return Next( (Colable *)this ) != 0p;
     42        }
    3143}
    3244
     
    5870                abort("A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock.");
    5971        } else if ( owner != 0p && owner != active_thread() ) {
    60                 append( blocked_threads, active_thread() );
     72                addTail( blocked_threads, *active_thread() );
    6173                wait_count++;
    6274                unlock( lock );
     
    96108
    97109void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    98         $thread * t = pop_head( blocked_threads );
     110        $thread * t = &dropHead( blocked_threads );
    99111        owner = t;
    100112        recursion_count = ( t ? 1 : 0 );
     
    128140    lock( lock __cfaabi_dbg_ctx2 );
    129141        if ( owner != 0p ) {
    130                 append( blocked_threads, t );
     142                addTail( blocked_threads, *t );
    131143                wait_count++;
    132144                unlock( lock );
     
    257269                size_t recursion_count = 0;
    258270                if (i->lock) {
    259                         i->t->link.next = 1p;
    260271                        recursion_count = get_recursion_count(*i->lock);
    261272                        remove_( *i->lock );
  • libcfa/src/concurrency/locks.hfa

    r72a3aff r7a70fb2  
    4343        void ?{}( info_thread(L) & this, $thread * t, uintptr_t info );
    4444        void ^?{}( info_thread(L) & this );
     45
     46        info_thread(L) *& Back( info_thread(L) * this );
     47        info_thread(L) *& Next( info_thread(L) * this );
     48        bool listed( info_thread(L) * this );
    4549}
    4650
     
    6468
    6569        // List of blocked threads
    66         __queue_t( $thread ) blocked_threads;
     70        Sequence( $thread ) blocked_threads;
    6771
    6872        // Count of current blocked threads
  • libcfa/src/concurrency/thread.cfa

    r72a3aff r7a70fb2  
    4343                canary = 0x0D15EA5E0D15EA5Ep;
    4444        #endif
     45
     46        seqable.next = 0p;
     47        seqable.back = 0p;
    4548
    4649        node.next = 0p;
  • libcfa/src/heap.cfa

    r72a3aff r7a70fb2  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 13 22:04:10 2020
    13 // Update Count     : 984
     12// Last Modified On : Wed Dec 16 12:28:25 2020
     13// Update Count     : 1023
    1414//
    1515
    1616#include <unistd.h>                                                                             // sbrk, sysconf
     17#include <stdlib.h>                                                                             // EXIT_FAILURE
    1718#include <stdbool.h>                                                                    // true, false
    1819#include <stdio.h>                                                                              // snprintf, fileno
     
    7172        // Define the default extension heap amount in units of bytes. When the uC++ supplied heap reaches the brk address,
    7273        // the brk address is extended by the extension amount.
    73         __CFA_DEFAULT_HEAP_EXPANSION__ = (1 * 1024 * 1024),
     74        __CFA_DEFAULT_HEAP_EXPANSION__ = (10 * 1024 * 1024),
    7475
    7576        // Define the mmap crossover point during allocation. Allocations less than this amount are allocated from buckets;
     
    115116
    116117// statically allocated variables => zero filled.
    117 static size_t pageSize;                                                                 // architecture pagesize
     118size_t __page_size;                                                                             // architecture pagesize
     119int __map_prot;                                                                                 // common mmap/mprotect protection
    118120static size_t heapExpand;                                                               // sbrk advance
    119121static size_t mmapStart;                                                                // cross over point for mmap
     
    249251#endif // FASTLOOKUP
    250252
    251 static int mmapFd = -1;                                                                 // fake or actual fd for anonymous file
     253static const off_t mmapFd = -1;                                                 // fake or actual fd for anonymous file
    252254#ifdef __CFA_DEBUG__
    253255static bool heapBoot = 0;                                                               // detect recursion during boot
     
    374376
    375377static inline bool setMmapStart( size_t value ) {               // true => mmapped, false => sbrk
    376   if ( value < pageSize || bucketSizes[NoBucketSizes - 1] < value ) return false;
     378  if ( value < __page_size || bucketSizes[NoBucketSizes - 1] < value ) return false;
    377379        mmapStart = value;                                                                      // set global
    378380
     
    436438        header = headerAddr( addr );
    437439
    438   if ( unlikely( heapEnd < addr ) ) {                                   // mmapped ?
     440  if ( unlikely( addr < heapBegin || heapEnd < addr ) ) { // mmapped ?
    439441                fakeHeader( header, alignment );
    440442                size = header->kind.real.blockSize & -3;                // mmap size
     
    443445
    444446        #ifdef __CFA_DEBUG__
    445         checkHeader( addr < heapBegin, name, addr );            // bad low address ?
     447        checkHeader( header < (HeapManager.Storage.Header *)heapBegin, name, addr ); // bad low address ?
    446448        #endif // __CFA_DEBUG__
    447449
     
    482484#endif // __CFA_DEBUG__
    483485
     486
    484487#define NO_MEMORY_MSG "insufficient heap memory available for allocating %zd new bytes."
    485488
     
    490493                // If the size requested is bigger than the current remaining storage, increase the size of the heap.
    491494
    492                 size_t increase = ceiling2( size > heapExpand ? size : heapExpand, pageSize );
     495                size_t increase = ceiling2( size > heapExpand ? size : heapExpand, __page_size );
     496                // Do not call abort or strerror( errno ) as they may call malloc.
    493497                if ( sbrk( increase ) == (void *)-1 ) {                 // failed, no memory ?
    494498                        unlock( extlock );
    495                         abort( NO_MEMORY_MSG, size );                           // give up
    496                 } // if
    497                 if ( mprotect( (char *)heapEnd + heapRemaining, increase, PROT_READ | PROT_WRITE | PROT_EXEC ) ) {
    498                         enum { BufferSize = 128 };
    499                         char helpText[BufferSize];
    500                         // Do not call strerror( errno ) as it may call malloc.
    501                         int len = snprintf( helpText, BufferSize, "internal error, extend(), mprotect failure, heapEnd:%p size:%zd, errno:%d.", heapEnd, increase, errno );
    502                         __cfaabi_bits_write( STDERR_FILENO, helpText, len );
     499                        __cfaabi_bits_print_nolock( STDERR_FILENO, NO_MEMORY_MSG, size );
     500                        _exit( EXIT_FAILURE );
     501                } // if
     502                if ( mprotect( (char *)heapEnd + heapRemaining, increase, __map_prot ) ) {
     503                        unlock( extlock );
     504                        __cfaabi_bits_print_nolock( STDERR_FILENO, "extend() : internal error, mprotect failure, heapEnd:%p size:%zd, errno:%d.\n", heapEnd, increase, errno );
     505                        _exit( EXIT_FAILURE );
    503506                } // if
    504507                #ifdef __STATISTICS__
     
    508511                #ifdef __CFA_DEBUG__
    509512                // Set new memory to garbage so subsequent uninitialized usages might fail.
    510                 //memset( (char *)heapEnd + heapRemaining, '\377', increase );
    511                 Memset( (char *)heapEnd + heapRemaining, increase );
     513                memset( (char *)heapEnd + heapRemaining, '\xde', increase );
     514                //Memset( (char *)heapEnd + heapRemaining, increase );
    512515                #endif // __CFA_DEBUG__
    513516                rem = heapRemaining + increase - size;
     
    568571                block->header.kind.real.home = freeElem;                // pointer back to free list of apropriate size
    569572        } else {                                                                                        // large size => mmap
    570   if ( unlikely( size > ULONG_MAX - pageSize ) ) return 0p;
    571                 tsize = ceiling2( tsize, pageSize );                    // must be multiple of page size
     573  if ( unlikely( size > ULONG_MAX - __page_size ) ) return 0p;
     574                tsize = ceiling2( tsize, __page_size );                 // must be multiple of page size
    572575                #ifdef __STATISTICS__
    573576                __atomic_add_fetch( &mmap_calls, 1, __ATOMIC_SEQ_CST );
     
    575578                #endif // __STATISTICS__
    576579
    577                 block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 );
     580                block = (HeapManager.Storage *)mmap( 0, tsize, __map_prot, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 );
    578581                if ( block == (HeapManager.Storage *)MAP_FAILED ) { // failed ?
    579582                        if ( errno == ENOMEM ) abort( NO_MEMORY_MSG, tsize ); // no memory
     
    583586                #ifdef __CFA_DEBUG__
    584587                // Set new memory to garbage so subsequent uninitialized usages might fail.
    585                 //memset( block, '\377', tsize );
    586                 Memset( block, tsize );
     588                memset( block, '\xde', tsize );
     589                //Memset( block, tsize );
    587590                #endif // __CFA_DEBUG__
    588591                block->header.kind.real.blockSize = tsize;              // storage size for munmap
     
    624627                #endif // __STATISTICS__
    625628                if ( munmap( header, size ) == -1 ) {
    626                         #ifdef __CFA_DEBUG__
    627629                        abort( "Attempt to deallocate storage %p not allocated or with corrupt header.\n"
    628630                                   "Possible cause is invalid pointer.",
    629631                                   addr );
    630                         #endif // __CFA_DEBUG__
    631632                } // if
    632633        } else {
    633634                #ifdef __CFA_DEBUG__
    634635                // Set free memory to garbage so subsequent usages might fail.
    635                 //memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) );
    636                 Memset( ((HeapManager.Storage *)header)->data, freeElem->blockSize - sizeof( HeapManager.Storage ) );
     636                memset( ((HeapManager.Storage *)header)->data, '\xde', freeElem->blockSize - sizeof( HeapManager.Storage ) );
     637                //Memset( ((HeapManager.Storage *)header)->data, freeElem->blockSize - sizeof( HeapManager.Storage ) );
    637638                #endif // __CFA_DEBUG__
    638639
     
    703704
    704705static void ?{}( HeapManager & manager ) with( manager ) {
    705         pageSize = sysconf( _SC_PAGESIZE );
     706        __page_size = sysconf( _SC_PAGESIZE );
     707        __map_prot = PROT_READ | PROT_WRITE | PROT_EXEC;
    706708
    707709        for ( unsigned int i = 0; i < NoBucketSizes; i += 1 ) { // initialize the free lists
     
    723725
    724726        char * end = (char *)sbrk( 0 );
    725         heapBegin = heapEnd = sbrk( (char *)ceiling2( (long unsigned int)end, pageSize ) - end ); // move start of heap to multiple of alignment
     727        heapBegin = heapEnd = sbrk( (char *)ceiling2( (long unsigned int)end, __page_size ) - end ); // move start of heap to multiple of alignment
    726728} // HeapManager
    727729
     
    741743        #ifdef __CFA_DEBUG__
    742744        if ( heapBoot ) {                                                                       // check for recursion during system boot
    743                 // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
    744745                abort( "boot() : internal error, recursively invoked during system boot." );
    745746        } // if
     
    10281029        } // cmemalign
    10291030
     1031
    10301032        // Same as memalign(), but ISO/IEC 2011 C11 Section 7.22.2 states: the value of size shall be an integral multiple
    10311033    // of alignment. This requirement is universally ignored.
     
    10451047        } // posix_memalign
    10461048
     1049
    10471050        // Allocates size bytes and returns a pointer to the allocated memory. The memory address shall be a multiple of the
    10481051        // page size.  It is equivalent to memalign(sysconf(_SC_PAGESIZE),size).
    10491052        void * valloc( size_t size ) {
    1050                 return memalign( pageSize, size );
     1053                return memalign( __page_size, size );
    10511054        } // valloc
    10521055
     
    10541057        // Same as valloc but rounds size to multiple of page size.
    10551058        void * pvalloc( size_t size ) {
    1056                 return memalign( pageSize, ceiling2( size, pageSize ) );
     1059                return memalign( __page_size, ceiling2( size, __page_size ) );
    10571060        } // pvalloc
    10581061
     
    11931196                choose( option ) {
    11941197                  case M_TOP_PAD:
    1195                         heapExpand = ceiling2( value, pageSize ); return 1;
     1198                        heapExpand = ceiling2( value, __page_size ); return 1;
    11961199                  case M_MMAP_THRESHOLD:
    11971200                        if ( setMmapStart( value ) ) return 1;
Note: See TracChangeset for help on using the changeset viewer.