Title: [277974] trunk/Source/_javascript_Core
Revision
277974
Author
sbar...@apple.com
Date
2021-05-24 15:34:19 -0700 (Mon, 24 May 2021)

Log Message

Allow CTI stubs to be generated off the main thread
https://bugs.webkit.org/show_bug.cgi?id=226180

Reviewed by Mark Lam.

We make this work by tracking if we're a compiler thread when generating
the CTI stub. If so, it means that the main thread needs to issue a
crossModifyingCodeFence when it's going to run the CTI stub for the first
time.

This patch also does away with pre-generating thunks. Thunks can now generate
other thunks while they're running. To do this, we make JITThunks lock a
recursive lock. The reason this is ok is that we don't have any recursive
thunks in the thunk graph. It's a DAG.

* dfg/DFGDriver.cpp:
(JSC::DFG::compileImpl):
* jit/JITOpcodes.cpp:
(JSC::JIT::op_check_traps_handlerGenerator):
* jit/JITPropertyAccess.cpp:
(JSC::JIT::slow_op_get_from_scopeGenerator):
(JSC::JIT::slow_op_put_to_scopeGenerator):
* jit/JITThunks.cpp:
(JSC::JITThunks::ctiInternalFunctionCall):
(JSC::JITThunks::ctiInternalFunctionConstruct):
(JSC::JITThunks::ctiStubImpl):
(JSC::JITThunks::ctiStub):
(JSC::JITThunks::ctiSlowPathFunctionStub):
(JSC::JITThunks::existingCTIStub): Deleted.
(JSC::JITThunks::preinitializeCTIThunks): Deleted.
* jit/JITThunks.h:
* jit/SlowPathCall.cpp:
(JSC::JITSlowPathCall::generateThunk):
* jit/ThunkGenerators.cpp:
(JSC::popThunkStackPreservesAndHandleExceptionGenerator):
(JSC::checkExceptionGenerator):
(JSC::virtualThunkFor):
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::getCTIInternalFunctionTrampolineFor):
* runtime/VM.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (277973 => 277974)


--- trunk/Source/_javascript_Core/ChangeLog	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-05-24 22:34:19 UTC (rev 277974)
@@ -1,3 +1,47 @@
+2021-05-24  Saam Barati  <sbar...@apple.com>
+
+        Allow CTI stubs to be generated off the main thread
+        https://bugs.webkit.org/show_bug.cgi?id=226180
+
+        Reviewed by Mark Lam.
+
+        We make this work by tracking if we're a compiler thread when generating
+        the CTI stub. If so, it means that the main thread needs to issue a
+        crossModifyingCodeFence when it's going to run the CTI stub for the first
+        time.
+        
+        This patch also does away with pre-generating thunks. Thunks can now generate
+        other thunks while they're running. To do this, we make JITThunks lock a
+        recursive lock. The reason this is ok is that we don't have any recursive
+        thunks in the thunk graph. It's a DAG.
+
+        * dfg/DFGDriver.cpp:
+        (JSC::DFG::compileImpl):
+        * jit/JITOpcodes.cpp:
+        (JSC::JIT::op_check_traps_handlerGenerator):
+        * jit/JITPropertyAccess.cpp:
+        (JSC::JIT::slow_op_get_from_scopeGenerator):
+        (JSC::JIT::slow_op_put_to_scopeGenerator):
+        * jit/JITThunks.cpp:
+        (JSC::JITThunks::ctiInternalFunctionCall):
+        (JSC::JITThunks::ctiInternalFunctionConstruct):
+        (JSC::JITThunks::ctiStubImpl):
+        (JSC::JITThunks::ctiStub):
+        (JSC::JITThunks::ctiSlowPathFunctionStub):
+        (JSC::JITThunks::existingCTIStub): Deleted.
+        (JSC::JITThunks::preinitializeCTIThunks): Deleted.
+        * jit/JITThunks.h:
+        * jit/SlowPathCall.cpp:
+        (JSC::JITSlowPathCall::generateThunk):
+        * jit/ThunkGenerators.cpp:
+        (JSC::popThunkStackPreservesAndHandleExceptionGenerator):
+        (JSC::checkExceptionGenerator):
+        (JSC::virtualThunkFor):
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        (JSC::VM::getCTIInternalFunctionTrampolineFor):
+        * runtime/VM.h:
+
 2021-05-24  Darin Adler  <da...@apple.com>
 
         Remove StringBuilder::appendLiteral

