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

Commit

Permalink
Added _d_delstruct for use by the delete operator when deleting a poi…
Browse files Browse the repository at this point in the history
…nter to a struct. Also removed the need for a separate array of struct infos by storing the pointer to it at the end of the page for structs allocated by the GC that have finalizers.
  • Loading branch information
Orvid committed Jan 13, 2015
1 parent 3f06283 commit 621b665
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 66 deletions.
1 change: 0 additions & 1 deletion mak/SRCS
Expand Up @@ -78,7 +78,6 @@ SRCS=\
src\gc\bits.d \
src\gc\config.d \
src\gc\stats.d \
src\gc\structinfo.d \
src\gc\proxy.d \
\
src\rt\aApply.d \
Expand Down
21 changes: 5 additions & 16 deletions src/gc/gc.d
Expand Up @@ -38,7 +38,6 @@ version = STACKGROWSDOWN; // growing the stack means subtracting from the

import gc.bits;
import gc.stats;
import gc.structinfo;
import gc.os;
import gc.config;

Expand Down Expand Up @@ -1555,7 +1554,7 @@ struct Gcx

if (pool.structFinals.nbits && pool.structFinals.test(biti))
{
auto si = pool.structInfo.data[biti];
auto si = *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof);
if (!rt_hasStructFinalizerInSegment(sentinel_add(p), si, segment))
continue;
rt_finalize_struct(sentinel_add(p), si, false);
Expand Down Expand Up @@ -1613,7 +1612,7 @@ struct Gcx

if (pool.structFinals.nbits && pool.structFinals.test(biti))
{
auto si = pool.structInfo.data[biti];
auto si = *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof);
if (!rt_hasStructFinalizerInSegment(sentinel_add(p), si, segment))
continue;
rt_finalize_struct(sentinel_add(p), si, false);
Expand Down Expand Up @@ -2661,7 +2660,7 @@ struct Gcx
sentinel_Invariant(sentinel_add(p));

if (pool.structFinals.nbits && pool.structFinals.testClear(biti))
rt_finalize_struct(sentinel_add(p), pool.structInfo.data[biti], false);
rt_finalize_struct(sentinel_add(p), *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof), false);
else if (pool.finals.nbits && pool.finals.testClear(biti))
rt_finalize2(sentinel_add(p), false, false);

Expand Down Expand Up @@ -2735,7 +2734,7 @@ struct Gcx
pool.freebits.set(biti);

if (pool.structFinals.nbits && pool.structFinals.test(biti))
rt_finalize_struct(sentinel_add(p), pool.structInfo.data[biti], false);
rt_finalize_struct(sentinel_add(p), *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof), false);
else if (pool.finals.nbits && pool.finals.test(biti))
rt_finalize2(sentinel_add(p), false, false);

Expand Down Expand Up @@ -2931,10 +2930,8 @@ struct Gcx
if (!pool.structFinals.nbits)
{
pool.structFinals.alloc(pool.mark.nbits);
pool.structInfo.alloc(pool.mark.nbits);
}
pool.structFinals.data[dataIndex] |= orWith;
pool.structInfo.data[biti] = inf;
}
if (mask & BlkAttr.NO_SCAN)
{
Expand Down Expand Up @@ -2976,11 +2973,8 @@ struct Gcx

if (mask & BlkAttr.FINALIZE && pool.finals.nbits)
pool.finals.data[dataIndex] &= keep;
else if (mask & BlkAttr.STRUCT_FINALIZE && pool.structFinals.nbits)
{
if (mask & BlkAttr.STRUCT_FINALIZE && pool.structFinals.nbits)
pool.structFinals.data[dataIndex] &= keep;
pool.structInfo.data[biti] = null;
}
if (mask & BlkAttr.NO_SCAN)
pool.noscan.data[dataIndex] &= keep;
// if (mask & BlkAttr.NO_MOVE && pool.nomove.nbits)
Expand All @@ -3002,10 +2996,7 @@ struct Gcx
if (pool.finals.nbits)
pool.finals.data[dataIndex] &= toKeep;
if (pool.structFinals.nbits)
{
pool.structFinals.data[dataIndex] &= toKeep;
pool.structInfo.data[(dataIndex << GCBits.BITS_SHIFT) - 1] = null;
}

pool.noscan.data[dataIndex] &= toKeep;

Expand Down Expand Up @@ -3152,7 +3143,6 @@ struct Pool
GCBits freebits; // entries that are on the free list
GCBits finals; // entries that need finalizer run on them
GCBits structFinals;// struct entries that need a finalzier run on them
GCStructInfoArray structInfo; // struct info for struct entries
GCBits noscan; // entries that should not be scanned
GCBits appendable; // entries that are appendable
GCBits nointerior; // interior pointers should be ignored.
Expand Down Expand Up @@ -3274,7 +3264,6 @@ struct Pool
}
finals.Dtor();
structFinals.Dtor();
structInfo.Dtor();
noscan.Dtor();
appendable.Dtor();
}
Expand Down
47 changes: 0 additions & 47 deletions src/gc/structinfo.d

