Misc cleanup in StructureIDTable after r242096.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2019 21:40:48 +0000 (21:40 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2019 21:40:48 +0000 (21:40 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242103 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/StructureIDTable.cpp
Source/JavaScriptCore/runtime/StructureIDTable.h

index 8c60b5f..dd196f8 100644 (file)
@@ -1,5 +1,23 @@
 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.
         https://bugs.webkit.org/show_bug.cgi?id=194989
 
index f2a87f1..b7a601f 100644 (file)
@@ -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
index 7d187a7..8fe92cc 100644 (file)
@@ -131,6 +131,25 @@ private:
     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;
@@ -140,12 +159,12 @@ public:
 
 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)