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

Commit

Permalink
add TypeInfo to GC calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed Jun 1, 2014
1 parent e8edc64 commit 3aa65ef
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 83 deletions.
49 changes: 31 additions & 18 deletions src/core/memory.d
Expand Up @@ -95,11 +95,11 @@ private
extern (C) uint gc_setAttr( void* p, uint a ) pure nothrow;
extern (C) uint gc_clrAttr( void* p, uint a ) pure nothrow;

extern (C) void* gc_malloc( size_t sz, uint ba = 0 ) pure nothrow;
extern (C) void* gc_calloc( size_t sz, uint ba = 0 ) pure nothrow;
extern (C) BlkInfo_ gc_qalloc( size_t sz, uint ba = 0 ) pure nothrow;
extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0 ) pure nothrow;
extern (C) size_t gc_extend( void* p, size_t mx, size_t sz ) pure nothrow;
extern (C) void* gc_malloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) void* gc_calloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) BlkInfo_ gc_qalloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) size_t gc_extend( void* p, size_t mx, size_t sz, const TypeInfo = null ) pure nothrow;
extern (C) size_t gc_reserve( size_t sz ) nothrow;
extern (C) void gc_free( void* p ) pure nothrow;

Expand All @@ -116,7 +116,7 @@ private
extern (C) BlkInfo_ gc_query( void* p ) pure nothrow;

extern (C) void gc_addRoot( in void* p ) nothrow;
extern (C) void gc_addRange( in void* p, size_t sz ) nothrow;
extern (C) void gc_addRange( in void* p, size_t sz, const TypeInfo ti = null ) nothrow;

extern (C) void gc_removeRoot( in void* p ) nothrow;
extern (C) void gc_removeRange( in void* p ) nothrow;
Expand Down Expand Up @@ -325,6 +325,8 @@ struct GC
* Params:
* sz = The desired allocation size in bytes.
* ba = A bitmask of the attributes to set on this block.
* ti = TypeInfo to describe the memory. The GC might use this information
* to improve scanning for pointers or to call finalizers.
*
* Returns:
* A reference to the allocated memory or null if insufficient memory
Expand All @@ -333,9 +335,9 @@ struct GC
* Throws:
* OutOfMemoryError on allocation failure.
*/
static void* malloc( size_t sz, uint ba = 0 ) pure nothrow
static void* malloc( size_t sz, uint ba = 0, const TypeInfo ti = null ) pure nothrow
{
return gc_malloc( sz, ba );
return gc_malloc( sz, ba, ti );
}


Expand All @@ -349,6 +351,8 @@ struct GC
* Params:
* sz = The desired allocation size in bytes.
* ba = A bitmask of the attributes to set on this block.
* ti = TypeInfo to describe the memory. The GC might use this information
* to improve scanning for pointers or to call finalizers.
*
* Returns:
* Information regarding the allocated memory block or BlkInfo.init on
Expand All @@ -357,9 +361,9 @@ struct GC
* Throws:
* OutOfMemoryError on allocation failure.
*/
static BlkInfo qalloc( size_t sz, uint ba = 0 ) pure nothrow
static BlkInfo qalloc( size_t sz, uint ba = 0, const TypeInfo ti = null ) pure nothrow
{
return gc_qalloc( sz, ba );
return gc_qalloc( sz, ba, ti );
}


Expand All @@ -374,6 +378,8 @@ struct GC
* Params:
* sz = The desired allocation size in bytes.
* ba = A bitmask of the attributes to set on this block.
* ti = TypeInfo to describe the memory. The GC might use this information
* to improve scanning for pointers or to call finalizers.
*
* Returns:
* A reference to the allocated memory or null if insufficient memory
Expand All @@ -382,9 +388,9 @@ struct GC
* Throws:
* OutOfMemoryError on allocation failure.
*/
static void* calloc( size_t sz, uint ba = 0 ) pure nothrow
static void* calloc( size_t sz, uint ba = 0, const TypeInfo ti = null ) pure nothrow
{
return gc_calloc( sz, ba );
return gc_calloc( sz, ba, ti );
}


