Changeset 7b0e8b7 for tests/collections


Ignore:
Timestamp:
Oct 18, 2021, 4:31:04 PM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
6f7aff3
Parents:
804bf677
Message:

String heap growth implemented

Location:
tests/collections
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tests/collections/.expect/string-ctx-manage.txt

    r804bf677 r7b0e8b7  
    44bye
    55hi
     6bye
    67done
  • tests/collections/.expect/string-gc.txt

    r804bf677 r7b0e8b7  
    3838x from 5 to 15
    3939y from 5 to 15
     40======================== fillNoCompact
     41about to expand, a = aaa
     42expanded, a = aaa
     43about to expand, a = aaa
     44expanded, a = aaa
     45about to expand, a = aaa
     46expanded, a = aaa
     47about to expand, a = aaa
     48expanded, a = aaa
     49about to expand, a = aaa
     50expanded, a = aaa
  • tests/collections/string-ctx-manage.cfa

    r804bf677 r7b0e8b7  
    3636    string y = x; // y allocates into private pad, implying eager copy
    3737    assert( y.inner->Handle.s != x.inner->Handle.s);
     38    assert( DEBUG_string_bytes_in_heap(y.inner->Handle.ulink) == y.inner->Handle.lnth );  // y is in a perfectly fitting heap
    3839    sout | y; // hi
    3940
    40     // -- following hits "need to implement actual growth"
    41     //    and it passes if I modify string_res.cfa to oversize the owned heaps
    42 
    43     // x = "bye";
    44     // y = x; // into private y => eager copy
    45     // assert( y.inner->Handle.s != x.inner->Handle.s);
    46     // sout | y; // bye
     41    x = "bye";
     42    y = x; // into private y => eager copy
     43    assert( y.inner->Handle.s != x.inner->Handle.s);
     44//    assert( DEBUG_string_bytes_in_heap(y.inner->Handle.ulink) == y.inner->Handle.lnth );  // optimization required
     45    sout | y; // bye
    4746}
    4847
  • tests/collections/string-gc.cfa

    r804bf677 r7b0e8b7  
    120120}
    121121
     122void fillNoCompact() {
     123    // show that allocating in a heap filled with mostly live strings (no collectable garbage) causes heap growth
     124
     125    sout | "======================== fillNoCompact";
     126
     127    size_t lastTimeBytesAvail = bytesRemaining();
     128    assert( lastTimeBytesAvail >= 200 ); // starting this test with nontrivial room
     129
     130    // mostly fill the pad
     131    string_res a = "aaa";  // will have to be moved
     132    string_res z = "zzz";
     133    for (i; 5) {
     134        while ( bytesRemaining() > 10 ) {
     135            z += ".";
     136        }
     137        sout | "about to expand, a = " | a;
     138        while ( bytesRemaining() <= 10 ) {
     139            z += ".";
     140        }
     141        sout | "expanded, a = " | a;
     142
     143        // each growth gives more usable space than the last
     144        assert( bytesRemaining() > lastTimeBytesAvail );
     145        lastTimeBytesAvail = bytesRemaining();
     146    }
     147}
     148
    122149int main() {
    123150    basicFillCompact();
    124151    fillCompact_withSharedEdits();
     152    fillNoCompact();
    125153}
Note: See TracChangeset for help on using the changeset viewer.