Modified: trunk/Source/_javascript_Core/dfg/DFGDriver.cpp (277973 => 277974)


--- trunk/Source/_javascript_Core/dfg/DFGDriver.cpp	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/dfg/DFGDriver.cpp	2021-05-24 22:34:19 UTC (rev 277974)
@@ -78,14 +78,6 @@
     if (logCompilationChanges(mode))
         dataLog("DFG(Driver) compiling ", *codeBlock, " with ", mode, ", instructions size = ", codeBlock->instructionsSize(), "\n");
     
-    // Make sure that any stubs that the DFG is going to use are initialized. We want to
-    // make sure that all JIT code generation does finalization on the main thread.
-    vm.getCTIStub(arityFixupGenerator);
-    vm.getCTIStub(osrExitGenerationThunkGenerator);
-    vm.getCTIStub(throwExceptionFromCallSlowPathGenerator);
-    vm.getCTIStub(linkCallThunkGenerator);
-    vm.getCTIStub(linkPolymorphicCallThunkGenerator);
-    
     if (vm.typeProfiler())
         vm.typeProfilerLog()->processLogEntries(vm, "Preparing for DFG compilation."_s);
     

Modified: trunk/Source/_javascript_Core/jit/JITOpcodes.cpp (277973 => 277974)


--- trunk/Source/_javascript_Core/jit/JITOpcodes.cpp	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/jit/JITOpcodes.cpp	2021-05-24 22:34:19 UTC (rev 277974)
@@ -1459,7 +1459,7 @@
 
     LinkBuffer patchBuffer(jit, GLOBAL_THUNK_ID, LinkBuffer::Profile::ExtraCTIThunk);
     patchBuffer.link(operation, FunctionPtr<OperationPtrTag>(operationHandleTraps));
-    auto handler = vm.jitStubs->existingCTIStub(popThunkStackPreservesAndHandleExceptionGenerator, NoLockingNecessary);
+    auto handler = vm.getCTIStub(popThunkStackPreservesAndHandleExceptionGenerator);
     patchBuffer.link(exceptionCheck, CodeLocationLabel(handler.retaggedCode<NoPtrTag>()));
     return FINALIZE_CODE(patchBuffer, JITThunkPtrTag, "Baseline: op_check_traps_handler");
 }

Modified: trunk/Source/_javascript_Core/jit/JITPropertyAccess.cpp (277973 => 277974)


--- trunk/Source/_javascript_Core/jit/JITPropertyAccess.cpp	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/jit/JITPropertyAccess.cpp	2021-05-24 22:34:19 UTC (rev 277974)
@@ -1905,7 +1905,7 @@
 
     LinkBuffer patchBuffer(jit, GLOBAL_THUNK_ID, LinkBuffer::Profile::ExtraCTIThunk);
     patchBuffer.link(operation, FunctionPtr<OperationPtrTag>(operationGetFromScope));
-    auto handler = vm.jitStubs->existingCTIStub(popThunkStackPreservesAndHandleExceptionGenerator, NoLockingNecessary);
+    auto handler = vm.getCTIStub(popThunkStackPreservesAndHandleExceptionGenerator);
     patchBuffer.link(exceptionCheck, CodeLocationLabel(handler.retaggedCode<NoPtrTag>()));
     return FINALIZE_CODE(patchBuffer, JITThunkPtrTag, "Baseline: slow_op_get_from_scope");
 }
