Skip to content

Commit 66eb726

Browse files
committed
avoid calling GetCallSiteInfo from background
1 parent 6ce839f commit 66eb726

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7627,10 +7627,7 @@ namespace Js
76277627
for (ProfileId i = 0; i < profiledCallSiteCount; i++)
76287628
{
76297629
Assert(HasDynamicProfileInfo());
7630-
bool ctor;
7631-
bool isPolymorphic;
7632-
FunctionInfo *info = dynamicProfileInfo->GetCallSiteInfo(this, i, &ctor, &isPolymorphic);
7633-
if (info == nullptr || info->HasBody())
7630+
if (dynamicProfileInfo->MayHaveNonBuiltinCallee(i))
76347631
{
76357632
return true;
76367633
}

lib/Runtime/Base/FunctionBody.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,7 @@ namespace Js
27542754
#if ENABLE_NATIVE_CODEGEN
27552755
void SetPolymorphicCallSiteInfoHead(PolymorphicCallSiteInfo *polyCallSiteInfo) { this->SetAuxPtr<AuxPointerType::PolymorphicCallSiteInfoHead>(polyCallSiteInfo); }
27562756
PolymorphicCallSiteInfo * GetPolymorphicCallSiteInfoHead() { return this->GetAuxPtr<AuxPointerType::PolymorphicCallSiteInfoHead>(); }
2757+
PolymorphicCallSiteInfo * GetPolymorphicCallSiteInfoWithLock() { return this->GetAuxPtrWithLock<AuxPointerType::PolymorphicCallSiteInfoHead>(); }
27572758

27582759
void SetCallbackInfoList(CallbackInfoList * callbackInfoList) { this->SetAuxPtr<AuxPointerType::CallbackArgOutInfoList>(callbackInfoList); }
27592760
CallbackInfoList * GetCallbackInfoList() { return this->GetAuxPtr<AuxPointerType::CallbackArgOutInfoList>(); }

lib/Runtime/Language/DynamicProfileInfo.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace Js
5353
bits = NotNativeIntBit | NotNativeFloatBit;
5454
}
5555

