@@ -156,7 +156,7 @@ debug (LOGGING)
156
156
157
157
void print () nothrow
158
158
{
159
- printf(" p = %p, size = %zd , parent = %p " , p, size, parent);
159
+ printf(" p = %p, size = %lld , parent = %p " , p, cast ( ulong ) size, parent);
160
160
if (file)
161
161
{
162
162
printf(" %s(%u)" , file, line);
@@ -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,9 +230,10 @@ debug (LOGGING)
230
230
}
231
231
232
232
233
- void copy (LogArray * from) nothrow
233
+ void copy (LogArray * from) nothrow @nogc
234
234
{
235
- reserve (from.dim - dim);
235
+ if (allocdim < from.dim)
236
+ reserve (from.dim - dim);
236
237
assert (from.dim <= allocdim);
237
238
memcpy(data, from.data, from.dim * Log .sizeof);
238
239
dim = from.dim;
@@ -652,12 +653,11 @@ class ConservativeGC : GC
652
653
auto lpool = cast (LargeObjectPool* ) pool;
653
654
auto paligned = cast (void * )(cast (size_t )p & ~ (PAGESIZE - 1 )); // abused by std.file.readImpl
654
655
auto psz = lpool.getPages(paligned); // get allocated size
656
+ psize = psz * PAGESIZE ;
655
657
656
658
if (size <= PAGESIZE / 2 )
657
- {
658
- psize = psz * PAGESIZE ;
659
659
goto Lmalloc; // switching from large object pool to small object pool
660
- }
660
+
661
661
auto newsz = lpool.numPages(size);
662
662
if (newsz == psz)
663
663
{
@@ -1323,8 +1323,8 @@ struct Gcx
1323
1323
Treap! Root roots;
1324
1324
Treap! Range ranges;
1325
1325
1326
- bool log; // turn on logging
1327
1326
debug (INVARIANT ) bool initialized;
1327
+ debug (INVARIANT ) bool inCollection;
1328
1328
uint disabled; // turn off collections if >0
1329
1329
1330
1330
import gc.pooltable;
@@ -1427,14 +1427,16 @@ struct Gcx
1427
1427
// printf("Gcx.invariant(): this = %p\n", &this);
1428
1428
pooltable.Invariant();
1429
1429
1430
- rangesLock.lock();
1430
+ if (! inCollection)
1431
+ (cast ()rangesLock).lock();
1431
1432
foreach (range; ranges)
1432
1433
{
1433
1434
assert (range.pbot);
1434
1435
assert (range.ptop);
1435
1436
assert (range.pbot <= range.ptop);
1436
1437
}
1437
- rangesLock.unlock();
1438
+ if (! inCollection)
1439
+ (cast ()rangesLock).unlock();
1438
1440
1439
1441
for (size_t i = 0 ; i < B_NUMSMALL ; i++ )
1440
1442
{
@@ -2404,8 +2406,10 @@ struct Gcx
2404
2406
// lock roots and ranges around suspending threads b/c they're not reentrant safe
2405
2407
rangesLock.lock();
2406
2408
rootsLock.lock();
2409
+ debug (INVARIANT ) inCollection = true ;
2407
2410
scope (exit)
2408
2411
{
2412
+ debug (INVARIANT ) inCollection = false ;
2409
2413
rangesLock.unlock();
2410
2414
rootsLock.unlock();
2411
2415
}
@@ -2996,15 +3000,6 @@ struct Pool
2996
3000
debug (INVARIANT )
2997
3001
invariant ()
2998
3002
{
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
3003
if (baseAddr)
3009
3004
{
3010
3005
// if (baseAddr + npages * PAGESIZE != topAddr)
@@ -3231,13 +3226,13 @@ struct LargeObjectPool
3231
3226
continue ;
3232
3227
3233
3228
auto p = sentinel_add(baseAddr + pn * PAGESIZE );
3234
- size_t size = getSize(pn) - SENTINEL_EXTRA ;
3229
+ size_t size = sentinel_size(p, getSize(pn)) ;
3235
3230
uint attr = getBits(biti);
3236
3231
3237
3232
if (! rt_hasFinalizerInSegment(p, size, attr, segment))
3238
3233
continue ;
3239
3234
3240
- rt_finalizeFromGC(p, sentinel_size (p, size) , attr);
3235
+ rt_finalizeFromGC(p, size, attr);
3241
3236
3242
3237
clrBits(biti, ~ BlkAttr.NONE );
3243
3238
@@ -3335,11 +3330,11 @@ struct SmallObjectPool
3335
3330
3336
3331
auto q = sentinel_add(p);
3337
3332
uint attr = getBits(biti);
3338
-
3339
- if (! rt_hasFinalizerInSegment(q, size , attr, segment))
3333
+ const ssize = sentinel_size(q, size);
3334
+ if (! rt_hasFinalizerInSegment(q, ssize , attr, segment))
3340
3335
continue ;
3341
3336
3342
- rt_finalizeFromGC(q, sentinel_size (q, size) , attr);
3337
+ rt_finalizeFromGC(q, ssize , attr);
3343
3338
3344
3339
freeBits = true ;
3345
3340
toFree.set(i);
@@ -3542,11 +3537,11 @@ debug (MEMSTOMP)
3542
3537
unittest
3543
3538
{
3544
3539
import core.memory ;
3545
- auto p = cast (uint * )GC .malloc(uint .sizeof* 3 );
3540
+ auto p = cast (uint * )GC .malloc(uint .sizeof* 5 );
3546
3541
assert (* p == 0xF0F0F0F0 );
3547
3542
p[2 ] = 0 ; // First two will be used for free list
3548
3543
GC .free(p);
3549
- assert (p[2 ] == 0xF2F2F2F2 );
3544
+ assert (p[4 ] == 0xF2F2F2F2 ); // skip List usage, for both 64-bit and 32-bit
3550
3545
}
3551
3546
3552
3547
debug (SENTINEL )
@@ -3619,6 +3614,7 @@ unittest
3619
3614
3620
3615
// https://issues.dlang.org/show_bug.cgi?id=19281
3621
3616
debug (SENTINEL ) {} else // cannot allow >= 4 GB with SENTINEL
3617
+ debug (MEMSTOMP ) {} else // might take too long to actually touch the memory
3622
3618
version (D_LP64 ) unittest
3623
3619
{
3624
3620
static if (__traits(compiles, os_physical_mem))
0 commit comments