2
0
Эх сурвалжийг харах

move ScriptContextInfo to be interface

Michael Holman 9 жил өмнө
parent
commit
7fc1860a57

+ 2 - 2
lib/Backend/LowerMDShared.cpp

@@ -2637,8 +2637,8 @@ bool LowererMD::GenerateFastCmXxTaggedInt(IR::Instr *instr)
     }
 
     bool isNeqOp = instr->m_opcode == Js::OpCode::CmSrNeq_A || instr->m_opcode == Js::OpCode::CmNeq_A;
-    intptr_t notEqualResult = m_func->GetScriptContextInfo()->GetTrueOrFalseAddr(isNeqOp);
-    intptr_t equalResult = m_func->GetScriptContextInfo()->GetTrueOrFalseAddr(!isNeqOp);
+    intptr_t notEqualResult = isNeqOp ? m_func->GetScriptContextInfo()->GetTrueAddr() : m_func->GetScriptContextInfo()->GetFalseAddr();
+    intptr_t equalResult = !isNeqOp ? m_func->GetScriptContextInfo()->GetTrueAddr() : m_func->GetScriptContextInfo()->GetFalseAddr();
 
     // Tagged ints?
     bool isTaggedInts = false;

+ 51 - 1
lib/Backend/ServerScriptContext.cpp

@@ -6,10 +6,17 @@
 #include "Backend.h"
 
 ServerScriptContext::ServerScriptContext(ScriptContextDataIDL * contextData) :
-    m_contextData(*contextData)
+    m_contextData(*contextData),
+    m_isPRNGSeeded(false),
+    m_activeJITCount(0)
 {
+    m_domFastPathHelperMap = HeapNew(JITDOMFastPathHelperMap, &HeapAllocator::Instance, 17);
 }
 
+ServerScriptContext::~ServerScriptContext()
+{
+    HeapDelete(m_domFastPathHelperMap);
+}
 
 intptr_t
 ServerScriptContext::GetNullAddr() const
@@ -197,3 +204,46 @@ ServerScriptContext::GetRecyclerVerifyPad() const
 {
     return m_contextData.recyclerVerifyPad;
 }
+
+bool
+ServerScriptContext::IsPRNGSeeded() const
+{
+    return m_isPRNGSeeded;
+}
+
+void
+ServerScriptContext::AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper)
+{
+    m_domFastPathHelperMap->Add(funcInfoAddr, helper);
+}
+
+IR::JnHelperMethod
+ServerScriptContext::GetDOMFastPathHelper(intptr_t funcInfoAddr)
+{
+    IR::JnHelperMethod helper;
+
+    m_domFastPathHelperMap->LockResize();
+    bool found = m_domFastPathHelperMap->TryGetValue(funcInfoAddr, &helper);
+    m_domFastPathHelperMap->UnlockResize();
+
+    Assert(found);
+    return helper;
+}
+
+void
+ServerScriptContext::BeginJIT()
+{
+    InterlockedExchangeAdd(&m_activeJITCount, 1);
+}
+
+void
+ServerScriptContext::EndJIT()
+{
+    InterlockedExchangeSubtract(&m_activeJITCount, 1);
+}
+
+bool
+ServerScriptContext::IsJITActive()
+{
+    return m_activeJITCount != 0;
+}

+ 14 - 0
lib/Backend/ServerScriptContext.h

@@ -9,6 +9,7 @@ class ServerScriptContext : public ScriptContextInfo
 {
 public:
     ServerScriptContext(ScriptContextDataIDL * contextData);
+    ~ServerScriptContext();
     virtual intptr_t GetNullAddr() const override;
     virtual intptr_t GetUndefinedAddr() const override;
     virtual intptr_t GetTrueAddr() const override;
@@ -35,6 +36,7 @@ public:
     virtual intptr_t GetRecyclerAddr() const override;
     virtual bool GetRecyclerAllowNativeCodeBumpAllocation() const override;
     virtual bool IsSIMDEnabled() const override;
+    virtual bool IsPRNGSeeded() const override;
     virtual intptr_t GetBuiltinFunctionsBaseAddr() const override;
 
     virtual intptr_t GetAddr() const override;
@@ -44,7 +46,19 @@ public:
     virtual bool IsRecyclerVerifyEnabled() const override;
     virtual uint GetRecyclerVerifyPad() const override;
 
+    virtual void AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper) override;
+    virtual IR::JnHelperMethod GetDOMFastPathHelper(intptr_t funcInfoAddr) override;
+
+    void BeginJIT();
+    void EndJIT();
+    bool IsJITActive();
 private:
