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

Commit

Permalink
Removed the STRUCT_FINALIZE block attribute. Also fixed an issue in m…
Browse files Browse the repository at this point in the history
…y initial implementation of the type info being moved to the end of the page.
  • Loading branch information
Orvid committed Dec 12, 2014
1 parent 800f100 commit 86beca0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 55 deletions.
1 change: 0 additions & 1 deletion src/core/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ struct GC
and is only implemented for data structures at least a page in size.
*/
NO_INTERIOR = 0b0001_0000,
STRUCT_FINALIZE = 0b0010_0000, /// Finalize the struct data in this block on collect.
}


Expand Down
91 changes: 46 additions & 45 deletions src/gc/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,12 @@ class GC
alloc_size = size;
}
gcx.log_malloc(p, size);

if (bits)
{
if (ti)
gcx.setBits(pool, cast(size_t)(sentinel_sub(p) - pool.baseAddr) >> pool.shiftBy, bits, cast(StructInfo)ti.next);
else
gcx.setBits(pool, cast(size_t)(sentinel_sub(p) - pool.baseAddr) >> pool.shiftBy, bits);
}

if (ti)
gcx.setBits(pool, cast(size_t)(p - pool.baseAddr) >> pool.shiftBy, bits, cast(StructInfo)ti.next);
else
gcx.setBits(pool, cast(size_t)(p - pool.baseAddr) >> pool.shiftBy, bits);

return p;
}

Expand Down Expand Up @@ -2897,12 +2895,8 @@ struct Gcx
{
uint bits;

if (pool.finals.nbits &&
pool.finals.test(biti))
if ((pool.finals.nbits && pool.finals.test(biti)) || (pool.structFinals.nbits && pool.structFinals.test(biti)))
bits |= BlkAttr.FINALIZE;
if (pool.structFinals.nbits &&
pool.structFinals.test(biti))
biti |= BlkAttr.STRUCT_FINALIZE;
if (pool.noscan.test(biti))
bits |= BlkAttr.NO_SCAN;
if (pool.nointerior.nbits && pool.nointerior.test(biti))
Expand Down Expand Up @@ -2931,41 +2925,45 @@ struct Gcx
immutable dataIndex = 1 + (biti >> GCBits.BITS_SHIFT);
immutable bitOffset = biti & GCBits.BITS_MASK;
immutable orWith = GCBits.BITS_1 << bitOffset;

if (mask & BlkAttr.FINALIZE)
{
if (!pool.finals.nbits)
pool.finals.alloc(pool.mark.nbits);
pool.finals.data[dataIndex] |= orWith;
}
else if (mask & BlkAttr.STRUCT_FINALIZE)

if (inf !is null && inf.xdtor !is null)
{
if (!pool.structFinals.nbits)
{
pool.structFinals.alloc(pool.mark.nbits);
}
pool.structFinals.data[dataIndex] |= orWith;
}
if (mask & BlkAttr.NO_SCAN)
{
pool.noscan.data[dataIndex] |= orWith;
}
// if (mask & BlkAttr.NO_MOVE)
// {
// if (!pool.nomove.nbits)
// pool.nomove.alloc(pool.mark.nbits);
// pool.nomove.data[dataIndex] |= orWith;
// }
if (mask & BlkAttr.APPENDABLE)
{
pool.appendable.data[dataIndex] |= orWith;
mask &= ~BlkAttr.FINALIZE; // prevent from setting normal finalize attribute.
}

if (pool.isLargeObject && (mask & BlkAttr.NO_INTERIOR))
if (mask)
{
if(!pool.nointerior.nbits)
pool.nointerior.alloc(pool.mark.nbits);
pool.nointerior.data[dataIndex] |= orWith;
if (mask & BlkAttr.FINALIZE)
{
if (!pool.finals.nbits)
pool.finals.alloc(pool.mark.nbits);
pool.finals.data[dataIndex] |= orWith;
}

if (mask & BlkAttr.NO_SCAN)
{
pool.noscan.data[dataIndex] |= orWith;
}
// if (mask & BlkAttr.NO_MOVE)
// {
// if (!pool.nomove.nbits)
// pool.nomove.alloc(pool.mark.nbits);
// pool.nomove.data[dataIndex] |= orWith;
// }
if (mask & BlkAttr.APPENDABLE)
{
pool.appendable.data[dataIndex] |= orWith;
}

if (pool.isLargeObject && (mask & BlkAttr.NO_INTERIOR))
{
if(!pool.nointerior.nbits)
pool.nointerior.alloc(pool.mark.nbits);
pool.nointerior.data[dataIndex] |= orWith;
}
}
}

