Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Backend/BailOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,8 @@ BailOutRecord::BailOutHelper(Js::JavascriptCallStackLayout * layout, Js::ScriptF
memset(newInstance->m_localSlots + constantCount, 0, varCount * sizeof(Js::Var));
}

Js::RegSlot localFrameDisplayReg = executeFunction->GetLocalFrameDisplayReg();
Js::RegSlot localClosureReg = executeFunction->GetLocalClosureReg();
Js::RegSlot localFrameDisplayReg = executeFunction->GetLocalFrameDisplayRegister();
Js::RegSlot localClosureReg = executeFunction->GetLocalClosureRegister();

if (!isInlinee)
{
Expand Down Expand Up @@ -1503,7 +1503,7 @@ BailOutRecord::BailOutHelper(Js::JavascriptCallStackLayout * layout, Js::ScriptF
uint32 innerScopeCount = executeFunction->GetInnerScopeCount();
for (uint32 i = 0; i < innerScopeCount; i++)
{
Js::RegSlot reg = executeFunction->FirstInnerScopeReg() + i;
Js::RegSlot reg = executeFunction->GetFirstInnerScopeRegister() + i;
newInstance->SetInnerScopeFromIndex(i, newInstance->GetNonVarReg(reg));
newInstance->SetNonVarReg(reg, nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/CodeGenWorkItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ struct JsFunctionCodeGen sealed : public CodeGenWorkItem

uint GetInterpretedCount() const override
{
return this->functionBody->interpretedCount;
return this->functionBody->GetInterpretedCount();
}

void Delete() override
Expand Down
4 changes: 2 additions & 2 deletions lib/Backend/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,15 +956,15 @@ void Func::InitLocalClosureSyms()
// Allocate stack space for closure pointers. Do this only if we're jitting for stack closures, and
// tell bailout that these are not byte code symbols so that we don't try to encode them in the bailout record,
// as they don't have normal lifetimes.
Js::RegSlot regSlot = this->GetJnFunction()->GetLocalClosureReg();
Js::RegSlot regSlot = this->GetJnFunction()->GetLocalClosureRegister();
if (regSlot != Js::Constants::NoRegister)
{
this->m_localClosureSym =
StackSym::FindOrCreate(static_cast<SymID>(regSlot),
this->DoStackFrameDisplay() ? (Js::RegSlot)-1 : regSlot,
this);
}
regSlot = this->GetJnFunction()->GetLocalFrameDisplayReg();
regSlot = this->GetJnFunction()->GetLocalFrameDisplayRegister();
if (regSlot != Js::Constants::NoRegister)
{
this->m_localFrameDisplaySym =
Expand Down
86 changes: 43 additions & 43 deletions lib/Backend/IRBuilder.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/Runtime/Base/AuxPtrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ namespace Js
template<class T, typename FieldsEnum>
void AuxPtrs<T, FieldsEnum>::AllocAuxPtr(T* host, uint8 count)
{
Assert(count >= AuxPtrs32::MaxCount);

Recycler* recycler = host->GetRecycler();
Assert(recycler != nullptr);
Assert(count >= AuxPtrs32::MaxCount);

auto requestSize = sizeof(AuxPtrs<T, FieldsEnum>) + (count - 1)*sizeof(void*);
auto allocSize = ::Math::Align<uint8>((uint8)requestSize, 16);
Expand Down Expand Up @@ -218,6 +217,7 @@ namespace Js
template<class T, typename FieldsEnum>
void AuxPtrs<T, FieldsEnum>::SetAuxPtr(T* host, FieldsEnum e, void* ptr)
{

if (host->auxPtrs == nullptr)
{
AuxPtrs<FunctionProxy, FieldsEnum>::AllocAuxPtrFix(host, 16);
Expand Down
1 change: 1 addition & 0 deletions lib/Runtime/Base/Chakra.Runtime.Base.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CompactCounters.h" />
<ClInclude Include="RuntimeBasePch.h" />
<ClInclude Include="AuxPtrs.h" />
<ClInclude Include="CallInfo.h" />
Expand Down
273 changes: 273 additions & 0 deletions lib/Runtime/Base/CompactCounters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once

#pragma warning(push)
#pragma warning(disable:6200) // C6200: Index is out of valid index range, compiler complains here we use variable length array

namespace Js
{
template<class T, typename CountT = T::CounterFields>
struct CompactCounters
{
uint8 fieldSize;
#if DBG
mutable bool bgThreadCallStarted;
bool isCleaningUp;
#endif
union {
uint8 u8Fields[CountT::Max];
int8 i8Fields[CountT::Max];
WriteBarrierPtr<uint16> u16Fields;
WriteBarrierPtr<uint32> u32Fields;
WriteBarrierPtr<int16> i16Fields;
WriteBarrierPtr<int32> i32Fields;
};

CompactCounters()
:fieldSize(1)
#if DBG
, bgThreadCallStarted(false), isCleaningUp(false)
#endif
{
memset(u8Fields, 0, (uint8)CountT::Max);
}

void AllocCounters(T* host, uint8 newSize);

uint32 Get(CountT typeEnum) const
{
#if DBG
if (ThreadContext::GetContextForCurrentThread() == nullptr)
{
bgThreadCallStarted = true;
}
#endif
uint8 type = static_cast<uint8>(typeEnum);
uint8 localFieldSize = fieldSize;
uint32 value = 0;
if (localFieldSize == 1)
{
value = this->u8Fields[type];
}
else if (localFieldSize == 2)
{
value = this->u16Fields[type];
}
else
{
Assert(localFieldSize == 4);
value = this->u32Fields[type];
}

return value;
}

int32 GetSigned(CountT typeEnum) const
{
#if DBG
if (ThreadContext::GetContextForCurrentThread() == nullptr)
{
bgThreadCallStarted = true;
}
#endif

uint8 type = static_cast<uint8>(typeEnum);
uint8 localFieldSize = fieldSize;
int32 value = 0;
if (localFieldSize == 1)
{
value = this->i8Fields[type];
}
else if (localFieldSize == 2)
{
value = this->i16Fields[type];
}
else
{
Assert(localFieldSize == 4);
value = this->i32Fields[type];
}
return value;
}

uint32 Set(CountT typeEnum, uint32 val, T* host)
{
Assert(bgThreadCallStarted == false || isCleaningUp == true);

uint8 type = static_cast<uint8>(typeEnum);
if (fieldSize == 1)
{
if (val <= UINT8_MAX)
{
return this->u8Fields[type] = static_cast<uint8>(val);
}
else
{
AllocCounters(host, val <= UINT16_MAX ? 2 : 4);
}
return this->Set(typeEnum, val, host);
}

if (fieldSize == 2)
{
if (val <= UINT16_MAX)
{
return this->u16Fields[type] = static_cast<uint16>(val);
}
else
{
AllocCounters(host, 4);
}
return this->Set(typeEnum, val, host);
}

Assert(fieldSize == 4);
return this->u32Fields[type] = val;
}

int32 SetSigned(CountT typeEnum, int32 val, T* host)
{
Assert(bgThreadCallStarted == false || isCleaningUp == true);

uint8 type = static_cast<uint8>(typeEnum);
if (fieldSize == 1)
{
if (val <= INT8_MAX && val >= INT8_MIN)
{
return this->i8Fields[type] = static_cast<uint8>(val);
}
else
{
AllocCounters(host, (val <= INT16_MAX && val >= INT16_MIN) ? 2 : 4);
}
return this->SetSigned(typeEnum, val, host);
}

if (fieldSize == 2)
{
if (val <= INT16_MAX && val >= INT16_MIN)
{
return this->i16Fields[type] = static_cast<uint16>(val);
}
else
{
AllocCounters(host, 4);
}
return this->SetSigned(typeEnum, val, host);
}

Assert(fieldSize == 4);
return this->i32Fields[type] = val;
}

uint32 Increase(CountT typeEnum, T* host)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name it "Increment"?

{
Assert(bgThreadCallStarted == false);

uint8 type = static_cast<uint8>(typeEnum);
if (fieldSize == 1)
{
if (this->u8Fields[type] < UINT8_MAX)
{
return this->u8Fields[type]++;
}
else
{
AllocCounters(host, 2);
}
return this->Increase(typeEnum, host);
}

if (fieldSize == 2)
{
if (this->u16Fields[type] < UINT16_MAX)
{
return this->u16Fields[type]++;
}
else
{
AllocCounters(host, 4);
}
return this->Increase(typeEnum, host);
}

Assert(fieldSize == 4);
return this->u32Fields[type]++;
}
};


template<class T, typename CountT>
void CompactCounters<T, CountT>::AllocCounters(T* host, uint8 newSize)
{
Assert(ThreadContext::GetContextForCurrentThread() || ThreadContext::GetCriticalSection()->IsLocked());

typedef CompactCounters<T, CountT> CounterT;
Assert(host->GetRecycler() != nullptr);

const uint8 signedStart = static_cast<uint8>(CountT::SignedFieldsStart);
const uint8 max = static_cast<uint8>(CountT::Max);

void* newFieldsArray = nullptr;
if (newSize == 2)
{
newFieldsArray = RecyclerNewArrayLeafZ(host->GetRecycler(), uint16, max);
}
else
{
Assert(newSize == 4);
newFieldsArray = RecyclerNewArrayLeafZ(host->GetRecycler(), uint32, max);
}

uint8 i = 0;
if (this->fieldSize == 1)
{
if (newSize == 2)
{
for (; i < signedStart; i++)
{
((uint16*)newFieldsArray)[i] = this->u8Fields[i];
}
for (; i < max; i++)
{
((int16*)newFieldsArray)[i] = this->i8Fields[i];
}
}
else
{
for (; i < signedStart; i++)
{
((uint32*)newFieldsArray)[i] = this->u8Fields[i];
}
for (; i < max; i++)
{
((int32*)newFieldsArray)[i] = this->i8Fields[i];
}
}
}
else if (this->fieldSize == 2)
{
for (; i < signedStart; i++)
{
((uint32*)newFieldsArray)[i] = this->u16Fields[i];
}
for (; i < max; i++)
{
((int32*)newFieldsArray)[i] = this->i16Fields[i];
}
}
else
{
Assert(false);
}

this->fieldSize = newSize;
this->u16Fields = (uint16*)newFieldsArray;

}
}

#pragma warning(pop)
Loading