+    JITDOMFastPathHelperMap * m_domFastPathHelperMap;
+
     ScriptContextDataIDL m_contextData;
+    uint m_activeJITCount;
+
+    // TODO: OOP JIT, set this when we initialize PRNG
+    bool m_isPRNGSeeded;
 
 };

+ 0 - 1
lib/Runtime/Base/Chakra.Runtime.Base.vcxproj

@@ -68,7 +68,6 @@
     <ClCompile Include="$(MSBuildThisFileDirectory)RuntimeBasePch.cpp">
       <PrecompiledHeader>Create</PrecompiledHeader>
     </ClCompile>
-    <ClCompile Include="ScriptContextInfo.cpp" />
     <ClCompile Include="ThreadContextInfo.cpp" />
     <ClCompile Include="jitprofiling.cpp" />
     <ClCompile Include="VTuneChakraProfile.cpp" />

+ 27 - 0
lib/Runtime/Base/ScriptContext.cpp

@@ -326,6 +326,7 @@ namespace Js
         intConstPropsOnGlobalObject = Anew(GeneralAllocator(), PropIdSetForConstProp, GeneralAllocator());
         intConstPropsOnGlobalUserObject = Anew(GeneralAllocator(), PropIdSetForConstProp, GeneralAllocator());
 
+        m_domFastPathHelperMap = HeapNew(JITDOMFastPathHelperMap, &HeapAllocator::Instance, 17);
         this->debugContext = HeapNew(DebugContext, this);
     }
 
@@ -377,6 +378,10 @@ namespace Js
         // Take etw rundown lock on this thread context. We are going to change/destroy this scriptContext.
         AutoCriticalSection autocs(GetThreadContext()->GetEtwRundownCriticalSection());
 
+        if (m_domFastPathHelperMap != nullptr)
+        {
+            HeapDelete(m_domFastPathHelperMap);
+        }
         if (m_remoteScriptContextAddr != 0)
         {
             Assert(JITManager::GetJITManager()->IsOOPJITEnabled());
@@ -4542,11 +4547,33 @@ void ScriptContext::RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertie
         return GetConfig()->IsSimdjsEnabled();
     }
 
+    bool ScriptContext::IsPRNGSeeded() const
+    {
+        return GetLibrary()->IsPRNGSeeded();
+    }
+
     intptr_t ScriptContext::GetAddr() const
     {
         return (intptr_t)this;
     }
 
+    void ScriptContext::AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper)
+    {
+        m_domFastPathHelperMap->Add(funcInfoAddr, helper);
+    }
+
+    IR::JnHelperMethod ScriptContext::GetDOMFastPathHelper(intptr_t funcInfoAddr)
+    {
+        IR::JnHelperMethod helper;
+
+        m_domFastPathHelperMap->LockResize();
+        bool found = m_domFastPathHelperMap->TryGetValue(funcInfoAddr, &helper);
+        m_domFastPathHelperMap->UnlockResize();
+
+        Assert(found);
+        return helper;
+    }
+
     intptr_t ScriptContext::GetVTableAddress(VTableValue vtableType) const
     {
         Assert(vtableType < VTableValue::Count);

+ 6 - 0
lib/Runtime/Base/ScriptContext.h

@@ -1731,8 +1731,12 @@ private:
         virtual intptr_t GetRecyclerAddr() const override;
         virtual bool GetRecyclerAllowNativeCodeBumpAllocation() const override;
         virtual bool IsSIMDEnabled() const override;
+        virtual bool IsPRNGSeeded() const override;
         virtual intptr_t GetBuiltinFunctionsBaseAddr() const override;
 
+        virtual void AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper) override;
+        virtual IR::JnHelperMethod GetDOMFastPathHelper(intptr_t funcInfoAddr) override;
+
         virtual intptr_t GetAddr() const override;
 
         virtual intptr_t GetVTableAddress(VTableValue vtableType) const override;
@@ -1746,6 +1750,8 @@ private:
     private:
         BuiltInLibraryFunctionMap* builtInLibraryFunctions;
 