56+
CriticalSection DynamicProfileInfo::callSiteInfoCS;
57+
5658
DynamicProfileInfo* DynamicProfileInfo::New(Recycler* recycler, FunctionBody* functionBody, bool persistsAcrossScriptContexts)
5759
{
5860
size_t totalAlloc = 0;
@@ -541,12 +543,14 @@ namespace Js
541543
#ifdef ASMJS_PLAT
542544
void DynamicProfileInfo::RecordAsmJsCallSiteInfo(FunctionBody* callerBody, ProfileId callSiteId, FunctionBody* calleeBody)
543545
{
546+
AutoCriticalSection cs(&this->callSiteInfoCS);
547+
544548
if (!callerBody || !callerBody->GetIsAsmjsMode() || !calleeBody || !calleeBody->GetIsAsmjsMode())
545549
{
546550
AssertMsg(UNREACHED, "Call to RecordAsmJsCallSiteInfo without two asm.js/wasm FunctionBody");
547551
return;
548552
}
549-
553+
550554
#if DBG_DUMP || defined(DYNAMIC_PROFILE_STORAGE) || defined(RUNTIME_DATA_COLLECTION)
551555
// If we persistsAcrossScriptContext, the dynamic profile info may be referred to by multiple function body from
552556
// different script context
@@ -688,6 +692,8 @@ namespace Js
688692

689693
void DynamicProfileInfo::RecordCallSiteInfo(FunctionBody* functionBody, ProfileId callSiteId, FunctionInfo* calleeFunctionInfo, JavascriptFunction* calleeFunction, uint actualArgCount, bool isConstructorCall, InlineCacheIndex ldFldInlineCacheId)
690694
{
695+
AutoCriticalSection cs(&this->callSiteInfoCS);
696+
691697
#if DBG_DUMP || defined(DYNAMIC_PROFILE_STORAGE) || defined(RUNTIME_DATA_COLLECTION)
692698
// If we persistsAcrossScriptContext, the dynamic profile info may be referred to by multiple function body from
693699
// different script context
@@ -788,6 +794,7 @@ namespace Js
788794
localPolyCallSiteInfo->functionIds[i] = CallSiteNoInfo;
789795
}
790796

797+
Assert(this->callSiteInfoCS.IsLocked());
791798
callSiteInfo[callSiteId].isPolymorphic = true;
792799
callSiteInfo[callSiteId].u.polymorphicCallSiteInfo = localPolyCallSiteInfo;
793800
funcBody->SetPolymorphicCallSiteInfoHead(localPolyCallSiteInfo);
@@ -797,6 +804,8 @@ namespace Js
797804
{
798805
if (dynamicProfileFunctionInfo)
799806
{
807+
AutoCriticalSection cs(&this->callSiteInfoCS);
808+
800809
for (ProfileId i = 0; i < dynamicProfileFunctionInfo->callSiteInfoCount; i++)
801810
{
802811
if (callSiteInfo[i].isPolymorphic)
@@ -809,6 +818,8 @@ namespace Js
809818

810819
void DynamicProfileInfo::ResetPolymorphicCallSiteInfo(ProfileId callSiteId, Js::LocalFunctionId functionId)
811820
{
821+
Assert(this->callSiteInfoCS.IsLocked());
822+
812823
callSiteInfo[callSiteId].isPolymorphic = false;
813824
callSiteInfo[callSiteId].u.functionData.sourceId = CurrentSourceId;
814825
callSiteInfo[callSiteId].u.functionData.functionId = functionId;
@@ -991,6 +1002,7 @@ namespace Js
9911002

9921003
FunctionInfo * DynamicProfileInfo::GetFunctionInfo(FunctionBody* functionBody, Js::SourceId sourceId, Js::LocalFunctionId functionId)
9931004
{
1005+
Assert(ThreadContext::GetContextForCurrentThread());
9941006
if (sourceId == BuiltInSourceId)
9951007
{
9961008
return JavascriptBuiltInFunction::GetFunctionInfo(functionId);
@@ -1048,8 +1060,30 @@ namespace Js
10481060
return nullptr;
10491061
}
10501062

1063+
bool DynamicProfileInfo::MayHaveNonBuiltinCallee(ProfileId callSiteId)
1064+
{
1065+
AutoCriticalSection cs(&this->callSiteInfoCS);
1066+
1067+
if (this->callSiteInfo[callSiteId].dontInline)
1068+
{
1069+
return true;
1070+
}
1071+
1072+
if (!this->callSiteInfo[callSiteId].isPolymorphic)
1073+
{
1074+
Js::SourceId sourceId = this->callSiteInfo[callSiteId].u.functionData.sourceId;
1075+
if (sourceId == BuiltInSourceId)
1076+
{
1077+
return false;
1078+
}
1079+
}
1080+
1081+
return true;
1082+
}
1083+
10511084
FunctionInfo * DynamicProfileInfo::GetCallSiteInfo(FunctionBody* functionBody, ProfileId callSiteId, bool *isConstructorCall, bool *isPolymorphicCall)
10521085
{
1086+
Assert(ThreadContext::GetContextForCurrentThread());
10531087
Assert(functionBody);
10541088
const auto callSiteCount = functionBody->GetProfiledCallSiteCount();
10551089
Assert(callSiteId < callSiteCount);

lib/Runtime/Language/DynamicProfileInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ namespace Js
464464
static bool HasCallSiteInfo(FunctionBody* functionBody);
465465
bool HasCallSiteInfo(FunctionBody* functionBody, ProfileId callSiteId); // Does a particular callsite have ProfileInfo?
466466
FunctionInfo * GetCallbackInfo(FunctionBody * functionBody, ProfileId callSiteId);
467+
bool MayHaveNonBuiltinCallee(ProfileId callSiteId);
467468
FunctionInfo * GetCallSiteInfo(FunctionBody* functionBody, ProfileId callSiteId, bool *isConstructorCall, bool *isPolymorphicCall);
468469
CallSiteInfo * GetCallSiteInfo() const { return callSiteInfo; }
469470
uint16 GetConstantArgInfo(ProfileId callSiteId);
@@ -607,6 +608,8 @@ namespace Js
607608
Field(bool) persistsAcrossScriptContexts;
608609
#endif
609610

611+
static CriticalSection callSiteInfoCS;
612+
610613
static JavascriptMethod EnsureDynamicProfileInfo(Js::ScriptFunction * function);
611614
#if DBG_DUMP
612615
static void DumpList(DynamicProfileInfoList * profileInfoList, ArenaAllocator * dynamicProfileInfoAllocator);
@@ -629,6 +632,7 @@ namespace Js
629632
void ResetPolymorphicCallSiteInfo(ProfileId callSiteId, Js::LocalFunctionId functionId);
630633
void SetFunctionIdSlotForNewPolymorphicCall(ProfileId callSiteId, Js::LocalFunctionId curFunctionId, Js::SourceId curSourceId, Js::FunctionBody *inliner);
631634
void RecordPolymorphicCallSiteInfo(FunctionBody* functionBody, ProfileId callSiteId, FunctionInfo * calleeFunctionInfo);
635+
632636
#ifdef RUNTIME_DATA_COLLECTION
633637
static CriticalSection s_csOutput;
634638
template <typename T>

0 commit comments

Comments
 (0)