From 71f259caa6fe9a167be38fa2433003a4c35c9657 Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 30 Nov 2018 01:25:57 -0800 Subject: [PATCH] Fix perf issues with GetCurrentThreadHomeHeapNumber (#21150) --- src/gc/gc.cpp | 15 ++++++--------- src/gc/objecthandle.cpp | 3 +-- src/vm/gcenv.ee.cpp | 6 +++++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index 285200b..3ff1aa8 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -35215,17 +35215,14 @@ int GCHeap::GetNumberOfHeaps () int GCHeap::GetHomeHeapNumber () { #ifdef MULTIPLE_HEAPS - Thread *pThread = GCToEEInterface::GetThread(); - for (int i = 0; i < gc_heap::n_heaps; i++) + gc_alloc_context* ctx = GCToEEInterface::GetAllocContext(); + if (!ctx) { - if (pThread) - { - gc_alloc_context* ctx = GCToEEInterface::GetAllocContext(); - GCHeap *hp = static_cast(ctx)->get_home_heap(); - if (hp == gc_heap::g_heaps[i]->vm_heap) return i; - } + return 0; } - return 0; + + GCHeap *hp = static_cast(ctx)->get_home_heap(); + return (hp ? hp->pGenGCHeap->heap_number : 0); #else return 0; #endif //MULTIPLE_HEAPS diff --git a/src/gc/objecthandle.cpp b/src/gc/objecthandle.cpp index b3d93b4..3045c67 100644 --- a/src/gc/objecthandle.cpp +++ b/src/gc/objecthandle.cpp @@ -1819,8 +1819,7 @@ int GetCurrentThreadHomeHeapNumber() { WRAPPER_NO_CONTRACT; - if (g_theGCHeap == nullptr) - return 0; + assert(g_theGCHeap != nullptr); return g_theGCHeap->GetHomeHeapNumber(); } diff --git a/src/vm/gcenv.ee.cpp b/src/vm/gcenv.ee.cpp index d99b12c..ff8f109 100644 --- a/src/vm/gcenv.ee.cpp +++ b/src/vm/gcenv.ee.cpp @@ -320,7 +320,11 @@ gc_alloc_context * GCToEEInterface::GetAllocContext() WRAPPER_NO_CONTRACT; Thread* pThread = ::GetThread(); - assert(pThread != nullptr); + if (!pThread) + { + return nullptr; + } + return pThread->GetAllocContext(); } -- 2.7.4