@@ -2126,7 +2126,7 @@
 
     LinkBuffer patchBuffer(jit, GLOBAL_THUNK_ID, LinkBuffer::Profile::ExtraCTIThunk);
     patchBuffer.link(operation, FunctionPtr<OperationPtrTag>(operationPutToScope));
-    auto handler = vm.jitStubs->existingCTIStub(popThunkStackPreservesAndHandleExceptionGenerator, NoLockingNecessary);
+    auto handler = vm.getCTIStub(popThunkStackPreservesAndHandleExceptionGenerator);
     patchBuffer.link(exceptionCheck, CodeLocationLabel(handler.retaggedCode<NoPtrTag>()));
     return FINALIZE_CODE(patchBuffer, JITThunkPtrTag, "Baseline: slow_op_put_to_scope");
 }

Modified: trunk/Source/_javascript_Core/jit/JITThunks.cpp (277973 => 277974)


--- trunk/Source/_javascript_Core/jit/JITThunks.cpp	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/jit/JITThunks.cpp	2021-05-24 22:34:19 UTC (rev 277974)
@@ -117,46 +117,58 @@
     return ctiStub(vm, nativeTailCallWithoutSavedTagsGenerator).code();
 }
 
-MacroAssemblerCodePtr<JITThunkPtrTag> JITThunks::ctiInternalFunctionCall(VM& vm, Optional<NoLockingNecessaryTag> noLockingNecessary)
+MacroAssemblerCodePtr<JITThunkPtrTag> JITThunks::ctiInternalFunctionCall(VM& vm)
 {
     ASSERT(Options::useJIT());
-    if (noLockingNecessary)
-        return existingCTIStub(internalFunctionCallGenerator, NoLockingNecessary).code();
     return ctiStub(vm, internalFunctionCallGenerator).code();
 }
 
-MacroAssemblerCodePtr<JITThunkPtrTag> JITThunks::ctiInternalFunctionConstruct(VM& vm, Optional<NoLockingNecessaryTag> noLockingNecessary)
+MacroAssemblerCodePtr<JITThunkPtrTag> JITThunks::ctiInternalFunctionConstruct(VM& vm)
 {
     ASSERT(Options::useJIT());
-    if (noLockingNecessary)
-        return existingCTIStub(internalFunctionConstructGenerator, NoLockingNecessary).code();
     return ctiStub(vm, internalFunctionConstructGenerator).code();
 }
 
