Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions include/hx/GC.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ namespace hx
// If inSize is small (<4k) it will be allocated from the immix pool.
// Larger, and it will be allocated from a separate memory pool
// inIsObject specifies whether "__Mark" should be called on the resulting object
void *InternalNew(int inSize,bool inIsObject);
void *InternalNew(size_t inSize,bool inIsObject);

// Used internall - realloc array data
void *InternalRealloc(int inFromSize, void *inData,int inSize,bool inAllowExpansion=false);
void *InternalRealloc(size_t inFromSize, void *inData,size_t inSize,bool inAllowExpansion=false);

void InternalReleaseMem(void *inMem);

unsigned int ObjectSizeSafe(void *inData);

// Const buffers are allocated outside the GC system, and do not require marking
// String buffers can optionally have a pre-computed hash appended with this method
void *InternalCreateConstBuffer(const void *inData,int inSize,bool inAddStringHash=false);
void *InternalCreateConstBuffer(const void *inData, size_t inSize, bool inAddStringHash=false);

// Called after collection by an unspecified thread
typedef void (*finalizer)(hx::Object *v);
Expand Down Expand Up @@ -197,8 +197,8 @@ char *NewString(int inLen);
// The concept of 'private' is from the old conservative Gc method.
// Now with explicit marking, these functions do the same thing, which is
// to allocate some GC memory and optionally copy the 'inData' into those bytes
HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCBytes(void *inData,int inSize);
HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCPrivate(void *inData,int inSize);
HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCBytes(void *inData,size_t inSize);
HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCPrivate(void *inData,size_t inSize);

// Force a collect from the calling thread
// Only one thread should call this at a time
Expand Down Expand Up @@ -336,24 +336,24 @@ EXTERN_FAST_TLS_DATA(StackContext, tlsStackContext);
extern StackContext *gMainThreadContext;

extern unsigned int gImmixStartFlag[128];
extern int gMarkID;
extern int gMarkIDWithContainer;
extern unsigned int gMarkID;
extern unsigned int gMarkIDWithContainer;
extern void BadImmixAlloc();


class ImmixAllocator
{
public:
virtual ~ImmixAllocator() {}
virtual void *CallAlloc(int inSize,unsigned int inObjectFlags) = 0;
virtual void *CallAlloc(size_t inSize,unsigned int inObjectFlags) = 0;
virtual void SetupStackAndCollect(bool inMajor, bool inForceCompact, bool inLocked=false,bool inFreeIsFragged=false) = 0;

#ifdef HXCPP_GC_NURSERY
unsigned char *spaceFirst;
unsigned char *spaceOversize;
#else
int spaceStart;
int spaceEnd;
size_t spaceStart;
size_t spaceEnd;
#endif
unsigned int *allocStartFlags;
unsigned char *allocBase;
Expand All @@ -367,25 +367,25 @@ class ImmixAllocator

#ifdef HXCPP_ALIGN_ALLOC
// make sure buffer is 8-byte aligned
unsigned char *buffer = alloc->spaceFirst + ( (size_t)alloc->spaceFirst & 4 );
unsigned char* buffer{ alloc->spaceFirst + (reinterpret_cast<uintptr_t>(alloc->spaceFirst) & 4) };
#else
unsigned char *buffer = alloc->spaceFirst;
unsigned char* buffer{ alloc->spaceFirst };
#endif
unsigned char *end = buffer + (inSize + 4);
unsigned char* end{ buffer + (inSize + 4) };

if ( end > alloc->spaceOversize )
{
// Fall back to external method
buffer = (unsigned char *)alloc->CallAlloc(inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0);
buffer = static_cast<unsigned char*>(alloc->CallAlloc(inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0));
}
else
{
alloc->spaceFirst = end;

if (inContainer)
((unsigned int *)buffer)[-1] = inSize | IMMIX_ALLOC_IS_CONTAINER;
reinterpret_cast<unsigned int*>(buffer)[-1] = static_cast<unsigned int>(inSize) | IMMIX_ALLOC_IS_CONTAINER;
else
((unsigned int *)buffer)[-1] = inSize;
reinterpret_cast<unsigned int*>(buffer)[-1] = static_cast<unsigned int>(inSize);
}

#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
Expand All @@ -401,30 +401,30 @@ class ImmixAllocator
#else
// Inline the fast-path if we can
// We know the object can hold a pointer (vtable) and that the size is int-aligned
int start = alloc->spaceStart;
size_t start{ alloc->spaceStart };
#ifdef HXCPP_ALIGN_ALLOC
// Ensure odd alignment in 8 bytes
start += 4 - (start & 4);
start += 4 - (start & size_t{ 4 });
#endif
int end = start + (int)(sizeof(int) + inSize);
size_t end{ start + sizeof(int) + inSize };

if ( end <= alloc->spaceEnd )
{
alloc->spaceStart = end;

unsigned int *buffer = (unsigned int *)(alloc->allocBase + start);
unsigned int* buffer{ reinterpret_cast<unsigned int*>(alloc->allocBase + start) };

int startRow = start>>IMMIX_LINE_BITS;
size_t startRow{ start >> IMMIX_LINE_BITS };

alloc->allocStartFlags[ startRow ] |= gImmixStartFlag[start&127];

if (inContainer)
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
((int)inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
*buffer++ = static_cast<unsigned int>(( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
static_cast<unsigned int>(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
hx::gMarkIDWithContainer;
else
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
((int)inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
*buffer++ = static_cast<unsigned int>(( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
static_cast<unsigned int>(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
hx::gMarkID;

#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
Expand All @@ -439,7 +439,7 @@ class ImmixAllocator
}

// Fall back to external method
void *result = alloc->CallAlloc((int)inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0);
void *result = alloc->CallAlloc(inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0);

#ifdef HXCPP_TELEMETRY
__hxt_gc_new((hx::StackContext *)alloc,result, inSize, inName);
Expand Down
4 changes: 2 additions & 2 deletions src/hx/gc/GcCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ HX_CHAR *NewString(int inLen)

}

void *NewGCBytes(void *inData,int inSize)
void *NewGCBytes(void *inData, size_t inSize)
{
void *result = hx::InternalNew(inSize,false);
if (inData)
Expand All @@ -133,7 +133,7 @@ void *NewGCBytes(void *inData,int inSize)
}


void *NewGCPrivate(void *inData,int inSize)
void *NewGCPrivate(void *inData, size_t inSize)
{
void *result = InternalNew(inSize,false);
if (inData)
Expand Down
Loading
Loading