33
44#include < hx/Tls.h>
55#include < stdio.h>
6- #include < atomic>
76
87// Under the current scheme (as defined by HX_HCSTRING/HX_CSTRING in hxcpp.h)
98// each constant string data is prepended with a 4-byte header that says the string
@@ -114,18 +113,18 @@ namespace hx
114113// If inSize is small (<4k) it will be allocated from the immix pool.
115114// Larger, and it will be allocated from a separate memory pool
116115// inIsObject specifies whether "__Mark" should be called on the resulting object
117- void *InternalNew (size_t inSize,bool inIsObject);
116+ void *InternalNew (int inSize,bool inIsObject);
118117
119118// Used internall - realloc array data
120- void *InternalRealloc (size_t inFromSize, void *inData,size_t inSize,bool inAllowExpansion=false );
119+ void *InternalRealloc (int inFromSize, void *inData,int inSize,bool inAllowExpansion=false );
121120
122121void InternalReleaseMem (void *inMem);
123122
124123unsigned int ObjectSizeSafe (void *inData);
125124
126125// Const buffers are allocated outside the GC system, and do not require marking
127126// String buffers can optionally have a pre-computed hash appended with this method
128- void *InternalCreateConstBuffer (const void *inData, size_t inSize, bool inAddStringHash=false );
127+ void *InternalCreateConstBuffer (const void *inData,int inSize,bool inAddStringHash=false );
129128
130129// Called after collection by an unspecified thread
131130typedef void (*finalizer)(hx::Object *v);
@@ -155,17 +154,17 @@ void GCSetFinalizer( hx::Object *, hx::finalizer f );
155154// This automatically gets checked when you call "new", but if you are in long-running
156155// loop with no new call, you might starve another thread if you to not check this.
157156// 0xffffffff = pause requested
158- extern std::atomic_uint gPauseForCollect ;
157+ extern int gPauseForCollect ;
159158
160159
161160// Minimum total memory - used + buffer for new objects
162- extern size_t sgMinimumWorkingMemory;
161+ extern int sgMinimumWorkingMemory;
163162
164163// Minimum free memory - not counting used memory
165- extern size_t sgMinimumFreeSpace;
164+ extern int sgMinimumFreeSpace;
166165
167166// Also ensure that the free memory is larger than this amount of used memory
168- extern size_t sgTargetFreeSpacePercentage;
167+ extern int sgTargetFreeSpacePercentage;
169168
170169
171170extern HXCPP_EXTERN_CLASS_ATTRIBUTES int gByteMarkID ;
@@ -198,8 +197,8 @@ char *NewString(int inLen);
198197// The concept of 'private' is from the old conservative Gc method.
199198// Now with explicit marking, these functions do the same thing, which is
200199// to allocate some GC memory and optionally copy the 'inData' into those bytes
201- HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCBytes (void *inData,size_t inSize);
202- HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCPrivate (void *inData,size_t inSize);
200+ HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCBytes (void *inData,int inSize);
201+ HXCPP_EXTERN_CLASS_ATTRIBUTES void *NewGCPrivate (void *inData,int inSize);
203202
204203// Force a collect from the calling thread
205204// Only one thread should call this at a time
@@ -283,17 +282,18 @@ void GCPrepareMultiThreaded();
283282
284283// Inline code tied to the immix implementation
285284
286- // Each line ast 128 bytes (2^7)
287- constexpr uint8_t IMMIX_LINE_BITS { 7 };
288- constexpr uint8_t IMMIX_LINE_LEN { 1 << IMMIX_LINE_BITS };
289-
290285namespace hx
291286{
292287
293288#define HX_USE_INLINE_IMMIX_OPERATOR_NEW
294289
295290// #define HX_STACK_CTX ::hx::ImmixAllocator *_hx_stack_ctx = ::hx::gMultiThreadMode ? ::hx::tlsImmixAllocator : ::hx::gMainThreadAlloc;
296291
292+
293+ // Each line ast 128 bytes (2^7)
294+ #define IMMIX_LINE_BITS 7
295+ #define IMMIX_LINE_LEN (1 <<IMMIX_LINE_BITS )
296+
297297#define HX_GC_REMEMBERED 0x40
298298
299299// The size info is stored in the header 8 bits to the right
@@ -336,24 +336,24 @@ EXTERN_FAST_TLS_DATA(StackContext, tlsStackContext);
336336extern StackContext *gMainThreadContext ;
337337
338338extern unsigned int gImmixStartFlag [128 ];
339- extern unsigned int gMarkID ;
340- extern unsigned int gMarkIDWithContainer ;
339+ extern int gMarkID ;
340+ extern int gMarkIDWithContainer ;
341341extern void BadImmixAlloc ();
342342
343343
344344class ImmixAllocator
345345{
346346public:
347347 virtual ~ImmixAllocator () {}
348- virtual void *CallAlloc (size_t inSize,unsigned int inObjectFlags) = 0;
348+ virtual void *CallAlloc (int inSize,unsigned int inObjectFlags) = 0;
349349 virtual void SetupStackAndCollect (bool inMajor, bool inForceCompact, bool inLocked=false ,bool inFreeIsFragged=false ) = 0;
350350
351351 #ifdef HXCPP_GC_NURSERY
352352 unsigned char *spaceFirst;
353353 unsigned char *spaceOversize;
354354 #else
355- size_t spaceStart;
356- size_t spaceEnd;
355+ int spaceStart;
356+ int spaceEnd;
357357 #endif
358358 unsigned int *allocStartFlags;
359359 unsigned char *allocBase;
@@ -367,25 +367,25 @@ class ImmixAllocator
367367
368368 #ifdef HXCPP_ALIGN_ALLOC
369369 // make sure buffer is 8-byte aligned
370- unsigned char * buffer{ alloc->spaceFirst + (reinterpret_cast < uintptr_t >( alloc->spaceFirst ) & 4 ) } ;
370+ unsigned char * buffer = alloc->spaceFirst + ( ( size_t ) alloc->spaceFirst & 4 ) ;
371371 #else
372- unsigned char * buffer{ alloc->spaceFirst } ;
372+ unsigned char * buffer = alloc->spaceFirst ;
373373 #endif
374- unsigned char * end{ buffer + (inSize + 4 ) } ;
374+ unsigned char * end = buffer + (inSize + 4 );
375375
376376 if ( end > alloc->spaceOversize )
377377 {
378378 // Fall back to external method
379- buffer = static_cast < unsigned char *>( alloc->CallAlloc (inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0 ) );
379+ buffer = ( unsigned char *) alloc->CallAlloc (inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0 );
380380 }
381381 else
382382 {
383383 alloc->spaceFirst = end;
384384
385385 if (inContainer)
386- reinterpret_cast < unsigned int *>( buffer)[-1 ] = static_cast < unsigned int >( inSize) | IMMIX_ALLOC_IS_CONTAINER ;
386+ (( unsigned int *) buffer)[-1 ] = inSize | IMMIX_ALLOC_IS_CONTAINER ;
387387 else
388- reinterpret_cast < unsigned int *>( buffer)[-1 ] = static_cast < unsigned int >( inSize) ;
388+ (( unsigned int *) buffer)[-1 ] = inSize;
389389 }
390390
391391 #if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
@@ -401,30 +401,30 @@ class ImmixAllocator
401401 #else
402402 // Inline the fast-path if we can
403403 // We know the object can hold a pointer (vtable) and that the size is int-aligned
404- size_t start{ alloc->spaceStart } ;
404+ int start = alloc->spaceStart ;
405405 #ifdef HXCPP_ALIGN_ALLOC
406406 // Ensure odd alignment in 8 bytes
407- start += 4 - (start & size_t { 4 } );
407+ start += 4 - (start & 4 );
408408 #endif
409- size_t end{ start + sizeof (int ) + inSize } ;
409+ int end = start + ( int )( sizeof (int ) + inSize) ;
410410
411411 if ( end <= alloc->spaceEnd )
412412 {
413413 alloc->spaceStart = end;
414414
415- unsigned int * buffer{ reinterpret_cast < unsigned int *> (alloc->allocBase + start) } ;
415+ unsigned int * buffer = ( unsigned int *) (alloc->allocBase + start);
416416
417- size_t startRow{ start >> IMMIX_LINE_BITS } ;
417+ int startRow = start>> IMMIX_LINE_BITS ;
418418
419419 alloc->allocStartFlags [ startRow ] |= gImmixStartFlag [start&127 ];
420420
421421 if (inContainer)
422- *buffer++ = static_cast < unsigned int > (( (end+(IMMIX_LINE_LEN -1 ))>>IMMIX_LINE_BITS ) -startRow) |
423- static_cast < unsigned int >( inSize<<IMMIX_ALLOC_SIZE_SHIFT ) |
422+ *buffer++ = (( (end+(IMMIX_LINE_LEN -1 ))>>IMMIX_LINE_BITS ) -startRow) |
423+ (( int ) inSize<<IMMIX_ALLOC_SIZE_SHIFT ) |
424424 hx::gMarkIDWithContainer ;
425425 else
426- *buffer++ = static_cast < unsigned int > (( (end+(IMMIX_LINE_LEN -1 ))>>IMMIX_LINE_BITS ) -startRow) |
427- static_cast < unsigned int >( inSize<<IMMIX_ALLOC_SIZE_SHIFT ) |
426+ *buffer++ = (( (end+(IMMIX_LINE_LEN -1 ))>>IMMIX_LINE_BITS ) -startRow) |
427+ (( int ) inSize<<IMMIX_ALLOC_SIZE_SHIFT ) |
428428 hx::gMarkID ;
429429
430430 #if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
@@ -439,7 +439,7 @@ class ImmixAllocator
439439 }
440440
441441 // Fall back to external method
442- void *result = alloc->CallAlloc (inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0 );
442+ void *result = alloc->CallAlloc (( int ) inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0 );
443443
444444 #ifdef HXCPP_TELEMETRY
445445 __hxt_gc_new ((hx::StackContext *)alloc,result, inSize, inName);
0 commit comments