Skip to content

Commit e09e5d2

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents c6bac3d + 5ed5825 commit e09e5d2

File tree

13 files changed

+193
-96
lines changed

13 files changed

+193
-96
lines changed

include/hx/GC.h

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ class ImmixAllocator
365365
{
366366
#ifdef HXCPP_GC_NURSERY
367367

368+
#ifdef HXCPP_ALIGN_ALLOC
369+
// make sure buffer is 8-byte aligned
370+
unsigned char *buffer = alloc->spaceFirst + ( (size_t)alloc->spaceFirst & 4 );
371+
#else
368372
unsigned char *buffer = alloc->spaceFirst;
373+
#endif
369374
unsigned char *end = buffer + (inSize + 4);
370375

371376
if ( end > alloc->spaceOversize )
@@ -383,49 +388,55 @@ class ImmixAllocator
383388
((unsigned int *)buffer)[-1] = inSize;
384389
}
385390

391+
#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
392+
hx::GCOnNewPointer(buffer);
393+
#endif
394+
386395
#ifdef HXCPP_TELEMETRY
387396
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
388397
#endif
389398

390399
return buffer;
391400

392401
#else
393-
#ifndef HXCPP_ALIGN_ALLOC
394-
// Inline the fast-path if we can
395-
// We know the object can hold a pointer (vtable) and that the size is int-aligned
396-
int start = alloc->spaceStart;
397-
int end = start + sizeof(int) + inSize;
398-
399-
if ( end <= alloc->spaceEnd )
400-
{
401-
alloc->spaceStart = end;
402-
403-
unsigned int *buffer = (unsigned int *)(alloc->allocBase + start);
404-
405-
int startRow = start>>IMMIX_LINE_BITS;
406-
407-
alloc->allocStartFlags[ startRow ] |= gImmixStartFlag[start&127];
408-
409-
if (inContainer)
410-
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
411-
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
412-
hx::gMarkIDWithContainer;
413-
else
414-
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
415-
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
416-
hx::gMarkID;
417-
418-
#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
419-
hx::GCOnNewPointer(buffer);
420-
#endif
421-
422-
#ifdef HXCPP_TELEMETRY
423-
__hxt_gc_alloc(buffer, inSize);
424-
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
425-
#endif
426-
return buffer;
427-
}
428-
#endif // HXCPP_ALIGN_ALLOC
402+
// Inline the fast-path if we can
403+
// We know the object can hold a pointer (vtable) and that the size is int-aligned
404+
int start = alloc->spaceStart;
405+
#ifdef HXCPP_ALIGN_ALLOC
406+
// Ensure odd alignment in 8 bytes
407+
start += 4 - (start & 4);
408+
#endif
409+
int end = start + sizeof(int) + inSize;
410+
411+
if ( end <= alloc->spaceEnd )
412+
{
413+
alloc->spaceStart = end;
414+
415+
unsigned int *buffer = (unsigned int *)(alloc->allocBase + start);
416+
417+
int startRow = start>>IMMIX_LINE_BITS;
418+
419+
alloc->allocStartFlags[ startRow ] |= gImmixStartFlag[start&127];
420+
421+
if (inContainer)
422+
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
423+
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
424+
hx::gMarkIDWithContainer;
425+
else
426+
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
427+
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
428+
hx::gMarkID;
429+
430+
#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
431+
hx::GCOnNewPointer(buffer);
432+
#endif
433+
434+
#ifdef HXCPP_TELEMETRY
435+
__hxt_gc_alloc(buffer, inSize);
436+
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
437+
#endif
438+
return buffer;
439+
}
429440

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

include/hxcpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
// Must allign allocs to 8 bytes to match floating point requirement?
7272
// Ints must br read on 4-byte boundary
73-
#if defined(EMSCRIPTEN) || defined(GCW0)
73+
#if (!defined(HXCPP_ALIGN_FLOAT) && (defined(EMSCRIPTEN) || defined(GCW0)) )
7474
#define HXCPP_ALIGN_ALLOC
7575
#endif
7676

0 commit comments

Comments
 (0)