+        JITDOMFastPathHelperMap * m_domFastPathHelperMap;
+
 #ifdef RECYCLER_PERF_COUNTERS
         size_t bindReferenceCount;
 #endif

+ 0 - 67
lib/Runtime/Base/ScriptContextInfo.cpp

@@ -1,67 +0,0 @@
-//-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-//-------------------------------------------------------------------------------------------------------
-
-#include "RuntimeBasePch.h"
-
-ScriptContextInfo::ScriptContextInfo() :
-    m_isPRNGSeeded(false),
-    m_activeJITCount(0)
-{
-    m_domFastPathHelperMap = HeapNew(JITDOMFastPathHelperMap, &HeapAllocator::Instance, 17);
-}
-
-ScriptContextInfo::~ScriptContextInfo()
-{
-    HeapDelete(m_domFastPathHelperMap);
-}
-
-intptr_t
-ScriptContextInfo::GetTrueOrFalseAddr(bool isTrue) const
-{
-    return isTrue ? GetTrueAddr() : GetFalseAddr();
-}
-
-bool
-ScriptContextInfo::IsPRNGSeeded() const
-{
-    return m_isPRNGSeeded;
-}
-
-void
-ScriptContextInfo::BeginJIT()
-{
-    InterlockedExchangeAdd(&m_activeJITCount, 1);
-}
-
-void
-ScriptContextInfo::EndJIT()
-{
-    InterlockedExchangeSubtract(&m_activeJITCount, 1);
-}
-
-bool
-ScriptContextInfo::IsJITActive()
-{
-    return m_activeJITCount != 0;
-}
-
-void
-ScriptContextInfo::AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper)
-{
-    m_domFastPathHelperMap->Add(funcInfoAddr, helper);
-}
-
-IR::JnHelperMethod
-ScriptContextInfo::GetDOMFastPathHelper(intptr_t funcInfoAddr)
-{
-    IR::JnHelperMethod helper;
-    
-    m_domFastPathHelperMap->LockResize();
-    bool found = m_domFastPathHelperMap->TryGetValue(funcInfoAddr, &helper);
-    m_domFastPathHelperMap->UnlockResize();
-
-    Assert(found);
-    return helper;
-}

+ 3 - 19
lib/Runtime/Base/ScriptContextInfo.h

@@ -8,11 +8,6 @@
 class ScriptContextInfo
 {
 public:
-    ScriptContextInfo();
-    ~ScriptContextInfo();
-
-    intptr_t GetTrueOrFalseAddr(bool value) const;
-
     virtual intptr_t GetNullAddr() const = 0;
     virtual intptr_t GetUndefinedAddr() const = 0;
     virtual intptr_t GetTrueAddr() const = 0;
@@ -39,6 +34,7 @@ public:
     virtual intptr_t GetRecyclerAddr() const = 0;
     virtual bool GetRecyclerAllowNativeCodeBumpAllocation() const = 0;
     virtual bool IsSIMDEnabled() const = 0;
+    virtual bool IsPRNGSeeded() const = 0;
     virtual intptr_t GetBuiltinFunctionsBaseAddr() const = 0;
 
     virtual intptr_t GetAddr() const = 0;
@@ -48,22 +44,10 @@ public:
     virtual bool IsRecyclerVerifyEnabled() const = 0;
     virtual uint GetRecyclerVerifyPad() const = 0;
 
-    void AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper);
-    IR::JnHelperMethod GetDOMFastPathHelper(intptr_t funcInfoAddr);
-
-    bool IsPRNGSeeded() const;
-
-    void BeginJIT();
-    void EndJIT();
-    bool IsJITActive();
-private:
-    // TODO: OOP JIT, set this when we initialize PRNG
-    bool m_isPRNGSeeded;
-
-    uint m_activeJITCount;
+    virtual void AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper) = 0;
+    virtual IR::JnHelperMethod GetDOMFastPathHelper(intptr_t funcInfoAddr) = 0;
 
     typedef JsUtil::BaseDictionary<intptr_t, IR::JnHelperMethod, HeapAllocator, PowerOf2SizePolicy,
         DefaultComparer, JsUtil::SimpleDictionaryEntry, JsUtil::AsymetricResizeLock> JITDOMFastPathHelperMap;
 
-    JITDOMFastPathHelperMap * m_domFastPathHelperMap;
 };