Skip to content

Commit 504403d

Browse files
author
Aidan Lee
committed
Revert gc twiddling
1 parent e638733 commit 504403d

6 files changed

Lines changed: 408 additions & 405 deletions

File tree

‎include/hx/Class.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ inline bool TIsInterface(hx::Object *inPtr)
277277
}
278278

279279

280-
HXCPP_EXTERN_CLASS_ATTRIBUTES void RegisterVTableOffset(uintptr_t inOffset);
280+
HXCPP_EXTERN_CLASS_ATTRIBUTES void RegisterVTableOffset(int inOffset);
281281

282282
#define HX_REGISTER_VTABLE_OFFSET( CLASS, INTERFACE ) \
283283
{ \
284284
CLASS *dummy = (CLASS *)0; \
285285
INTERFACE *intf = dummy; \
286-
::hx::RegisterVTableOffset( reinterpret_cast<uintptr_t>(reinterpret_cast<char *>(intf) - reinterpret_cast<char *>(dummy) )); \
286+
::hx::RegisterVTableOffset( (int)( (size_t)((char *)intf - (char *)dummy)) ); \
287287
}
288288

289289

‎include/hx/GC.h‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
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

122121
void InternalReleaseMem(void *inMem);
123122

124123
unsigned 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
131130
typedef 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

171170
extern 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-
290285
namespace 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);
336336
extern StackContext *gMainThreadContext;
337337

338338
extern unsigned int gImmixStartFlag[128];
339-
extern unsigned int gMarkID;
340-
extern unsigned int gMarkIDWithContainer;
339+
extern int gMarkID;
340+
extern int gMarkIDWithContainer;
341341
extern void BadImmixAlloc();
342342

343343

344344
class ImmixAllocator
345345
{
346346
public:
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);

‎include/hx/QuickVec.h‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace hx
1010
template<typename T>
1111
struct QuickVec
1212
{
13-
size_t mAlloc;
14-
size_t mSize;
13+
int mAlloc;
14+
int mSize;
1515
T *mPtr;
1616

1717
QuickVec() : mPtr(0), mAlloc(0), mSize(0) { }
@@ -26,7 +26,7 @@ struct QuickVec
2626
if (mSize+1>mAlloc)
2727
{
2828
mAlloc = 10 + (mSize*3/2);
29-
mPtr = static_cast<T*>(realloc(mPtr,sizeof(T)*mAlloc));
29+
mPtr = (T *)realloc(mPtr,sizeof(T)*mAlloc);
3030
}
3131
mPtr[mSize]=inT;
3232
mSize++;
@@ -37,31 +37,31 @@ struct QuickVec
3737
std::swap(mSize, inOther.mSize);
3838
std::swap(mPtr, inOther.mPtr);
3939
}
40-
T *setSize(size_t inSize)
40+
T *setSize(int inSize)
4141
{
4242
if (inSize>mAlloc)
4343
{
4444
mAlloc = inSize;
45-
mPtr = static_cast<T*>(realloc(mPtr,sizeof(T)*mAlloc));
45+
mPtr = (T *)realloc(mPtr,sizeof(T)*mAlloc);
4646
}
4747
mSize = inSize;
4848
return mPtr;
4949
}
5050
// Can push this many without realloc
51-
bool hasExtraCapacity(size_t inN)
51+
bool hasExtraCapacity(int inN)
5252
{
5353
return mSize+inN<=mAlloc;
5454
}
5555

56-
bool safeReserveExtra(size_t inN)
56+
bool safeReserveExtra(int inN)
5757
{
58-
size_t want{ mSize + inN };
58+
int want = mSize + inN;
5959
if (want>mAlloc)
6060
{
61-
size_t wantAlloc{ 10 + (mSize * 3 / 2) };
61+
int wantAlloc = 10 + (mSize*3/2);
6262
if (wantAlloc<want)
6363
wantAlloc = want;
64-
T *newBuffer = static_cast<T*>(malloc( sizeof(T)*wantAlloc ));
64+
T *newBuffer = (T *)malloc( sizeof(T)*wantAlloc );
6565
if (!newBuffer)
6666
return false;
6767
mAlloc = wantAlloc;
@@ -80,12 +80,12 @@ struct QuickVec
8080
{
8181
return mPtr[--mSize];
8282
}
83-
inline void qerase(size_t inPos)
83+
inline void qerase(int inPos)
8484
{
8585
--mSize;
8686
mPtr[inPos] = mPtr[mSize];
8787
}
88-
inline void erase(size_t inPos)
88+
inline void erase(int inPos)
8989
{
9090
--mSize;
9191
if (mSize>inPos)
@@ -95,33 +95,31 @@ struct QuickVec
9595

9696
inline bool qerase_val(T inVal)
9797
{
98-
for (size_t i{ 0 }; i < mSize; i++)
99-
{
100-
if (mPtr[i] == inVal)
98+
for(int i=0;i<mSize;i++)
99+
if (mPtr[i]==inVal)
101100
{
102101
--mSize;
103102
mPtr[i] = mPtr[mSize];
104103
return true;
105104
}
106-
}
107105
return false;
108106
}
109107

110108
inline bool some_left() { return mSize; }
111109
inline bool empty() const { return !mSize; }
112110
inline void clear() { mSize = 0; }
113-
inline size_t next()
111+
inline int next()
114112
{
115113
if (mSize+1>=mAlloc)
116114
{
117115
mAlloc = 10 + (mSize*3/2);
118-
mPtr = static_cast<T*>(realloc(mPtr,sizeof(T)*mAlloc));
116+
mPtr = (T *)realloc(mPtr,sizeof(T)*mAlloc);
119117
}
120118
return mSize++;
121119
}
122-
inline size_t size() const { return mSize; }
123-
inline T &operator[](size_t inIndex) { return mPtr[inIndex]; }
124-
inline const T &operator[](size_t inIndex) const { return mPtr[inIndex]; }
120+
inline int size() const { return mSize; }
121+
inline T &operator[](int inIndex) { return mPtr[inIndex]; }
122+
inline const T &operator[](int inIndex) const { return mPtr[inIndex]; }
125123

126124
private:
127125
QuickVec(const QuickVec<T> &);
@@ -140,8 +138,8 @@ class QuickDeque
140138
QuickVec<Slab *> mSpare;
141139
QuickVec<Slab *> mActive;
142140

143-
size_t mHeadPos;
144-
size_t mTailPos;
141+
int mHeadPos;
142+
int mTailPos;
145143
Slab *mHead;
146144
Slab *mTail;
147145

@@ -155,9 +153,9 @@ class QuickDeque
155153
}
156154
~QuickDeque()
157155
{
158-
for (size_t i{0}; i < mSpare.size(); i++)
156+
for(int i=0;i<mSpare.size();i++)
159157
delete mSpare[i];
160-
for (size_t i{0}; i < mActive.size(); i++)
158+
for(int i=0;i<mActive.size();i++)
161159
delete mActive[i];
162160
delete mHead;
163161
if (mTail!=mHead)

0 commit comments

Comments
 (0)