-MacroAssemblerCodeRef<JITThunkPtrTag> JITThunks::ctiStub(VM& vm, ThunkGenerator generator)
+template <typename GenerateThunk>
+MacroAssemblerCodeRef<JITThunkPtrTag> JITThunks::ctiStubImpl(ThunkGenerator key, GenerateThunk generateThunk)
 {
     Locker locker { m_lock };
-    CTIStubMap::AddResult entry = m_ctiStubMap.add(generator, MacroAssemblerCodeRef<JITThunkPtrTag>());
-    if (entry.isNewEntry) {
-        // Compilation thread can only retrieve existing entries.
-        ASSERT(!isCompilationThread());
-        entry.iterator->value = generator(vm);
+
+    auto handleEntry = [&] (Entry& entry) {
+        if (entry.needsCrossModifyingCodeFence && !isCompilationThread()) {
+            // The main thread will issue a crossModifyingCodeFence before running
+            // any code the compiler thread generates, including any thunks that they
+            // generate. However, the main thread may grab the thunk a compiler thread
+            // generated before we've issued that crossModifyingCodeFence. Hence, we
+            // conservatively say that when the main thread grabs a thunk generated
+            // from a compiler thread for the first time, it issues a crossModifyingCodeFence.
+            WTF::crossModifyingCodeFence();
+            entry.needsCrossModifyingCodeFence = false;
+        }
+
+        return MacroAssemblerCodeRef<JITThunkPtrTag>(*entry.handle);
+    };
+
+    {
+        auto iter = m_ctiStubMap.find(key);
+        if (iter != m_ctiStubMap.end())
+            return handleEntry(iter->value);
     }
-    return entry.iterator->value;
-}
 
-MacroAssemblerCodeRef<JITThunkPtrTag> JITThunks::existingCTIStub(ThunkGenerator generator)
-{
-    Locker locker { m_lock };
-    return existingCTIStub(generator, NoLockingNecessary);
+    // We do two lookups on first addition to the hash table because generateThunk may add to it.
+    MacroAssemblerCodeRef<JITThunkPtrTag> codeRef = generateThunk();
+
+    bool needsCrossModifyingCodeFence = isCompilationThread();
+    auto addResult = m_ctiStubMap.add(key, Entry { PackedRefPtr<ExecutableMemoryHandle>(codeRef.executableMemory()), needsCrossModifyingCodeFence });
+    RELEASE_ASSERT(addResult.isNewEntry); // Thunks aren't recursive, so anything we generated transitively shouldn't have generated 'key'.
+    return handleEntry(addResult.iterator->value);
 }
 
-MacroAssemblerCodeRef<JITThunkPtrTag> JITThunks::existingCTIStub(ThunkGenerator generator, NoLockingNecessaryTag)
+MacroAssemblerCodeRef<JITThunkPtrTag> JITThunks::ctiStub(VM& vm, ThunkGenerator generator)
 {
-    CTIStubMap::iterator entry = m_ctiStubMap.find(generator);
-    if (entry == m_ctiStubMap.end())
-        return MacroAssemblerCodeRef<JITThunkPtrTag>();
-    return entry->value;
+    return ctiStubImpl(generator, [&] {
+        return generator(vm);
+    });
 }
 
 #if ENABLE(EXTRA_CTI_THUNKS)
@@ -163,15 +175,10 @@
 
 MacroAssemblerCodeRef<JITThunkPtrTag> JITThunks::ctiSlowPathFunctionStub(VM& vm, SlowPathFunction slowPathFunction)
 {
-    Locker locker { m_lock };
     auto key = bitwise_cast<ThunkGenerator>(slowPathFunction);
-    CTIStubMap::AddResult entry = m_ctiStubMap.add(key, MacroAssemblerCodeRef<JITThunkPtrTag>());
-    if (entry.isNewEntry) {
-        // Compilation thread can only retrieve existing entries.
-        ASSERT(!isCompilationThread());
-        entry.iterator->value = JITSlowPathCall::generateThunk(vm, slowPathFunction);
-    }
-    return entry.iterator->value;
+    return ctiStubImpl(key, [&] {
+        return JITSlowPathCall::generateThunk(vm, slowPathFunction);
+    });
 }
 
 #endif // ENABLE(EXTRA_CTI_THUNKS)
@@ -262,133 +269,6 @@
     return hostFunctionStub(vm, function, callHostFunctionAsConstructor, generator, intrinsic, nullptr, name);
 }
 
