Skip to content

Commit

Permalink
Merge r242103 - Misc cleanup in StructureIDTable after r242096.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=195063

Reviewed by Saam Barati.

* runtime/StructureIDTable.cpp:
(JSC::StructureIDTable::allocateID):
- RELEASE_ASSERT that the StructureID allocation will succeed.

* runtime/StructureIDTable.h:
(JSC::StructureIDTable::decode):
(JSC::StructureIDTable::encode):
- Add back a comment that Yusuke requested but was lost when the patch was rolled
  out and relanded.
- Applied bitwise_casts that Saam requested.
  • Loading branch information
Mark Lam authored and carlosgcampos committed Mar 5, 2019
1 parent 15f132f commit 23550e1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
18 changes: 18 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,21 @@
2019-02-26 Mark Lam <mark.lam@apple.com>

Misc cleanup in StructureIDTable after r242096.
https://bugs.webkit.org/show_bug.cgi?id=195063

Reviewed by Saam Barati.

* runtime/StructureIDTable.cpp:
(JSC::StructureIDTable::allocateID):
- RELEASE_ASSERT that the StructureID allocation will succeed.

* runtime/StructureIDTable.h:
(JSC::StructureIDTable::decode):
(JSC::StructureIDTable::encode):
- Add back a comment that Yusuke requested but was lost when the patch was rolled
out and relanded.
- Applied bitwise_casts that Saam requested.

2019-02-26 Mark Lam <mark.lam@apple.com>

Gardening: 32-bit build fix after r242096.
Expand Down
4 changes: 1 addition & 3 deletions Source/JavaScriptCore/runtime/StructureIDTable.cpp
Expand Up @@ -135,11 +135,9 @@ StructureID StructureIDTable::allocateID(Structure* structure)
ASSERT(m_size == m_capacity);
resize(m_capacity * 2);
ASSERT(m_size < m_capacity);
ASSERT(m_firstFreeOffset);
RELEASE_ASSERT(m_firstFreeOffset);
}

ASSERT(m_firstFreeOffset != s_unusedID);

// entropyBits must not be zero. This ensures that if a corrupted
// structureID is encountered (with incorrect entropyBits), the decoded
// structure pointer for that ID will be always be a bad pointer with
Expand Down
23 changes: 21 additions & 2 deletions Source/JavaScriptCore/runtime/StructureIDTable.h
Expand Up @@ -131,6 +131,25 @@ class StructureIDTable {
static constexpr StructureID s_unusedID = 0;

public:
// 1. StructureID is encoded as:
//
// ----------------------------------------------------------------
// | 1 Nuke Bit | 24 StructureIDTable index bits | 7 entropy bits |
// ----------------------------------------------------------------
//
// The entropy bits are chosen at random and assigned when a StructureID
// is allocated.
//
// 2. For each StructureID, the StructureIDTable stores encodedStructureBits
// which are encoded from the structure pointer as such:
//
// ----------------------------------------------------------------
// | 7 entropy bits | 57 structure pointer bits |
// ----------------------------------------------------------------
//
// The entropy bits here are the same 7 bits used in the encoding of the
// StructureID for this structure entry in the StructureIDTable.

static constexpr uint32_t s_numberOfNukeBits = 1;
static constexpr uint32_t s_numberOfEntropyBits = 7;
static constexpr uint32_t s_entropyBitsShiftForStructurePointer = (sizeof(intptr_t) * 8) - s_numberOfEntropyBits;
Expand All @@ -140,12 +159,12 @@ class StructureIDTable {

ALWAYS_INLINE Structure* StructureIDTable::decode(EncodedStructureBits bits, StructureID structureID)
{
return reinterpret_cast<Structure*>(bits ^ (static_cast<uintptr_t>(structureID) << s_entropyBitsShiftForStructurePointer));
return bitwise_cast<Structure*>(bits ^ (static_cast<uintptr_t>(structureID) << s_entropyBitsShiftForStructurePointer));
}

ALWAYS_INLINE EncodedStructureBits StructureIDTable::encode(Structure* structure, StructureID structureID)
{
return reinterpret_cast<EncodedStructureBits>(structure) ^ (static_cast<EncodedStructureBits>(structureID) << s_entropyBitsShiftForStructurePointer);
return bitwise_cast<EncodedStructureBits>(structure) ^ (static_cast<EncodedStructureBits>(structureID) << s_entropyBitsShiftForStructurePointer);
}

inline Structure* StructureIDTable::get(StructureID structureID)
Expand Down

0 comments on commit 23550e1

Please sign in to comment.