Changeset e99e43f for tests/heap.cfa


Ignore:
Timestamp:
Jan 10, 2019, 3:50:34 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
d97c3a4
Parents:
aeb8f70 (diff), 08222c7 (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.
git-author:
Aaron Moss <a3moss@…> (01/10/19 14:46:09)
git-committer:
Aaron Moss <a3moss@…> (01/10/19 15:50:34)
Message:

Merge remote-tracking branch 'plg/master' into deferred_resn

File:
1 moved

Legend:

Unmodified
Added
Removed
  • tests/heap.cfa

    raeb8f70 re99e43f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// heap.cfa --
     8//
     9// Author           : Peter A. Buhr
     10// Created On       : Tue Nov  6 17:54:56 2018
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 11 21:52:40 2018
     13// Update Count     : 18
     14//
     15
    116#include <thread.hfa>
    2 #include <kernel.hfa>                                                                           // processor
    3 #include <stdlib.hfa>                                                                           // *allocs
     17#include <kernel.hfa>                                                                   // processor
     18#include <stdlib.hfa>                                                                   // *allocs
    419#include <malloc.h>                                                                             // malloc_*
    520
     
    2237void main( Worker & ) {
    2338    enum { NoOfAllocs = 5000, NoOfMmaps = 10 };
    24     char *locns[NoOfAllocs];
     39    char * locns[NoOfAllocs];
    2540    int i;
    2641
    2742    // check alloc/free
    2843
    29     for ( int j = 0; j < 40; j += 1 ) {
    30                 for ( i = 0; i < NoOfAllocs; i += 1 ) {
     44    for ( j; 40 ) {
     45                for ( i; NoOfAllocs ) {
    3146                        locns[i] = alloc( i );
    32                         //sout | (void *)locns[i] | endl;
    33                         for ( int k = 0; k < i; k += 1 ) locns[i][k] = '\345';
    34                 } // for
    35                 //sout | (char *)sbrk(0) - start | " bytes" | endl;
    36 
    37                 for ( i = 0; i < NoOfAllocs; i += 1 ) {
    38                         //sout | (void *)locns[i] | endl;
    39                         for ( int k = 0; k < i; k += 1 ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage1" );
     47                        //sout | (void *)locns[i];
     48                        for ( k; i ) locns[i][k] = '\345';
     49                } // for
     50                //sout | (char *)sbrk(0) - start | " bytes";
     51
     52                for ( i; NoOfAllocs ) {
     53                        //sout | (void *)locns[i];
     54                        for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage1" );
    4055                        free( locns[i] );
    4156                } // for
    42                 //sout | (char *)sbrk(0) - start | " bytes" | endl;
    43 
    44                 for ( i = 0; i < NoOfAllocs; i += 1 ) {
     57                //sout | (char *)sbrk(0) - start | " bytes";
     58
     59                for ( i; NoOfAllocs ) {
    4560                        locns[i] = alloc( i );
    46                         //sout | (void *)locns[i] | endl;
    47                         for ( int k = 0; k < i; k += 1 ) locns[i][k] = '\345';
    48                 } // for
    49                 for ( i = NoOfAllocs - 1; i >=0 ; i -= 1 ) {
    50                         //sout | (void *)locns[i] | endl;
    51                         for ( int k = 0; k < i; k += 1 ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage2" );
     61                        //sout | (void *)locns[i];
     62                        for ( k; i ) locns[i][k] = '\345';
     63                } // for
     64                for ( i; NoOfAllocs - 1 -~= 0 ) {
     65                        //sout | (void *)locns[i];
     66                        for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage2" );
    5267                        free( locns[i] );
    5368                } // for
     
    5671    // check malloc/free (sbrk)
    5772
    58     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     73    for ( i; NoOfAllocs ) {
    5974                size_t s = (i + 1) * 20;
    60                 char *area = (char *)malloc( s );
     75                char * area = (char *)malloc( s );
    6176                if ( area == 0 ) abort( "malloc/free out of memory" );
    6277                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
     
    6580    } // for
    6681
    67     for ( i = 0; i < NoOfAllocs; i += 1 ) {
    68                 size_t s = i + 1;                               // +1 to make initialization simpler
     82    for ( i; NoOfAllocs ) {
     83                size_t s = i + 1;                                                               // +1 to make initialization simpler
    6984                locns[i] = (char *)malloc( s );
    7085                if ( locns[i] == 0 ) abort( "malloc/free out of memory" );
     
    7287                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    7388    } // for
    74     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     89    for ( i; NoOfAllocs ) {
    7590                size_t s = i + 1;
    7691                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
     
    8196    // check malloc/free (mmap)
    8297
    83     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    84                 size_t s = i + default_mmap_start();                            // cross over point
    85                 char *area = (char *)malloc( s );
     98    for ( i; NoOfMmaps ) {
     99                size_t s = i + default_mmap_start();                    // cross over point
     100                char * area = (char *)malloc( s );
    86101                if ( area == 0 ) abort( "malloc/free out of memory" );
    87102                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
     
    90105    } // for
    91106
    92     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    93                 size_t s = i + default_mmap_start();                            // cross over point
     107    for ( i; NoOfMmaps ) {
     108                size_t s = i + default_mmap_start();                    // cross over point
    94109                locns[i] = (char *)malloc( s );
    95110                if ( locns[i] == 0 ) abort( "malloc/free out of memory" );
     
    97112                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    98113    } // for
    99     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    100                 size_t s = i + default_mmap_start();                            // cross over point
     114    for ( i; NoOfMmaps ) {
     115                size_t s = i + default_mmap_start();                    // cross over point
    101116                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
    102117                         locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "malloc/free corrupt storage" );
     
    106121    // check calloc/free (sbrk)
    107122
    108     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     123    for ( i; NoOfAllocs ) {
    109124                size_t s = (i + 1) * 20;
    110                 char *area = (char *)calloc( 5, s );
     125                char * area = (char *)calloc( 5, s );
    111126                if ( area == 0 ) abort( "calloc/free out of memory" );
    112127                if ( area[0] != '\0' || area[s - 1] != '\0' ||
     
    118133    } // for
    119134
    120     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     135    for ( i; NoOfAllocs ) {
    121136                size_t s = i + 1;
    122137                locns[i] = (char *)calloc( 5, s );
     
    128143                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    129144    } // for
    130     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     145    for ( i; NoOfAllocs ) {
    131146                size_t s = i + 1;
    132147                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
     
    137152    // check calloc/free (mmap)
    138153
    139     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    140                 size_t s = i + default_mmap_start();                            // cross over point
    141                 char *area = (char *)calloc( 1, s );
     154    for ( i; NoOfMmaps ) {
     155                size_t s = i + default_mmap_start();                    // cross over point
     156                char * area = (char *)calloc( 1, s );
    142157                if ( area == 0 ) abort( "calloc/free out of memory" );
    143158                if ( area[0] != '\0' || area[s - 1] != '\0' ) abort( "calloc/free corrupt storage4.1" );
     
    149164    } // for
    150165
    151     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    152                 size_t s = i + default_mmap_start();                            // cross over point
     166    for ( i; NoOfMmaps ) {
     167                size_t s = i + default_mmap_start();                    // cross over point
    153168                locns[i] = (char *)calloc( 1, s );
    154169                if ( locns[i] == 0 ) abort( "calloc/free out of memory" );
     
    159174                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    160175    } // for
    161     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    162                 size_t s = i + default_mmap_start();                            // cross over point
     176    for ( i; NoOfMmaps ) {
     177                size_t s = i + default_mmap_start();                    // cross over point
    163178                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
    164179                         locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "calloc/free corrupt storage6" );
     
    170185    enum { limit = 64 * 1024 };                                                 // check alignments up to here
    171186
    172     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
    173                 //sout | alignments[a] | endl;
    174                 for ( int s = 1; s < NoOfAllocs; s += 1 ) {             // allocation of size 0 can return null
    175                         char *area = (char *)memalign( a, s );
     187        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
     188                //sout | alignments[a];
     189                for ( s; 1 ~ NoOfAllocs ) {                                             // allocation of size 0 can return null
     190                        char * area = (char *)memalign( a, s );
    176191                        if ( area == 0 ) abort( "memalign/free out of memory" );
    177                         //sout | i | " " | area | endl;
     192                        //sout | i | " " | area;
    178193                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
    179194                                abort( "memalign/free bad alignment : memalign(%d,%d) = %p", (int)a, s, area );
     
    187202    // check memalign/free (mmap)
    188203
    189     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
    190                 //sout | alignments[a] | endl;
    191                 for ( i = 1; i < NoOfMmaps; i += 1 ) {
    192                         size_t s = i + default_mmap_start();                    // cross over point
    193                         char *area = (char *)memalign( a, s );
     204        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
     205                //sout | alignments[a];
     206                for ( i; 1 ~ NoOfMmaps ) {
     207                        size_t s = i + default_mmap_start();            // cross over point
     208                        char * area = (char *)memalign( a, s );
    194209                        if ( area == 0 ) abort( "memalign/free out of memory" );
    195                         //sout | i | " " | area | endl;
     210                        //sout | i | " " | area;
    196211                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
    197212                                abort( "memalign/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)s, area );
     
    205220    // check calloc/realloc/free (sbrk)
    206221
    207     for ( i = 1; i < 10000; i += 12 ) {
     222    for ( i; 1 ~ 10_000 ~ 12 ) {
    208223                // initial N byte allocation
    209                 char *area = (char *)calloc( 5, i );
     224                char * area = (char *)calloc( 5, i );
    210225                if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
    211226                if ( area[0] != '\0' || area[i - 1] != '\0' ||
     
    214229
    215230                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    216                 for ( int s = i; s < 256 * 1024; s += 26 ) {    // start at initial memory request
     231                for ( s; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
    217232                        area = (char *)realloc( area, s );                      // attempt to reuse storage
    218233                        if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
     
    226241    // check calloc/realloc/free (mmap)
    227242
    228     for ( i = 1; i < 1000; i += 12 ) {
     243    for ( i; 1 ~ 10_000 ~ 12 ) {
    229244                // initial N byte allocation
    230                 size_t s = i + default_mmap_start();                            // cross over point
    231                 char *area = (char *)calloc( 1, s );
     245                size_t s = i + default_mmap_start();                    // cross over point
     246                char * area = (char *)calloc( 1, s );
    232247                if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
    233248                if ( area[0] != '\0' || area[s - 1] != '\0' ||
     
    236251
    237252                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    238                 for ( int r = i; r < 256 * 1024; r += 26 ) {    // start at initial memory request
    239                         area = (char *)realloc( area, r );              // attempt to reuse storage
     253                for ( r; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
     254                        area = (char *)realloc( area, r );                      // attempt to reuse storage
    240255                        if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
    241256                        if ( area[0] != '\0' || area[r - 1] != '\0' ||
     
    249264
    250265    size_t amount = 2;
    251     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
     266        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
    252267                // initial N byte allocation
    253                 char *area = (char *)memalign( a, amount );             // aligned N-byte allocation
     268                char * area = (char *)memalign( a, amount );    // aligned N-byte allocation
    254269                if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ?
    255                 //sout | alignments[a] | " " | area | endl;
     270                //sout | alignments[a] | " " | area;
    256271                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
    257272                        abort( "memalign/realloc/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)amount, area );
     
    260275
    261276                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    262                 for ( int s = amount; s < 256 * 1024; s += 1 ) { // start at initial memory request
     277                for ( s; amount ~ 256 * 1024 ) {                                // start at initial memory request
    263278                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "memalign/realloc/free corrupt storage" );
    264279                        area = (char *)realloc( area, s );                      // attempt to reuse storage
    265280                        if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ?
    266                         //sout | i | " " | area | endl;
     281                        //sout | i | " " | area;
    267282                        if ( (size_t)area % a != 0 ) {                          // check for initial alignment
    268283                                abort( "memalign/realloc/free bad alignment %p", area );
     
    275290    // check cmemalign/free
    276291
    277     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
    278                 //sout | alignments[a] | endl;
    279                 for ( int s = 1; s < limit; s += 1 ) {                  // allocation of size 0 can return null
    280                         char *area = (char *)cmemalign( a, 1, s );
     292        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
     293                //sout | alignments[a];
     294                for ( s; 1 ~ limit ) {                                                  // allocation of size 0 can return null
     295                        char * area = (char *)cmemalign( a, 1, s );
    281296                        if ( area == 0 ) abort( "cmemalign/free out of memory" );
    282                         //sout | i | " " | area | endl;
     297                        //sout | i | " " | area;
    283298                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
    284299                                abort( "cmemalign/free bad alignment : cmemalign(%d,%d) = %p", (int)a, s, area );
     
    295310
    296311    amount = 2;
    297     for ( size_t a = libAlign() + libAlign(); a <= limit; a += a ) { // generate powers of 2
     312        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
    298313                // initial N byte allocation
    299                 char *area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation
     314                char * area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation
    300315                if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ?
    301                 //sout | alignments[a] | " " | area | endl;
     316                //sout | alignments[a] | " " | area;
    302317                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
    303318                        abort( "cmemalign/realloc/free bad alignment : cmemalign(%d,%d) = %p", (int)a, (int)amount, area );
     
    309324
    310325                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    311                 for ( int s = amount; s < 256 * 1024; s += 1 ) { // start at initial memory request
     326                for ( s; amount ~ 256 * 1024 ) {                                // start at initial memory request
    312327                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "cmemalign/realloc/free corrupt storage2" );
    313328                        area = (char *)realloc( area, s );                      // attempt to reuse storage
    314329                        if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ?
    315                         //sout | i | " " | area | endl;
     330                        //sout | i | " " | area;
    316331                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
    317332                                abort( "cmemalign/realloc/free bad alignment %p", area );
     
    324339                free( area );
    325340    } // for
    326         //sout | "worker" | thisTask() | "successful completion" | endl;
     341        //sout | "worker" | thisTask() | "successful completion";
    327342} // Worker main
    328343
     
    339354// Local Variables: //
    340355// tab-width: 4 //
    341 // compile-command: "cfa -nodebug -O2 heap.c" //
     356// compile-command: "cfa -nodebug -O2 heap.cfa" //
    342357// End: //
Note: See TracChangeset for help on using the changeset viewer.