-void JITThunks::preinitializeCTIThunks(VM& vm)
-{
-    if (!Options::useJIT())
-        return;
-
-#if ENABLE(EXTRA_CTI_THUNKS)
-    // These 4 should always be initialized first in the following order because
-    // the other thunk generators rely on these already being initialized.
-    ctiStub(vm, handleExceptionGenerator);
-    ctiStub(vm, handleExceptionWithCallFrameRollbackGenerator);
-    ctiStub(vm, popThunkStackPreservesAndHandleExceptionGenerator);
-    ctiStub(vm, checkExceptionGenerator);
-
-#define INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(name) ctiSlowPathFunctionStub(vm, slow_path_##name)
-
-    // From the BaselineJIT DEFINE_SLOW_OP list:
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(in_by_val);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(has_private_name);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(has_private_brand);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(less);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(lesseq);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(greater);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(greatereq);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(is_callable);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(is_constructor);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(typeof);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(typeof_is_object);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(typeof_is_function);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(strcat);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(push_with_scope);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_lexical_environment);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(get_by_val_with_this);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(put_by_id_with_this);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(put_by_val_with_this);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(resolve_scope_for_hoisting_func_decl_in_eval);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(define_data_property);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(define_accessor_property);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(unreachable);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(throw_static_error);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(new_array_with_spread);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(new_array_buffer);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(spread);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(get_enumerable_length);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(has_enumerable_property);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(get_property_enumerator);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_index_string);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_direct_arguments);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_scoped_arguments);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_cloned_arguments);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_arguments_butterfly);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_rest);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_promise);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(new_promise);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_generator);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_async_generator);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(new_generator);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(pow);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(mod);
-
-    ctiSlowPathFunctionStub(vm, iterator_open_try_fast_narrow);
-    ctiSlowPathFunctionStub(vm, iterator_open_try_fast_wide16);
-    ctiSlowPathFunctionStub(vm, iterator_open_try_fast_wide32);
-    ctiSlowPathFunctionStub(vm, iterator_next_try_fast_narrow);
-    ctiSlowPathFunctionStub(vm, iterator_next_try_fast_wide16);
-    ctiSlowPathFunctionStub(vm, iterator_next_try_fast_wide32);
-
-    // From the BaselineJIT DEFINE_SLOWCASE_SLOW_OP list:
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(unsigned);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(inc);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(dec);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(bitnot);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(bitand);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(bitor);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(bitxor);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(lshift);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(rshift);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(urshift);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(div);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_this);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_promise);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_generator);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(create_async_generator);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_this);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_primitive);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_number);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_numeric);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_string);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_object);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(not);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(stricteq);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(nstricteq);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(get_direct_pname);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(get_prototype_of);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(has_enumerable_structure_property);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(has_own_structure_property);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(in_structure_property);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(resolve_scope);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(check_tdz);
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(to_property_key);
-
-    INIT_BASELINE_SLOW_PATH_CALL_ROUTINE(throw_strict_mode_readonly_property_write_error);
-#undef INIT_BASELINE_ROUTINE
-
-    // From the BaselineJIT DEFINE_SLOWCASE_OP list:
-    ctiStub(vm, JIT::slow_op_del_by_id_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_del_by_val_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_get_by_id_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_get_by_id_with_this_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_get_by_val_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_get_from_scopeGenerator);
-    ctiStub(vm, JIT::slow_op_get_private_name_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_put_by_id_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_put_by_val_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_put_private_name_prepareCallGenerator);
-    ctiStub(vm, JIT::slow_op_put_to_scopeGenerator);
-
-    ctiStub(vm, JIT::op_check_traps_handlerGenerator);
-    ctiStub(vm, JIT::op_enter_handlerGenerator);
-    ctiStub(vm, JIT::op_ret_handlerGenerator);
-    ctiStub(vm, JIT::op_throw_handlerGenerator);
-#endif // ENABLE(EXTRA_CTI_THUNKS)
-
-    ctiStub(vm, linkCallThunkGenerator);
-    ctiStub(vm, arityFixupGenerator);
-}
-
-
 } // namespace JSC
 
 #endif // ENABLE(JIT)

Modified: trunk/Source/_javascript_Core/jit/JITThunks.h (277973 => 277974)


--- trunk/Source/_javascript_Core/jit/JITThunks.h	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/jit/JITThunks.h	2021-05-24 22:34:19 UTC (rev 277974)
@@ -37,6 +37,8 @@
 #include <tuple>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/PackedRefPtr.h>
