Title: [262591] trunk/Source/_javascript_Core
Revision
262591
Author
msab...@apple.com
Date
2020-06-04 19:40:58 -0700 (Thu, 04 Jun 2020)

Log Message

Add a Thread Specific Cache for LinkBuffer::CompactAndLinkCode()
https://bugs.webkit.org/show_bug.cgi?id=212765

Reviewed by Saam Barati.

Added a thread local buffer for CPU types that use a second buffer when compacting.
This is very similary to the work done in https://bugs.webkit.org/show_bug.cgi?id=212562.

* assembler/LinkBuffer.cpp:
(JSC::threadSpecificBranchCompactionLinkBuffer):
(JSC::BranchCompactionLinkBuffer::BranchCompactionLinkBuffer):
(JSC::BranchCompactionLinkBuffer::~BranchCompactionLinkBuffer):
(JSC::BranchCompactionLinkBuffer::data):
(JSC::BranchCompactionLinkBuffer::takeBufferIfLarger):
(JSC::BranchCompactionLinkBuffer::size):
(JSC::LinkBuffer::copyCompactAndLinkCode):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (262590 => 262591)


--- trunk/Source/_javascript_Core/ChangeLog	2020-06-05 00:19:13 UTC (rev 262590)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-06-05 02:40:58 UTC (rev 262591)
@@ -1,3 +1,22 @@
+2020-06-04  Michael Saboff  <msab...@apple.com>
+
+        Add a Thread Specific Cache for LinkBuffer::CompactAndLinkCode()
+        https://bugs.webkit.org/show_bug.cgi?id=212765
+
+        Reviewed by Saam Barati.
+
+        Added a thread local buffer for CPU types that use a second buffer when compacting.
+        This is very similary to the work done in https://bugs.webkit.org/show_bug.cgi?id=212562.
+
+        * assembler/LinkBuffer.cpp:
+        (JSC::threadSpecificBranchCompactionLinkBuffer):
+        (JSC::BranchCompactionLinkBuffer::BranchCompactionLinkBuffer):
+        (JSC::BranchCompactionLinkBuffer::~BranchCompactionLinkBuffer):
+        (JSC::BranchCompactionLinkBuffer::data):
+        (JSC::BranchCompactionLinkBuffer::takeBufferIfLarger):
+        (JSC::BranchCompactionLinkBuffer::size):
+        (JSC::LinkBuffer::copyCompactAndLinkCode):
+
 2020-06-04  Mark Lam  <mark....@apple.com>
 
         Add Options::validateDoesGC() for turning DoesGC validation on/off.

Modified: trunk/Source/_javascript_Core/assembler/LinkBuffer.cpp (262590 => 262591)


--- trunk/Source/_javascript_Core/assembler/LinkBuffer.cpp	2020-06-05 00:19:13 UTC (rev 262590)
+++ trunk/Source/_javascript_Core/assembler/LinkBuffer.cpp	2020-06-05 02:40:58 UTC (rev 262591)
@@ -119,6 +119,85 @@
 }
 
 #if ENABLE(BRANCH_COMPACTION)
+#if !CPU(ARM64E) || !ENABLE(FAST_JIT_PERMISSIONS)
+class BranchCompactionLinkBuffer;
+
+using ThreadSpecificBranchCompactionLinkBuffer = ThreadSpecific<BranchCompactionLinkBuffer, WTF::CanBeGCThread::True>;
+
+static ThreadSpecificBranchCompactionLinkBuffer* threadSpecificBranchCompactionLinkBufferPtr;
+
+static ThreadSpecificBranchCompactionLinkBuffer& threadSpecificBranchCompactionLinkBuffer()
+{
+static std::once_flag flag;
+    std::call_once(
+        flag,
+        [] () {
+            threadSpecificBranchCompactionLinkBufferPtr = new ThreadSpecificBranchCompactionLinkBuffer();
+        });
+    return *threadSpecificBranchCompactionLinkBufferPtr;
+}
+
+DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(BranchCompactionLinkBuffer);
+
+class BranchCompactionLinkBuffer {
+    WTF_MAKE_NONCOPYABLE(BranchCompactionLinkBuffer);
+public:
+    BranchCompactionLinkBuffer()
+    {
+    }
+
+    BranchCompactionLinkBuffer(size_t size)
+    {
+        auto& threadSpecific = threadSpecificBranchCompactionLinkBuffer();
+
+        if (threadSpecific->size() >= size)
+            takeBufferIfLarger(*threadSpecific);
+        else {
+            m_size = size;
+            m_data = static_cast<uint8_t*>(BranchCompactionLinkBufferMalloc::malloc(size));
+        }
+    }
+
+    ~BranchCompactionLinkBuffer()
+    {
+        auto& threadSpecific = threadSpecificBranchCompactionLinkBuffer();
+        threadSpecific->takeBufferIfLarger(*this);
+
+        if (m_data)
+            BranchCompactionLinkBufferMalloc::free(m_data);
+    }
+
+    uint8_t* data()
+    {
+        return m_data;
+    }
+
+private:
+    void takeBufferIfLarger(BranchCompactionLinkBuffer& other)
+    {
+        if (size() >= other.size())
+            return;
+
+        if (m_data)
+            BranchCompactionLinkBufferMalloc::free(m_data);
+
+        m_data = other.m_data;
+        m_size = other.m_size;
+
+        other.m_data = nullptr;
+        other.m_size = 0;
+    }
+
+    size_t size()
+    {
+        return m_size;
+    }
+
+    uint8_t* m_data { nullptr };
+    size_t m_size { 0 };
+};
+#endif
+
 static ALWAYS_INLINE void recordLinkOffsets(AssemblerData& assemblerData, int32_t regionStart, int32_t regionEnd, int32_t offset)
 {
     int32_t ptr = regionStart / sizeof(int32_t);
@@ -146,8 +225,8 @@
     ARM64EHash verifyUncompactedHash;
     uint8_t* outData = codeOutData;
 #else
-    AssemblerData outBuffer(m_size);
-    uint8_t* outData = reinterpret_cast<uint8_t*>(outBuffer.buffer());
+    BranchCompactionLinkBuffer outBuffer(m_size);
+    uint8_t* outData = reinterpret_cast<uint8_t*>(outBuffer.data());
 #endif
 #if CPU(ARM64)
     RELEASE_ASSERT(roundUpToMultipleOf<sizeof(unsigned)>(outData) == outData);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to