This file was deleted.

36 changes: 34 additions & 2 deletions src/rt/lifetime.d
Expand Up @@ -178,6 +178,20 @@ extern (C) void _d_delstruct(void** p, TypeInfo_Struct inf)
}
}

/**
*
*/
extern (C) void _d_delstruct(void** p, StructInfo inf)
{
if (*p)
{
debug(PRINTF) printf("_d_delstruct(%p, %p)\n", *p, cast(void*)inf);
rt_finalize_struct(*p, inf);
GC.free(*p);
*p = null;
}
}

/** dummy class used to lock for shared array appending */
private class ArrayAllocLengthLock
{}
Expand Down Expand Up @@ -1009,11 +1023,13 @@ extern (C) void[] _d_newarraymiT(const TypeInfo ti, size_t ndims, ...)

extern (C) void* _d_newitemT(TypeInfo ti)
{
auto size = ti.tsize; // array element size
auto size = ti.tsize; // array element size
auto baseFlags = !(ti.flags & 1) ? BlkAttr.NO_SCAN : 0;
if (auto si = cast(StructInfo)ti)
{
baseFlags |= si.xdtor ? BlkAttr.STRUCT_FINALIZE : 0;
size += size_t.sizeof; // Need space for the type info
}

debug(PRINTF) printf("_d_newitemT(size = %d)\n", size);
/* not sure if we need this...
Expand All @@ -1032,6 +1048,10 @@ extern (C) void* _d_newitemT(TypeInfo ti)
*cast(uint*)ptr = 0;
else
memset(ptr, 0, size);

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

return ptr;
//}

Expand All @@ -1042,7 +1062,10 @@ extern (C) void* _d_newitemiT(TypeInfo ti)
auto size = ti.tsize; // array element size
auto baseFlags = !(ti.flags & 1) ? BlkAttr.NO_SCAN : 0;
if (auto si = cast(StructInfo)ti)
{
baseFlags |= si.xdtor ? BlkAttr.STRUCT_FINALIZE : 0;
size += size_t.sizeof; // Need space for the type info
}

debug(PRINTF) printf("_d_newitemiT(size = %d)\n", size);

Expand All @@ -1064,6 +1087,9 @@ extern (C) void* _d_newitemiT(TypeInfo ti)
*cast(uint*)ptr = *cast(uint*)q;
else
memcpy(ptr, q, isize);

if (baseFlags & BlkAttr.STRUCT_FINALIZE)
*cast(TypeInfo*)(ptr + GC.sizeOf(ptr) - size_t.sizeof) = ti;
return ptr;
//}
}
Expand Down Expand Up @@ -1233,13 +1259,19 @@ extern (C) void rt_finalize_struct(void* p, StructInfo inf, bool resetMemory = t

try
{
// Mark it as finalized so that the GC doesn't attempt to
// finalize it again.
GC.clrAttr(p, BlkAttr.FINALIZE | BlkAttr.STRUCT_FINALIZE);
if (inf.xdtor)
inf.xdtor(p); // call destructor

if(resetMemory)
{
ubyte[] w = cast(ubyte[])inf.m_init;
(cast(ubyte*) p)[0 .. w.length] = w[];
if (w.ptr is null)
(cast(ubyte*) p)[0 .. w.length] = 0;
else
(cast(ubyte*) p)[0 .. w.length] = w[];
}
}
catch (Throwable e)
Expand Down

0 comments on commit 621b665

Please sign in to comment.