Skip to content

Commit

Permalink
Fix GetAllocatedBytesForCurrentThread when not using Thread Allocatio…
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry committed Apr 15, 2019
1 parent 2573e4e commit 5c3709b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/vm/comutilnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,12 +1229,7 @@ FCIMPL0(INT64, GCInterface::GetAllocatedBytesForCurrentThread)
{
FCALL_CONTRACT;

INT64 currentAllocated = 0;
Thread *pThread = GetThread();
gc_alloc_context* ac = pThread->GetAllocContext();
currentAllocated = ac->alloc_bytes + ac->alloc_bytes_loh - (ac->alloc_limit - ac->alloc_ptr);

return currentAllocated;
return ::GetAllocatedBytesForCurrentThread();
}
FCIMPLEND

Expand Down
19 changes: 19 additions & 0 deletions src/vm/gchelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,3 +1618,22 @@ SetCardsAfterBulkCopy(Object **start, size_t len)
#if defined(_MSC_VER) && defined(_TARGET_X86_)
#pragma optimize("", on) // Go back to command line default optimizations
#endif //_MSC_VER && _TARGET_X86_

INT64 GetAllocatedBytesForCurrentThread()
{
INT64 currentAllocated;

if (GCHeapUtilities::UseThreadAllocationContexts())
{
gc_alloc_context* ac = GetThread()->GetAllocContext();
currentAllocated = ac->alloc_bytes + ac->alloc_bytes_loh - (ac->alloc_limit - ac->alloc_ptr);
}
else
{
GlobalAllocLockHolder holder(&g_global_alloc_lock);
gc_alloc_context* ac = &g_global_alloc_context;
currentAllocated = ac->alloc_bytes + ac->alloc_bytes_loh - (ac->alloc_limit - ac->alloc_ptr);
}

return currentAllocated;
}
2 changes: 2 additions & 0 deletions src/vm/gchelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ extern void FlushWriteBarrierInstructionCache();

extern void ThrowOutOfMemoryDimensionsExceeded();

extern INT64 GetAllocatedBytesForCurrentThread();

//========================================================================
//
// WRITE BARRIER HELPERS
Expand Down

0 comments on commit 5c3709b

Please sign in to comment.