Title: [245926] branches/safari-607-branch
Revision
245926
Author
[email protected]
Date
2019-05-30 17:30:17 -0700 (Thu, 30 May 2019)

Log Message

Cherry-pick r245586. rdar://problem/51264876

    Cleanup Yarr regexp code around paren contexts.
    https://bugs.webkit.org/show_bug.cgi?id=198063

    Reviewed by Yusuke Suzuki.

    JSTests:

    * stress/regexp-many-named-sequential-capture-groups.js: Added.
    (i.s):
    * stress/regexp-many-unnamed-sequential-capture-groups.js: Added.

    Source/_javascript_Core:

    There are three refactoring changes around paren contexts:
    1. Make EncodedMatchResult the same type as MatchResult on X86_64 and arm64 and uint64_t elsewhere.
    2. All function pointer types for Yarr JIT generated code reserve space for paren contexts.
    3. initParenContextFreeList should bail based on VM::patternContextBufferSize as that's the buffer size anyway.

    * runtime/MatchResult.h:
    (JSC::MatchResult::MatchResult):
    * runtime/RegExpInlines.h:
    (JSC::PatternContextBufferHolder::PatternContextBufferHolder):
    (JSC::PatternContextBufferHolder::~PatternContextBufferHolder):
    (JSC::PatternContextBufferHolder::size):
    (JSC::RegExp::matchInline):
    * runtime/VM.h:
    * yarr/YarrJIT.cpp:
    (JSC::Yarr::YarrGenerator::initParenContextFreeList):
    * yarr/YarrJIT.h:
    (JSC::Yarr::YarrCodeBlock::execute):

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-607-branch/JSTests/ChangeLog (245925 => 245926)


--- branches/safari-607-branch/JSTests/ChangeLog	2019-05-31 00:30:13 UTC (rev 245925)
+++ branches/safari-607-branch/JSTests/ChangeLog	2019-05-31 00:30:17 UTC (rev 245926)
@@ -1,5 +1,53 @@
 2019-05-30  Kocsen Chung  <[email protected]>
 
+        Cherry-pick r245586. rdar://problem/51264876
+
+    Cleanup Yarr regexp code around paren contexts.
+    https://bugs.webkit.org/show_bug.cgi?id=198063
+    
+    Reviewed by Yusuke Suzuki.
+    
+    JSTests:
+    
+    * stress/regexp-many-named-sequential-capture-groups.js: Added.
+    (i.s):
+    * stress/regexp-many-unnamed-sequential-capture-groups.js: Added.
+    
+    Source/_javascript_Core:
+    
+    There are three refactoring changes around paren contexts:
+    1. Make EncodedMatchResult the same type as MatchResult on X86_64 and arm64 and uint64_t elsewhere.
+    2. All function pointer types for Yarr JIT generated code reserve space for paren contexts.
+    3. initParenContextFreeList should bail based on VM::patternContextBufferSize as that's the buffer size anyway.
+    
+    * runtime/MatchResult.h:
+    (JSC::MatchResult::MatchResult):
+    * runtime/RegExpInlines.h:
+    (JSC::PatternContextBufferHolder::PatternContextBufferHolder):
+    (JSC::PatternContextBufferHolder::~PatternContextBufferHolder):
+    (JSC::PatternContextBufferHolder::size):
+    (JSC::RegExp::matchInline):
+    * runtime/VM.h:
+    * yarr/YarrJIT.cpp:
+    (JSC::Yarr::YarrGenerator::initParenContextFreeList):
+    * yarr/YarrJIT.h:
+    (JSC::Yarr::YarrCodeBlock::execute):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245586 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-20  Keith Miller  <[email protected]>
+
+            Cleanup Yarr regexp code around paren contexts.
+            https://bugs.webkit.org/show_bug.cgi?id=198063
+
+            Reviewed by Yusuke Suzuki.
+
+            * stress/regexp-many-named-sequential-capture-groups.js: Added.
+            (i.s):
+            * stress/regexp-many-unnamed-sequential-capture-groups.js: Added.
+
+2019-05-30  Kocsen Chung  <[email protected]>
+
         Cherry-pick r245071. rdar://problem/51264850
 
     Invalid DFG JIT genereation in high CPU usage state

