Title: [247854] trunk/Source/_javascript_Core
Revision
247854
Author
[email protected]
Date
2019-07-25 21:58:09 -0700 (Thu, 25 Jul 2019)

Log Message

[JSC] Use unalignedLoad for JSRopeString fiber accesses
https://bugs.webkit.org/show_bug.cgi?id=200148

Reviewed by Mark Lam.

JSRopeString always have some subsequent bytes that can be accessible because MarkedBlock has Footer.
We use WTF::unalignedLoad to get fibers. And it will be converted to one load CPU instruction.

* heap/MarkedBlock.h:
* runtime/JSString.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (247853 => 247854)


--- trunk/Source/_javascript_Core/ChangeLog	2019-07-26 02:38:39 UTC (rev 247853)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-07-26 04:58:09 UTC (rev 247854)
@@ -1,3 +1,16 @@
+2019-07-25  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Use unalignedLoad for JSRopeString fiber accesses
+        https://bugs.webkit.org/show_bug.cgi?id=200148
+
+        Reviewed by Mark Lam.
+
+        JSRopeString always have some subsequent bytes that can be accessible because MarkedBlock has Footer.
+        We use WTF::unalignedLoad to get fibers. And it will be converted to one load CPU instruction.
+
+        * heap/MarkedBlock.h:
+        * runtime/JSString.h:
+
 2019-07-25  Ross Kirsling  <[email protected]>
 
         Legacy numeric literals should not permit separators or BigInt

Modified: trunk/Source/_javascript_Core/heap/MarkedBlock.h (247853 => 247854)


--- trunk/Source/_javascript_Core/heap/MarkedBlock.h	2019-07-26 02:38:39 UTC (rev 247853)
+++ trunk/Source/_javascript_Core/heap/MarkedBlock.h	2019-07-26 04:58:09 UTC (rev 247854)
@@ -302,6 +302,9 @@
     static constexpr size_t footerSize = blockSize - payloadSize;
 
     static_assert(payloadSize == ((blockSize - sizeof(MarkedBlock::Footer)) & ~(atomSize - 1)), "Payload size computed the alternate way should give the same result");
+    // Some of JSCell types assume that the last JSCell in a MarkedBlock has a subsequent memory region (Footer) that can still safely accessed.
+    // For example, JSRopeString assumes that it can safely access up to 2 bytes beyond the JSRopeString cell.
+    static_assert(sizeof(Footer) >= sizeof(uint16_t));
     
     static MarkedBlock::Handle* tryCreate(Heap&, AlignedMemoryAllocator*);
         

Modified: trunk/Source/_javascript_Core/runtime/JSString.h (247853 => 247854)


--- trunk/Source/_javascript_Core/runtime/JSString.h	2019-07-26 02:38:39 UTC (rev 247853)
+++ trunk/Source/_javascript_Core/runtime/JSString.h	2019-07-26 04:58:09 UTC (rev 247854)
@@ -270,9 +270,14 @@
     static_assert(sizeof(uintptr_t) == sizeof(uint64_t), "");
     class CompactFibers {
     public:
+        static constexpr uintptr_t addressMask = (1ULL << WTF_CPU_EFFECTIVE_ADDRESS_WIDTH) - 1;
         JSString* fiber1() const
         {
+#if CPU(LITTLE_ENDIAN)
+            return bitwise_cast<JSString*>(WTF::unalignedLoad<uintptr_t>(&m_fiber1Lower) & addressMask);
+#else
             return bitwise_cast<JSString*>(static_cast<uintptr_t>(m_fiber1Lower) | (static_cast<uintptr_t>(m_fiber1Upper) << 32));
+#endif
         }
 
         void initializeFiber1(JSString* fiber)
@@ -284,7 +289,14 @@
 
         JSString* fiber2() const
         {
+#if CPU(LITTLE_ENDIAN)
+            // This access exceeds the sizeof(JSRopeString). But this is OK because JSRopeString is always allocated in MarkedBlock,
+            // and the last JSRopeString cell in the block has some subsequent bytes which are used for MarkedBlock::Footer.
+            // So the following access does not step over the page boundary in which the latter page does not have read permission.
+            return bitwise_cast<JSString*>(WTF::unalignedLoad<uintptr_t>(&m_fiber2Lower) & addressMask);
+#else
             return bitwise_cast<JSString*>(static_cast<uintptr_t>(m_fiber2Lower) | (static_cast<uintptr_t>(m_fiber2Upper) << 16));
+#endif
         }
         void initializeFiber2(JSString* fiber)
         {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to