Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit c116918

Browse files
committed
fix issue 15393 - Debug versions in GC code doesn't compile.
also fixes size in call to rt_hasFinalizerInSegment
1 parent 3228441 commit c116918

File tree

3 files changed

+63
-34
lines changed

3 files changed

+63
-34
lines changed

src/gc/impl/conservative/gc.d

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ debug (LOGGING)
172172
size_t allocdim;
173173
Log *data;
174174

175-
void Dtor() nothrow
175+
void Dtor() nothrow @nogc
176176
{
177177
if (data)
178178
cstdlib.free(data);
179179
data = null;
180180
}
181181

182-
void reserve(size_t nentries) nothrow
182+
void reserve(size_t nentries) nothrow @nogc
183183
{
184184
assert(dim <= allocdim);
185185
if (allocdim - dim < nentries)
@@ -206,20 +206,20 @@ debug (LOGGING)
206206
}
207207

208208

209-
void push(Log log) nothrow
209+
void push(Log log) nothrow @nogc
210210
{
211211
reserve(1);
212212
data[dim++] = log;
213213
}
214214

215-
void remove(size_t i) nothrow
215+
void remove(size_t i) nothrow @nogc
216216
{
217217
memmove(data + i, data + i + 1, (dim - i) * Log.sizeof);
218218
dim--;
219219
}
220220

221221

