@@ -263,7 +263,7 @@ void fxCheckCStack(txMachine* the)
263263 }
264264}
265265
266- void fxCollect (txMachine * the , txBoolean theFlag )
266+ void fxCollect (txMachine * the , txFlag theFlag )
267267{
268268 txSize aCount ;
269269 txSlot * freeSlot ;
@@ -275,8 +275,9 @@ void fxCollect(txMachine* the, txBoolean theFlag)
275275 the -> collectFlag |= XS_SKIPPED_COLLECT_FLAG ;
276276 return ;
277277 }
278+ the -> collectFlag |= theFlag & XS_ORGANIC_FLAG ;
278279
279- if (theFlag ) {
280+ if (theFlag & XS_COMPACT_FLAG ) {
280281 fxMark (the , fxMarkValue );
281282 fxMarkWeakStuff (the );
282283 fxSweep (the );
@@ -347,6 +348,7 @@ void fxCollect(txMachine* the, txBoolean theFlag)
347348 else
348349 the -> collectFlag &= ~XS_TRASHING_FLAG ;
349350 }
351+ the -> collectFlag &= ~XS_ORGANIC_FLAG ;
350352
351353#if mxReport
352354 if (theFlag )
@@ -391,7 +393,7 @@ void* fxFindChunk(txMachine* the, txSize size, txBoolean *once)
391393#if mxStress
392394 if (fxShouldStress ()) {
393395 if (* once ) {
394- fxCollect (the , 1 );
396+ fxCollect (the , XS_COMPACT_FLAG | XS_ORGANIC_FLAG );
395397 * once = 0 ;
396398 }
397399 }
@@ -415,7 +417,7 @@ void* fxFindChunk(txMachine* the, txSize size, txBoolean *once)
415417 block = block -> nextBlock ;
416418 }
417419 if (* once ) {
418- fxCollect (the , 1 );
420+ fxCollect (the , XS_COMPACT_FLAG | XS_ORGANIC_FLAG );
419421 * once = 0 ;
420422 goto again ;
421423 }
@@ -1008,9 +1010,20 @@ void fxMarkReference(txMachine* the, txSlot* theSlot)
10081010 }
10091011 break ;
10101012 case XS_WEAK_REF_KIND :
1011- if (theSlot -> value .weakRef .target ) {
1013+ aSlot = theSlot -> value .weakRef .target ;
1014+ if (aSlot ) {
1015+ #ifdef mxSnapshot
1016+ if (the -> collectFlag & XS_ORGANIC_FLAG ) {
1017+ fxMarkReference (the , aSlot );
1018+ }
1019+ else {
1020+ theSlot -> value .weakRef .link = the -> firstWeakRefLink ;
1021+ the -> firstWeakRefLink = theSlot ;
1022+ }
1023+ #else
10121024 theSlot -> value .weakRef .link = the -> firstWeakRefLink ;
10131025 the -> firstWeakRefLink = theSlot ;
1026+ #endif
10141027 }
10151028 break ;
10161029 case XS_FINALIZATION_REGISTRY_KIND :
@@ -1250,9 +1263,20 @@ void fxMarkValue(txMachine* the, txSlot* theSlot)
12501263 }
12511264 break ;
12521265 case XS_WEAK_REF_KIND :
1253- if (theSlot -> value .weakRef .target ) {
1266+ aSlot = theSlot -> value .weakRef .target ;
1267+ if (aSlot ) {
1268+ #ifdef mxSnapshot
1269+ if (the -> collectFlag & XS_ORGANIC_FLAG ) {
1270+ fxMarkValue (the , aSlot );
1271+ }
1272+ else {
1273+ theSlot -> value .weakRef .link = the -> firstWeakRefLink ;
1274+ the -> firstWeakRefLink = theSlot ;
1275+ }
1276+ #else
12541277 theSlot -> value .weakRef .link = the -> firstWeakRefLink ;
12551278 the -> firstWeakRefLink = theSlot ;
1279+ #endif
12561280 }
12571281 break ;
12581282 case XS_FINALIZATION_REGISTRY_KIND :
@@ -1406,7 +1430,7 @@ txSlot* fxNewSlot(txMachine* the)
14061430
14071431#if mxStress
14081432 if (fxShouldStress ()) {
1409- fxCollect (the , 1 );
1433+ fxCollect (the , XS_COMPACT_FLAG | XS_ORGANIC_FLAG );
14101434 once = 0 ;
14111435 }
14121436#endif
@@ -1435,7 +1459,7 @@ txSlot* fxNewSlot(txMachine* the)
14351459 if (once ) {
14361460 txBoolean wasThrashing = ((the -> collectFlag & XS_TRASHING_FLAG ) != 0 ), isThrashing ;
14371461
1438- fxCollect (the , 0 );
1462+ fxCollect (the , XS_ORGANIC_FLAG );
14391463
14401464 isThrashing = ((the -> collectFlag & XS_TRASHING_FLAG ) != 0 );
14411465 allocate = wasThrashing && isThrashing ;
0 commit comments