Skip to content

Commit

Permalink
Opportunistically use stack allocation for GC dynamic events (#91001)
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Sep 1, 2023
1 parent 5b68fbf commit 528a5cf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/coreclr/gc/gceventstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,16 @@ void FireDynamicEvent(const char* name, EventArgument... arguments)
return;
}

uint8_t* buf = new (nothrow) uint8_t[size];
bool heap_allocated = size > 256;
uint8_t* buf;
if (heap_allocated)
{
buf = new (nothrow) uint8_t[size];
}
else
{
buf = (uint8_t*)alloca(size);
}
if (!buf)
{
// best effort - if we're OOM, don't bother with the event.
Expand All @@ -226,7 +235,10 @@ void FireDynamicEvent(const char* name, EventArgument... arguments)
IGCToCLREventSink* sink = GCToEEInterface::EventSink();
assert(sink != nullptr);
sink->FireDynamicEvent(name, buf, static_cast<uint32_t>(size));
delete[] buf;
if (heap_allocated)
{
delete[] buf;
}
};

/*
Expand Down

0 comments on commit 528a5cf

Please sign in to comment.