[JSC] Should have default NativeJITCode
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2019 19:10:15 +0000 (19:10 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2019 19:10:15 +0000 (19:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194634

Reviewed by Mark Lam.

In JSC_useJIT=false mode, we always create identical NativeJITCode for call and construct when we create NativeExecutable.
This is meaningless since we do not modify NativeJITCode after the creation. This patch adds singleton used as a default one.
Since NativeJITCode (& JITCode) is ThreadSafeRefCounted, we can just share it in a whole process level. This removes 446 NativeJITCode
allocations, which takes 14KB.

* runtime/VM.cpp:
(JSC::jitCodeForCallTrampoline):
(JSC::jitCodeForConstructTrampoline):
(JSC::VM::getHostFunction):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/VM.cpp

index f832d05..f1323bb 100644 (file)
@@ -1,3 +1,20 @@
+2019-02-14  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Should have default NativeJITCode
+        https://bugs.webkit.org/show_bug.cgi?id=194634
+
+        Reviewed by Mark Lam.
+
+        In JSC_useJIT=false mode, we always create identical NativeJITCode for call and construct when we create NativeExecutable.
+        This is meaningless since we do not modify NativeJITCode after the creation. This patch adds singleton used as a default one.
+        Since NativeJITCode (& JITCode) is ThreadSafeRefCounted, we can just share it in a whole process level. This removes 446 NativeJITCode
+        allocations, which takes 14KB.
+
+        * runtime/VM.cpp:
+        (JSC::jitCodeForCallTrampoline):
+        (JSC::jitCodeForConstructTrampoline):
+        (JSC::VM::getHostFunction):
+
 2019-02-14  Tadeu Zagallo  <tzagallo@apple.com>
 
         generateUnlinkedCodeBlockForFunctions shouldn't need to create a FunctionExecutable just to get its source code
index a3091d0..8b133f6 100644 (file)
@@ -688,6 +688,26 @@ NativeExecutable* VM::getHostFunction(NativeFunction function, NativeFunction co
     return getHostFunction(function, NoIntrinsic, constructor, nullptr, name);
 }
 
+static Ref<NativeJITCode> jitCodeForCallTrampoline()
+{
+    static NativeJITCode* result;
+    static std::once_flag onceKey;
+    std::call_once(onceKey, [&] {
+        result = new NativeJITCode(LLInt::getCodeRef<JSEntryPtrTag>(llint_native_call_trampoline), JITCode::HostCallThunk, NoIntrinsic);
+    });
+    return makeRef(*result);
+}
+
+static Ref<NativeJITCode> jitCodeForConstructTrampoline()
+{
+    static NativeJITCode* result;
+    static std::once_flag onceKey;
+    std::call_once(onceKey, [&] {
+        result = new NativeJITCode(LLInt::getCodeRef<JSEntryPtrTag>(llint_native_construct_trampoline), JITCode::HostCallThunk, NoIntrinsic);
+    });
+    return makeRef(*result);
+}
+
 NativeExecutable* VM::getHostFunction(NativeFunction function, Intrinsic intrinsic, NativeFunction constructor, const DOMJIT::Signature* signature, const String& name)
 {
 #if ENABLE(JIT)
@@ -700,11 +720,7 @@ NativeExecutable* VM::getHostFunction(NativeFunction function, Intrinsic intrins
 #endif // ENABLE(JIT)
     UNUSED_PARAM(intrinsic);
     UNUSED_PARAM(signature);
-
-    return NativeExecutable::create(*this,
-        adoptRef(*new NativeJITCode(LLInt::getCodeRef<JSEntryPtrTag>(llint_native_call_trampoline), JITCode::HostCallThunk, NoIntrinsic)), function,
-        adoptRef(*new NativeJITCode(LLInt::getCodeRef<JSEntryPtrTag>(llint_native_construct_trampoline), JITCode::HostCallThunk, NoIntrinsic)), constructor,
-        name);
+    return NativeExecutable::create(*this, jitCodeForCallTrampoline(), function, jitCodeForConstructTrampoline(), constructor, name);
 }
 
 MacroAssemblerCodePtr<JSEntryPtrTag> VM::getCTIInternalFunctionTrampolineFor(CodeSpecializationKind kind)