Added: branches/safari-607-branch/JSTests/stress/regexp-many-named-sequential-capture-groups.js (0 => 245926)


--- branches/safari-607-branch/JSTests/stress/regexp-many-named-sequential-capture-groups.js	                        (rev 0)
+++ branches/safari-607-branch/JSTests/stress/regexp-many-named-sequential-capture-groups.js	2019-05-31 00:30:17 UTC (rev 245926)
@@ -0,0 +1,8 @@
+let s = '';
+for (let i = 0; i < 1000; i++) {
+    s += `(?<foo${i}>a){0,2}`;
+}
+
+let r = new RegExp(s);
+for (let i = 0; i < 1000; i++)
+    ''.match(r);

Added: branches/safari-607-branch/JSTests/stress/regexp-many-unnamed-sequential-capture-groups.js (0 => 245926)


--- branches/safari-607-branch/JSTests/stress/regexp-many-unnamed-sequential-capture-groups.js	                        (rev 0)
+++ branches/safari-607-branch/JSTests/stress/regexp-many-unnamed-sequential-capture-groups.js	2019-05-31 00:30:17 UTC (rev 245926)
@@ -0,0 +1,8 @@
+let s = '';
+for (let i = 0; i < 1000; i++) {
+    s += '(?:a){0,2}';
+}
+
+let r = new RegExp(s);
+for (let i = 0; i < 1000; i++)
+    ''.match(r);

Modified: branches/safari-607-branch/Source/_javascript_Core/ChangeLog (245925 => 245926)


--- branches/safari-607-branch/Source/_javascript_Core/ChangeLog	2019-05-31 00:30:13 UTC (rev 245925)
+++ branches/safari-607-branch/Source/_javascript_Core/ChangeLog	2019-05-31 00:30:17 UTC (rev 245926)
@@ -1,5 +1,67 @@
 2019-05-30  Kocsen Chung  <[email protected]>
 
+        Cherry-pick r245586. rdar://problem/51264876
+
+    Cleanup Yarr regexp code around paren contexts.
+    https://bugs.webkit.org/show_bug.cgi?id=198063
+    
+    Reviewed by Yusuke Suzuki.
+    
+    JSTests:
+    
+    * stress/regexp-many-named-sequential-capture-groups.js: Added.
+    (i.s):
+    * stress/regexp-many-unnamed-sequential-capture-groups.js: Added.
+    
+    Source/_javascript_Core:
+    
+    There are three refactoring changes around paren contexts:
+    1. Make EncodedMatchResult the same type as MatchResult on X86_64 and arm64 and uint64_t elsewhere.
+    2. All function pointer types for Yarr JIT generated code reserve space for paren contexts.
+    3. initParenContextFreeList should bail based on VM::patternContextBufferSize as that's the buffer size anyway.
+    
+    * runtime/MatchResult.h:
+    (JSC::MatchResult::MatchResult):
+    * runtime/RegExpInlines.h:
+    (JSC::PatternContextBufferHolder::PatternContextBufferHolder):
+    (JSC::PatternContextBufferHolder::~PatternContextBufferHolder):
+    (JSC::PatternContextBufferHolder::size):
+    (JSC::RegExp::matchInline):
+    * runtime/VM.h:
+    * yarr/YarrJIT.cpp:
+    (JSC::Yarr::YarrGenerator::initParenContextFreeList):
+    * yarr/YarrJIT.h:
+    (JSC::Yarr::YarrCodeBlock::execute):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245586 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-20  Keith Miller  <[email protected]>
+
+            Cleanup Yarr regexp code around paren contexts.
+            https://bugs.webkit.org/show_bug.cgi?id=198063
+
+            Reviewed by Yusuke Suzuki.
+
+            There are three refactoring changes around paren contexts:
+            1. Make EncodedMatchResult the same type as MatchResult on X86_64 and arm64 and uint64_t elsewhere.
+            2. All function pointer types for Yarr JIT generated code reserve space for paren contexts.
+            3. initParenContextFreeList should bail based on VM::patternContextBufferSize as that's the buffer size anyway.
+
+            * runtime/MatchResult.h:
+            (JSC::MatchResult::MatchResult):
+            * runtime/RegExpInlines.h:
+            (JSC::PatternContextBufferHolder::PatternContextBufferHolder):
+            (JSC::PatternContextBufferHolder::~PatternContextBufferHolder):
+            (JSC::PatternContextBufferHolder::size):
+            (JSC::RegExp::matchInline):
+            * runtime/VM.h:
+            * yarr/YarrJIT.cpp:
+            (JSC::Yarr::YarrGenerator::initParenContextFreeList):
+            * yarr/YarrJIT.h:
+            (JSC::Yarr::YarrCodeBlock::execute):
+
+2019-05-30  Kocsen Chung  <[email protected]>
+
         Cherry-pick r245071. rdar://problem/51264850
 
     Invalid DFG JIT genereation in high CPU usage state