222-
size_t find(void *p) nothrow
222+
size_t find(void *p) nothrow @nogc
223223
{
224224
for (size_t i = 0; i < dim; i++)
225225
{
@@ -230,7 +230,7 @@ debug (LOGGING)
230230
}
231231

232232

233-
void copy(LogArray *from) nothrow
233+
void copy(LogArray *from) nothrow @nogc
234234
{
235235
reserve(from.dim - dim);
236236
assert(from.dim <= allocdim);
@@ -652,12 +652,11 @@ class ConservativeGC : GC
652652
auto lpool = cast(LargeObjectPool*) pool;
653653
auto paligned = cast(void*)(cast(size_t)p & ~(PAGESIZE - 1)); // abused by std.file.readImpl
654654
auto psz = lpool.getPages(paligned); // get allocated size
655+
psize = psz * PAGESIZE;
655656

656657
if (size <= PAGESIZE / 2)
657-
{
658-
psize = psz * PAGESIZE;
659658
goto Lmalloc; // switching from large object pool to small object pool
660-
}
659+
661660
auto newsz = lpool.numPages(size);
662661
if (newsz == psz)
663662
{
@@ -1323,8 +1322,8 @@ struct Gcx
13231322
Treap!Root roots;
13241323
Treap!Range ranges;
13251324

1326-
bool log; // turn on logging
13271325
debug(INVARIANT) bool initialized;
1326+
debug(INVARIANT) bool inCollection;
13281327
uint disabled; // turn off collections if >0
13291328

13301329
import gc.pooltable;
@@ -1427,14 +1426,16 @@ struct Gcx
14271426
//printf("Gcx.invariant(): this = %p\n", &this);
14281427
pooltable.Invariant();
14291428

1430-
rangesLock.lock();
1429+
if (!inCollection)
1430+
(cast()rangesLock).lock();
14311431
foreach (range; ranges)
14321432
{
14331433
assert(range.pbot);
14341434
assert(range.ptop);
14351435
assert(range.pbot <= range.ptop);
14361436
}
1437-
rangesLock.unlock();
1437+
if (!inCollection)
1438+
(cast()rangesLock).unlock();
14381439

14391440
for (size_t i = 0; i < B_NUMSMALL; i++)
14401441
{
@@ -2404,8 +2405,10 @@ struct Gcx
24042405
// lock roots and ranges around suspending threads b/c they're not reentrant safe
24052406
rangesLock.lock();
24062407
rootsLock.lock();
2408+
debug(INVARIANT) inCollection = true;
24072409
scope (exit)
24082410
{
2411+
debug(INVARIANT) inCollection = false;
24092412
rangesLock.unlock();
24102413
rootsLock.unlock();
24112414
}
@@ -2996,15 +2999,6 @@ struct Pool
29962999
debug(INVARIANT)
29973000
invariant()
29983001
{
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-
30083002
if (baseAddr)
30093003
{
30103004
//if (baseAddr + npages * PAGESIZE != topAddr)
@@ -3231,13 +3225,13 @@ struct LargeObjectPool
32313225
continue;
32323226

32333227
auto p = sentinel_add(baseAddr + pn * PAGESIZE);
3234-
size_t size = getSize(pn) - SENTINEL_EXTRA;
3228+
size_t size = sentinel_size(p, getSize(pn));
32353229
uint attr = getBits(biti);
32363230

32373231
if (!rt_hasFinalizerInSegment(p, size, attr, segment))
32383232
continue;
32393233

3240-
rt_finalizeFromGC(p, sentinel_size(p, size), attr);
3234+
rt_finalizeFromGC(p, size, attr);
32413235

32423236
clrBits(biti, ~BlkAttr.NONE);
32433237

@@ -3335,11 +3329,11 @@ struct SmallObjectPool
33353329

33363330
auto q = sentinel_add(p);
33373331
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))
33403334
continue;
33413335

3342-
rt_finalizeFromGC(q, sentinel_size(q, size), attr);
3336+
rt_finalizeFromGC(q, ssize, attr);
33433337

33443338
freeBits = true;
33453339
toFree.set(i);
@@ -3542,11 +3536,11 @@ debug (MEMSTOMP)
35423536
unittest
35433537
{
35443538
import core.memory;
3545-
auto p = cast(uint*)GC.malloc(uint.sizeof*3);
3539+
auto p = cast(uint*)GC.malloc(uint.sizeof*5);
35463540
assert(*p == 0xF0F0F0F0);
35473541
p[2] = 0; // First two will be used for free list
35483542
GC.free(p);
3549-
assert(p[2] == 0xF2F2F2F2);
3543+
assert(p[4] == 0xF2F2F2F2); // skip List usage, for both 64-bit and 32-bit
35503544
}
35513545

35523546
debug (SENTINEL)
@@ -3619,6 +3613,7 @@ unittest
36193613

36203614
// https://issues.dlang.org/show_bug.cgi?id=19281
36213615
debug (SENTINEL) {} else // cannot allow >= 4 GB with SENTINEL
3616+
debug (MEMSTOMP) {} else // might take too long to actually touch the memory
36223617
version (D_LP64) unittest
36233618
{
36243619
static if (__traits(compiles, os_physical_mem))

test/gc/Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
include ../common.mak
22

3-
TESTS := sentinel
3+
TESTS := sentinel printf memstomp invariant logging
44

5-
SRC = ../../src/gc/impl/conservative/gc.d ../../src/rt/lifetime.d
5+
SRC_GC = ../../src/gc/impl/conservative/gc.d
6+
SRC = $(SRC_GC) ../../src/rt/lifetime.d
67
# ../../src/object.d causes duplicate symbols
78
UDFLAGS = $(DFLAGS) -unittest -main
89

@@ -17,5 +18,17 @@ $(ROOT)/%.done: $(ROOT)/%
1718
$(ROOT)/sentinel: $(SRC)
1819
$(DMD) -debug=SENTINEL $(UDFLAGS) -of$@ $(SRC)
1920

21+
$(ROOT)/printf: $(SRC)
22+
$(DMD) -debug=PRINTF -debug=PRINTF_TO_FILE -debug=COLLECT_PRINTF $(UDFLAGS) -of$@ $(SRC_GC)
23+
24+
$(ROOT)/memstomp: $(SRC)
25+
$(DMD) -debug=MEMSTOMP $(UDFLAGS) -of$@ $(SRC)
26+
27+
$(ROOT)/invariant: $(SRC)
28+
$(DMD) -debug -debug=INVARIANT -debug=PTRCHECK -debug=PTRCHECK2 $(UDFLAGS) -of$@ $(SRC)
29+
30+
$(ROOT)/logging: $(SRC)
31+
$(DMD) -debug=LOGGING $(UDFLAGS) -of$@ $(SRC)
32+
2033
clean:
2134
rm -rf $(ROOT)

test/gc/win64.mak

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,33 @@ DMD=dmd
44
MODEL=64
55
DRUNTIMELIB=druntime64.lib
66

7-
SRC = src/gc/impl/conservative/gc.d src/rt/lifetime.d src/object.d
7+
SRC_GC = src/gc/impl/conservative/gc.d
8+
SRC = $(SRC_GC) src/rt/lifetime.d src/object.d
89
UDFLAGS = -m$(MODEL) -g -unittest -conf= -Isrc -defaultlib=$(DRUNTIMELIB) -main
910

10-
test: sentinel
11+
test: sentinel printf memstomp invariant logging
1112

1213
sentinel:
1314
$(DMD) -debug=SENTINEL $(UDFLAGS) -of$@.exe $(SRC)
14-
$@.exe
15-
del $@.exe $@.obj
15+
.\$@.exe
16+
del $@.exe $@.obj $@.ilk $@.pdb
17+
18+
printf:
19+
$(DMD) -debug=PRINTF -debug=PRINTF_TO_FILE -debug=COLLECT_PRINTF $(UDFLAGS) -of$@.exe $(SRC_GC)
20+
.\$@.exe
21+
del $@.exe $@.obj $@.ilk $@.pdb gcx.log
22+
23+
memstomp:
24+
$(DMD) -debug=MEMSTOMP $(UDFLAGS) -of$@.exe $(SRC)
25+
.\$@.exe
26+
del $@.exe $@.obj $@.ilk $@.pdb
27+
28+
invariant:
29+
$(DMD) -debug -debug=INVARIANT -debug=PTRCHECK -debug=PTRCHECK2 $(UDFLAGS) -of$@.exe $(SRC)
30+
.\$@.exe
31+
del $@.exe $@.obj $@.ilk $@.pdb
32+
33+
logging:
34+
$(DMD) -debug=LOGGING $(UDFLAGS) -of$@.exe $(SRC)
35+
.\$@.exe
36+
del $@.exe $@.obj $@.ilk $@.pdb

0 commit comments

Comments
 (0)