Expand Down Expand Up @@ -412,6 +418,8 @@ struct GC
* p = A pointer to the root of a valid memory block or to null.
* sz = The desired allocation size in bytes.
* ba = A bitmask of the attributes to set on this block.
* ti = TypeInfo to describe the memory. The GC might use this information
* to improve scanning for pointers or to call finalizers.
*
* Returns:
* A reference to the allocated memory on success or null if sz is
Expand All @@ -420,9 +428,9 @@ struct GC
* Throws:
* OutOfMemoryError on allocation failure.
*/
static void* realloc( void* p, size_t sz, uint ba = 0 ) pure nothrow
static void* realloc( void* p, size_t sz, uint ba = 0, const TypeInfo ti = null ) pure nothrow
{
return gc_realloc( p, sz, ba );
return gc_realloc( p, sz, ba, ti );
}


Expand All @@ -437,6 +445,9 @@ struct GC
* p = A pointer to the root of a valid memory block or to null.
* mx = The minimum extension size in bytes.
* sz = The desired extension size in bytes.
* ti = TypeInfo to describe the full memory block. The GC might use
* this information to improve scanning for pointers or to
* call finalizers.
*
* Returns:
* The size in bytes of the extended memory block referenced by p or zero
Expand All @@ -448,9 +459,9 @@ struct GC
* as an indicator of success. $(LREF capacity) should be used to
* retrieve actual useable slice capacity.
*/
static size_t extend( void* p, size_t mx, size_t sz ) pure nothrow
static size_t extend( void* p, size_t mx, size_t sz, const TypeInfo ti = null ) pure nothrow
{
return gc_extend( p, mx, sz );
return gc_extend( p, mx, sz, ti );
}
/// Standard extending
unittest
Expand Down Expand Up @@ -685,6 +696,8 @@ struct GC
* p = A pointer to a valid memory address or to null.
* sz = The size in bytes of the block to add. If sz is zero then the
* no operation will occur. If p is null then sz must be zero.
* ti = TypeInfo to describe the memory. The GC might use this information
* to improve scanning for pointers or to call finalizers
*
* Example:
* ---
Expand All @@ -699,9 +712,9 @@ struct GC
* // rawMemory will be recognized on collection.
* ---
*/
static void addRange( in void* p, size_t sz ) nothrow /* FIXME pure */
static void addRange( in void* p, size_t sz, const TypeInfo ti = null ) nothrow /* FIXME pure */
{
gc_addRange( p, sz );
gc_addRange( p, sz, ti );
}


