@@ -172,14 +172,14 @@ debug (LOGGING)
172
172
size_t allocdim;
173
173
Log * data;
174
174
175
- void Dtor () nothrow
175
+ void Dtor () nothrow @nogc
176
176
{
177
177
if (data)
178
178
cstdlib.free(data);
179
179
data = null ;
180
180
}
181
181
182
- void reserve (size_t nentries) nothrow
182
+ void reserve (size_t nentries) nothrow @nogc
183
183
{
184
184
assert (dim <= allocdim);
185
185
if (allocdim - dim < nentries)
@@ -206,20 +206,20 @@ debug (LOGGING)
206
206
}
207
207
208
208
209
- void push (Log log) nothrow
209
+ void push (Log log) nothrow @nogc
210
210
{
211
211
reserve (1 );
212
212
data[dim++ ] = log;
213
213
}
214
214
215
- void remove (size_t i) nothrow
215
+ void remove (size_t i) nothrow @nogc
216
216
{
217
217
memmove(data + i, data + i + 1 , (dim - i) * Log .sizeof);
218
218
dim-- ;
219
219
}
220
220
221
221
222
- size_t find (void * p) nothrow
222
+ size_t find (void * p) nothrow @nogc
223
223
{
224
224
for (size_t i = 0 ; i < dim; i++ )
225
225
{
@@ -230,7 +230,7 @@ debug (LOGGING)
230
230
}
231
231
232
232
233
- void copy (LogArray * from) nothrow
233
+ void copy (LogArray * from) nothrow @nogc
234
234
{
235
235
reserve (from.dim - dim);
236
236
assert (from.dim <= allocdim);
@@ -652,12 +652,11 @@ class ConservativeGC : GC
652
652
auto lpool = cast (LargeObjectPool* ) pool;
653
653
auto paligned = cast (void * )(cast (size_t )p & ~ (PAGESIZE - 1 )); // abused by std.file.readImpl
654
654
auto psz = lpool.getPages(paligned); // get allocated size
655
+ psize = psz * PAGESIZE ;
655
656
656
657
if (size <= PAGESIZE / 2 )
657
- {
658
- psize = psz * PAGESIZE ;
659
658
goto Lmalloc; // switching from large object pool to small object pool
660
- }
659
+
661
660
auto newsz = lpool.numPages(size);
662
661
if (newsz == psz)
663
662
{
@@ -1323,8 +1322,8 @@ struct Gcx
1323
1322
Treap! Root roots;
1324
1323
Treap! Range ranges;
1325
1324
1326
- bool log; // turn on logging
1327
1325
debug (INVARIANT ) bool initialized;
1326
+ debug (INVARIANT ) bool inCollection;
1328
1327
uint disabled; // turn off collections if >0
1329
1328
1330
1329
import gc.pooltable;
@@ -1427,14 +1426,16 @@ struct Gcx
1427
1426
// printf("Gcx.invariant(): this = %p\n", &this);
1428
1427
pooltable.Invariant();
1429
1428
1430
- rangesLock.lock();
1429
+ if (! inCollection)
1430
+ (cast ()rangesLock).lock();
1431
1431
foreach (range; ranges)
1432
1432
{
1433
1433
assert (range.pbot);
1434
1434
assert (range.ptop);
1435
1435
assert (range.pbot <= range.ptop);
1436
1436
}
1437
- rangesLock.unlock();
1437
+ if (! inCollection)
1438
+ (cast ()rangesLock).unlock();
1438
1439
1439
1440
for (size_t i = 0 ; i < B_NUMSMALL ; i++ )
1440
1441
{
@@ -2404,8 +2405,10 @@ struct Gcx
2404
2405
// lock roots and ranges around suspending threads b/c they're not reentrant safe
2405
2406
rangesLock.lock();
2406
2407
rootsLock.lock();
2408
+ debug (INVARIANT ) inCollection = true ;
2407
2409
scope (exit)
2408
2410
{
2411
+ debug (INVARIANT ) inCollection = false ;
2409
2412
rangesLock.unlock();
2410
2413
rootsLock.unlock();
2411
2414
}
@@ -2996,15 +2999,6 @@ struct Pool
2996
2999
debug (INVARIANT )
2997
3000
invariant ()
2998
3001
{
2999
- // mark.Invariant();
3000
- // scan.Invariant();
3001
- // freebits.Invariant();
3002
- // finals.Invariant();
3003
- // structFinals.Invariant();
3004
- // noscan.Invariant();
3005
- // appendable.Invariant();
3006
- // nointerior.Invariant();
3007
-
3008
3002
if (baseAddr)
3009
3003
{
3010
3004
// if (baseAddr + npages * PAGESIZE != topAddr)
@@ -3231,13 +3225,13 @@ struct LargeObjectPool
3231
3225
continue ;
3232
3226
3233
3227
auto p = sentinel_add(baseAddr + pn * PAGESIZE );
3234
- size_t size = getSize(pn) - SENTINEL_EXTRA ;
3228
+ size_t size = sentinel_size(p, getSize(pn)) ;
3235
3229
uint attr = getBits(biti);
3236
3230
3237
3231
if (! rt_hasFinalizerInSegment(p, size, attr, segment))
3238
3232
continue ;
3239
3233
3240
- rt_finalizeFromGC(p, sentinel_size (p, size) , attr);
3234
+ rt_finalizeFromGC(p, size, attr);
3241
3235
3242
3236
clrBits(biti, ~ BlkAttr.NONE );
3243
3237
@@ -3335,11 +3329,11 @@ struct SmallObjectPool
3335
3329
3336
3330
auto q = sentinel_add(p);
3337
3331
uint attr = getBits(biti);
3338
-
3339
- if (! rt_hasFinalizerInSegment(q, size , attr, segment))
3332
+ const ssize = sentinel_size(q, size);
3333
+ if (! rt_hasFinalizerInSegment(q, ssize , attr, segment))
3340
3334
continue ;
3341
3335
3342
- rt_finalizeFromGC(q, sentinel_size (q, size) , attr);
3336
+ rt_finalizeFromGC(q, ssize , attr);
3343
3337
3344
3338
freeBits = true ;
3345
3339
toFree.set(i);
@@ -3542,11 +3536,11 @@ debug (MEMSTOMP)
3542
3536
unittest
3543
3537
{
3544
3538
import core.memory ;
3545
- auto p = cast (uint * )GC .malloc(uint .sizeof* 3 );
3539
+ auto p = cast (uint * )GC .malloc(uint .sizeof* 5 );
3546
3540
assert (* p == 0xF0F0F0F0 );
3547
3541
p[2 ] = 0 ; // First two will be used for free list
3548
3542
GC .free(p);
3549
- assert (p[2 ] == 0xF2F2F2F2 );
3543
+ assert (p[4 ] == 0xF2F2F2F2 ); // skip List usage, for both 64-bit and 32-bit
3550
3544
}
3551
3545
3552
3546
debug (SENTINEL )
@@ -3619,6 +3613,7 @@ unittest
3619
3613
3620
3614
// https://issues.dlang.org/show_bug.cgi?id=19281
3621
3615
debug (SENTINEL ) {} else // cannot allow >= 4 GB with SENTINEL
3616
+ debug (MEMSTOMP ) {} else // might take too long to actually touch the memory
3622
3617
version (D_LP64 ) unittest
3623
3618
{
3624
3619
static if (__traits(compiles, os_physical_mem))
0 commit comments