+#include <wtf/RecursiveLockAdapter.h>
 #include <wtf/text/StringHash.h>
 
 namespace JSC {
@@ -53,18 +55,14 @@
     JITThunks();
     ~JITThunks() final;
 
-    void preinitializeCTIThunks(VM&);
-
     MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeCall(VM&);
     MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeConstruct(VM&);
     MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeTailCall(VM&);
     MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeTailCallWithoutSavedTags(VM&);
-    MacroAssemblerCodePtr<JITThunkPtrTag> ctiInternalFunctionCall(VM&, Optional<NoLockingNecessaryTag> = WTF::nullopt);
-    MacroAssemblerCodePtr<JITThunkPtrTag> ctiInternalFunctionConstruct(VM&, Optional<NoLockingNecessaryTag> = WTF::nullopt);
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiInternalFunctionCall(VM&);
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiInternalFunctionConstruct(VM&);
 
     MacroAssemblerCodeRef<JITThunkPtrTag> ctiStub(VM&, ThunkGenerator);
-    MacroAssemblerCodeRef<JITThunkPtrTag> existingCTIStub(ThunkGenerator);
-    MacroAssemblerCodeRef<JITThunkPtrTag> existingCTIStub(ThunkGenerator, NoLockingNecessaryTag);
 #if ENABLE(EXTRA_CTI_THUNKS)
     MacroAssemblerCodeRef<JITThunkPtrTag> ctiSlowPathFunctionStub(VM&, SlowPathFunction);
 #endif
@@ -74,9 +72,16 @@
     NativeExecutable* hostFunctionStub(VM&, TaggedNativeFunction, ThunkGenerator, Intrinsic, const String& name);
 
 private:
+    template <typename GenerateThunk>
+    MacroAssemblerCodeRef<JITThunkPtrTag> ctiStubImpl(ThunkGenerator key, GenerateThunk);
+
     void finalize(Handle<Unknown>, void* context) final;
     
-    typedef HashMap<ThunkGenerator, MacroAssemblerCodeRef<JITThunkPtrTag>> CTIStubMap;
+    struct Entry {
+        PackedRefPtr<ExecutableMemoryHandle> handle;
+        bool needsCrossModifyingCodeFence;
+    };
+    using CTIStubMap = HashMap<ThunkGenerator, Entry>;
     CTIStubMap m_ctiStubMap;
 
     using HostFunctionKey = std::tuple<TaggedNativeFunction, TaggedNativeFunction, String>;
@@ -116,7 +121,8 @@
 
     using WeakNativeExecutableSet = HashSet<Weak<NativeExecutable>, WeakNativeExecutableHash>;
     WeakNativeExecutableSet m_nativeExecutableSet;
-    Lock m_lock;
+
+    WTF::RecursiveLock m_lock;
 };
 
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/jit/SlowPathCall.cpp (277973 => 277974)


--- trunk/Source/_javascript_Core/jit/SlowPathCall.cpp	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/jit/SlowPathCall.cpp	2021-05-24 22:34:19 UTC (rev 277974)
@@ -84,7 +84,7 @@
 #endif
     jit.ret();
 
-    auto handler = vm.jitStubs->existingCTIStub(popThunkStackPreservesAndHandleExceptionGenerator, NoLockingNecessary);
+    auto handler = vm.getCTIStub(popThunkStackPreservesAndHandleExceptionGenerator);
 
     LinkBuffer patchBuffer(jit, GLOBAL_THUNK_ID, LinkBuffer::Profile::ExtraCTIThunk);
     patchBuffer.link(call, FunctionPtr<OperationPtrTag>(slowPathFunction));

Modified: trunk/Source/_javascript_Core/jit/ThunkGenerators.cpp (277973 => 277974)


--- trunk/Source/_javascript_Core/jit/ThunkGenerators.cpp	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/jit/ThunkGenerators.cpp	2021-05-24 22:34:19 UTC (rev 277974)
@@ -90,7 +90,7 @@
     CCallHelpers::Jump continuation = jit.jump();
 
     LinkBuffer patchBuffer(jit, GLOBAL_THUNK_ID, LinkBuffer::Profile::ExtraCTIThunk);
-    auto handler = vm.jitStubs->existingCTIStub(handleExceptionGenerator, NoLockingNecessary);
+    auto handler = vm.getCTIStub(handleExceptionGenerator);
     RELEASE_ASSERT(handler);
     patchBuffer.link(continuation, CodeLocationLabel(handler.retaggedCode<NoPtrTag>()));
     return FINALIZE_CODE(patchBuffer, JITThunkPtrTag, "popThunkStackPreservesAndHandleException");
