Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@66bc22eceb] [1.6>1.7] [MERGE #3382 @rajatd
Browse files Browse the repository at this point in the history
] On .caller, only invalidate cached scopes for nested parents

Merge pull request #3382 from rajatd:cachedScopeStackWalk

When a function escapes as the return value of .caller, we currently walk the whole stack and invalidate cached scope on every function on the stack that has one set. However, it seems that we only need to do the invalidation for nested parents of the result of .caller. This PR attempts to do just that.
  • Loading branch information
chakrabot committed Jul 22, 2017
1 parent 4c77b78 commit 5195b96
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deps/chakrashim/core/lib/Runtime/Debug/TTSnapObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ namespace TTD

if(snapFuncInfo->CachedScopeObjId != TTD_INVALID_PTR_ID)
{
fobj->SetCachedScope((Js::ActivationObjectEx*)inflator->LookupObject(snapFuncInfo->CachedScopeObjId));
fobj->SetCachedScope(Js::ActivationObjectEx::FromVar(inflator->LookupObject(snapFuncInfo->CachedScopeObjId)));
}

if(snapFuncInfo->HomeObjId != TTD_INVALID_PTR_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5542,7 +5542,7 @@ namespace Js

Var InterpreterStackFrame::OP_GetCachedFunc(Var instance, int32 index)
{
ActivationObjectEx *obj = (ActivationObjectEx*)ActivationObjectEx::FromVar(instance);
ActivationObjectEx *obj = ActivationObjectEx::FromVar(instance);

FuncCacheEntry *entry = obj->GetFuncCacheEntry((uint)index);
return entry->func;
Expand All @@ -5556,7 +5556,7 @@ namespace Js

void InterpreterStackFrame::OP_CommitScopeHelper(const PropertyIdArray *propIds)
{
ActivationObjectEx *obj = (ActivationObjectEx*)ActivationObjectEx::FromVar(this->localClosure);
ActivationObjectEx *obj = ActivationObjectEx::FromVar(this->localClosure);
ScriptFunction *func = obj->GetParentFunc();

Assert(obj->GetParentFunc() == func);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5626,7 +5626,7 @@ namespace Js

void JavascriptOperators::OP_InitCachedFuncs(Var varScope, FrameDisplay *pDisplay, const FuncInfoArray *info, ScriptContext *scriptContext)
{
ActivationObjectEx *scopeObj = (ActivationObjectEx*)ActivationObjectEx::FromVar(varScope);
ActivationObjectEx *scopeObj = ActivationObjectEx::FromVar(varScope);
Assert(scopeObj->GetTypeHandler()->GetInlineSlotCapacity() == 0);

uint funcCount = info->count;
Expand Down
15 changes: 8 additions & 7 deletions deps/chakrashim/core/lib/Runtime/Library/JavascriptFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2730,16 +2730,17 @@ void __cdecl _alloca_probe_16()
// If this is the internal function of a generator function then return the original generator function
funcCaller = ScriptFunction::FromVar(funcCaller)->GetRealFunctionObject();

// This function is escaping, so make sure there isn't some caller that has a cached scope.
JavascriptFunction * func;
while (walker.GetCaller(&func))
// This function is escaping, so make sure there isn't some nested parent that has a cached scope.
if (ScriptFunction::Is(funcCaller))
{
if (ScriptFunction::Is(func))
FrameDisplay * pFrameDisplay = Js::ScriptFunction::FromVar(funcCaller)->GetEnvironment();
uint length = (uint)pFrameDisplay->GetLength();
for (uint i = 0; i < length; i++)
{
ActivationObjectEx * obj = ScriptFunction::FromVar(func)->GetCachedScope();
if (obj)
void * scope = pFrameDisplay->GetItem(i);
if (!Js::ScopeSlots::Is(scope) && Js::ActivationObjectEx::Is(scope))
{
obj->InvalidateCachedScope();
Js::ActivationObjectEx::FromVar(scope)->InvalidateCachedScope();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions deps/chakrashim/core/lib/Runtime/Types/ActivationObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ namespace Js
return VirtualTableInfo<Js::ActivationObjectEx>::HasVirtualTable(instance);
}

static ActivationObjectEx * FromVar(Var instance)
{
AssertOrFailFast(Is(instance));
return reinterpret_cast<ActivationObjectEx *>(instance);
}

private:
Field(ScriptFunction *) parentFunc;
Field(uint) cachedFuncCount;
Expand Down

0 comments on commit 5195b96

Please sign in to comment.