Modified: branches/safari-607-branch/Source/_javascript_Core/runtime/MatchResult.h (245925 => 245926)


--- branches/safari-607-branch/Source/_javascript_Core/runtime/MatchResult.h	2019-05-31 00:30:13 UTC (rev 245925)
+++ branches/safari-607-branch/Source/_javascript_Core/runtime/MatchResult.h	2019-05-31 00:30:17 UTC (rev 245926)
@@ -30,7 +30,12 @@
 
 namespace JSC {
 
-typedef uint64_t EncodedMatchResult;
+struct MatchResult;
+#if CPU(ARM64) || CPU(X86_64)
+using EncodedMatchResult = MatchResult;
+#else
+using EncodedMatchResult = uint64_t;
+#endif
 
 struct MatchResult {
     MatchResult()
@@ -45,19 +50,13 @@
     {
     }
 
-    explicit ALWAYS_INLINE MatchResult(EncodedMatchResult encoded)
+#if !(CPU(ARM64) || CPU(X86_64))
+    ALWAYS_INLINE MatchResult(EncodedMatchResult match)
+        : start(bitwise_cast<MatchResult>(match).start)
+        , end(bitwise_cast<MatchResult>(match).end)
     {
-        union u {
-            uint64_t encoded;
-            struct s {
-                size_t start;
-                size_t end;
-            } split;
-        } value;
-        value.encoded = encoded;
-        start = value.split.start;
-        end = value.split.end;
     }
+#endif
 
     ALWAYS_INLINE static MatchResult failed()
     {
@@ -80,4 +79,6 @@
     size_t end;
 };
 
+static_assert(sizeof(MatchResult) == sizeof(EncodedMatchResult), "Match result and EncodedMatchResult should be the same size");
+
 } // namespace JSC

Modified: branches/safari-607-branch/Source/_javascript_Core/runtime/RegExpInlines.h (245925 => 245926)


--- branches/safari-607-branch/Source/_javascript_Core/runtime/RegExpInlines.h	2019-05-31 00:30:13 UTC (rev 245925)
+++ branches/safari-607-branch/Source/_javascript_Core/runtime/RegExpInlines.h	2019-05-31 00:30:17 UTC (rev 245926)
@@ -85,38 +85,36 @@
     return false;
 }
 
