Skip to content

Commit

Permalink
[1.10>master] [MERGE #5490 @rajatd] Fix field types in InlineeCallInf…
Browse files Browse the repository at this point in the history
…o. OS #15566165

Merge pull request #5490 from rajatd:inlineeCallInfo-type
  • Loading branch information
rajatd committed Jul 25, 2018
2 parents 0051d4a + a9358ce commit 8354bbc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
4 changes: 4 additions & 0 deletions lib/Backend/InlineeFrameInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ void InlineeFrameRecord::PopulateParent(Func* func)
void InlineeFrameRecord::Finalize(Func* inlinee, uint32 currentOffset)
{
this->PopulateParent(inlinee);
#if TARGET_32
const uint32 offsetMask = (~(uint32)0) >> (sizeof(uint) * CHAR_BIT - Js::InlineeCallInfo::ksizeofInlineeStartOffset);
AssertOrFailFast(currentOffset == (currentOffset & offsetMask));
#endif
this->inlineeStartOffset = currentOffset;
this->inlineDepth = inlinee->inlineDepth;

Expand Down
6 changes: 3 additions & 3 deletions lib/Backend/amd64/EncoderMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,11 +1518,11 @@ EncoderMD::FixRelocListEntry(uint32 index, int totalBytesSaved, BYTE *buffStart,
// ptr points to imm32 offset of the instruction that needs to be adjusted
// offset is in top 28-bits, arg count in bottom 4
size_t field = *((size_t*) relocRecord.m_origPtr);
size_t offset = field >> 4;
size_t offset = field >> Js::InlineeCallInfo::inlineeStartOffsetShiftCount;
uint32 count = field & 0xf;

AssertMsg(offset < (size_t)(buffEnd - buffStart), "Inlinee entry offset out of range");
relocRecord.SetInlineOffset(((offset - totalBytesSaved) << 4) | count);
relocRecord.SetInlineOffset(((offset - totalBytesSaved) << Js::InlineeCallInfo::inlineeStartOffsetShiftCount) | count);
}
// adjust the ptr to the buffer itself
relocRecord.m_ptr = (BYTE*) relocRecord.m_ptr - totalBytesSaved;
Expand Down Expand Up @@ -1777,7 +1777,7 @@ EncoderMD::EncodeInlineeCallInfo(IR::Instr *instr, uint32 codeOffset)
// than can fit in as many bits.
const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo,
instr->GetSrc1()->AsIntConstOpnd()->GetValue(), codeOffset);
Assert(encodeResult);
AssertOrFailFast(encodeResult);

instr->GetSrc1()->AsIntConstOpnd()->SetValue(inlineeCallInfo);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Backend/i386/EncoderMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,11 @@ EncoderMD::FixRelocListEntry(uint32 index, int32 totalBytesSaved, BYTE *buffStar
// ptr points to imm32 offset of the instruction that needs to be adjusted
// offset is in top 28-bits, arg count in bottom 4
uint32 field = *((uint32*) relocRecord.m_origPtr);
uint32 offset = field >> 4;
uint32 offset = field >> Js::InlineeCallInfo::inlineeStartOffsetShiftCount;
uint32 count = field & 0xf;

AssertMsg(offset < (uint32)(buffEnd - buffStart), "Inlinee entry offset out of range");
relocRecord.SetInlineOffset(((offset - totalBytesSaved) << 4) | count);
relocRecord.SetInlineOffset(((offset - totalBytesSaved) << Js::InlineeCallInfo::inlineeStartOffsetShiftCount) | count);
}
// adjust the ptr to the buffer itself
relocRecord.m_ptr = (BYTE*) relocRecord.m_ptr - totalBytesSaved;
Expand Down Expand Up @@ -1588,7 +1588,7 @@ EncoderMD::EncodeInlineeCallInfo(IR::Instr *instr, uint32 codeOffset)
// offset of the start of the inlinee. We shouldn't have gotten here with more arguments
// than can fit in as many bits.
const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo, (uint32)instr->GetSrc1()->AsIntConstOpnd()->GetValue(), codeOffset);
Assert(encodeResult);
AssertOrFailFast(encodeResult);

instr->GetSrc1()->AsIntConstOpnd()->SetValue(inlineeCallInfo);
}
Expand Down
20 changes: 15 additions & 5 deletions lib/Runtime/Base/CallInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,24 @@ namespace Js
struct InlineeCallInfo
{
// Assumes big-endian layout.
size_t Count: 4;
size_t InlineeStartOffset: sizeof(void*) * CHAR_BIT - 4;
uint Count : 4;
#if TARGET_32
uint InlineeStartOffset : 28;
#else
uint unused : 28;
uint InlineeStartOffset;
#endif
static size_t const MaxInlineeArgoutCount = 0xF;
#if TARGET_32
static uint const ksizeofInlineeStartOffset = 28;
#else
static uint const ksizeofInlineeStartOffset = 32;
#endif
static uint const inlineeStartOffsetShiftCount = (sizeof(void*) * CHAR_BIT - Js::InlineeCallInfo::ksizeofInlineeStartOffset);

static bool Encode(intptr_t &callInfo, size_t count, size_t offset)
{
const size_t offsetMask = (~(size_t)0) >> 4;
const size_t offsetMask = ~(uint)0 >> (sizeof(uint) * CHAR_BIT - ksizeofInlineeStartOffset);
const size_t countMask = 0x0000000F;
if (count != (count & countMask))
{
Expand All @@ -163,8 +174,7 @@ namespace Js
return false;
}

callInfo = (offset << 4) | count;

callInfo = (offset << inlineeStartOffsetShiftCount) | count;
return true;
}

Expand Down
7 changes: 1 addition & 6 deletions lib/Runtime/Language/JavascriptStackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,20 +1461,15 @@ namespace Js
{
Assert(!IsTopMostFrame());
Assert(currentIndex);
#pragma warning(push)
#pragma warning(disable: 4254)

return GetFrameAtIndex(currentIndex - 1)->callInfo.InlineeStartOffset;
#pragma warning(pop)
}

uint32 InlinedFrameWalker::GetBottomMostInlineeOffset() const
{
Assert(frameCount);

#pragma warning(push)
#pragma warning(disable: 4254)
return GetFrameAtIndex(frameCount - 1)->callInfo.InlineeStartOffset;
#pragma warning(pop)
}

Js::JavascriptFunction *InlinedFrameWalker::GetBottomMostFunctionObject() const
Expand Down

0 comments on commit 8354bbc

Please sign in to comment.