Skip to content

Commit

Permalink
eagerly free large objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan63 committed Sep 12, 2024
1 parent 1b53779 commit 9ecfa08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/hx/GC.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifdef HXCPP_TELEMETRY
extern void __hxt_gc_new(hx::StackContext *inStack, void* obj, int inSize, const char *inName);
extern void __hxt_gc_alloc(void* obj, int inSize);
extern void __hxt_gc_free_large(void* obj);
#endif


Expand Down
1 change: 1 addition & 0 deletions src/hx/Telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ void __hxt_new_hash(void* obj, int inSize)
#endif
}
void __hxt_gc_alloc(void* obj, int inSize) { }
void __hxt_gc_free_large(void*) {}
void __hxt_gc_new(hx::StackContext *stack, void* obj, int inSize, const char* name)
{
#ifdef HXCPP_STACK_TRACE
Expand Down
26 changes: 17 additions & 9 deletions src/hx/TelemetryTracy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ void __hxt_gc_alloc(void* obj, int inSize)
{
AutoLock lock(largeAllocsLock);

// Skip multiple large object allocations since they can be recycled in-between GC collections.
for (auto i = 0; i < largeAllocs.size(); i++)
{
if (largeAllocs[i] == obj)
{
return;
}
}

largeAllocs.push(obj);

TracyAllocN(obj, inSize, lohName);
Expand All @@ -104,6 +95,23 @@ void __hxt_gc_alloc(void* obj, int inSize)
#endif
}

void __hxt_gc_free_large(void* obj)
{
AutoLock lock(largeAllocsLock);

for (auto i = 0; i < largeAllocs.size(); i++)
{
if (largeAllocs[i] == obj)
{
largeAllocs.erase(i);

TracyFreeN(obj, lohName);

return;
}
}
}

void __hxt_gc_realloc(void* oldObj, void* newObj, int newSize) { }

void __hxt_gc_after_mark(int byteMarkId, int endianByteMarkId)
Expand Down
4 changes: 4 additions & 0 deletions src/hx/gc/Immix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,10 @@ class GlobalAllocator

void FreeLarge(void *inLarge)
{
#ifdef HXCPP_TELEMETRY
__hxt_gc_free_large(inLarge);
#endif

((unsigned char *)inLarge)[HX_ENDIAN_MARK_ID_BYTE] = 0;
// AllocLarge will not lock this list unless it decides there is a suitable
// value, so we can't doa realloc without potentially crashing it.
Expand Down

0 comments on commit 9ecfa08

Please sign in to comment.