-#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
 class PatternContextBufferHolder {
+    WTF_FORBID_HEAP_ALLOCATION;
 public:
     PatternContextBufferHolder(VM& vm, bool needBuffer)
         : m_vm(vm)
-        , m_needBuffer(needBuffer)
     {
-        if (m_needBuffer) {
+#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
+        if (needBuffer)
             m_buffer = m_vm.acquireRegExpPatternContexBuffer();
-            m_size = VM::patternContextBufferSize;
-        } else {
-            m_buffer = nullptr;
-            m_size = 0;
-        }
+#endif
+
     }
 
     ~PatternContextBufferHolder()
     {
-        if (m_needBuffer)
+#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
+        if (buffer())
             m_vm.releaseRegExpPatternContexBuffer();
+#else
+        UNUSED_PARAM(m_vm);
+#endif
     }
 
     void* buffer() { return m_buffer; }
-    unsigned size() { return m_size; }
+    unsigned size() { return buffer() ? VM::patternContextBufferSize : 0; }
 
 private:
     VM& m_vm;
-    bool m_needBuffer;
     void* m_buffer;
-    unsigned m_size;
 };
-#endif
 
 ALWAYS_INLINE void RegExp::compileIfNecessary(VM& vm, Yarr::YarrCharSize charSize)
 {
@@ -156,20 +154,13 @@
 #if ENABLE(YARR_JIT)
     if (m_state == JITCode) {
         {
-#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
+            ASSERT(m_regExpJITCode);
             PatternContextBufferHolder patternContextBufferHolder(vm, m_regExpJITCode.usesPatternContextBuffer());
 
-#define EXTRA_JIT_PARAMS  , patternContextBufferHolder.buffer(), patternContextBufferHolder.size()
-#else
-#define EXTRA_JIT_PARAMS
-#endif
-
             if (s.is8Bit())
-                result = m_regExpJITCode.execute(s.characters8(), startOffset, s.length(), offsetVector EXTRA_JIT_PARAMS).start;
+                result = m_regExpJITCode.execute(s.characters8(), startOffset, s.length(), offsetVector, patternContextBufferHolder.buffer(), patternContextBufferHolder.size()).start;
             else
-                result = m_regExpJITCode.execute(s.characters16(), startOffset, s.length(), offsetVector EXTRA_JIT_PARAMS).start;
-
-#undef EXTRA_JIT_PARAMS
+                result = m_regExpJITCode.execute(s.characters16(), startOffset, s.length(), offsetVector, patternContextBufferHolder.buffer(), patternContextBufferHolder.size()).start;
         }
 
         if (result == Yarr::JSRegExpJITCodeFailure) {
@@ -277,20 +268,12 @@
 
     if (m_state == JITCode) {
         {
-#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
+            ASSERT(m_regExpJITCode);
             PatternContextBufferHolder patternContextBufferHolder(vm, m_regExpJITCode.usesPatternContextBuffer());
-
-#define EXTRA_JIT_PARAMS  , patternContextBufferHolder.buffer(), patternContextBufferHolder.size()
-#else
-#define EXTRA_JIT_PARAMS
-#endif
-
             if (s.is8Bit())
-                result = m_regExpJITCode.execute(s.characters8(), startOffset, s.length() EXTRA_JIT_PARAMS);
+                result = m_regExpJITCode.execute(s.characters8(), startOffset, s.length(), patternContextBufferHolder.buffer(), patternContextBufferHolder.size());
             else
-                result = m_regExpJITCode.execute(s.characters16(), startOffset, s.length() EXTRA_JIT_PARAMS);
-
-#undef EXTRA_JIT_PARAMS
+                result = m_regExpJITCode.execute(s.characters16(), startOffset, s.length(), patternContextBufferHolder.buffer(), patternContextBufferHolder.size());
         }
 
 #if ENABLE(REGEXP_TRACING)

Modified: branches/safari-607-branch/Source/_javascript_Core/runtime/VM.h (245925 => 245926)


--- branches/safari-607-branch/Source/_javascript_Core/runtime/VM.h	2019-05-31 00:30:13 UTC (rev 245925)
+++ branches/safari-607-branch/Source/_javascript_Core/runtime/VM.h	2019-05-31 00:30:17 UTC (rev 245926)
@@ -792,6 +792,8 @@
     Lock m_regExpPatternContextLock;
     char* acquireRegExpPatternContexBuffer();
     void releaseRegExpPatternContexBuffer();
+#else
+    static constexpr size_t patternContextBufferSize = 0; // Space allocated to save nested parenthesis context
 #endif
 
     Ref<CompactVariableMap> m_compactVariableMap;

Modified: branches/safari-607-branch/Source/_javascript_Core/yarr/YarrJIT.cpp (245925 => 245926)


--- branches/safari-607-branch/Source/_javascript_Core/yarr/YarrJIT.cpp	2019-05-31 00:30:13 UTC (rev 245925)
+++ branches/safari-607-branch/Source/_javascript_Core/yarr/YarrJIT.cpp	2019-05-31 00:30:17 UTC (rev 245926)
@@ -229,7 +229,7 @@
         parenContextSize = WTF::roundUpToMultipleOf<sizeof(uintptr_t)>(parenContextSize);
 
         // Check that the paren context is a reasonable size.
-        if (parenContextSize > INT16_MAX)
+        if (parenContextSize > VM::patternContextBufferSize)
             m_abortExecution.append(jump());
 
         Jump emptyFreeList = branchTestPtr(Zero, freelistRegister);

Modified: branches/safari-607-branch/Source/_javascript_Core/yarr/YarrJIT.h (245925 => 245926)


--- branches/safari-607-branch/Source/_javascript_Core/yarr/YarrJIT.h	2019-05-31 00:30:13 UTC (rev 245925)
+++ branches/safari-607-branch/Source/_javascript_Core/yarr/YarrJIT.h	2019-05-31 00:30:17 UTC (rev 245926)
@@ -38,10 +38,6 @@
 #define YARR_CALL
 #endif
 
-#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
-constexpr size_t patternContextBufferSize = 8192; // Space caller allocates to save nested parenthesis context
-#endif
-
 namespace JSC {
 
 class VM;
@@ -60,24 +56,11 @@
 };
 
 class YarrCodeBlock {
-#if CPU(X86_64) || CPU(ARM64)
-#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
-    typedef MatchResult (*YarrJITCode8)(const LChar* input, unsigned start, unsigned length, int* output, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
-    typedef MatchResult (*YarrJITCode16)(const UChar* input, unsigned start, unsigned length, int* output, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
-    typedef MatchResult (*YarrJITCodeMatchOnly8)(const LChar* input, unsigned start, unsigned length, void*, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
-    typedef MatchResult (*YarrJITCodeMatchOnly16)(const UChar* input, unsigned start, unsigned length, void*, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
-#else
-    typedef MatchResult (*YarrJITCode8)(const LChar* input, unsigned start, unsigned length, int* output) YARR_CALL;
-    typedef MatchResult (*YarrJITCode16)(const UChar* input, unsigned start, unsigned length, int* output) YARR_CALL;
-    typedef MatchResult (*YarrJITCodeMatchOnly8)(const LChar* input, unsigned start, unsigned length) YARR_CALL;
-    typedef MatchResult (*YarrJITCodeMatchOnly16)(const UChar* input, unsigned start, unsigned length) YARR_CALL;
-#endif
-#else
-    typedef EncodedMatchResult (*YarrJITCode8)(const LChar* input, unsigned start, unsigned length, int* output) YARR_CALL;
-    typedef EncodedMatchResult (*YarrJITCode16)(const UChar* input, unsigned start, unsigned length, int* output) YARR_CALL;
-    typedef EncodedMatchResult (*YarrJITCodeMatchOnly8)(const LChar* input, unsigned start, unsigned length) YARR_CALL;
-    typedef EncodedMatchResult (*YarrJITCodeMatchOnly16)(const UChar* input, unsigned start, unsigned length) YARR_CALL;
-#endif
+    // Technically freeParenContext and parenContextSize are only used if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS) is set. Fortunately, all the calling conventions we support have caller save argument registers.
+    using YarrJITCode8 = EncodedMatchResult (*)(const LChar* input, unsigned start, unsigned length, int* output, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
+    using YarrJITCode16 = EncodedMatchResult (*)(const UChar* input, unsigned start, unsigned length, int* output, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
+    using YarrJITCodeMatchOnly8 = EncodedMatchResult (*)(const LChar* input, unsigned start, unsigned length, void*, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
+    using YarrJITCodeMatchOnly16 = EncodedMatchResult (*)(const UChar* input, unsigned start, unsigned length, void*, void* freeParenContext, unsigned parenContextSize) YARR_CALL;
 
 public:
     YarrCodeBlock() = default;
@@ -95,9 +78,10 @@
     void set8BitCodeMatchOnly(MacroAssemblerCodeRef<YarrMatchOnly8BitPtrTag> matchOnly) { m_matchOnly8 = matchOnly; }
     void set16BitCodeMatchOnly(MacroAssemblerCodeRef<YarrMatchOnly16BitPtrTag> matchOnly) { m_matchOnly16 = matchOnly; }
 
+    bool usesPatternContextBuffer() { return m_usesPatternContextBuffer; }
 #if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
-    bool usesPatternContextBuffer() { return m_usesPatternContextBuffer; }
     void setUsesPatternContextBuffer() { m_usesPatternContextBuffer = true; }
+#endif
 
     MatchResult execute(const LChar* input, unsigned start, unsigned length, int* output, void* freeParenContext, unsigned parenContextSize)
     {
@@ -122,32 +106,7 @@
         ASSERT(has16BitCodeMatchOnly());
         return MatchResult(untagCFunctionPtr<YarrJITCodeMatchOnly16, YarrMatchOnly16BitPtrTag>(m_matchOnly16.code().executableAddress())(input, start, length, 0, freeParenContext, parenContextSize));
     }
-#else
-    MatchResult execute(const LChar* input, unsigned start, unsigned length, int* output)
-    {
-        ASSERT(has8BitCode());
-        return MatchResult(reinterpret_cast<YarrJITCode8>(m_ref8.code().executableAddress())(input, start, length, output));
-    }
 
-    MatchResult execute(const UChar* input, unsigned start, unsigned length, int* output)
-    {
-        ASSERT(has16BitCode());
-        return MatchResult(reinterpret_cast<YarrJITCode16>(m_ref16.code().executableAddress())(input, start, length, output));
-    }
-
-    MatchResult execute(const LChar* input, unsigned start, unsigned length)
-    {
-        ASSERT(has8BitCodeMatchOnly());
-        return MatchResult(reinterpret_cast<YarrJITCodeMatchOnly8>(m_matchOnly8.code().executableAddress())(input, start, length));
-    }
-
-    MatchResult execute(const UChar* input, unsigned start, unsigned length)
-    {
-        ASSERT(has16BitCodeMatchOnly());
-        return MatchResult(reinterpret_cast<YarrJITCodeMatchOnly16>(m_matchOnly16.code().executableAddress())(input, start, length));
-    }
-#endif
-
 #if ENABLE(REGEXP_TRACING)
     void *get8BitMatchOnlyAddr()
     {
@@ -201,9 +160,7 @@
     MacroAssemblerCodeRef<Yarr16BitPtrTag> m_ref16;
     MacroAssemblerCodeRef<YarrMatchOnly8BitPtrTag> m_matchOnly8;
     MacroAssemblerCodeRef<YarrMatchOnly16BitPtrTag> m_matchOnly16;
-#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
-    bool m_usesPatternContextBuffer;
-#endif
+    bool m_usesPatternContextBuffer { false };
     Optional<JITFailureReason> m_failureReason;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to