[JSC] Do not create JIT related data under non-JIT mode
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 19:14:12 +0000 (19:14 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 19:14:12 +0000 (19:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195982

Reviewed by Mark Lam.

We avoid creations of JIT related data structures under non-JIT mode.
This patch removes the following allocations.

1. JITThunks
2. FTLThunks
3. FixedVMPoolExecutableAllocator
4. noJITValueProfileSingleton since it is no longer used
5. ARM disassembler should be initialized when it is used
6. Wasm related data structures are accidentally allocated if VM::canUseJIT() == false &&
   Options::useWebAssembly() == true. Add Wasm::isSupported() function to check the both conditions.

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* heap/Heap.cpp:
(JSC::Heap::runEndPhase):
* jit/ExecutableAllocator.cpp:
(JSC::FixedVMPoolExecutableAllocator::~FixedVMPoolExecutableAllocator):
(JSC::ExecutableAllocator::initializeUnderlyingAllocator):
(JSC::ExecutableAllocator::isValid const):
(JSC::ExecutableAllocator::underMemoryPressure):
(JSC::ExecutableAllocator::memoryPressureMultiplier):
(JSC::ExecutableAllocator::allocate):
(JSC::ExecutableAllocator::isValidExecutableMemory):
(JSC::ExecutableAllocator::getLock const):
(JSC::ExecutableAllocator::committedByteCount):
(JSC::ExecutableAllocator::dumpProfile):
(JSC::startOfFixedExecutableMemoryPoolImpl):
(JSC::endOfFixedExecutableMemoryPoolImpl):
(JSC::ExecutableAllocator::initialize):
(JSC::ExecutableAllocator::initializeAllocator): Deleted.
(JSC::ExecutableAllocator::ExecutableAllocator): Deleted.
(JSC::ExecutableAllocator::~ExecutableAllocator): Deleted.
* jit/ExecutableAllocator.h:
(JSC::ExecutableAllocatorBase::isValid const):
(JSC::ExecutableAllocatorBase::underMemoryPressure):
(JSC::ExecutableAllocatorBase::memoryPressureMultiplier):
(JSC::ExecutableAllocatorBase::dumpProfile):
(JSC::ExecutableAllocatorBase::allocate):
(JSC::ExecutableAllocatorBase::setJITEnabled):
(JSC::ExecutableAllocatorBase::isValidExecutableMemory):
(JSC::ExecutableAllocatorBase::committedByteCount):
(JSC::ExecutableAllocatorBase::getLock const):
(JSC::ExecutableAllocator::isValid const): Deleted.
(JSC::ExecutableAllocator::underMemoryPressure): Deleted.
(JSC::ExecutableAllocator::memoryPressureMultiplier): Deleted.
(JSC::ExecutableAllocator::allocate): Deleted.
(JSC::ExecutableAllocator::setJITEnabled): Deleted.
(JSC::ExecutableAllocator::isValidExecutableMemory): Deleted.
(JSC::ExecutableAllocator::committedByteCount): Deleted.
(JSC::ExecutableAllocator::getLock const): Deleted.
* jsc.cpp:
(functionWebAssemblyMemoryMode):
* runtime/InitializeThreading.cpp:
(JSC::initializeThreading):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* runtime/JSLock.cpp:
(JSC::JSLock::didAcquireLock):
* runtime/Options.cpp:
(JSC::recomputeDependentOptions):
* runtime/VM.cpp:
(JSC::enableAssembler):
(JSC::VM::canUseAssembler):
(JSC::VM::VM):
* runtime/VM.h:
* wasm/WasmCapabilities.h: Added.
(JSC::Wasm::isSupported):
* wasm/WasmFaultSignalHandler.cpp:
(JSC::Wasm::enableFastMemory):

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

15 files changed:
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/heap/Heap.cpp
Source/JavaScriptCore/jit/ExecutableAllocator.cpp
Source/JavaScriptCore/jit/ExecutableAllocator.h
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/InitializeThreading.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSLock.cpp
Source/JavaScriptCore/runtime/Options.cpp
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h
Source/JavaScriptCore/wasm/WasmCapabilities.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmFaultSignalHandler.cpp

index 67fdb70..4fa0c3b 100644 (file)
@@ -977,6 +977,7 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
     runtime/WriteBarrier.h
     runtime/WriteBarrierInlines.h
 
+    wasm/WasmCapabilities.h
     wasm/WasmCodeBlock.h
     wasm/WasmContext.h
     wasm/WasmEmbedder.h
index 3e8a5e1..867387b 100644 (file)
@@ -1,5 +1,82 @@
 2019-03-21  Yusuke Suzuki  <ysuzuki@apple.com>
 
+        [JSC] Do not create JIT related data under non-JIT mode
+        https://bugs.webkit.org/show_bug.cgi?id=195982
+
+        Reviewed by Mark Lam.
+
+        We avoid creations of JIT related data structures under non-JIT mode.
+        This patch removes the following allocations.
+
+        1. JITThunks
+        2. FTLThunks
+        3. FixedVMPoolExecutableAllocator
+        4. noJITValueProfileSingleton since it is no longer used
+        5. ARM disassembler should be initialized when it is used
+        6. Wasm related data structures are accidentally allocated if VM::canUseJIT() == false &&
+           Options::useWebAssembly() == true. Add Wasm::isSupported() function to check the both conditions.
+
+        * CMakeLists.txt:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * heap/Heap.cpp:
+        (JSC::Heap::runEndPhase):
+        * jit/ExecutableAllocator.cpp:
+        (JSC::FixedVMPoolExecutableAllocator::~FixedVMPoolExecutableAllocator):
+        (JSC::ExecutableAllocator::initializeUnderlyingAllocator):
+        (JSC::ExecutableAllocator::isValid const):
+        (JSC::ExecutableAllocator::underMemoryPressure):
+        (JSC::ExecutableAllocator::memoryPressureMultiplier):
+        (JSC::ExecutableAllocator::allocate):
+        (JSC::ExecutableAllocator::isValidExecutableMemory):
+        (JSC::ExecutableAllocator::getLock const):
+        (JSC::ExecutableAllocator::committedByteCount):
+        (JSC::ExecutableAllocator::dumpProfile):
+        (JSC::startOfFixedExecutableMemoryPoolImpl):
+        (JSC::endOfFixedExecutableMemoryPoolImpl):
+        (JSC::ExecutableAllocator::initialize):
+        (JSC::ExecutableAllocator::initializeAllocator): Deleted.
+        (JSC::ExecutableAllocator::ExecutableAllocator): Deleted.
+        (JSC::ExecutableAllocator::~ExecutableAllocator): Deleted.
+        * jit/ExecutableAllocator.h:
+        (JSC::ExecutableAllocatorBase::isValid const):
+        (JSC::ExecutableAllocatorBase::underMemoryPressure):
+        (JSC::ExecutableAllocatorBase::memoryPressureMultiplier):
+        (JSC::ExecutableAllocatorBase::dumpProfile):
+        (JSC::ExecutableAllocatorBase::allocate):
+        (JSC::ExecutableAllocatorBase::setJITEnabled):
+        (JSC::ExecutableAllocatorBase::isValidExecutableMemory):
+        (JSC::ExecutableAllocatorBase::committedByteCount):
+        (JSC::ExecutableAllocatorBase::getLock const):
+        (JSC::ExecutableAllocator::isValid const): Deleted.
+        (JSC::ExecutableAllocator::underMemoryPressure): Deleted.
+        (JSC::ExecutableAllocator::memoryPressureMultiplier): Deleted.
+        (JSC::ExecutableAllocator::allocate): Deleted.
+        (JSC::ExecutableAllocator::setJITEnabled): Deleted.
+        (JSC::ExecutableAllocator::isValidExecutableMemory): Deleted.
+        (JSC::ExecutableAllocator::committedByteCount): Deleted.
+        (JSC::ExecutableAllocator::getLock const): Deleted.
+        * jsc.cpp:
+        (functionWebAssemblyMemoryMode):
+        * runtime/InitializeThreading.cpp:
+        (JSC::initializeThreading):
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        * runtime/JSLock.cpp:
+        (JSC::JSLock::didAcquireLock):
+        * runtime/Options.cpp:
+        (JSC::recomputeDependentOptions):
+        * runtime/VM.cpp:
+        (JSC::enableAssembler):
+        (JSC::VM::canUseAssembler):
+        (JSC::VM::VM):
+        * runtime/VM.h:
+        * wasm/WasmCapabilities.h: Added.
+        (JSC::Wasm::isSupported):
+        * wasm/WasmFaultSignalHandler.cpp:
+        (JSC::Wasm::enableFastMemory):
+
+2019-03-21  Yusuke Suzuki  <ysuzuki@apple.com>
+
         [JSC] Fix JSC build with newer ICU
         https://bugs.webkit.org/show_bug.cgi?id=196098
 
index 56f2e99..b1fbf16 100644 (file)
                E32AB2441DCD75F400D7533A /* MacroAssemblerHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = E380A76B1DCD7195000F89E6 /* MacroAssemblerHelpers.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E334CBB521FD96A9000EB178 /* RegExpGlobalData.h in Headers */ = {isa = PBXBuildFile; fileRef = E334CBB321FD96A9000EB178 /* RegExpGlobalData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E33637A61B63220200EE0840 /* ReflectObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E33637A41B63220200EE0840 /* ReflectObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E337B967224324EA0093A820 /* WasmCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = E337B966224324E50093A820 /* WasmCapabilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E33B3E261B7ABD750048DB2E /* InspectorInstrumentationObject.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = E33B3E251B7ABD750048DB2E /* InspectorInstrumentationObject.lut.h */; };
                E33E8D1D1B9013C300346B52 /* JSNativeStdFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = E33E8D1B1B9013C300346B52 /* JSNativeStdFunction.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E33E8D211B9013DE00346B52 /* NativeStdFunctionCell.h in Headers */ = {isa = PBXBuildFile; fileRef = E33E8D1F1B9013DE00346B52 /* NativeStdFunctionCell.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E334CBB321FD96A9000EB178 /* RegExpGlobalData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegExpGlobalData.h; sourceTree = "<group>"; };
                E33637A31B63220200EE0840 /* ReflectObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReflectObject.cpp; sourceTree = "<group>"; };
                E33637A41B63220200EE0840 /* ReflectObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReflectObject.h; sourceTree = "<group>"; };
+               E337B966224324E50093A820 /* WasmCapabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WasmCapabilities.h; sourceTree = "<group>"; };
                E33B3E251B7ABD750048DB2E /* InspectorInstrumentationObject.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorInstrumentationObject.lut.h; sourceTree = "<group>"; };
                E33E8D1A1B9013C300346B52 /* JSNativeStdFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNativeStdFunction.cpp; sourceTree = "<group>"; };
                E33E8D1B1B9013C300346B52 /* JSNativeStdFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNativeStdFunction.h; sourceTree = "<group>"; };
                                0F6183431C45F62A0072450B /* testair */,
                                14BD59BF0A3E8F9000BAF59C /* testapi */,
                                0FEC85AD1BDB5CF10080FF74 /* testb3 */,
+                               52CD0F642242F569004A18A5 /* testdfg */,
                                FE533CAC1F217DB40016A1FE /* testmasm */,
                                79281BDC20B62B3E002E2A60 /* testmem */,
                                6511230514046A4C002B101D /* testRegExp */,
                                932F5BD90822A1C700736975 /* JavaScriptCore.framework */,
-                               52CD0F642242F569004A18A5 /* testdfg */,
                        );
                        name = Products;
                        sourceTree = "<group>";
                                525C0DD81E935847002184CD /* WasmCallee.h */,
                                53FD04D11D7AB187003287D3 /* WasmCallingConvention.cpp */,
                                53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */,
+                               E337B966224324E50093A820 /* WasmCapabilities.h */,
                                526AC4B41E977C5D003500E1 /* WasmCodeBlock.cpp */,
                                526AC4B51E977C5D003500E1 /* WasmCodeBlock.h */,
                                AD412B321E7B2E8A008AF157 /* WasmContext.h */,
                                AD4B1DFA1DF244E20071AE32 /* WasmBinding.h in Headers */,
                                525C0DDA1E935847002184CD /* WasmCallee.h in Headers */,
                                53FD04D41D7AB291003287D3 /* WasmCallingConvention.h in Headers */,
+                               E337B967224324EA0093A820 /* WasmCapabilities.h in Headers */,
                                526AC4B71E977C5D003500E1 /* WasmCodeBlock.h in Headers */,
                                AD412B341E7B2E9E008AF157 /* WasmContext.h in Headers */,
                                7593C898BE714A64BE93A6E7 /* WasmContextInlines.h in Headers */,
index 1945104..7fdb72a 100644 (file)
@@ -1496,9 +1496,6 @@ NEVER_INLINE bool Heap::runEndPhase(GCConductor conn)
     if (vm()->typeProfiler())
         vm()->typeProfiler()->invalidateTypeSetCache();
 
-    if (ValueProfile* profile = vm()->noJITValueProfileSingleton.get())
-        *profile = ValueProfile(0);
-        
     reapWeakHandles();
     pruneStaleEntriesFromWeakGCMaps();
     sweepArrayBuffers();
index bc6c33c..7e637f6 100644 (file)
@@ -115,7 +115,6 @@ static uintptr_t startOfFixedWritableMemoryPool;
 
 class FixedVMPoolExecutableAllocator;
 static FixedVMPoolExecutableAllocator* allocator = nullptr;
-static ExecutableAllocator* executableAllocator = nullptr;
 
 static bool s_isJITEnabled = true;
 static bool isJITEnabled()
@@ -404,49 +403,37 @@ private:
     MacroAssemblerCodePtr<ExecutableMemoryPtrTag> m_memoryEnd;
 };
 
-void ExecutableAllocator::initializeAllocator()
-{
-    ASSERT(!allocator);
-    allocator = new FixedVMPoolExecutableAllocator();
-    CodeProfiling::notifyAllocator(allocator);
-
-    executableAllocator = new ExecutableAllocator;
-}
-
-ExecutableAllocator& ExecutableAllocator::singleton()
-{
-    ASSERT(allocator);
-    ASSERT(executableAllocator);
-    return *executableAllocator;
-}
-
-ExecutableAllocator::ExecutableAllocator()
-{
-    ASSERT(allocator);
-}
-
-ExecutableAllocator::~ExecutableAllocator()
+FixedVMPoolExecutableAllocator::~FixedVMPoolExecutableAllocator()
 {
+    m_reservation.deallocate();
 }
 
-FixedVMPoolExecutableAllocator::~FixedVMPoolExecutableAllocator()
+void ExecutableAllocator::initializeUnderlyingAllocator()
 {
-    m_reservation.deallocate();
+    ASSERT(!allocator);
+    allocator = new FixedVMPoolExecutableAllocator();
+    CodeProfiling::notifyAllocator(allocator);
 }
 
 bool ExecutableAllocator::isValid() const
 {
+    if (!allocator)
+        return Base::isValid();
     return !!allocator->bytesReserved();
 }
 
 bool ExecutableAllocator::underMemoryPressure()
 {
+    if (!allocator)
+        return Base::underMemoryPressure();
     MetaAllocator::Statistics statistics = allocator->currentStatistics();
     return statistics.bytesAllocated > statistics.bytesReserved / 2;
 }
 
 double ExecutableAllocator::memoryPressureMultiplier(size_t addedMemoryUsage)
 {
+    if (!allocator)
+        return Base::memoryPressureMultiplier(addedMemoryUsage);
     MetaAllocator::Statistics statistics = allocator->currentStatistics();
     ASSERT(statistics.bytesAllocated <= statistics.bytesReserved);
     size_t bytesAllocated = statistics.bytesAllocated + addedMemoryUsage;
@@ -465,6 +452,8 @@ double ExecutableAllocator::memoryPressureMultiplier(size_t addedMemoryUsage)
 
 RefPtr<ExecutableMemoryHandle> ExecutableAllocator::allocate(size_t sizeInBytes, void* ownerUID, JITCompilationEffort effort)
 {
+    if (!allocator)
+        return Base::allocate(sizeInBytes, ownerUID, effort);
     if (Options::logExecutableAllocation()) {
         MetaAllocator::Statistics stats = allocator->currentStatistics();
         dataLog("Allocating ", sizeInBytes, " bytes of executable memory with ", stats.bytesAllocated, " bytes allocated, ", stats.bytesReserved, " bytes reserved, and ", stats.bytesCommitted, " committed.\n");
@@ -514,33 +503,45 @@ RefPtr<ExecutableMemoryHandle> ExecutableAllocator::allocate(size_t sizeInBytes,
 
 bool ExecutableAllocator::isValidExecutableMemory(const AbstractLocker& locker, void* address)
 {
+    if (!allocator)
+        return Base::isValidExecutableMemory(locker, address);
     return allocator->isInAllocatedMemory(locker, address);
 }
 
 Lock& ExecutableAllocator::getLock() const
 {
+    if (!allocator)
+        return Base::getLock();
     return allocator->getLock();
 }
 
 size_t ExecutableAllocator::committedByteCount()
 {
+    if (!allocator)
+        return Base::committedByteCount();
     return allocator->bytesCommitted();
 }
 
 #if ENABLE(META_ALLOCATOR_PROFILE)
 void ExecutableAllocator::dumpProfile()
 {
+    if (!allocator)
+        return;
     allocator->dumpProfile();
 }
 #endif
 
 void* startOfFixedExecutableMemoryPoolImpl()
 {
+    if (!allocator)
+        return nullptr;
     return allocator->memoryStart();
 }
 
 void* endOfFixedExecutableMemoryPoolImpl()
 {
+    if (!allocator)
+        return nullptr;
     return allocator->memoryEnd();
 }
 
@@ -551,13 +552,13 @@ bool isJITPC(void* pc)
 
 } // namespace JSC
 
-#else // !ENABLE(JIT)
+#endif // ENABLE(JIT)
 
 namespace JSC {
 
 static ExecutableAllocator* executableAllocator;
 
-void ExecutableAllocator::initializeAllocator()
+void ExecutableAllocator::initialize()
 {
     executableAllocator = new ExecutableAllocator;
 }
@@ -569,5 +570,3 @@ ExecutableAllocator& ExecutableAllocator::singleton()
 }
 
 } // namespace JSC
-
-#endif // ENABLE(JIT)
index bb98f52..f75501f 100644 (file)
@@ -59,6 +59,39 @@ static const unsigned jitAllocationGranule = 32;
 
 typedef WTF::MetaAllocatorHandle ExecutableMemoryHandle;
 
+class ExecutableAllocatorBase {
+    WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_NONCOPYABLE(ExecutableAllocatorBase);
+public:
+    bool isValid() const { return false; }
+
+    static bool underMemoryPressure() { return false; }
+
+    static double memoryPressureMultiplier(size_t) { return 1.0; }
+
+    static void dumpProfile() { }
+
+    RefPtr<ExecutableMemoryHandle> allocate(size_t, void*, JITCompilationEffort) { return nullptr; }
+
+    static void setJITEnabled(bool) { };
+    
+    bool isValidExecutableMemory(const AbstractLocker&, void*) { return false; }
+
+    static size_t committedByteCount() { return 0; }
+
+    Lock& getLock() const
+    {
+        return m_lock;
+    }
+
+protected:
+    ExecutableAllocatorBase() = default;
+    ~ExecutableAllocatorBase() = default;
+
+private:
+    mutable Lock m_lock;
+};
+
 #if ENABLE(JIT)
 
 JS_EXPORT_PRIVATE void* startOfFixedExecutableMemoryPoolImpl();
@@ -122,14 +155,13 @@ static inline void* performJITMemcpy(void *dst, const void *src, size_t n)
     return memcpy(dst, src, n);
 }
 
-class ExecutableAllocator {
-    WTF_MAKE_FAST_ALLOCATED;
-    WTF_MAKE_NONCOPYABLE(ExecutableAllocator);
-    enum ProtectionSetting { Writable, Executable };
-
+class ExecutableAllocator : private ExecutableAllocatorBase {
 public:
+    using Base = ExecutableAllocatorBase;
+
     static ExecutableAllocator& singleton();
-    static void initializeAllocator();
+    static void initialize();
+    static void initializeUnderlyingAllocator();
 
     bool isValid() const;
 
@@ -152,44 +184,22 @@ public:
     static size_t committedByteCount();
 
     Lock& getLock() const;
-private:
 
-    ExecutableAllocator();
-    ~ExecutableAllocator();
+private:
+    ExecutableAllocator() = default;
+    ~ExecutableAllocator() = default;
 };
 
 #else
 
-class ExecutableAllocator {
-    enum ProtectionSetting { Writable, Executable };
-
+class ExecutableAllocator : public ExecutableAllocatorBase {
 public:
     static ExecutableAllocator& singleton();
-    static void initializeAllocator();
-
-    bool isValid() const { return false; }
-
-    static bool underMemoryPressure() { return false; }
-
-    static double memoryPressureMultiplier(size_t) { return 1.0; }
-
-    static void dumpProfile() { }
-
-    RefPtr<ExecutableMemoryHandle> allocate(size_t, void*, JITCompilationEffort) { return nullptr; }
-
-    static void setJITEnabled(bool) { };
-    
-    bool isValidExecutableMemory(const AbstractLocker&, void*) { return false; }
-
-    static size_t committedByteCount() { return 0; }
-
-    Lock& getLock() const
-    {
-        return m_lock;
-    }
+    static void initialize();
 
 private:
-    mutable Lock m_lock;
+    ExecutableAllocator() = default;
+    ~ExecutableAllocator() = default;
 };
 
 static inline void* performJITMemcpy(void *dst, const void *src, size_t n)
index d0399dd..6fd1f6a 100644 (file)
@@ -69,6 +69,7 @@
 #include "SuperSampler.h"
 #include "TestRunnerUtils.h"
 #include "TypedArrayInlines.h"
+#include "WasmCapabilities.h"
 #include "WasmContext.h"
 #include "WasmFaultSignalHandler.h"
 #include "WasmMemory.h"
@@ -2307,7 +2308,7 @@ static EncodedJSValue JSC_HOST_CALL functionWebAssemblyMemoryMode(ExecState* exe
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
     
-    if (!Options::useWebAssembly())
+    if (!Wasm::isSupported())
         return throwVMTypeError(exec, scope, "WebAssemblyMemoryMode should only be called if the useWebAssembly option is set"_s);
 
     if (JSObject* object = exec->argument(0).getObject()) {
index a1ac058..02c54db 100644 (file)
 #include "LLIntData.h"
 #include "MacroAssemblerCodeRef.h"
 #include "Options.h"
+#include "SigillCrashAnalyzer.h"
 #include "StructureIDTable.h"
 #include "SuperSampler.h"
+#include "WasmCapabilities.h"
 #include "WasmThunks.h"
 #include "WriteBarrier.h"
 #include <mutex>
@@ -68,11 +70,12 @@ void initializeThreading()
         WriteBarrierCounters::initialize();
 #endif
 
-#if ENABLE(ASSEMBLER)
-        ExecutableAllocator::initializeAllocator();
-#endif
+        ExecutableAllocator::initialize();
         VM::computeCanUseJIT();
 
+        if (VM::canUseJIT() && Options::useSigillCrashAnalyzer())
+            enableSigillCrashAnalyzer();
+
         LLInt::initialize();
 #ifndef NDEBUG
         DisallowGC::initialize();
@@ -83,7 +86,7 @@ void initializeThreading()
         thread.setSavedLastStackTop(thread.stack().origin());
 
 #if ENABLE(WEBASSEMBLY)
-        if (Options::useWebAssembly())
+        if (Wasm::isSupported())
             Wasm::Thunks::initialize();
 #endif
 
index b1b2854..7afe703 100644 (file)
 #include "SymbolObject.h"
 #include "SymbolPrototype.h"
 #include "VariableWriteFireDetail.h"
+#include "WasmCapabilities.h"
 #include "WeakGCMapInlines.h"
 #include "WeakMapConstructor.h"
 #include "WeakMapPrototype.h"
@@ -1042,7 +1043,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
         exposeDollarVM(vm);
 
 #if ENABLE(WEBASSEMBLY)
-    if (Options::useWebAssembly()) {
+    if (Wasm::isSupported()) {
         auto* webAssemblyPrototype = WebAssemblyPrototype::create(vm, this, WebAssemblyPrototype::createStructure(vm, this, m_objectPrototype.get()));
         m_webAssemblyModuleRecordStructure.initLater(
             [] (const Initializer<Structure>& init) {
index ece526d..24de74e 100644 (file)
@@ -28,6 +28,7 @@
 #include "JSCInlines.h"
 #include "MachineStackMarker.h"
 #include "SamplingProfiler.h"
+#include "WasmCapabilities.h"
 #include "WasmMachineThreads.h"
 #include <thread>
 #include <wtf/StackPointer.h>
@@ -149,7 +150,7 @@ void JSLock::didAcquireLock()
 
     m_vm->heap.machineThreads().addCurrentThread();
 #if ENABLE(WEBASSEMBLY)
-    if (Options::useWebAssembly())
+    if (Wasm::isSupported())
         Wasm::startTrackingCurrentThread();
 #endif
 
index bef9773..ea8b90a 100644 (file)
@@ -420,8 +420,10 @@ static void recomputeDependentOptions()
         Options::useJIT() = false;
 #endif
 
-    if (!Options::useJIT())
+    if (!Options::useJIT()) {
+        Options::useSigillCrashAnalyzer() = false;
         Options::useWebAssembly() = false;
+    }
 
     if (!Options::useWebAssembly())
         Options::useFastTLSForWasmContext() = false;
@@ -510,9 +512,6 @@ static void recomputeDependentOptions()
         Options::scribbleFreeCells() = true;
     }
 
-    if (Options::useSigillCrashAnalyzer())
-        enableSigillCrashAnalyzer();
-
     if (Options::reservedZoneSize() < minimumReservedZoneSize)
         Options::reservedZoneSize() = minimumReservedZoneSize;
     if (Options::softReservedZoneSize() < Options::reservedZoneSize() + minimumReservedZoneSize)
index f404299..43753da 100644 (file)
@@ -185,19 +185,23 @@ Atomic<unsigned> VM::s_numberOfIDs;
 // just checks for ENABLE(JIT) or ENABLE(YARR_JIT) with this premise in mind.
 
 #if ENABLE(ASSEMBLER)
-static bool enableAssembler(ExecutableAllocator& executableAllocator)
+static bool enableAssembler()
 {
     if (!Options::useJIT() && !Options::useRegExpJIT())
         return false;
 
-    if (!executableAllocator.isValid()) {
+    char* canUseJITString = getenv("JavaScriptCoreUseJIT");
+    if (canUseJITString && !atoi(canUseJITString))
+        return false;
+
+    ExecutableAllocator::initializeUnderlyingAllocator();
+    if (!ExecutableAllocator::singleton().isValid()) {
         if (Options::crashIfCantAllocateJITMemory())
             CRASH();
         return false;
     }
 
-    char* canUseJITString = getenv("JavaScriptCoreUseJIT");
-    return !canUseJITString || atoi(canUseJITString);
+    return true;
 }
 #endif // ENABLE(!ASSEMBLER)
 
@@ -207,7 +211,7 @@ bool VM::canUseAssembler()
     static std::once_flag onceKey;
     static bool enabled = false;
     std::call_once(onceKey, [] {
-        enabled = enableAssembler(ExecutableAllocator::singleton());
+        enabled = enableAssembler();
     });
     return enabled;
 #else
@@ -407,14 +411,6 @@ VM::VM(VMType vmType, HeapType heapType)
     }
 
     Thread::current().setCurrentAtomicStringTable(existingEntryAtomicStringTable);
-
-#if ENABLE(JIT)
-    jitStubs = std::make_unique<JITThunks>();
-#endif
-
-#if ENABLE(FTL_JIT)
-    ftlThunks = std::make_unique<FTL::Thunks>();
-#endif // ENABLE(FTL_JIT)
     
 #if !ENABLE(C_LOOP)
     initializeHostCallReturnValue(); // This is needed to convince the linker not to drop host call return support.
@@ -472,14 +468,15 @@ VM::VM(VMType vmType, HeapType heapType)
 #if ENABLE(JIT)
     // Make sure that any stubs that the JIT is going to use are initialized in non-compilation threads.
     if (canUseJIT()) {
+        jitStubs = std::make_unique<JITThunks>();
+#if ENABLE(FTL_JIT)
+        ftlThunks = std::make_unique<FTL::Thunks>();
+#endif // ENABLE(FTL_JIT)
         getCTIInternalFunctionTrampolineFor(CodeForCall);
         getCTIInternalFunctionTrampolineFor(CodeForConstruct);
     }
 #endif
 
-    if (!canUseJIT())
-        noJITValueProfileSingleton = std::make_unique<ValueProfile>(0);
-
     if (Options::forceDebuggerBytecodeGeneration() || Options::alwaysUseShadowChicken())
         ensureShadowChicken();
 
index 939466e..d9ff42b 100644 (file)
@@ -804,8 +804,6 @@ public:
     RTTraceList* m_rtTraceList;
 #endif
 
-    std::unique_ptr<ValueProfile> noJITValueProfileSingleton;
-
     JS_EXPORT_PRIVATE void resetDateCache();
 
     RegExpCache* regExpCache() { return m_regExpCache; }
diff --git a/Source/JavaScriptCore/wasm/WasmCapabilities.h b/Source/JavaScriptCore/wasm/WasmCapabilities.h
new file mode 100644 (file)
index 0000000..ab90934
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Options.h"
+#include "VM.h"
+
+namespace JSC {
+namespace Wasm {
+
+inline bool isSupported()
+{
+    return VM::canUseJIT() && Options::useWebAssembly();
+}
+
+} } // namespace JSC::Wasm
index f9069e2..64c3590 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "ExecutableAllocator.h"
 #include "MachineContext.h"
+#include "WasmCapabilities.h"
 #include "WasmExceptionType.h"
 #include "WasmMemory.h"
 #include "WasmThunks.h"
@@ -126,6 +127,9 @@ void enableFastMemory()
 #if ENABLE(WEBASSEMBLY_FAST_MEMORY)
     static std::once_flag once;
     std::call_once(once, [] {
+        if (!Wasm::isSupported())
+            return;
+
         if (!Options::useWebAssemblyFastMemory())
             return;