Expand Down
34 changes: 17 additions & 17 deletions src/gc/gc.d
Expand Up @@ -394,7 +394,7 @@ class GC
/**
*
*/
void *malloc(size_t size, uint bits = 0, size_t *alloc_size = null) nothrow
void *malloc(size_t size, uint bits = 0, size_t *alloc_size = null, const TypeInfo ti = null) nothrow
{
if (!size)
{
Expand All @@ -412,7 +412,7 @@ class GC
// when allocating.
{
gcLock.lock();
p = mallocNoSync(size, bits, alloc_size);
p = mallocNoSync(size, bits, alloc_size, ti);
gcLock.unlock();
}

Expand All @@ -428,7 +428,7 @@ class GC
//
//
//
private void *mallocNoSync(size_t size, uint bits = 0, size_t *alloc_size = null) nothrow
private void *mallocNoSync(size_t size, uint bits = 0, size_t *alloc_size = null, const TypeInfo ti = null) nothrow
{
assert(size != 0);

Expand Down Expand Up @@ -519,7 +519,7 @@ class GC
/**
*
*/
void *calloc(size_t size, uint bits = 0, size_t *alloc_size = null) nothrow
void *calloc(size_t size, uint bits = 0, size_t *alloc_size = null, const TypeInfo ti = null) nothrow
{
if (!size)
{
Expand All @@ -537,7 +537,7 @@ class GC
// when allocating.
{
gcLock.lock();
p = mallocNoSync(size, bits, alloc_size);
p = mallocNoSync(size, bits, alloc_size, ti);
gcLock.unlock();
}

Expand All @@ -553,7 +553,7 @@ class GC
/**
*
*/
void *realloc(void *p, size_t size, uint bits = 0, size_t *alloc_size = null) nothrow
void *realloc(void *p, size_t size, uint bits = 0, size_t *alloc_size = null, const TypeInfo ti = null) nothrow
{
size_t localAllocSize = void;
auto oldp = p;
Expand All @@ -564,7 +564,7 @@ class GC
// when allocating.
{
gcLock.lock();
p = reallocNoSync(p, size, bits, alloc_size);
p = reallocNoSync(p, size, bits, alloc_size, ti);
gcLock.unlock();
}

Expand All @@ -580,7 +580,7 @@ class GC
//
//
//
private void *reallocNoSync(void *p, size_t size, uint bits = 0, size_t *alloc_size = null) nothrow
private void *reallocNoSync(void *p, size_t size, uint bits = 0, size_t *alloc_size = null, const TypeInfo ti = null) nothrow
{
if (gcx.running)
onInvalidMemoryOperationError();
Expand All @@ -595,7 +595,7 @@ class GC
}
else if (!p)
{
p = mallocNoSync(size, bits, alloc_size);
p = mallocNoSync(size, bits, alloc_size, ti);
}
else
{ void *p2;
Expand Down Expand Up @@ -627,7 +627,7 @@ class GC
}
}
}
p2 = mallocNoSync(size, bits, alloc_size);
p2 = mallocNoSync(size, bits, alloc_size, ti);
if (psize < size)
size = psize;
//debug(PRINTF) printf("\tcopying %d bytes\n",size);
Expand Down Expand Up @@ -694,7 +694,7 @@ class GC
bits = gcx.getBits(pool, biti);
}
}
p2 = mallocNoSync(size, bits, alloc_size);
p2 = mallocNoSync(size, bits, alloc_size, ti);
if (psize < size)
size = psize;
//debug(PRINTF) printf("\tcopying %d bytes\n",size);
Expand All @@ -718,10 +718,10 @@ class GC
* 0 if could not extend p,
* total size of entire memory block if successful.
*/
size_t extend(void* p, size_t minsize, size_t maxsize) nothrow
size_t extend(void* p, size_t minsize, size_t maxsize, const TypeInfo ti = null) nothrow
{
gcLock.lock();
auto rc = extendNoSync(p, minsize, maxsize);
auto rc = extendNoSync(p, minsize, maxsize, ti);
gcLock.unlock();
return rc;
}
Expand All @@ -730,7 +730,7 @@ class GC
//
//
//
private size_t extendNoSync(void* p, size_t minsize, size_t maxsize) nothrow
private size_t extendNoSync(void* p, size_t minsize, size_t maxsize, const TypeInfo ti = null) nothrow
in
{
assert(minsize <= maxsize);
Expand Down Expand Up @@ -1111,7 +1111,7 @@ class GC
/**
* add range to scan for roots
*/
void addRange(void *p, size_t sz) nothrow
void addRange(void *p, size_t sz, const TypeInfo ti = null) nothrow
{
if (!p || !sz)
{
Expand All @@ -1121,7 +1121,7 @@ class GC
//debug(PRINTF) printf("+GC.addRange(p = %p, sz = 0x%zx), p + sz = %p\n", p, sz, p + sz);

gcLock.lock();
gcx.addRange(p, p + sz);
gcx.addRange(p, p + sz, ti);
gcLock.unlock();

//debug(PRINTF) printf("-GC.addRange()\n");
Expand Down Expand Up @@ -1494,7 +1494,7 @@ struct Gcx
/**
*
*/
void addRange(void *pbot, void *ptop) nothrow
void addRange(void *pbot, void *ptop, const TypeInfo ti) nothrow
{
//debug(PRINTF) printf("Thread %x ", pthread_self());
debug(PRINTF) printf("%p.Gcx::addRange(%p, %p)\n", &this, pbot, ptop);
Expand Down

0 comments on commit 3aa65ef

Please sign in to comment.