Changeset 7b0e8b7
- Timestamp:
- Oct 18, 2021, 4:31:04 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 6f7aff3
- Parents:
- 804bf677
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/string_res.cfa
r804bf677 r7b0e8b7 44 44 45 45 static inline void compaction( VbyteHeap & ); // compaction of the byte area 46 static inline void garbage( VbyteHeap & ); // garbage collect the byte area46 static inline void garbage( VbyteHeap &, int ); // garbage collect the byte area 47 47 static inline void extend( VbyteHeap &, int ); // extend the size of the byte area 48 48 static inline void reduce( VbyteHeap &, int ); // reduce the size of the byte area … … 179 179 } 180 180 181 size_t DEBUG_string_bytes_in_heap( VbyteHeap * heap ) { 182 return heap->CurrSize; 183 } 184 181 185 const char * DEBUG_string_heap_start( VbyteHeap * heap ) { 182 186 return heap->StartVbyte; 183 187 } 184 185 188 186 189 // Returns the size of the string in bytes … … 759 762 NoBytes = ( uintptr_t )EndVbyte + size; 760 763 if ( NoBytes > ( uintptr_t )ExtVbyte ) { // enough room for new byte-string ? 761 garbage( this ); // firer up the garbage collector764 garbage( this, size ); // firer up the garbage collector 762 765 NoBytes = ( uintptr_t )EndVbyte + size; // try again 763 766 if ( NoBytes > ( uintptr_t )ExtVbyte ) { // enough room for new byte-string ? 764 // unimplemented feature - assert, not verify 765 assert( 0 && "need to implement actual growth" ); 766 // extend( size ); // extend the byte-string area 767 assert( 0 && "garbage run did not free up required space" ); 767 768 } // if 768 769 } // if … … 925 926 // the heap. The heap is then compacted in the existing heap or into the newly allocated heap. 926 927 927 void garbage(VbyteHeap & this ) with(this) {928 void garbage(VbyteHeap & this, int minreq ) with(this) { 928 929 #ifdef VbyteDebug 929 930 serr | "enter:garbage"; … … 949 950 AmountFree = ( uintptr_t )ExtVbyte - ( uintptr_t )StartVbyte - AmountUsed; 950 951 951 if ( AmountFree < ( int )( CurrSize * 0.1 )) { // free space less than 10% ? 952 953 // unimplemented feature - assert, not verify 954 assert( 0 && "need to implement actual growth" ); 955 // extend( CurrSize ); // extend the heap 952 if ( ( double ) AmountFree < ( CurrSize * 0.1 ) || AmountFree < minreq ) { // free space less than 10% or not enough to serve cur request 953 954 extend( this, max( CurrSize, minreq ) ); // extend the heap 956 955 957 956 // Peter says, "This needs work before it should be used." … … 980 979 #undef VbyteDebug 981 980 982 //WIP983 #if 0984 981 985 982 … … 987 984 // area is deleted. 988 985 989 void VbyteHeap::extend( int size) {986 void extend( VbyteHeap & this, int size ) with (this) { 990 987 #ifdef VbyteDebug 991 988 serr | "enter:extend, size:" | size; … … 997 994 998 995 CurrSize += size > InitSize ? size : InitSize; // minimum extension, initial size 999 StartVbyte = EndVbyte = new char[CurrSize];996 StartVbyte = EndVbyte = alloc(CurrSize); 1000 997 ExtVbyte = (void *)( StartVbyte + CurrSize ); 1001 compaction( ); // copy from old heap to new & adjust pointers to new heap1002 delete OldStartVbyte; // release old heap998 compaction(this); // copy from old heap to new & adjust pointers to new heap 999 free( OldStartVbyte ); // release old heap 1003 1000 #ifdef VbyteDebug 1004 1001 serr | "exit:extend, CurrSize:" | CurrSize; … … 1006 1003 } // extend 1007 1004 1005 //WIP 1006 #if 0 1008 1007 1009 1008 // Extend the size of the byte-string area by creating a new area and copying the old area into it. The old byte-string -
libcfa/src/containers/string_res.hfa
r804bf677 r7b0e8b7 34 34 35 35 VbyteHeap * DEBUG_string_heap(); 36 size_t DEBUG_string_bytes_in_heap( VbyteHeap * heap ); 36 37 size_t DEBUG_string_bytes_avail_until_gc( VbyteHeap * heap ); 37 38 const char * DEBUG_string_heap_start( VbyteHeap * heap ); -
tests/collections/.expect/string-ctx-manage.txt
r804bf677 r7b0e8b7 4 4 bye 5 5 hi 6 bye 6 7 done -
tests/collections/.expect/string-gc.txt
r804bf677 r7b0e8b7 38 38 x from 5 to 15 39 39 y from 5 to 15 40 ======================== fillNoCompact 41 about to expand, a = aaa 42 expanded, a = aaa 43 about to expand, a = aaa 44 expanded, a = aaa 45 about to expand, a = aaa 46 expanded, a = aaa 47 about to expand, a = aaa 48 expanded, a = aaa 49 about to expand, a = aaa 50 expanded, a = aaa -
tests/collections/string-ctx-manage.cfa
r804bf677 r7b0e8b7 36 36 string y = x; // y allocates into private pad, implying eager copy 37 37 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 38 39 sout | y; // hi 39 40 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 47 46 } 48 47 -
tests/collections/string-gc.cfa
r804bf677 r7b0e8b7 120 120 } 121 121 122 void 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 122 149 int main() { 123 150 basicFillCompact(); 124 151 fillCompact_withSharedEdits(); 152 fillNoCompact(); 125 153 }
Note: See TracChangeset
for help on using the changeset viewer.