@@ -132,7 +132,7 @@
 #endif
 
     LinkBuffer patchBuffer(jit, GLOBAL_THUNK_ID, LinkBuffer::Profile::ExtraCTIThunk);
-    patchBuffer.link(handleException, CodeLocationLabel(vm.jitStubs->existingCTIStub(handlerGenerator, NoLockingNecessary).retaggedCode<NoPtrTag>()));
+    patchBuffer.link(handleException, CodeLocationLabel(vm.getCTIStub(handlerGenerator).retaggedCode<NoPtrTag>()));
     return FINALIZE_CODE(patchBuffer, JITThunkPtrTag, "CheckException");
 }
 
@@ -324,7 +324,7 @@
     // NullSetterFunctionType does not get the fast path support. But it is OK since using NullSetterFunctionType is extremely rare.
     notJSFunction.link(&jit);
     slowCase.append(jit.branchIfNotType(GPRInfo::regT0, InternalFunctionType));
-    void* executableAddress = vm.getCTIInternalFunctionTrampolineFor(kind, NoLockingNecessary).executableAddress();
+    void* executableAddress = vm.getCTIInternalFunctionTrampolineFor(kind).executableAddress();
     jit.move(CCallHelpers::TrustedImmPtr(executableAddress), GPRInfo::regT4);
     jit.jump().linkTo(callCode, &jit);
 

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (277973 => 277974)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2021-05-24 22:34:19 UTC (rev 277974)
@@ -567,8 +567,6 @@
 #endif // ENABLE(FTL_JIT)
         getCTIInternalFunctionTrampolineFor(CodeForCall);
         getCTIInternalFunctionTrampolineFor(CodeForConstruct);
-
-        jitStubs->preinitializeCTIThunks(*this);
     }
 #endif // ENABLE(JIT)
 
@@ -888,14 +886,13 @@
     return getOrCreate(m_fastBoundExecutable);
 }
 
-MacroAssemblerCodePtr<JSEntryPtrTag> VM::getCTIInternalFunctionTrampolineFor(CodeSpecializationKind kind, Optional<NoLockingNecessaryTag> noLockingNecessary)
+MacroAssemblerCodePtr<JSEntryPtrTag> VM::getCTIInternalFunctionTrampolineFor(CodeSpecializationKind kind)
 {
-    UNUSED_PARAM(noLockingNecessary);
 #if ENABLE(JIT)
     if (Options::useJIT()) {
         if (kind == CodeForCall)
-            return jitStubs->ctiInternalFunctionCall(*this, noLockingNecessary).retagged<JSEntryPtrTag>();
-        return jitStubs->ctiInternalFunctionConstruct(*this, noLockingNecessary).retagged<JSEntryPtrTag>();
+            return jitStubs->ctiInternalFunctionCall(*this).retagged<JSEntryPtrTag>();
+        return jitStubs->ctiInternalFunctionConstruct(*this).retagged<JSEntryPtrTag>();
     }
 #endif
     if (kind == CodeForCall)

Modified: trunk/Source/_javascript_Core/runtime/VM.h (277973 => 277974)


--- trunk/Source/_javascript_Core/runtime/VM.h	2021-05-24 22:31:54 UTC (rev 277973)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2021-05-24 22:34:19 UTC (rev 277974)
@@ -851,7 +851,7 @@
 
     NativeExecutable* getBoundFunction(bool isJSFunction, bool canConstruct);
 
-    MacroAssemblerCodePtr<JSEntryPtrTag> getCTIInternalFunctionTrampolineFor(CodeSpecializationKind, Optional<NoLockingNecessaryTag> = WTF::nullopt);
+    MacroAssemblerCodePtr<JSEntryPtrTag> getCTIInternalFunctionTrampolineFor(CodeSpecializationKind);
 
     static ptrdiff_t exceptionOffset()
     {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to