Templatize CodePtr/Refs/FunctionPtrs with PtrTags.
[WebKit-https.git] / Source / JavaScriptCore / jit / JITThunks.h
index 64a06b5..bd72208 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef JITThunks_h
-#define JITThunks_h
+#pragma once
 
 #if ENABLE(JIT)
 
 #include "CallData.h"
 #include "Intrinsic.h"
-#include "LowLevelInterpreter.h"
 #include "MacroAssemblerCodeRef.h"
 #include "ThunkGenerator.h"
 #include "Weak.h"
 #include "WeakHandleOwner.h"
-#include "WeakInlines.h"
+#include <tuple>
 #include <wtf/HashMap.h>
-#include <wtf/RefPtr.h>
-#include <wtf/ThreadingPrimitives.h>
+#include <wtf/text/StringHash.h>
 
 namespace JSC {
+namespace DOMJIT {
+class Signature;
+}
 
 class VM;
 class NativeExecutable;
@@ -51,27 +51,60 @@ public:
     JITThunks();
     virtual ~JITThunks();
 
-    MacroAssemblerCodePtr ctiNativeCall(VM*);
-    MacroAssemblerCodePtr ctiNativeConstruct(VM*);
-    MacroAssemblerCodePtr ctiNativeTailCall(VM*);    
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeCall(VM*);
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeConstruct(VM*);
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeTailCall(VM*);
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiNativeTailCallWithoutSavedTags(VM*);
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiInternalFunctionCall(VM*);
+    MacroAssemblerCodePtr<JITThunkPtrTag> ctiInternalFunctionConstruct(VM*);
 
-    MacroAssemblerCodeRef ctiStub(VM*, ThunkGenerator);
+    MacroAssemblerCodeRef<JITThunkPtrTag> ctiStub(VM*, ThunkGenerator);
+    MacroAssemblerCodeRef<JITThunkPtrTag> existingCTIStub(ThunkGenerator);
 
-    NativeExecutable* hostFunctionStub(VM*, NativeFunction, NativeFunction constructor);
-    NativeExecutable* hostFunctionStub(VM*, NativeFunction, ThunkGenerator, Intrinsic);
+    NativeExecutable* hostFunctionStub(VM*, TaggedNativeFunction, TaggedNativeFunction constructor, const String& name);
+    NativeExecutable* hostFunctionStub(VM*, TaggedNativeFunction, TaggedNativeFunction constructor, ThunkGenerator, Intrinsic, const DOMJIT::Signature*, const String& name);
+    NativeExecutable* hostFunctionStub(VM*, TaggedNativeFunction, ThunkGenerator, Intrinsic, const String& name);
 
     void clearHostFunctionStubs();
 
 private:
-    // Main thread can hold this lock for a while, so use an adaptive mutex.
-    typedef Mutex Lock;
-    typedef MutexLocker Locker;
-
     void finalize(Handle<Unknown>, void* context) override;
     
-    typedef HashMap<ThunkGenerator, MacroAssemblerCodeRef> CTIStubMap;
+    typedef HashMap<ThunkGenerator, MacroAssemblerCodeRef<JITThunkPtrTag>> CTIStubMap;
     CTIStubMap m_ctiStubMap;
-    typedef HashMap<std::pair<NativeFunction, NativeFunction>, Weak<NativeExecutable>> HostFunctionStubMap;
+
+    typedef std::tuple<TaggedNativeFunction, TaggedNativeFunction, String> HostFunctionKey;
+
+    struct HostFunctionHash {
+        static unsigned hash(const HostFunctionKey& key)
+        {
+            unsigned hash = WTF::pairIntHash(hashPointer(std::get<0>(key)), hashPointer(std::get<1>(key)));
+            if (!std::get<2>(key).isNull())
+                hash = WTF::pairIntHash(hash, DefaultHash<String>::Hash::hash(std::get<2>(key)));
+            return hash;
+        }
+        static bool equal(const HostFunctionKey& a, const HostFunctionKey& b)
+        {
+            return (std::get<0>(a) == std::get<0>(b)) && (std::get<1>(a) == std::get<1>(b)) && (std::get<2>(a) == std::get<2>(b));
+        }
+        static const bool safeToCompareToEmptyOrDeleted = true;
+
+    private:
+        static inline unsigned hashPointer(TaggedNativeFunction p)
+        {
+            return DefaultHash<TaggedNativeFunction>::Hash::hash(p);
+        }
+    };
+
+    struct HostFunctionHashTrait : WTF::GenericHashTraits<HostFunctionKey> {
+        static const bool emptyValueIsZero = true;
+        static EmptyValueType emptyValue() { return std::make_tuple(nullptr, nullptr, String()); }
+
+        static void constructDeletedValue(HostFunctionKey& slot) { std::get<0>(slot) = TaggedNativeFunction(-1); }
+        static bool isDeletedValue(const HostFunctionKey& value) { return std::get<0>(value) == TaggedNativeFunction(-1); }
+    };
+    
+    typedef HashMap<HostFunctionKey, Weak<NativeExecutable>, HostFunctionHash, HostFunctionHashTrait> HostFunctionStubMap;
     std::unique_ptr<HostFunctionStubMap> m_hostFunctionStubMap;
     Lock m_lock;
 };
@@ -79,6 +112,3 @@ private:
 } // namespace JSC
 
 #endif // ENABLE(JIT)
-
-#endif // JITThunks_h
-