Expand All @@ -2984,10 +2982,13 @@ struct Gcx
immutable bitOffset = biti & GCBits.BITS_MASK;
immutable keep = ~(GCBits.BITS_1 << bitOffset);

if (mask & BlkAttr.FINALIZE && pool.finals.nbits)
pool.finals.data[dataIndex] &= keep;
if (mask & BlkAttr.STRUCT_FINALIZE && pool.structFinals.nbits)
pool.structFinals.data[dataIndex] &= keep;
if (mask & BlkAttr.FINALIZE)
{
if (pool.finals.nbits)
pool.finals.data[dataIndex] &= keep;
if (pool.structFinals.nbits)
pool.structFinals.data[dataIndex] &= keep;
}
if (mask & BlkAttr.NO_SCAN)
pool.noscan.data[dataIndex] &= keep;
// if (mask & BlkAttr.NO_MOVE && pool.nomove.nbits)
Expand Down
26 changes: 17 additions & 9 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,14 @@ extern (C) void* _d_newitemT(TypeInfo ti)
{
auto size = ti.tsize; // array element size
auto baseFlags = !(ti.flags & 1) ? BlkAttr.NO_SCAN : 0;
bool needsTypeInfo = false;
if (auto si = cast(StructInfo)ti)
{
baseFlags |= si.xdtor ? BlkAttr.STRUCT_FINALIZE : 0;
size += size_t.sizeof; // Need space for the type info
if (si.xdtor !is null)
{
needsTypeInfo = true;
size += size_t.sizeof; // Need space for the type info
}
}

debug(PRINTF) printf("_d_newitemT(size = %d)\n", size);
Expand All @@ -1049,8 +1053,8 @@ extern (C) void* _d_newitemT(TypeInfo ti)
else
memset(ptr, 0, size);

if (baseFlags & BlkAttr.STRUCT_FINALIZE)
*cast(TypeInfo*)(ptr + GC.sizeOf(ptr) - size_t.sizeof) = ti;
if (needsTypeInfo)
*cast(TypeInfo*)(ptr + GC.sizeOf(ptr) - size_t.sizeof) = ti.next;

return ptr;
//}
Expand All @@ -1061,10 +1065,14 @@ extern (C) void* _d_newitemiT(TypeInfo ti)
{
auto size = ti.tsize; // array element size
auto baseFlags = !(ti.flags & 1) ? BlkAttr.NO_SCAN : 0;
bool needsTypeInfo = false;
if (auto si = cast(StructInfo)ti)
{
baseFlags |= si.xdtor ? BlkAttr.STRUCT_FINALIZE : 0;
size += size_t.sizeof; // Need space for the type info
if (si.xdtor !is null)
{
needsTypeInfo = true;
size += size_t.sizeof; // Need space for the type info
}
}

debug(PRINTF) printf("_d_newitemiT(size = %d)\n", size);
Expand All @@ -1088,8 +1096,8 @@ extern (C) void* _d_newitemiT(TypeInfo ti)
else
memcpy(ptr, q, isize);

if (baseFlags & BlkAttr.STRUCT_FINALIZE)
*cast(TypeInfo*)(ptr + GC.sizeOf(ptr) - size_t.sizeof) = ti;
if (needsTypeInfo)
*cast(TypeInfo*)(ptr + GC.sizeOf(ptr) - size_t.sizeof) = ti.next;
return ptr;
//}
}
Expand Down Expand Up @@ -1261,7 +1269,7 @@ extern (C) void rt_finalize_struct(void* p, StructInfo inf, bool resetMemory = t
{
// Mark it as finalized so that the GC doesn't attempt to
// finalize it again.
GC.clrAttr(p, BlkAttr.FINALIZE | BlkAttr.STRUCT_FINALIZE);
GC.clrAttr(p, BlkAttr.FINALIZE);
if (inf.xdtor)
inf.xdtor(p); // call destructor

Expand Down

0 comments on commit 86beca0

Please sign in to comment.