Forráskód Böngészése

checkpoint on refactor to get in proc jit working again

Michael Holman 9 éve
szülő
commit
2d862feb0f
42 módosított fájl, 1207 hozzáadás és 720 törlés
  1. 2 2
      lib/Backend/Backend.h
  2. 6 6
      lib/Backend/BailOut.cpp
  3. 4 4
      lib/Backend/Chakra.Backend.vcxproj
  4. 4 4
      lib/Backend/Chakra.Backend.vcxproj.filters
  5. 2 6
      lib/Backend/Func.cpp
  6. 1 4
      lib/Backend/Func.h
  7. 1 1
      lib/Backend/LinearScan.cpp
  8. 23 7
      lib/Backend/NativeCodeGenerator.cpp
  9. 1 1
      lib/Backend/NativeCodeGenerator.h
  10. 0 257
      lib/Backend/ScriptContextInfo.cpp
  11. 0 67
      lib/Backend/ScriptContextInfo.h
  12. 199 0
      lib/Backend/ServerScriptContext.cpp
  13. 50 0
      lib/Backend/ServerScriptContext.h
  14. 189 0
      lib/Backend/ServerThreadContext.cpp
  15. 63 0
      lib/Backend/ServerThreadContext.h
  16. 45 0
      lib/JITClient/JITManager.cpp
  17. 3 0
      lib/JITClient/JITManager.h
  18. 1 1
      lib/JITIDL/ChakraJIT.idl
  19. 18 17
      lib/JITServer/JITServer.cpp
  20. 4 0
      lib/Runtime/Base/Chakra.Runtime.Base.vcxproj
  21. 2 2
      lib/Runtime/Base/Constants.cpp
  22. 1 1
      lib/Runtime/Base/Constants.h
  23. 2 2
      lib/Runtime/Base/PropertyRecord.h
  24. 165 0
      lib/Runtime/Base/ScriptContext.cpp
  25. 39 2
      lib/Runtime/Base/ScriptContext.h
  26. 67 0
      lib/Runtime/Base/ScriptContextInfo.cpp
  27. 69 0
      lib/Runtime/Base/ScriptContextInfo.h
  28. 1 1
      lib/Runtime/Base/ScriptContextOptimizationOverrideInfo.h
  29. 6 6
      lib/Runtime/Base/StackProber.cpp
  30. 4 4
      lib/Runtime/Base/StackProber.h
  31. 2 2
      lib/Runtime/Base/ThreadBoundThreadContextManager.cpp
  32. 135 67
      lib/Runtime/Base/ThreadContext.cpp
  33. 34 15
      lib/Runtime/Base/ThreadContext.h
  34. 15 188
      lib/Runtime/Base/ThreadContextInfo.cpp
  35. 33 45
      lib/Runtime/Base/ThreadContextInfo.h
  36. 4 4
      lib/Runtime/Base/ThreadContextTlsEntry.cpp
  37. 1 1
      lib/Runtime/Base/ThreadContextTlsEntry.h
  38. 5 0
      lib/Runtime/Debug/DebugManager.cpp
  39. 1 0
      lib/Runtime/Debug/DebugManager.h
  40. 1 1
      lib/Runtime/Language/amd64/StackFrame.cpp
  41. 2 2
      lib/Runtime/Language/i386/StackFrame.cpp
  42. 2 0
      lib/Runtime/Runtime.h

+ 2 - 2
lib/Backend/Backend.h

@@ -116,12 +116,11 @@ enum IRDumpFlags
 #include "JITTimePolymorphicInlineCacheInfo.h"
 #include "CodeGenWorkItemType.h"
 #include "CodeGenAllocators.h"
-#include "ThreadContextInfo.h"
 #include "JITTimeConstructorCache.h"
 #include "JITTypeHandler.h"
 #include "JITType.h"
 #include "JITObjTypeSpecFldInfo.h"
-#include "ScriptContextInfo.h"
+#include "ServerScriptContext.h"
 #include "JITOutput.h"
 #include "JITTimeScriptContext.h"
 #include "AsmJsJITInfo.h"
@@ -160,6 +159,7 @@ enum IRDumpFlags
 
 #include "PDataManager.h"
 
+#include "ServerThreadContext.h"
 #include "CaseNode.h"
 #include "SwitchIRBuilder.h"
 #include "IRBuilder.h"

+ 6 - 6
lib/Backend/BailOut.cpp

@@ -580,7 +580,7 @@ BailOutRecord::RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStac
                         // The value is in register
                         // Index is one based, so subtract one
                         Assert((uint)offset <= GetBailOutRegisterSaveSlotCount());
-                        Js::Var * registerSaveSpace = registerSaves ? registerSaves : scriptContext->GetThreadContext()->GetBailOutRegisterSaveSpace();
+                        Js::Var * registerSaveSpace = registerSaves ? registerSaves : (Js::Var *)scriptContext->GetThreadContext()->GetBailOutRegisterSaveSpace();
                         Assert(RegTypes[LinearScanMD::GetRegisterFromSaveIndex(offset)] != TyFloat64);
                         value = registerSaveSpace[offset - 1];
                     }
@@ -671,7 +671,7 @@ BailOutRecord::RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStac
 
 #if DBG
     // Clear the register save area for the next bailout
-    memset(scriptContext->GetThreadContext()->GetBailOutRegisterSaveSpace(), 0, GetBailOutRegisterSaveSlotCount() * sizeof(Js::Var));
+    memset((void*)scriptContext->GetThreadContext()->GetBailOutRegisterSaveSpace(), 0, GetBailOutRegisterSaveSlotCount() * sizeof(Js::Var));
 #endif
 }
 
@@ -839,7 +839,7 @@ BailOutRecord::RestoreValue(IR::BailOutKind bailOutKind, Js::JavascriptCallStack
         {
             // Register save space (offset is the register number and index into the register save space)
             // Index is one based, so subtract one
-            Js::Var * registerSaveSpace = registerSaves ? registerSaves : scriptContext->GetThreadContext()->GetBailOutRegisterSaveSpace();
+            Js::Var * registerSaveSpace = registerSaves ? registerSaves : (Js::Var *)scriptContext->GetThreadContext()->GetBailOutRegisterSaveSpace();
 
             if (isFloat64)
             {
@@ -1132,7 +1132,7 @@ uint32 bailOutOffset, void * returnAddress, IR::BailOutKind bailOutKind, Js::Imp
     // Need to capture the int registers on stack as threadContext->bailOutRegisterSaveSpace is allocated from ThreadAlloc and is not scanned by recycler.
     // We don't want to save float (xmm) registers as they can be huge and they cannot contain a var.
     Js::Var registerSaves[INT_REG_COUNT];
-    js_memcpy_s(registerSaves, sizeof(registerSaves), layout->functionObject->GetScriptContext()->GetThreadContext()->GetBailOutRegisterSaveSpace(),
+    js_memcpy_s(registerSaves, sizeof(registerSaves), (Js::Var *)layout->functionObject->GetScriptContext()->GetThreadContext()->GetBailOutRegisterSaveSpace(),
         sizeof(registerSaves));
 
     Js::Var result = BailOutCommonNoCodeGen(layout, bailOutRecord, bailOutOffset, returnAddress, bailOutKind, branchValue, nullptr, bailOutReturnValue, argoutRestoreAddress);
@@ -1149,7 +1149,7 @@ BailOutRecord::BailOutInlinedCommon(Js::JavascriptCallStackLayout * layout, Bail
     // Need to capture the register save, one of the bailout might get into jitted code again and bailout again
     // overwriting the current register saves
     Js::Var registerSaves[BailOutRegisterSaveSlotCount];
-    js_memcpy_s(registerSaves, sizeof(registerSaves), layout->functionObject->GetScriptContext()->GetThreadContext()->GetBailOutRegisterSaveSpace(),
+    js_memcpy_s(registerSaves, sizeof(registerSaves), (Js::Var *)layout->functionObject->GetScriptContext()->GetThreadContext()->GetBailOutRegisterSaveSpace(),
         sizeof(registerSaves));
     BailOutRecord const * currentBailOutRecord = bailOutRecord;
     BailOutReturnValue bailOutReturnValue;
@@ -1176,7 +1176,7 @@ BailOutRecord::BailOutFromLoopBodyInlinedCommon(Js::JavascriptCallStackLayout *
 {
     Assert(bailOutRecord->parent != nullptr);
     Js::Var registerSaves[BailOutRegisterSaveSlotCount];
-    js_memcpy_s(registerSaves, sizeof(registerSaves), layout->functionObject->GetScriptContext()->GetThreadContext()->GetBailOutRegisterSaveSpace(),
+    js_memcpy_s(registerSaves, sizeof(registerSaves), (Js::Var *)layout->functionObject->GetScriptContext()->GetThreadContext()->GetBailOutRegisterSaveSpace(),
         sizeof(registerSaves));
     BailOutRecord const * currentBailOutRecord = bailOutRecord;
     BailOutReturnValue bailOutReturnValue;

+ 4 - 4
lib/Backend/Chakra.Backend.vcxproj

@@ -196,8 +196,6 @@
     <ClCompile Include="JITTimeFunctionBody.cpp" />
     <ClCompile Include="JITTimeProfileInfo.cpp" />
     <ClCompile Include="JITTimeScriptContext.cpp" />
-    <ClCompile Include="ScriptContextInfo.cpp" />
-    <ClCompile Include="ThreadContextInfo.cpp" />
     <ClCompile Include="JITTimeWorkItem.cpp" />
   </ItemGroup>
   <ItemGroup>
@@ -379,8 +377,6 @@
     <ClInclude Include="JITTimeScriptContext.h" />
     <ClInclude Include="JITType.h" />
     <ClInclude Include="JITTypeHandler.h" />
-    <ClInclude Include="ScriptContextInfo.h" />
-    <ClInclude Include="ThreadContextInfo.h" />
     <ClInclude Include="JITTimeWorkItem.h" />
     <ClInclude Include="JnHelperMethod.h" />
     <ClInclude Include="JnHelperMethodList.h" />
@@ -401,6 +397,8 @@
     <ClInclude Include="Region.h" />
     <ClInclude Include="SccLiveness.h" />
     <ClInclude Include="Security.h" />
+    <ClInclude Include="ServerScriptContext.h" />
+    <ClInclude Include="ServerThreadContext.h" />
     <ClInclude Include="SimpleJitProfilingHelpers.h" />
     <ClInclude Include="SimpleLayout.h" />
     <ClInclude Include="Sym.h" />
@@ -449,6 +447,8 @@
     <ClCompile Include="JITTimePolymorphicInlineCacheInfo.cpp" />
     <ClCompile Include="JITType.cpp" />
     <ClCompile Include="JITTypeHandler.cpp" />
+    <ClCompile Include="ServerScriptContext.cpp" />
+    <ClCompile Include="ServerThreadContext.cpp" />
   </ItemGroup>
   <Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

+ 4 - 4
lib/Backend/Chakra.Backend.vcxproj.filters

@@ -109,8 +109,6 @@
     <ClCompile Include="JITTimeFunctionBody.cpp" />
     <ClCompile Include="JITOutput.cpp" />
     <ClCompile Include="JITTimeScriptContext.cpp" />
-    <ClCompile Include="ThreadContextInfo.cpp" />
-    <ClCompile Include="ScriptContextInfo.cpp" />
     <ClCompile Include="JITTimeProfileInfo.cpp" />
     <ClCompile Include="AsmJsJITInfo.cpp" />
     <ClCompile Include="FunctionJITTimeInfo.cpp" />
@@ -124,6 +122,8 @@
     </ClCompile>
     <ClCompile Include="JITTimePolymorphicInlineCacheInfo.cpp" />
     <ClCompile Include="JITTimePolymorphicInlineCache.cpp" />
+    <ClCompile Include="ServerThreadContext.cpp" />
+    <ClCompile Include="ServerScriptContext.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="AgenPeeps.h" />
@@ -319,8 +319,6 @@
     <ClInclude Include="JITTimeFunctionBody.h" />
     <ClInclude Include="JITOutput.h" />
     <ClInclude Include="JITTimeScriptContext.h" />
-    <ClInclude Include="ThreadContextInfo.h" />
-    <ClInclude Include="ScriptContextInfo.h" />
     <ClInclude Include="JITTimeProfileInfo.h" />
     <ClInclude Include="AsmJsJITInfo.h" />
     <ClInclude Include="FunctionJITTimeInfo.h" />
@@ -331,6 +329,8 @@
     <ClInclude Include="JITTypeHandler.h" />
     <ClInclude Include="JITTimePolymorphicInlineCacheInfo.h" />
     <ClInclude Include="JITTimePolymorphicInlineCache.h" />
+    <ClInclude Include="ServerThreadContext.h" />
+    <ClInclude Include="ServerScriptContext.h" />
   </ItemGroup>
   <ItemGroup>
     <MASM Include="$(MSBuildThisFileDirectory)amd64\LinearScanMdA.asm">

+ 2 - 6
lib/Backend/Func.cpp

@@ -258,9 +258,7 @@ Func::Codegen(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
     const FunctionJITRuntimeInfo *const runtimeInfo,
     JITTimePolymorphicInlineCacheInfo * const polymorphicInlineCacheInfo, CodeGenAllocators *const codeGenAllocators,
     CodeGenNumberAllocator * numberAllocator,
-    Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT, Func * parentFunc,
-    uint postCallByteCodeOffset, Js::RegSlot returnValueRegSlot, const bool isInlinedConstructor,
-    Js::ProfileId callSiteIdInParentFunc, bool isGetterSetter)
+    Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT)
 {
     bool rejit;
     do
@@ -268,9 +266,7 @@ Func::Codegen(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
         Func func(alloc, workItem, threadContextInfo,
             scriptContextInfo, outputData, runtimeInfo,
             polymorphicInlineCacheInfo, codeGenAllocators, numberAllocator,
-            codeGenProfiler, isBackgroundJIT, parentFunc,
-            postCallByteCodeOffset, returnValueRegSlot, isInlinedConstructor,
-            callSiteIdInParentFunc, isGetterSetter);
+            codeGenProfiler, isBackgroundJIT);
         try
         {
             func.TryCodegen();

+ 1 - 4
lib/Backend/Func.h

@@ -237,10 +237,7 @@ public:
         const FunctionJITRuntimeInfo *const runtimeInfo,
         JITTimePolymorphicInlineCacheInfo * const polymorphicInlineCacheInfo, CodeGenAllocators *const codeGenAllocators,
         CodeGenNumberAllocator * numberAllocator,
-        Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT, Func * parentFunc = nullptr,
-        uint postCallByteCodeOffset = Js::Constants::NoByteCodeOffset,
-        Js::RegSlot returnValueRegSlot = Js::Constants::NoRegister, const bool isInlinedConstructor = false,
-        Js::ProfileId callSiteIdInParentFunc = UINT16_MAX, bool isGetterSetter = false);
+        Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT);
 
     int32 StackAllocate(int size);
     int32 StackAllocate(StackSym *stackSym, int size);

+ 1 - 1
lib/Backend/LinearScan.cpp

@@ -1316,7 +1316,7 @@ LinearScan::EnsureGlobalBailOutRecordTable(Func *func)
         globalBailOutRecordDataTable->isLoopBody = topFunc->IsLoopBody();
         globalBailOutRecordDataTable->returnValueRegSlot = func->returnValueRegSlot;
         globalBailOutRecordDataTable->firstActualStackOffset = -1;
-        globalBailOutRecordDataTable->registerSaveSpace = (Js::Var*)func->GetThreadContextInfo()->GetBailOutRegisterSaveSpace();
+        globalBailOutRecordDataTable->registerSaveSpace = (Js::Var*)func->GetThreadContextInfo()->GetBailOutRegisterSaveSpaceAddr();
         globalBailOutRecordDataTable->globalBailOutRecordDataRows = nullptr;
 
 #ifdef PROFILE_BAILOUT_RECORD_MEMORY

+ 23 - 7
lib/Backend/NativeCodeGenerator.cpp

@@ -907,16 +907,32 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
 
     threadContext->GetXProcNumberPageSegmentManager()->GetFreeSegment(workItem->GetJITData()->xProcNumberPageSegment);
 
-    HRESULT hr = JITManager::GetJITManager()->RemoteCodeGenCall(
-        workItem->GetJITData(),
-        scriptContext->GetThreadContext()->GetRemoteThreadContextAddr(),
-        scriptContext->GetRemoteScriptAddr(),
-        &jitWriteData);
-    if (hr != S_OK)
+    if (JITManager::GetJITManager()->IsOOPJITEnabled())
     {
-        Js::Throw::InternalError();
+        HRESULT hr = JITManager::GetJITManager()->RemoteCodeGenCall(
+            workItem->GetJITData(),
+            scriptContext->GetThreadContext()->GetRemoteThreadContextAddr(),
+            scriptContext->GetRemoteScriptAddr(),
+            &jitWriteData);
+        if (hr != S_OK)
+        {
+            Js::Throw::InternalError();
+        }
+    }
+    else
+    {
+        CodeGenAllocators *const allocators =
+            foreground ? EnsureForegroundAllocators(pageAllocator) : GetBackgroundAllocator(pageAllocator); // okay to do outside lock since the respective function is called only from one thread
+        NoRecoverMemoryJitArenaAllocator jitArena(L"JITArena", pageAllocator, Js::Throw::OutOfMemory);
+
+        JITTimeWorkItem * jitWorkItem = Anew(&jitArena, JITTimeWorkItem, workItem->GetJITData());
+
+        Func::Codegen(&jitArena, jitWorkItem, scriptContext->GetThreadContext(),
+            scriptContext, &jitWriteData, nullptr, jitWorkItem->GetPolymorphicInlineCacheInfo(),
+            allocators, nullptr, nullptr, !foreground);
     }
 
+
     workItem->GetFunctionBody()->SetFrameHeight(workItem->GetEntryPoint(), jitWriteData.writeableEPData.frameHeight);
 
     if (jitWriteData.writeableEPData.hasJittedStackClosure != FALSE)

+ 1 - 1
lib/Backend/NativeCodeGenerator.h

@@ -127,7 +127,7 @@ private:
 
     CodeGenAllocators *CreateAllocators(PageAllocator *const pageAllocator)
     {
-        return HeapNew(CodeGenAllocators, pageAllocator->GetAllocationPolicyManager(), scriptContext, scriptContext->GetThreadContext()->GetCodePageAllocators(), nullptr);
+        return HeapNew(CodeGenAllocators, pageAllocator->GetAllocationPolicyManager(), scriptContext, scriptContext->GetThreadContext()->GetCodePageAllocators(), GetCurrentProcess());
     }
 
     CodeGenAllocators *EnsureForegroundAllocators(PageAllocator * pageAllocator)

+ 0 - 257
lib/Backend/ScriptContextInfo.cpp

@@ -1,257 +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 "Backend.h"
-
-ScriptContextInfo::ScriptContextInfo(ScriptContextDataIDL * contextData) :
-    m_contextData(*contextData),
-    m_isPRNGSeeded(false),
-    m_activeJITCount(0)
-{
-    m_domFastPathHelperMap = HeapNew(JITDOMFastPathHelperMap, &HeapAllocator::Instance, 17);
-}
-
-ScriptContextInfo::~ScriptContextInfo()
-{
-    HeapDelete(m_domFastPathHelperMap);
-}
-
-intptr_t
-ScriptContextInfo::GetNullAddr() const
-{
-    return m_contextData.nullAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetUndefinedAddr() const
-{
-    return m_contextData.undefinedAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetTrueAddr() const
-{
-    return m_contextData.trueAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetFalseAddr() const
-{
-    return m_contextData.falseAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetTrueOrFalseAddr(bool isTrue) const
-{
-    return isTrue ? GetTrueAddr() : GetFalseAddr();
-}
-
-intptr_t
-ScriptContextInfo::GetUndeclBlockVarAddr() const
-{
-    return m_contextData.undeclBlockVarAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetEmptyStringAddr() const
-{
-    return m_contextData.emptyStringAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetNegativeZeroAddr() const
-{
-    return m_contextData.negativeZeroAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetNumberTypeStaticAddr() const
-{
-    return m_contextData.numberTypeStaticAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetStringTypeStaticAddr() const
-{
-    return m_contextData.stringTypeStaticAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetObjectTypeAddr() const
-{
-    return m_contextData.objectTypeAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetObjectHeaderInlinedTypeAddr() const
-{
-    return m_contextData.objectHeaderInlinedTypeAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetRegexTypeAddr() const
-{
-    return m_contextData.regexTypeAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetArrayTypeAddr() const
-{
-    return m_contextData.arrayTypeAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetNativeIntArrayTypeAddr() const
-{
-    return m_contextData.nativeIntArrayTypeAddr;
-
-}
-
-intptr_t
-ScriptContextInfo::GetNativeFloatArrayTypeAddr() const
-{
-    return m_contextData.nativeFloatArrayTypeAddr;
-
-}
-
-intptr_t
-ScriptContextInfo::GetArrayConstructorAddr() const
-{
-    return m_contextData.arrayConstructorAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetCharStringCacheAddr() const
-{
-    return m_contextData.charStringCacheAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetSideEffectsAddr() const
-{
-    return m_contextData.sideEffectsAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetArraySetElementFastPathVtableAddr() const
-{
-    return m_contextData.arraySetElementFastPathVtableAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetIntArraySetElementFastPathVtableAddr() const
-{
-    return m_contextData.intArraySetElementFastPathVtableAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetFloatArraySetElementFastPathVtableAddr() const
-{
-    return m_contextData.floatArraySetElementFastPathVtableAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetLibraryAddr() const
-{
-    return m_contextData.libraryAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetNumberAllocatorAddr() const
-{
-    return m_contextData.numberAllocatorAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetRecyclerAddr() const
-{
-    return m_contextData.recyclerAddr;
-}
-
-bool
-ScriptContextInfo::GetRecyclerAllowNativeCodeBumpAllocation() const
-{
-    return m_contextData.recyclerAllowNativeCodeBumpAllocation != 0;
-}
-
-bool
-ScriptContextInfo::IsSIMDEnabled() const
-{
-    return m_contextData.isSIMDEnabled != 0;
-}
-
-intptr_t
-ScriptContextInfo::GetBuiltinFunctionsBaseAddr() const
-{
-    return m_contextData.builtinFunctionsBaseAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetAddr() const
-{
-    return m_contextData.scriptContextAddr;
-}
-
-intptr_t
-ScriptContextInfo::GetVTableAddress(VTableValue vtableType) const
-{
-    Assert(vtableType < VTableValue::Count);
-    return m_contextData.vtableAddresses[vtableType];
-}
-
-bool
-ScriptContextInfo::IsRecyclerVerifyEnabled() const
-{
-    return m_contextData.isRecyclerVerifyEnabled != FALSE;
-}
-
-uint
-ScriptContextInfo::GetRecyclerVerifyPad() const
-{
-    return m_contextData.recyclerVerifyPad;
-}
-
-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;
-}

+ 0 - 67
lib/Backend/ScriptContextInfo.h

@@ -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.
-//-------------------------------------------------------------------------------------------------------
-
-#pragma once
-
-class ScriptContextInfo
-{
-public:
-    ScriptContextInfo(ScriptContextDataIDL * contextData);
-    ~ScriptContextInfo();
-    intptr_t GetNullAddr() const;
-    intptr_t GetUndefinedAddr() const;
-    intptr_t GetTrueAddr() const;
-    intptr_t GetFalseAddr() const;
-    intptr_t GetTrueOrFalseAddr(bool value) const;
-    intptr_t GetUndeclBlockVarAddr() const;
-    intptr_t GetEmptyStringAddr() const;
-    intptr_t GetNegativeZeroAddr() const;
-    intptr_t GetNumberTypeStaticAddr() const;
-    intptr_t GetStringTypeStaticAddr() const;
-    intptr_t GetObjectTypeAddr() const;
-    intptr_t GetObjectHeaderInlinedTypeAddr() const;
-    intptr_t GetRegexTypeAddr() const;
-    intptr_t GetArrayTypeAddr() const;
-    intptr_t GetNativeIntArrayTypeAddr() const;
-    intptr_t GetNativeFloatArrayTypeAddr() const;
-    intptr_t GetArrayConstructorAddr() const;
-    intptr_t GetCharStringCacheAddr() const;
-    intptr_t GetSideEffectsAddr() const;
-    intptr_t GetArraySetElementFastPathVtableAddr() const;
-    intptr_t GetIntArraySetElementFastPathVtableAddr() const;
-    intptr_t GetFloatArraySetElementFastPathVtableAddr() const;
-    intptr_t GetLibraryAddr() const;
-    intptr_t GetNumberAllocatorAddr() const;
-    intptr_t GetRecyclerAddr() const;
-    bool GetRecyclerAllowNativeCodeBumpAllocation() const;
-    bool IsSIMDEnabled() const;
-    intptr_t GetBuiltinFunctionsBaseAddr() const;
-
-    intptr_t GetAddr() const;
-
-    intptr_t GetVTableAddress(VTableValue vtableType) const;
-
-    void AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper);
-    IR::JnHelperMethod GetDOMFastPathHelper(intptr_t funcInfoAddr);
-
-    bool IsRecyclerVerifyEnabled() const;
-    uint GetRecyclerVerifyPad() const;
-    bool IsPRNGSeeded() const;
-
-    void BeginJIT();
-    void EndJIT();
-    bool IsJITActive();
-private:
-    ScriptContextDataIDL m_contextData;
-    // TODO: OOP JIT, set this when we initialize PRNG
-    bool m_isPRNGSeeded;
-
-    uint m_activeJITCount;
-
-    typedef JsUtil::BaseDictionary<intptr_t, IR::JnHelperMethod, HeapAllocator, PowerOf2SizePolicy,
-        DefaultComparer, JsUtil::SimpleDictionaryEntry, JsUtil::AsymetricResizeLock> JITDOMFastPathHelperMap;
-
-    JITDOMFastPathHelperMap * m_domFastPathHelperMap;
-};

+ 199 - 0
lib/Backend/ServerScriptContext.cpp

@@ -0,0 +1,199 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+#include "Backend.h"
+
+ServerScriptContext::ServerScriptContext(ScriptContextDataIDL * contextData) :
+    m_contextData(*contextData)
+{
+}
+
+
+intptr_t
+ServerScriptContext::GetNullAddr() const
+{
+    return m_contextData.nullAddr;
+}
+
+intptr_t
+ServerScriptContext::GetUndefinedAddr() const
+{
+    return m_contextData.undefinedAddr;
+}
+
+intptr_t
+ServerScriptContext::GetTrueAddr() const
+{
+    return m_contextData.trueAddr;
+}
+
+intptr_t
+ServerScriptContext::GetFalseAddr() const
+{
+    return m_contextData.falseAddr;
+}
+
+intptr_t
+ServerScriptContext::GetUndeclBlockVarAddr() const
+{
+    return m_contextData.undeclBlockVarAddr;
+}
+
+intptr_t
+ServerScriptContext::GetEmptyStringAddr() const
+{
+    return m_contextData.emptyStringAddr;
+}
+
+intptr_t
+ServerScriptContext::GetNegativeZeroAddr() const
+{
+    return m_contextData.negativeZeroAddr;
+}
+
+intptr_t
+ServerScriptContext::GetNumberTypeStaticAddr() const
+{
+    return m_contextData.numberTypeStaticAddr;
+}
+
+intptr_t
+ServerScriptContext::GetStringTypeStaticAddr() const
+{
+    return m_contextData.stringTypeStaticAddr;
+}
+
+intptr_t
+ServerScriptContext::GetObjectTypeAddr() const
+{
+    return m_contextData.objectTypeAddr;
+}
+
+intptr_t
+ServerScriptContext::GetObjectHeaderInlinedTypeAddr() const
+{
+    return m_contextData.objectHeaderInlinedTypeAddr;
+}
+
+intptr_t
+ServerScriptContext::GetRegexTypeAddr() const
+{
+    return m_contextData.regexTypeAddr;
+}
+
+intptr_t
+ServerScriptContext::GetArrayTypeAddr() const
+{
+    return m_contextData.arrayTypeAddr;
+}
+
+intptr_t
+ServerScriptContext::GetNativeIntArrayTypeAddr() const
+{
+    return m_contextData.nativeIntArrayTypeAddr;
+}
+
+intptr_t
+ServerScriptContext::GetNativeFloatArrayTypeAddr() const
+{
+    return m_contextData.nativeFloatArrayTypeAddr;
+}
+
+intptr_t
+ServerScriptContext::GetArrayConstructorAddr() const
+{
+    return m_contextData.arrayConstructorAddr;
+}
+
+intptr_t
+ServerScriptContext::GetCharStringCacheAddr() const
+{
+    return m_contextData.charStringCacheAddr;
+}
+
+intptr_t
+ServerScriptContext::GetSideEffectsAddr() const
+{
+    return m_contextData.sideEffectsAddr;
+}
+
+intptr_t
+ServerScriptContext::GetArraySetElementFastPathVtableAddr() const
+{
+    return m_contextData.arraySetElementFastPathVtableAddr;
+}
+
+intptr_t
+ServerScriptContext::GetIntArraySetElementFastPathVtableAddr() const
+{
+    return m_contextData.intArraySetElementFastPathVtableAddr;
+}
+
+intptr_t
+ServerScriptContext::GetFloatArraySetElementFastPathVtableAddr() const
+{
+    return m_contextData.floatArraySetElementFastPathVtableAddr;
+}
+
+intptr_t
+ServerScriptContext::GetLibraryAddr() const
+{
+    return m_contextData.libraryAddr;
+}
+
+intptr_t
+ServerScriptContext::GetNumberAllocatorAddr() const
+{
+    return m_contextData.numberAllocatorAddr;
+}
+
+intptr_t
+ServerScriptContext::GetRecyclerAddr() const
+{
+    return m_contextData.recyclerAddr;
+}
+
+bool
+ServerScriptContext::GetRecyclerAllowNativeCodeBumpAllocation() const
+{
+    return m_contextData.recyclerAllowNativeCodeBumpAllocation != 0;
+}
+
+bool
+ServerScriptContext::IsSIMDEnabled() const
+{
+    return m_contextData.isSIMDEnabled != 0;
+}
+
+intptr_t
+ServerScriptContext::GetBuiltinFunctionsBaseAddr() const
+{
+    return m_contextData.builtinFunctionsBaseAddr;
+}
+
+intptr_t
+ServerScriptContext::GetAddr() const
+{
+    return m_contextData.scriptContextAddr;
+}
+
+intptr_t
+ServerScriptContext::GetVTableAddress(VTableValue vtableType) const
+{
+    Assert(vtableType < VTableValue::Count);
+    return m_contextData.vtableAddresses[vtableType];
+}
+
+bool
+ServerScriptContext::IsRecyclerVerifyEnabled() const
+{
+    return m_contextData.isRecyclerVerifyEnabled != FALSE;
+}
+
+uint
+ServerScriptContext::GetRecyclerVerifyPad() const
+{
+    return m_contextData.recyclerVerifyPad;
+}

+ 50 - 0
lib/Backend/ServerScriptContext.h

@@ -0,0 +1,50 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+#pragma once
+
+class ServerScriptContext : public ScriptContextInfo
+{
+public:
+    ServerScriptContext(ScriptContextDataIDL * contextData);
+    virtual intptr_t GetNullAddr() const override;
+    virtual intptr_t GetUndefinedAddr() const override;
+    virtual intptr_t GetTrueAddr() const override;
+    virtual intptr_t GetFalseAddr() const override;
+    virtual intptr_t GetUndeclBlockVarAddr() const override;
+    virtual intptr_t GetEmptyStringAddr() const override;
+    virtual intptr_t GetNegativeZeroAddr() const override;
+    virtual intptr_t GetNumberTypeStaticAddr() const override;
+    virtual intptr_t GetStringTypeStaticAddr() const override;
+    virtual intptr_t GetObjectTypeAddr() const override;
+    virtual intptr_t GetObjectHeaderInlinedTypeAddr() const override;
+    virtual intptr_t GetRegexTypeAddr() const override;
+    virtual intptr_t GetArrayTypeAddr() const override;
+    virtual intptr_t GetNativeIntArrayTypeAddr() const override;
+    virtual intptr_t GetNativeFloatArrayTypeAddr() const override;
+    virtual intptr_t GetArrayConstructorAddr() const override;
+    virtual intptr_t GetCharStringCacheAddr() const override;
+    virtual intptr_t GetSideEffectsAddr() const override;
+    virtual intptr_t GetArraySetElementFastPathVtableAddr() const override;
+    virtual intptr_t GetIntArraySetElementFastPathVtableAddr() const override;
+    virtual intptr_t GetFloatArraySetElementFastPathVtableAddr() const override;
+    virtual intptr_t GetLibraryAddr() const override;
+    virtual intptr_t GetNumberAllocatorAddr() const override;
+    virtual intptr_t GetRecyclerAddr() const override;
+    virtual bool GetRecyclerAllowNativeCodeBumpAllocation() const override;
+    virtual bool IsSIMDEnabled() const override;
+    virtual intptr_t GetBuiltinFunctionsBaseAddr() const override;
+
+    virtual intptr_t GetAddr() const override;
+
+    virtual intptr_t GetVTableAddress(VTableValue vtableType) const override;
+
+    virtual bool IsRecyclerVerifyEnabled() const override;
+    virtual uint GetRecyclerVerifyPad() const override;
+
+private:
+    ScriptContextDataIDL m_contextData;
+
+};

+ 189 - 0
lib/Backend/ServerThreadContext.cpp

@@ -0,0 +1,189 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+#include "Backend.h"
+
+ServerThreadContext::ServerThreadContext(ThreadContextDataIDL * data) :
+    m_threadContextData(*data),
+    m_policyManager(true),
+    m_pageAlloc(&m_policyManager, Js::Configuration::Global.flags, PageAllocatorType_BGJIT,
+        AutoSystemInfo::Data.IsLowMemoryProcess() ?
+        PageAllocator::DefaultLowMaxFreePageCount :
+        PageAllocator::DefaultMaxFreePageCount),
+    m_preReservedVirtualAllocator(),
+    m_codePageAllocators(&m_policyManager, ALLOC_XDATA, &m_preReservedVirtualAllocator, (HANDLE)data->processHandle),
+    m_codeGenAlloc(&m_policyManager, nullptr, &m_codePageAllocators, (HANDLE)data->processHandle),
+    m_jitChakraBaseAddress((intptr_t)GetModuleHandle(L"Chakra.dll")), // TODO: OOP JIT, don't hardcode name
+    m_jitCRTBaseAddress((intptr_t)GetModuleHandle(UCrtC99MathApis::LibraryName))
+{
+    m_propertyMap = HeapNew(PropertyMap, &HeapAllocator::Instance, TotalNumberOfBuiltInProperties + 700);
+}
+
+ServerThreadContext::~ServerThreadContext()
+{
+    // TODO: OOP JIT, clear out elements of map. maybe should arena alloc?
+    if (this->m_propertyMap != nullptr)
+    {
+        HeapDelete(m_propertyMap);
+        this->m_propertyMap = nullptr;
+    }
+}
+
+intptr_t
+ServerThreadContext::GetBailOutRegisterSaveSpaceAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.bailOutRegisterSaveSpaceAddr);
+}
+
+intptr_t
+ServerThreadContext::GetDebuggingFlagsAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.debuggingFlagsAddr);
+}
+
+intptr_t
+ServerThreadContext::GetDebugStepTypeAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.debugStepTypeAddr);
+}
+
+intptr_t
+ServerThreadContext::GetDebugFrameAddressAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.debugFrameAddressAddr);
+}
+
+intptr_t
+ServerThreadContext::GetDebugScriptIdWhenSetAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.debugScriptIdWhenSetAddr);
+}
+
+ptrdiff_t
+ServerThreadContext::GetChakraBaseAddressDifference() const
+{
+    return GetRuntimeChakraBaseAddress() - m_jitChakraBaseAddress;
+}
+
+ptrdiff_t
+ServerThreadContext::GetCRTBaseAddressDifference() const
+{
+    return GetRuntimeCRTBaseAddress() - m_jitCRTBaseAddress;
+}
+
+intptr_t
+ServerThreadContext::GetDisableImplicitFlagsAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.disableImplicitFlagsAddr);
+}
+
+intptr_t
+ServerThreadContext::GetImplicitCallFlagsAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.implicitCallFlagsAddr);
+}
+
+intptr_t
+ServerThreadContext::GetSimdTempAreaAddr(uint8 tempIndex) const
+{
+    Assert(tempIndex < SIMD_TEMP_SIZE);
+    return m_threadContextData.simdTempAreaBaseAddr + tempIndex * sizeof(_x86_SIMDValue);
+}
+
+intptr_t
+ServerThreadContext::GetThreadStackLimitAddr() const
+{
+    return static_cast<intptr_t>(m_threadContextData.threadStackLimitAddr);
+}
+
+size_t
+ServerThreadContext::GetScriptStackLimit() const
+{
+    return static_cast<size_t>(m_threadContextData.scriptStackLimit);
+}
+
+bool
+ServerThreadContext::IsThreadBound() const
+{
+    return m_threadContextData.isThreadBound != FALSE;
+}
+
+HANDLE
+ServerThreadContext::GetProcessHandle() const
+{
+    return reinterpret_cast<HANDLE>(m_threadContextData.processHandle);
+}
+
+CustomHeap::CodePageAllocators *
+ServerThreadContext::GetCodePageAllocators()
+{
+    return &m_codePageAllocators;
+}
+
+CodeGenAllocators *
+ServerThreadContext::GetCodeGenAllocators()
+{
+    return &m_codeGenAlloc;
+}
+
+AllocationPolicyManager *
+ServerThreadContext::GetAllocationPolicyManager()
+{
+    return &m_policyManager;
+}
+
+intptr_t
+ServerThreadContext::GetRuntimeChakraBaseAddress() const
+{
+    return static_cast<intptr_t>(m_threadContextData.chakraBaseAddress);
+}
+
+intptr_t
+ServerThreadContext::GetRuntimeCRTBaseAddress() const
+{
+    return static_cast<intptr_t>(m_threadContextData.crtBaseAddress);
+}
+
+Js::PropertyRecord const *
+ServerThreadContext::GetPropertyRecord(Js::PropertyId propertyId)
+{
+    if (propertyId >= 0 && Js::IsInternalPropertyId(propertyId))
+    {
+        return Js::InternalPropertyRecords::GetInternalPropertyName(propertyId);
+    }
+
+    const Js::PropertyRecord * propertyRecord = nullptr;
+    m_propertyMap->LockResize();
+    bool found = m_propertyMap->TryGetValue(propertyId, &propertyRecord);
+    m_propertyMap->UnlockResize();
+
+    AssertMsg(found && propertyRecord != nullptr, "using invalid propertyid");
+    return propertyRecord;
+}
+
+void
+ServerThreadContext::AddToPropertyMap(const Js::PropertyRecord * origRecord)
+{
+
+    size_t allocLength = origRecord->byteCount + sizeof(char16) + (origRecord->isNumeric ? sizeof(uint32) : 0);
+    Js::PropertyRecord * record = HeapNewPlus(allocLength, Js::PropertyRecord, origRecord->byteCount, origRecord->isNumeric, origRecord->hash, origRecord->isSymbol);
+    record->isBound = origRecord->isBound;
+
+    char16* buffer = (char16 *)(record + 1);
+    js_memcpy_s(buffer, origRecord->byteCount, origRecord->GetBuffer(), origRecord->byteCount);
+
+    buffer[record->GetLength()] = _u('\0');
+
+    if (record->isNumeric)
+    {
+        *(uint32 *)(buffer + record->GetLength() + 1) = origRecord->GetNumericValue();
+        Assert(record->GetNumericValue() == origRecord->GetNumericValue());
+    }
+    record->pid = origRecord->pid;
+
+    m_propertyMap->Add(record);
+
+    PropertyRecordTrace(_u("Added JIT property '%s' at 0x%08x, pid = %d\n"), record->GetBuffer(), record, record->pid);
+}

+ 63 - 0
lib/Backend/ServerThreadContext.h

@@ -0,0 +1,63 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+#pragma once
+
+class ServerThreadContext : public ThreadContextInfo
+{
+public:
+    ServerThreadContext(ThreadContextDataIDL * data);
+    ~ServerThreadContext();
+
+    virtual HANDLE GetProcessHandle() const override;
+
+    virtual bool IsThreadBound() const override;
+
+    virtual size_t GetScriptStackLimit() const override;
+
+    virtual intptr_t GetThreadStackLimitAddr() const override;
+
+    virtual intptr_t GetSimdTempAreaAddr(uint8 tempIndex) const override;
+
+    virtual intptr_t GetDisableImplicitFlagsAddr() const override;
+    virtual intptr_t GetImplicitCallFlagsAddr() const override;
+    virtual intptr_t GetBailOutRegisterSaveSpaceAddr() const override;
+
+    virtual intptr_t GetDebuggingFlagsAddr() const override;
+    virtual intptr_t GetDebugStepTypeAddr() const override;
+    virtual intptr_t GetDebugFrameAddressAddr() const override;
+    virtual intptr_t GetDebugScriptIdWhenSetAddr() const override;
+
+    virtual ptrdiff_t GetChakraBaseAddressDifference() const override;
+    virtual ptrdiff_t GetCRTBaseAddressDifference() const override;
+
+    virtual Js::PropertyRecord const * GetPropertyRecord(Js::PropertyId propertyId) override;
+
+    CodeGenAllocators * GetCodeGenAllocators();
+    AllocationPolicyManager * GetAllocationPolicyManager();
+    CustomHeap::CodePageAllocators * GetCodePageAllocators();
+
+    void AddToPropertyMap(const Js::PropertyRecord * propertyRecord);
+private:
+    intptr_t GetRuntimeChakraBaseAddress() const;
+    intptr_t GetRuntimeCRTBaseAddress() const;
+
+    typedef JsUtil::BaseHashSet<const Js::PropertyRecord *, HeapAllocator, PrimeSizePolicy, const Js::PropertyRecord *,
+        DefaultComparer, JsUtil::SimpleHashedEntry, JsUtil::AsymetricResizeLock> PropertyMap;
+    PropertyMap * m_propertyMap;
+
+    Js::DelayLoadWinCoreProcessThreads m_delayLoadWinCoreProcessThreads;
+    PreReservedVirtualAllocWrapper m_preReservedVirtualAllocator;
+    CustomHeap::CodePageAllocators m_codePageAllocators;
+    PageAllocator m_pageAlloc;
+    AllocationPolicyManager m_policyManager;
+    CodeGenAllocators m_codeGenAlloc;
+
+    ThreadContextDataIDL m_threadContextData;
+
+    ThreadContext * m_threadContext;
+    intptr_t m_jitChakraBaseAddress;
+    intptr_t m_jitCRTBaseAddress;
+};

+ 45 - 0
lib/JITClient/JITManager.cpp

@@ -24,6 +24,7 @@ JITManager::JITManager() :
     m_rpcBindingHandle(nullptr),
     m_rpcServerProcessHandle(nullptr),
     m_jitProcessId(0),
+    m_oopJitEnabled(false),
     m_jitConnectionId()
 {
 }
@@ -48,6 +49,8 @@ JITManager::CreateBinding(
     __in UUID * connectionUuid,
     __out RPC_BINDING_HANDLE * bindingHandle)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     RPC_STATUS status;
     RPC_SECURITY_QOS_V4 securityQOS; // TODO: V5???
     DWORD attemptCount = 0;
@@ -152,12 +155,29 @@ JITManager::CreateBinding(
 bool
 JITManager::IsConnected() const
 {
+    Assert(JITManager::IsOOPJITEnabled());
     return m_rpcBindingHandle != nullptr && m_rpcServerProcessHandle != nullptr && m_targetHandle != nullptr;
 }
 
+void
+JITManager::EnableOOPJIT()
+{
+    m_oopJitEnabled = true;
+}
+
+bool
+JITManager::IsOOPJITEnabled() const
+{
+    return m_oopJitEnabled;
+}
+
 HANDLE
 JITManager::GetJITTargetHandle() const
 {
+    if (!IsOOPJITEnabled())
+    {
+        return GetCurrentProcess();
+    }
     Assert(m_targetHandle != nullptr);
     return m_targetHandle;
 }
@@ -165,6 +185,8 @@ JITManager::GetJITTargetHandle() const
 HRESULT
 JITManager::ConnectRpcServer(DWORD proccessId, UUID connectionUuid)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr;
     HANDLE localServerProcessHandle = nullptr;
     WCHAR* connectionUuidString = nullptr;
@@ -228,8 +250,11 @@ JITManager::DisconnectRpcServer()
         return hr;
     }
 
+    Assert(JITManager::IsOOPJITEnabled());
+
     CleanupProcess((intptr_t)m_targetHandle);
 
+    // TODO: OOP JIT, host should do this
     RpcTryExcept
     {
         ClientShutdown(m_rpcBindingHandle);
@@ -265,6 +290,8 @@ JITManager::InitializeThreadContext(
     __in ThreadContextDataIDL * data,
     __out intptr_t * threadContextInfoAddress)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -283,6 +310,8 @@ HRESULT
 JITManager::CleanupProcess(
     __in intptr_t processHandle)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -301,6 +330,8 @@ HRESULT
 JITManager::CleanupThreadContext(
     __in intptr_t threadContextInfoAddress)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -321,6 +352,8 @@ JITManager::AddDOMFastPathHelper(
     __in intptr_t funcInfoAddr,
     __in int helper)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -340,6 +373,8 @@ JITManager::AddPropertyRecord(
     __in intptr_t threadContextInfoAddress,
     __in PropertyRecordIDL * propertyRecord)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -359,6 +394,8 @@ JITManager::InitializeScriptContext(
     __in ScriptContextDataIDL * data,
     __out intptr_t * scriptContextInfoAddress)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -377,6 +414,8 @@ HRESULT
 JITManager::CleanupScriptContext(
     __in intptr_t scriptContextInfoAddress)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -396,6 +435,8 @@ JITManager::FreeAllocation(
     __in intptr_t threadContextInfoAddress,
     __in intptr_t address)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -416,6 +457,8 @@ JITManager::IsNativeAddr(
     __in intptr_t address,
     __out boolean * result)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
@@ -437,6 +480,8 @@ JITManager::RemoteCodeGenCall(
     __in intptr_t scriptContextInfoAddress,
     __out JITOutputIDL *jitData)
 {
+    Assert(JITManager::IsOOPJITEnabled());
+
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {

+ 3 - 0
lib/JITClient/JITManager.h

@@ -11,6 +11,8 @@ public:
     HRESULT ConnectRpcServer(__in DWORD processId, __in UUID connectionUuid);
 
     bool IsConnected() const;
+    bool IsOOPJITEnabled() const;
+    void EnableOOPJIT();
 
     ~JITManager();
 
@@ -72,6 +74,7 @@ private:
     HANDLE m_targetHandle;
     DWORD m_jitProcessId;
     UUID m_jitConnectionId;
+    bool m_oopJitEnabled;
 
     static JITManager s_jitManager;
 };

+ 1 - 1
lib/JITIDL/ChakraJIT.idl

@@ -201,7 +201,7 @@ typedef struct ThreadContextDataIDL
     __int3264 crtBaseAddress;
     __int3264 threadStackLimitAddr;
     __int3264 scriptStackLimit;
-    __int3264 bailOutRegisterSaveSpace;
+    __int3264 bailOutRegisterSaveSpaceAddr;
     __int3264 disableImplicitFlagsAddr;
     __int3264 implicitCallFlagsAddr;
     __int3264 debuggingFlagsAddr;

+ 18 - 17
lib/JITServer/JITServer.cpp

@@ -57,6 +57,7 @@ HRESULT JsInitializeRpcServer(
     {
         return status;
     }
+    JITManager::GetJITManager()->EnableOOPJIT();
 
     status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, FALSE);
 
@@ -88,9 +89,9 @@ ServerInitializeThreadContext(
     /* [in] */ __RPC__in ThreadContextDataIDL * threadContextData,
     /* [out] */ __RPC__out __int3264 *threadContextRoot)
 {
-    AUTO_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
+    AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
 
-    ThreadContextInfo * contextInfo = HeapNew(ThreadContextInfo, threadContextData);
+    ServerThreadContext * contextInfo = HeapNew(ServerThreadContext, threadContextData);
 
     *threadContextRoot = (intptr_t)contextInfo;
     return S_OK;
@@ -110,9 +111,9 @@ ServerCleanupThreadContext(
     /* [in] */ handle_t binding,
     /* [in] */ __int3264 threadContextRoot)
 {
-    AUTO_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
+    AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
 
-    ThreadContextInfo * threadContextInfo = reinterpret_cast<ThreadContextInfo*>(threadContextRoot);
+    ServerThreadContext * threadContextInfo = reinterpret_cast<ServerThreadContext*>(threadContextRoot);
 
     while (threadContextInfo->IsJITActive()) { Sleep(30); }
     HeapDelete(threadContextInfo);
@@ -126,9 +127,9 @@ ServerAddPropertyRecord(
     /* [in] */ __int3264 threadContextRoot,
     /* [in] */ PropertyRecordIDL * propertyRecord)
 {
-    AUTO_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
+    AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
 
-    ThreadContextInfo * threadContextInfo = reinterpret_cast<ThreadContextInfo*>(threadContextRoot);
+    ServerThreadContext * threadContextInfo = reinterpret_cast<ServerThreadContext*>(threadContextRoot);
     threadContextInfo->AddToPropertyMap((Js::PropertyRecord *)propertyRecord);
 
     return S_OK;
@@ -141,9 +142,9 @@ ServerAddDOMFastPathHelper(
     /* [in] */ __int3264 funcInfoAddr,
     /* [in] */ int helper)
 {
-    AUTO_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
+    AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
 
-    ScriptContextInfo * scriptContextInfo = reinterpret_cast<ScriptContextInfo*>(scriptContextRoot);
+    ServerScriptContext * scriptContextInfo = reinterpret_cast<ServerScriptContext*>(scriptContextRoot);
     scriptContextInfo->AddToDOMFastPathHelperMap(funcInfoAddr, (IR::JnHelperMethod)helper);
 
     return S_OK;
@@ -155,9 +156,9 @@ ServerInitializeScriptContext(
     /* [in] */ __RPC__in ScriptContextDataIDL * scriptContextData,
     /* [out] */ __RPC__out __int3264 * scriptContextInfoAddress)
 {
-    AUTO_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
+    AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
 
-    ScriptContextInfo * contextInfo = HeapNew(ScriptContextInfo, scriptContextData);
+    ServerScriptContext * contextInfo = HeapNew(ServerScriptContext, scriptContextData);
     *scriptContextInfoAddress = (intptr_t)contextInfo;
     return S_OK;
 }
@@ -167,7 +168,7 @@ ServerCleanupScriptContext(
     /* [in] */ handle_t binding,
     /* [in] */ __int3264 scriptContextRoot)
 {
-    ScriptContextInfo * scriptContextInfo = reinterpret_cast<ScriptContextInfo*>(scriptContextRoot);
+    ServerScriptContext * scriptContextInfo = reinterpret_cast<ServerScriptContext*>(scriptContextRoot);
     while (scriptContextInfo->IsJITActive()) { Sleep(30); }
     HeapDelete(scriptContextInfo);
     return S_OK;
@@ -179,8 +180,8 @@ ServerFreeAllocation(
     /* [in] */ __int3264 threadContextInfo,
     /* [in] */ __int3264 address)
 {
-    AUTO_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
-    ThreadContextInfo * context = reinterpret_cast<ThreadContextInfo*>(threadContextInfo);
+    AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
+    ServerThreadContext * context = reinterpret_cast<ServerThreadContext*>(threadContextInfo);
     bool succeeded = context->GetCodeGenAllocators()->emitBufferManager.FreeAllocation((void*)address);
     return succeeded ? S_OK : E_FAIL;
 }
@@ -192,7 +193,7 @@ ServerIsNativeAddr(
     /* [in] */ __int3264 address,
     /* [out] */ boolean * result)
 {
-    ThreadContextInfo * context = reinterpret_cast<ThreadContextInfo*>(threadContextInfo);
+    ServerThreadContext * context = reinterpret_cast<ServerThreadContext*>(threadContextInfo);
     // TODO: OOP JIT, prereserved segment
     CustomHeap::CodePageAllocators::AutoLock autoLock(context->GetCodePageAllocators());
     *result = context->GetCodePageAllocators()->IsInNonPreReservedPageAllocator((void*)address);
@@ -208,9 +209,9 @@ ServerRemoteCodeGen(
     /* [out] */ JITOutputIDL *jitData)
 {
     UNREFERENCED_PARAMETER(binding);
-    AUTO_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
+    AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
 
-    ThreadContextInfo * threadContextInfo = reinterpret_cast<ThreadContextInfo*>(threadContextInfoAddress);
+    ServerThreadContext * threadContextInfo = reinterpret_cast<ServerThreadContext*>(threadContextInfoAddress);
 
 
     PageAllocator backgroundPageAllocator(threadContextInfo->GetAllocationPolicyManager(), Js::Configuration::Global.flags, PageAllocatorType_BGJIT,
@@ -219,7 +220,7 @@ ServerRemoteCodeGen(
             PageAllocator::DefaultMaxFreePageCount));
 
     NoRecoverMemoryJitArenaAllocator jitArena(L"JITArena", &backgroundPageAllocator, Js::Throw::OutOfMemory);
-    ScriptContextInfo * scriptContextInfo = reinterpret_cast<ScriptContextInfo*>(scriptContextInfoAddress);
+    ServerScriptContext * scriptContextInfo = reinterpret_cast<ServerScriptContext*>(scriptContextInfoAddress);
 
     scriptContextInfo->BeginJIT(); // TODO: OOP JIT, improve how we do this
     threadContextInfo->BeginJIT();

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

@@ -69,6 +69,8 @@
     <ClCompile Include="$(MSBuildThisFileDirectory)RuntimeBasePch.cpp">
       <PrecompiledHeader>Create</PrecompiledHeader>
     </ClCompile>
+    <ClCompile Include="ScriptContextInfo.cpp" />
+    <ClCompile Include="ThreadContextInfo.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="CompactCounters.h" />
@@ -97,6 +99,7 @@
     <ClInclude Include="RegexPatternMruMap.h" />
     <ClInclude Include="ScriptContext.h" />
     <ClInclude Include="ScriptContextBase.h" />
+    <ClInclude Include="ScriptContextInfo.h" />
     <ClInclude Include="ScriptContextOptimizationOverrideInfo.h" />
     <ClInclude Include="ScriptContextProfiler.h" />
     <ClInclude Include="ScriptMemoryDumper.h" />
@@ -107,6 +110,7 @@
     <ClInclude Include="ThreadBoundThreadContextManager.h" />
     <ClInclude Include="ThreadConfigFlagsList.h" />
     <ClInclude Include="ThreadContext.h" />
+    <ClInclude Include="ThreadContextInfo.h" />
     <ClInclude Include="ThreadContextTlsEntry.h" />
     <ClInclude Include="ThreadServiceWrapper.h" />
     <ClInclude Include="ThreadServiceWrapperBase.h" />

+ 2 - 2
lib/Runtime/Base/Constants.cpp

@@ -26,9 +26,9 @@ const char16 Constants::StringReplace[] = _u("String.prototype.replace");
 const char16 Constants::StringMatch[] = _u("String.prototype.match");
 
 #ifdef _M_AMD64
-const PBYTE Constants::StackLimitForScriptInterrupt = (PBYTE)0x7fffffffffffffff;
+const size_t Constants::StackLimitForScriptInterrupt = 0x7fffffffffffffff;
 #else
-const PBYTE Constants::StackLimitForScriptInterrupt = (PBYTE)0x7fffffff;
+const size_t Constants::StackLimitForScriptInterrupt = 0x7fffffff;
 #endif
 
 #pragma warning(push)

+ 1 - 1
lib/Runtime/Base/Constants.h

@@ -113,7 +113,7 @@ namespace Js
         static const unsigned MaxProcessJITCodeHeapSize = 1024 * 1024 * 1024;
 #endif
 
-        static const PBYTE StackLimitForScriptInterrupt;
+        static const size_t StackLimitForScriptInterrupt;
 
 
         // Arguments object created on the fly is 1 slot before the frame

+ 2 - 2
lib/Runtime/Base/PropertyRecord.h

@@ -16,14 +16,14 @@
 #endif
 
 class ThreadContext;
-class ThreadContextInfo;
+class ServerThreadContext;
 
 namespace Js
 {
     class PropertyRecord : public FinalizableObject
     {
         friend class ::ThreadContext;
-        friend class ::ThreadContextInfo;
+        friend class ::ServerThreadContext;
         template <int LEN>
         friend struct BuiltInPropertyRecord;
         friend class InternalPropertyRecords;

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

@@ -380,6 +380,7 @@ namespace Js
 
         if (m_remoteScriptContextAddr != 0)
         {
+            Assert(JITManager::GetJITManager()->IsOOPJITEnabled());
             JITManager::GetJITManager()->CleanupScriptContext(m_remoteScriptContextAddr);
         }
 
@@ -4412,6 +4413,170 @@ void ScriptContext::RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertie
         }
     }
 
+    intptr_t ScriptContext::GetNullAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetNull();
+    }
+
+    intptr_t ScriptContext::GetUndefinedAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetUndefined();
+    }
+
+    intptr_t ScriptContext::GetTrueAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetTrue();
+    }
+
+    intptr_t ScriptContext::GetFalseAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetFalse();
+    }
+
+    intptr_t ScriptContext::GetUndeclBlockVarAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetUndeclBlockVar();
+    }
+
+    intptr_t ScriptContext::GetEmptyStringAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetEmptyString();
+    }
+
+    intptr_t ScriptContext::GetNegativeZeroAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetNegativeZero();
+    }
+
+    intptr_t ScriptContext::GetNumberTypeStaticAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetNumberTypeStatic();
+    }
+
+    intptr_t ScriptContext::GetStringTypeStaticAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetStringTypeStatic();
+    }
+
+    intptr_t ScriptContext::GetObjectTypeAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetObjectType();
+    }
+
+    intptr_t ScriptContext::GetObjectHeaderInlinedTypeAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetObjectHeaderInlinedType();
+    }
+
+    intptr_t ScriptContext::GetRegexTypeAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetRegexType();
+    }
+
+    intptr_t ScriptContext::GetArrayTypeAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetArrayType();
+    }
+
+    intptr_t ScriptContext::GetNativeIntArrayTypeAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetNativeIntArrayType();
+    }
+
+    intptr_t ScriptContext::GetNativeFloatArrayTypeAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetNativeFloatArrayType();
+    }
+
+    intptr_t ScriptContext::GetArrayConstructorAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetArrayConstructor();
+    }
+
+    intptr_t ScriptContext::GetCharStringCacheAddr() const
+    {
+        return (intptr_t)&GetLibrary()->GetCharStringCache();
+    }
+
+    intptr_t ScriptContext::GetSideEffectsAddr() const
+    {
+        return optimizationOverrides.GetAddressOfSideEffects();
+    }
+
+    intptr_t ScriptContext::GetArraySetElementFastPathVtableAddr() const
+    {
+        return optimizationOverrides.GetArraySetElementFastPathVtable();
+    }
+
+    intptr_t ScriptContext::GetIntArraySetElementFastPathVtableAddr() const
+    {
+        return optimizationOverrides.GetIntArraySetElementFastPathVtable();
+    }
+
+    intptr_t ScriptContext::GetFloatArraySetElementFastPathVtableAddr() const
+    {
+        return optimizationOverrides.GetFloatArraySetElementFastPathVtable();
+    }
+
+    intptr_t ScriptContext::GetBuiltinFunctionsBaseAddr() const
+    {
+        return (intptr_t)GetLibrary()->GetBuiltinFunctions();
+    }
+
+    intptr_t ScriptContext::GetLibraryAddr() const
+    {
+        return (intptr_t)GetLibrary();
+    }
+
+    intptr_t ScriptContext::GetNumberAllocatorAddr() const
+    {
+        return (intptr_t)&numberAllocator;
+    }
+
+    intptr_t ScriptContext::GetRecyclerAddr() const
+    {
+        return (intptr_t)GetRecycler();
+    }
+
+    bool ScriptContext::GetRecyclerAllowNativeCodeBumpAllocation() const
+    {
+        return GetRecycler()->AllowNativeCodeBumpAllocation();
+    }
+
+    bool ScriptContext::IsSIMDEnabled() const
+    {
+        return GetConfig()->IsSimdjsEnabled();
+    }
+
+    intptr_t ScriptContext::GetAddr() const
+    {
+        return (intptr_t)this;
+    }
+
+    intptr_t ScriptContext::GetVTableAddress(VTableValue vtableType) const
+    {
+        Assert(vtableType < VTableValue::Count);
+        return GetLibrary()->GetVTableAddresses()[vtableType];
+    }
+
+    bool ScriptContext::IsRecyclerVerifyEnabled() const
+    {
+#ifdef RECYCLER_MEMORY_VERIFY
+        return recycler->VerifyEnabled() != FALSE;
+#else
+        return false;
+#endif
+    }
+
+    uint ScriptContext::GetRecyclerVerifyPad() const
+    {
+#ifdef RECYCLER_MEMORY_VERIFY
+        return recycler->GetVerifyPad();
+#else
+        return 0;
+#endif
+    }
+
     JavascriptFunction* ScriptContext::GetBuiltInLibraryFunction(JavascriptMethod entryPoint)
     {
         JavascriptFunction * function = NULL;

+ 39 - 2
lib/Runtime/Base/ScriptContext.h

@@ -377,7 +377,7 @@ namespace Js
         BuiltInLibraryFunctionMap* builtInLibraryFunctions;
     };
 
-    class ScriptContext : public ScriptContextBase
+    class ScriptContext : public ScriptContextBase, public ScriptContextInfo
     {
         friend class LowererMD;
         friend class RemoteScriptContext;
@@ -442,6 +442,8 @@ namespace Js
 
         void InitializeRemoteScriptContext()
         {
+            Assert(JITManager::GetJITManager()->IsOOPJITEnabled());
+
             ScriptContextDataIDL contextData;
             contextData.nullAddr = (intptr_t)GetLibrary()->GetNull();
             contextData.undefinedAddr = (intptr_t)GetLibrary()->GetUndefined();
@@ -463,7 +465,7 @@ namespace Js
             contextData.charStringCacheAddr = (intptr_t)&GetLibrary()->GetCharStringCache();
             contextData.libraryAddr = (intptr_t)GetLibrary();
             contextData.builtinFunctionsBaseAddr = (intptr_t)GetLibrary()->GetBuiltinFunctions();
-            contextData.sideEffectsAddr = (intptr_t)optimizationOverrides.GetAddressOfSideEffects();
+            contextData.sideEffectsAddr = optimizationOverrides.GetAddressOfSideEffects();
             contextData.arraySetElementFastPathVtableAddr = (intptr_t)optimizationOverrides.GetAddressOfArraySetElementFastPathVtable();
             contextData.intArraySetElementFastPathVtableAddr = (intptr_t)optimizationOverrides.GetAddressOfIntArraySetElementFastPathVtable();
             contextData.floatArraySetElementFastPathVtableAddr = (intptr_t)optimizationOverrides.GetAddressOfFloatArraySetElementFastPathVtable();
@@ -1702,6 +1704,41 @@ private:
 #endif
 
     public:
+        virtual intptr_t GetNullAddr() const override;
+        virtual intptr_t GetUndefinedAddr() const override;
+        virtual intptr_t GetTrueAddr() const override;
+        virtual intptr_t GetFalseAddr() const override;
+        virtual intptr_t GetUndeclBlockVarAddr() const override;
+        virtual intptr_t GetEmptyStringAddr() const override;
+        virtual intptr_t GetNegativeZeroAddr() const override;
+        virtual intptr_t GetNumberTypeStaticAddr() const override;
+        virtual intptr_t GetStringTypeStaticAddr() const override;
+        virtual intptr_t GetObjectTypeAddr() const override;
+        virtual intptr_t GetObjectHeaderInlinedTypeAddr() const override;
+        virtual intptr_t GetRegexTypeAddr() const override;
+        virtual intptr_t GetArrayTypeAddr() const override;
+        virtual intptr_t GetNativeIntArrayTypeAddr() const override;
+        virtual intptr_t GetNativeFloatArrayTypeAddr() const override;
+        virtual intptr_t GetArrayConstructorAddr() const override;
+        virtual intptr_t GetCharStringCacheAddr() const override;
+        virtual intptr_t GetSideEffectsAddr() const override;
+        virtual intptr_t GetArraySetElementFastPathVtableAddr() const override;
+        virtual intptr_t GetIntArraySetElementFastPathVtableAddr() const override;
+        virtual intptr_t GetFloatArraySetElementFastPathVtableAddr() const override;
+        virtual intptr_t GetLibraryAddr() const override;
+        virtual intptr_t GetNumberAllocatorAddr() const override;
+        virtual intptr_t GetRecyclerAddr() const override;
+        virtual bool GetRecyclerAllowNativeCodeBumpAllocation() const override;
+        virtual bool IsSIMDEnabled() const override;
+        virtual intptr_t GetBuiltinFunctionsBaseAddr() const override;
+
+        virtual intptr_t GetAddr() const override;
+
+        virtual intptr_t GetVTableAddress(VTableValue vtableType) const override;
+
+        virtual bool IsRecyclerVerifyEnabled() const override;
+        virtual uint GetRecyclerVerifyPad() const override;
+
         void SetBuiltInLibraryFunction(JavascriptMethod entryPoint, JavascriptFunction* function);
         JavascriptFunction* GetBuiltInLibraryFunction(JavascriptMethod entryPoint);
 

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

@@ -0,0 +1,67 @@
+//-------------------------------------------------------------------------------------------------------
+// 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;
+}

+ 69 - 0
lib/Runtime/Base/ScriptContextInfo.h

@@ -0,0 +1,69 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+#pragma once
+
+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;
+    virtual intptr_t GetFalseAddr() const = 0;
+    virtual intptr_t GetUndeclBlockVarAddr() const = 0;
+    virtual intptr_t GetEmptyStringAddr() const = 0;
+    virtual intptr_t GetNegativeZeroAddr() const = 0;
+    virtual intptr_t GetNumberTypeStaticAddr() const = 0;
+    virtual intptr_t GetStringTypeStaticAddr() const = 0;
+    virtual intptr_t GetObjectTypeAddr() const = 0;
+    virtual intptr_t GetObjectHeaderInlinedTypeAddr() const = 0;
+    virtual intptr_t GetRegexTypeAddr() const = 0;
+    virtual intptr_t GetArrayTypeAddr() const = 0;
+    virtual intptr_t GetNativeIntArrayTypeAddr() const = 0;
+    virtual intptr_t GetNativeFloatArrayTypeAddr() const = 0;
+    virtual intptr_t GetArrayConstructorAddr() const = 0;
+    virtual intptr_t GetCharStringCacheAddr() const = 0;
+    virtual intptr_t GetSideEffectsAddr() const = 0;
+    virtual intptr_t GetArraySetElementFastPathVtableAddr() const = 0;
+    virtual intptr_t GetIntArraySetElementFastPathVtableAddr() const = 0;
+    virtual intptr_t GetFloatArraySetElementFastPathVtableAddr() const = 0;
+    virtual intptr_t GetLibraryAddr() const = 0;
+    virtual intptr_t GetNumberAllocatorAddr() const = 0;
+    virtual intptr_t GetRecyclerAddr() const = 0;
+    virtual bool GetRecyclerAllowNativeCodeBumpAllocation() const = 0;
+    virtual bool IsSIMDEnabled() const = 0;
+    virtual intptr_t GetBuiltinFunctionsBaseAddr() const = 0;
+
+    virtual intptr_t GetAddr() const = 0;
+
+    virtual intptr_t GetVTableAddress(VTableValue vtableType) const = 0;
+
+    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;
+
+    typedef JsUtil::BaseDictionary<intptr_t, IR::JnHelperMethod, HeapAllocator, PowerOf2SizePolicy,
+        DefaultComparer, JsUtil::SimpleDictionaryEntry, JsUtil::AsymetricResizeLock> JITDOMFastPathHelperMap;
+
+    JITDOMFastPathHelperMap * m_domFastPathHelperMap;
+};

+ 1 - 1
lib/Runtime/Base/ScriptContextOptimizationOverrideInfo.h

@@ -20,7 +20,7 @@ public:
 
     void SetSideEffects(SideEffects se);
     SideEffects GetSideEffects() { return sideEffects; }
-    SideEffects * GetAddressOfSideEffects() { return &sideEffects; }
+    intptr_t GetAddressOfSideEffects() const { return (intptr_t)&sideEffects; }
 
     bool IsEnabledArraySetElementFastPath() const;
     void DisableArraySetElementFastPath();

+ 6 - 6
lib/Runtime/Base/StackProber.cpp

@@ -41,26 +41,26 @@ StackProber::Initialize()
     const size_t guardPageSize = Js::Constants::NumGuardPages * AutoSystemInfo::PageSize;
     const size_t stackOverflowBuffer = Js::Constants::StackOverflowHandlingBufferPages * AutoSystemInfo::PageSize;
 
-    PBYTE stackBottom = 0;      // This is the low address limit (here we consider stack growing down).
+    size_t stackBottom = 0;      // This is the low address limit (here we consider stack growing down).
     ULONG stackGuarantee = 0;
 
 #if defined(_M_IX86) && defined(_MSC_VER)
-    stackBottom = (PBYTE)__readfsdword(0xE0C); // points to the DeAllocationStack on the TEB - which turns to be the stack bottom.
+    stackBottom = __readfsdword(0xE0C); // points to the DeAllocationStack on the TEB - which turns to be the stack bottom.
 #elif defined(_M_AMD64) && defined(_MSC_VER)
-    stackBottom = (PBYTE)__readgsqword(0x1478);
+    stackBottom = __readgsqword(0x1478);
 #elif defined(_M_ARM)
     ULONG lowLimit, highLimit;
     ::GetCurrentThreadStackLimits(&lowLimit, &highLimit);
-    stackBottom = (PBYTE)lowLimit;
+    stackBottom = lowLimit;
 #elif defined(_M_ARM64)
     ULONG64 lowLimit, highLimit;
     ::GetCurrentThreadStackLimits(&lowLimit, &highLimit);
-    stackBottom = (PBYTE) lowLimit;
+    stackBottom =  lowLimit;
 #elif !defined(_MSC_VER)
     ULONG_PTR lowLimit = 0;
     ULONG_PTR highLimit = 0;
     ::GetCurrentThreadStackLimits(&lowLimit, &highLimit);
-    stackBottom = (PBYTE)lowLimit;
+    stackBottom = lowLimit;
 #else
     stackBottom = NULL;
     Js::Throw::NotImplemented();

+ 4 - 4
lib/Runtime/Base/StackProber.h

@@ -8,9 +8,9 @@ class StackProber
 {
 public:
     void Initialize();
-    PBYTE GetScriptStackLimit() const { return stackLimit; }
+    size_t GetScriptStackLimit() const { return stackLimit; }
 #if DBG
-    void AdjustKnownStackLimit(PBYTE sp, size_t size)
+    void AdjustKnownStackLimit(size_t sp, size_t size)
     {
         if (knownStackLimit == 0) knownStackLimit = sp - size;
         knownStackLimit = ((sp - size) < knownStackLimit) ? (sp - size) : knownStackLimit;
@@ -18,8 +18,8 @@ public:
 #endif
 
 private:
-    PBYTE stackLimit;
+    size_t stackLimit;
 #if DBG
-    PBYTE knownStackLimit;
+    size_t knownStackLimit;
 #endif
 };

+ 2 - 2
lib/Runtime/Base/ThreadBoundThreadContextManager.cpp

@@ -64,7 +64,7 @@ void ThreadBoundThreadContextManager::DestroyContextAndEntryForCurrentThread()
     ThreadContext * threadContext = static_cast<ThreadContext *>(entry->GetThreadContext());
     entries.Remove(entry);
 
-    if (threadContext != NULL && threadContext->GetIsThreadBound())
+    if (threadContext != NULL && threadContext->IsThreadBound())
     {
         ShutdownThreadContext(threadContext);
     }
@@ -106,7 +106,7 @@ void ThreadBoundThreadContextManager::DestroyAllContexts()
 
             if (threadContext != NULL)
             {
-                if (threadContext->GetIsThreadBound())
+                if (threadContext->IsThreadBound())
                 {
                     ShutdownThreadContext(threadContext);
                     ThreadContextTLSEntry::ClearThreadContext(currentEntry, false);

+ 135 - 67
lib/Runtime/Base/ThreadContext.cpp

@@ -161,7 +161,6 @@ ThreadContext::ThreadContext(AllocationPolicyManager * allocationPolicyManager,
     hasCatchHandler(FALSE),
     disableImplicitFlags(DisableImplicitNoFlag),
     hasCatchHandlerToUserCode(false),
-    propertyMap(nullptr),
     caseInvariantPropertySet(nullptr),
     entryPointToBuiltInOperationIdCache(&threadAlloc, 0),
 #if ENABLE_NATIVE_CODEGEN
@@ -182,7 +181,6 @@ ThreadContext::ThreadContext(AllocationPolicyManager * allocationPolicyManager,
     isProfilingUserCode(true),
     loopDepth(0),
     maxGlobalFunctionExecTime(0.0),
-    isAllJITCodeInPreReservedRegion(true),
     tridentLoadAddress(nullptr),
     m_remoteThreadContextInfo(0),
     debugManager(nullptr)
@@ -195,6 +193,7 @@ ThreadContext::ThreadContext(AllocationPolicyManager * allocationPolicyManager,
     , TTSnapHistoryLength(UINT32_MAX)
     , TTDLog(nullptr)
     , TTDInitializeTTDUriFunction(nullptr)
+    , m_propertyMap(nullptr)
     , TTDWriteInitializeFunction(nullptr)
     , TTDStreamFunctions({ 0 })
 #endif
@@ -304,11 +303,77 @@ void ThreadContext::SetStackProber(StackProber * stackProber)
     }
 }
 
-PBYTE ThreadContext::GetScriptStackLimit() const
+size_t ThreadContext::GetScriptStackLimit() const
 {
     return stackProber->GetScriptStackLimit();
 }
 
+HANDLE
+ThreadContext::GetProcessHandle() const
+{
+    return GetCurrentProcess();
+}
+
+intptr_t
+ThreadContext::GetThreadStackLimitAddr() const
+{
+    return (intptr_t)GetAddressOfStackLimitForCurrentThread();
+}
+
+intptr_t
+ThreadContext::GetSimdTempAreaAddr(uint8 tempIndex) const
+{
+    return (intptr_t)&X86_TEMP_SIMD[tempIndex];
+}
+
+intptr_t 
+ThreadContext::GetDisableImplicitFlagsAddr() const
+{
+    return (intptr_t)&disableImplicitFlags;
+}
+
+intptr_t
+ThreadContext::GetImplicitCallFlagsAddr() const
+{
+    return (intptr_t)&implicitCallFlags;
+}
+
+intptr_t
+ThreadContext::GetDebuggingFlagsAddr() const
+{
+    return this->debugManager->GetDebuggingFlagsAddr();
+}
+
+intptr_t
+ThreadContext::GetDebugStepTypeAddr() const
+{
+    return (intptr_t)this->debugManager->stepController.GetAddressOfStepType();
+}
+
+intptr_t
+ThreadContext::GetDebugFrameAddressAddr() const
+{
+    return (intptr_t)this->debugManager->stepController.GetAddressOfFrameAddress();
+}
+
+intptr_t
+ThreadContext::GetDebugScriptIdWhenSetAddr() const
+{
+    return (intptr_t)this->debugManager->stepController.GetAddressOfScriptIdWhenSet();
+}
+
+ptrdiff_t
+ThreadContext::GetChakraBaseAddressDifference() const
+{
+    return 0;
+}
+
+ptrdiff_t
+ThreadContext::GetCRTBaseAddressDifference() const
+{
+    return 0;
+}
+
 IActiveScriptProfilerHeapEnum* ThreadContext::GetHeapEnum()
 {
     return heapEnum;
@@ -419,10 +484,10 @@ ThreadContext::~ThreadContext()
             this->recyclableData->returnedValueList = nullptr;
         }
 
-        if (this->propertyMap != nullptr)
+        if (this->m_propertyMap != nullptr)
         {
-            HeapDelete(this->propertyMap);
-            this->propertyMap = nullptr;
+            HeapDelete(this->m_propertyMap);
+            this->m_propertyMap = nullptr;
         }
 
         // Unpin the memory for leak report so we don't report this as a leak.
@@ -695,7 +760,7 @@ Recycler* ThreadContext::EnsureRecycler()
 
         this->recyclableData.Root(RecyclerNewZ(newRecycler, RecyclableData, newRecycler), newRecycler);
 
-        if (this->GetIsThreadBound())
+        if (this->IsThreadBound())
         {
             newRecycler->SetIsThreadBound();
         }
@@ -784,15 +849,15 @@ ThreadContext::GetPropertyNameImpl(Js::PropertyId propertyId)
 
     int propertyIndex = propertyId - Js::PropertyIds::_none;
 
-    if (propertyIndex < 0 || propertyIndex > propertyMap->GetLastIndex())
+    if (propertyIndex < 0 || propertyIndex > m_propertyMap->GetLastIndex())
     {
         propertyIndex = 0;
     }
 
     const Js::PropertyRecord * propertyRecord = nullptr;
-    if (locked) { propertyMap->LockResize(); }
-    bool found = propertyMap->TryGetValueAt(propertyIndex, &propertyRecord);
-    if (locked) { propertyMap->UnlockResize(); }
+    if (locked) { m_propertyMap->LockResize(); }
+    bool found = m_propertyMap->TryGetValueAt(propertyIndex, &propertyRecord);
+    if (locked) { m_propertyMap->UnlockResize(); }
 
     AssertMsg(found && propertyRecord != nullptr, "using invalid propertyid");
     return propertyRecord;
@@ -813,6 +878,12 @@ ThreadContext::FindPropertyRecord(__in LPCWSTR propertyName, __in int propertyNa
     LeavePinnedScope();
 }
 
+Js::PropertyRecord const *
+ThreadContext::GetPropertyRecord(Js::PropertyId propertyId)
+{
+    return GetPropertyNameLocked(propertyId);
+}
+
 const Js::PropertyRecord *
 ThreadContext::FindPropertyRecord(const char16 * propertyName, int propertyNameLength)
 {
@@ -821,11 +892,11 @@ ThreadContext::FindPropertyRecord(const char16 * propertyName, int propertyNameL
     if (IsDirectPropertyName(propertyName, propertyNameLength))
     {
         propertyRecord = propertyNamesDirect[propertyName[0]];
-        Assert(propertyRecord == propertyMap->LookupWithKey(Js::HashedCharacterBuffer<char16>(propertyName, propertyNameLength)));
+        Assert(propertyRecord == m_propertyMap->LookupWithKey(Js::HashedCharacterBuffer<char16>(propertyName, propertyNameLength)));
     }
     else
     {
-        propertyRecord = propertyMap->LookupWithKey(Js::HashedCharacterBuffer<char16>(propertyName, propertyNameLength));
+        propertyRecord = m_propertyMap->LookupWithKey(Js::HashedCharacterBuffer<char16>(propertyName, propertyNameLength));
     }
 
     return propertyRecord;
@@ -841,12 +912,12 @@ void ThreadContext::InitializePropertyMaps()
 {
     Assert(this->recycler != nullptr);
     Assert(this->recyclableData != nullptr);
-    Assert(this->propertyMap == nullptr);
+    Assert(this->m_propertyMap == nullptr);
     Assert(this->caseInvariantPropertySet == nullptr);
 
     try
     {
-        this->propertyMap = HeapNew(PropertyMap, &HeapAllocator::Instance, TotalNumberOfBuiltInProperties + 700);
+        this->m_propertyMap = HeapNew(PropertyMap, &HeapAllocator::Instance, TotalNumberOfBuiltInProperties + 700);
 
         this->recyclableData->boundPropertyStrings = RecyclerNew(this->recycler, JsUtil::List<Js::PropertyRecord const*>, this->recycler);
 
@@ -861,11 +932,11 @@ void ThreadContext::InitializePropertyMaps()
         // Initialization failed, undo what was done above. Callees that throw must clean up after themselves. The recycler will
         // be trashed, so clear members that point to recyclable memory. Stuff in 'recyclableData' will be taken care of by the
         // recycler, and the 'recyclableData' instance will be trashed as well.
-        if (this->propertyMap != nullptr)
+        if (this->m_propertyMap != nullptr)
         {
-            HeapDelete(this->propertyMap);
+            HeapDelete(this->m_propertyMap);
         }
-        this->propertyMap = nullptr;
+        this->m_propertyMap = nullptr;
 
         this->caseInvariantPropertySet = nullptr;
         memset(propertyNamesDirect, 0, 128*sizeof(Js::PropertyRecord *));
@@ -928,7 +999,7 @@ ThreadContext::UncheckedAddPropertyId(JsUtil::CharacterBuffer<WCHAR> const& prop
     }
 #endif
 
-    this->propertyMap->EnsureCapacity();
+    this->m_propertyMap->EnsureCapacity();
 
     // Automatically bind direct (single-character) property names, so that they can be
     // stored in the direct property table
@@ -1019,9 +1090,9 @@ ThreadContext::AddPropertyRecordInternal(const Js::PropertyRecord * propertyReco
 #endif
 
     // Add to the map
-    propertyMap->Add(propertyRecord);
+    m_propertyMap->Add(propertyRecord);
 
-    if (m_remoteThreadContextInfo)
+    if (JITManager::GetJITManager()->IsOOPJITEnabled())
     {
         JITManager::GetJITManager()->AddPropertyRecord(m_remoteThreadContextInfo, (PropertyRecordIDL*)propertyRecord);
     }
@@ -1166,7 +1237,7 @@ bool ThreadContext::IsActivePropertyId(Js::PropertyId pid)
     int propertyIndex = pid - Js::PropertyIds::_none;
 
     const Js::PropertyRecord * propertyRecord;
-    if (propertyMap->TryGetValueAt(propertyIndex, &propertyRecord) && propertyRecord != nullptr)
+    if (m_propertyMap->TryGetValueAt(propertyIndex, &propertyRecord) && propertyRecord != nullptr)
     {
         return true;
     }
@@ -1178,7 +1249,7 @@ void ThreadContext::InvalidatePropertyRecord(const Js::PropertyRecord * property
 {
     InternalInvalidateProtoTypePropertyCaches(propertyRecord->GetPropertyId());     // use the internal version so we don't check for active property id
 
-    this->propertyMap->Remove(propertyRecord);
+    this->m_propertyMap->Remove(propertyRecord);
 
     PropertyRecordTrace(_u("Reclaimed property '%s' at 0x%08x, pid = %d\n"),
         propertyRecord->GetBuffer(), propertyRecord, propertyRecord->GetPropertyId());
@@ -1186,12 +1257,12 @@ void ThreadContext::InvalidatePropertyRecord(const Js::PropertyRecord * property
 
 Js::PropertyId ThreadContext::GetNextPropertyId()
 {
-    return this->propertyMap->GetNextIndex() + Js::PropertyIds::_none;
+    return this->m_propertyMap->GetNextIndex() + Js::PropertyIds::_none;
 }
 
 Js::PropertyId ThreadContext::GetMaxPropertyId()
 {
-    auto maxPropertyId = this->propertyMap->Count() + Js::InternalPropertyIds::Count;
+    auto maxPropertyId = this->m_propertyMap->Count() + Js::InternalPropertyIds::Count;
     return maxPropertyId;
 }
 
@@ -1210,10 +1281,10 @@ void ThreadContext::CreateNoCasePropertyMap()
     // Thus, don't use BaseDictionary::Map here, as it cannot tolerate changes while mapping.
     // Instead, walk the PropertyRecord entries in index order.  This will work even if a GC occurs.
 
-    for (int propertyIndex = 0; propertyIndex <= this->propertyMap->GetLastIndex(); propertyIndex++)
+    for (int propertyIndex = 0; propertyIndex <= this->m_propertyMap->GetLastIndex(); propertyIndex++)
     {
         const Js::PropertyRecord * propertyRecord;
-        if (this->propertyMap->TryGetValueAt(propertyIndex, &propertyRecord) && propertyRecord != nullptr)
+        if (this->m_propertyMap->TryGetValueAt(propertyIndex, &propertyRecord) && propertyRecord != nullptr)
         {
             AddCaseInvariantPropertyRecord(propertyRecord);
         }
@@ -1512,18 +1583,18 @@ ThreadContext::IsOnStack(void const *ptr)
 #endif
 }
 
- PBYTE
+ size_t
  ThreadContext::GetStackLimitForCurrentThread() const
 {
     FAULTINJECT_SCRIPT_TERMINATION;
-    PBYTE limit = this->stackLimitForCurrentThread;
+    size_t limit = this->stackLimitForCurrentThread;
     Assert(limit == Js::Constants::StackLimitForScriptInterrupt
         || !this->GetStackProber()
         || limit == this->GetStackProber()->GetScriptStackLimit());
     return limit;
 }
 void
-ThreadContext::SetStackLimitForCurrentThread(PBYTE limit)
+ThreadContext::SetStackLimitForCurrentThread(size_t limit)
 {
     this->stackLimitForCurrentThread = limit;
 }
@@ -1532,9 +1603,9 @@ __declspec(noinline) //Win8 947081: might use wrong _AddressOfReturnAddress() if
 bool
 ThreadContext::IsStackAvailable(size_t size)
 {
-    PBYTE sp = (PBYTE)_AddressOfReturnAddress();
-    PBYTE stackLimit = this->GetStackLimitForCurrentThread();
-    bool stackAvailable = ((size_t)sp > size && (sp - size) > stackLimit);
+    size_t sp = (size_t)_AddressOfReturnAddress();
+    size_t stackLimit = this->GetStackLimitForCurrentThread();
+    bool stackAvailable = (sp > size && (sp - size) > stackLimit);
 
     // Verify that JIT'd frames didn't mess up the ABI stack alignment
     Assert(((uintptr_t)sp & (AutoSystemInfo::StackAlign - 1)) == (sizeof(void*) & (AutoSystemInfo::StackAlign - 1)));
@@ -1568,9 +1639,9 @@ __declspec(noinline) //Win8 947081: might use wrong _AddressOfReturnAddress() if
 bool
 ThreadContext::IsStackAvailableNoThrow(size_t size)
 {
-    PBYTE sp = (PBYTE)_AddressOfReturnAddress();
-    PBYTE stackLimit = this->GetStackLimitForCurrentThread();
-    bool stackAvailable = (sp > stackLimit) && ((size_t)sp > size) && ((sp - size) > stackLimit);
+    size_t sp = (size_t)_AddressOfReturnAddress();
+    size_t stackLimit = this->GetStackLimitForCurrentThread();
+    bool stackAvailable = (sp > stackLimit) && (sp > size) && ((sp - size) > stackLimit);
 
     FAULTINJECT_STACK_PROBE
 
@@ -1846,6 +1917,7 @@ ThreadContext::IsInAsyncHostOperation() const
 void
 ThreadContext::SetJITConnectionInfo(DWORD processId, UUID connectionId)
 {
+    Assert(JITManager::GetJITManager()->IsOOPJITEnabled());
     if (m_remoteThreadContextInfo)
     {
         return;
@@ -1865,16 +1937,15 @@ ThreadContext::SetJITConnectionInfo(DWORD processId, UUID connectionId)
     contextData.chakraBaseAddress = (intptr_t)GetModuleHandle(L"Chakra.dll");
     contextData.crtBaseAddress = (intptr_t)GetModuleHandle(UCrtC99MathApis::LibraryName);
     contextData.threadStackLimitAddr = reinterpret_cast<intptr_t>(GetAddressOfStackLimitForCurrentThread());
-    contextData.bailOutRegisterSaveSpace = (intptr_t)bailOutRegisterSaveSpace;
+    contextData.bailOutRegisterSaveSpaceAddr = (intptr_t)bailOutRegisterSaveSpace;
     contextData.disableImplicitFlagsAddr = (intptr_t)GetAddressOfDisableImplicitFlags();
     contextData.implicitCallFlagsAddr = (intptr_t)GetAddressOfImplicitCallFlags();
-    contextData.stringReplaceNameAddr = (intptr_t)Js::Constants::StringReplace;
     contextData.debuggingFlagsAddr = (intptr_t)this->debugManager->GetDebuggingFlags();
     contextData.debugStepTypeAddr = (intptr_t)this->debugManager->stepController.GetAddressOfStepType();
     contextData.debugFrameAddressAddr = (intptr_t)this->debugManager->stepController.GetAddressOfFrameAddress();
     contextData.debugScriptIdWhenSetAddr = (intptr_t)this->debugManager->stepController.GetAddressOfScriptIdWhenSet();
-    contextData.scriptStackLimit = reinterpret_cast<size_t>(GetScriptStackLimit());
-    contextData.isThreadBound = GetIsThreadBound();
+    contextData.scriptStackLimit = GetScriptStackLimit();
+    contextData.isThreadBound = IsThreadBound();
 
 #if _M_IX86 || _M_AMD64
     contextData.simdTempAreaBaseAddr = (intptr_t)GetSimdTempArea();
@@ -1883,9 +1954,9 @@ ThreadContext::SetJITConnectionInfo(DWORD processId, UUID connectionId)
     JITManager::GetJITManager()->InitializeThreadContext(&contextData, &m_remoteThreadContextInfo);
 
     // we may have populated propertyMap prior to initializing JIT connection
-    if (propertyMap != nullptr)
+    if (m_propertyMap != nullptr)
     {
-        propertyMap->Map([=](const Js::PropertyRecord * record)
+        m_propertyMap->Map([=](const Js::PropertyRecord * record)
         {
             JITManager::GetJITManager()->AddPropertyRecord(m_remoteThreadContextInfo, (PropertyRecordIDL*)record);
         });
@@ -3639,28 +3710,31 @@ void DumpRecyclerObjectGraph()
 BOOL ThreadContext::IsNativeAddress(void * pCodeAddr)
 {
     boolean result;
-    HRESULT hr = JITManager::GetJITManager()->IsNativeAddr(this->m_remoteThreadContextInfo, (intptr_t)pCodeAddr, &result);
-    if (FAILED(hr))
+    if (JITManager::GetJITManager()->IsOOPJITEnabled())
     {
-        // TODO: OOP JIT, what to do in failure case?
-        Js::Throw::FatalInternalError();
+        HRESULT hr = JITManager::GetJITManager()->IsNativeAddr(this->m_remoteThreadContextInfo, (intptr_t)pCodeAddr, &result);
+        if (FAILED(hr))
+        {
+            // TODO: OOP JIT, what to do in failure case?
+            Js::Throw::FatalInternalError();
+        }
+        return result;
     }
-    return result;
-
-#if 0 // TODO: OOP JIT, non-oop jit
-    PreReservedVirtualAllocWrapper *preReservedVirtualAllocWrapper = this->GetPreReservedVirtualAllocator();
-    if (preReservedVirtualAllocWrapper->IsInRange(pCodeAddr))
+    else
     {
-        return TRUE;
-    }
+        PreReservedVirtualAllocWrapper *preReservedVirtualAllocWrapper = this->GetPreReservedVirtualAllocator();
+        if (preReservedVirtualAllocWrapper->IsInRange(pCodeAddr))
+        {
+            return TRUE;
+        }
 
-    if (!this->IsAllJITCodeInPreReservedRegion())
-    {
-        CustomHeap::CodePageAllocators::AutoLock autoLock(&this->codePageAllocators);
-        return this->codePageAllocators.IsInNonPreReservedPageAllocator(pCodeAddr);
+        if (!this->IsAllJITCodeInPreReservedRegion())
+        {
+            CustomHeap::CodePageAllocators::AutoLock autoLock(&this->codePageAllocators);
+            return this->codePageAllocators.IsInNonPreReservedPageAllocator(pCodeAddr);
+        }
+        return FALSE;
     }
-    return FALSE;
-#endif
 }
 #endif
 
@@ -3873,7 +3947,7 @@ uint ThreadContext::GetRandomNumber()
 #ifdef ENABLE_JS_ETW
 void ThreadContext::EtwLogPropertyIdList()
 {
-    propertyMap->Map([&](const Js::PropertyRecord* propertyRecord){
+    m_propertyMap->Map([&](const Js::PropertyRecord* propertyRecord){
         EventWriteJSCRIPT_HOSTING_PROPERTYID_LIST(propertyRecord, propertyRecord->GetBuffer());
     });
 }
@@ -4098,12 +4172,6 @@ Js::DelayLoadWinCoreMemory * ThreadContext::GetWinCoreMemoryLibrary()
 }
 #endif
 
-Js::DelayLoadWinCoreProcessThreads * ThreadContext::GetWinCoreProcessThreads()
-{
-    delayLoadWinCoreProcessThreads.EnsureFromSystemDirOnly();
-    return &delayLoadWinCoreProcessThreads;
-}
-
 Js::DelayLoadWinRtString * ThreadContext::GetWinRTStringLibrary()
 {
     delayLoadWinRtString.EnsureFromSystemDirOnly();
@@ -4241,7 +4309,7 @@ void ThreadContext::SetValidCallTargetForCFG(PVOID callTargetAddress, bool isSet
 
 uint ThreadContext::GetHighestPropertyNameIndex() const
 {
-    return propertyMap->GetLastIndex() + 1 + Js::InternalPropertyIds::Count;
+    return m_propertyMap->GetLastIndex() + 1 + Js::InternalPropertyIds::Count;
 }
 
 #if defined(CHECK_MEMORY_LEAK) || defined(LEAK_REPORT)

+ 34 - 15
lib/Runtime/Base/ThreadContext.h

@@ -370,7 +370,8 @@ private:
 
 class ThreadContext sealed :
     public DefaultRecyclerCollectionWrapper,
-    public JsUtil::DoublyLinkedListElement<ThreadContext>
+    public JsUtil::DoublyLinkedListElement<ThreadContext>,
+    public ThreadContextInfo
 {
 public:
     static void GlobalInitialize();
@@ -400,9 +401,8 @@ public:
         this->isThreadBound = true;
     }
     bool IsJSRT() const { return !this->isThreadBound; }
-    bool GetIsThreadBound() const { return this->isThreadBound; }
+    virtual bool IsThreadBound() const override { return this->isThreadBound; }
     void SetStackProber(StackProber * stackProber);
-    PBYTE GetScriptStackLimit() const;
     static DWORD GetStackLimitForCurrentThreadOffset() { return offsetof(ThreadContext, stackLimitForCurrentThread); }
 
     template <class Fn>
@@ -423,7 +423,7 @@ public:
         return curImplicitCallFlags;
     }
 
-    void * GetAddressOfStackLimitForCurrentThread()
+    void * GetAddressOfStackLimitForCurrentThread() const
     {
         FAULTINJECT_SCRIPT_TERMINATION
 
@@ -438,6 +438,8 @@ public:
     void SetHeapEnum(IActiveScriptProfilerHeapEnum* newHeapEnum);
     void ClearHeapEnum();
 
+    virtual Js::PropertyRecord const * GetPropertyRecord(Js::PropertyId propertyId) override;
+
 #ifdef ENABLE_BASIC_TELEMETRY
     Js::LanguageStats* GetLanguageStats()
     {
@@ -488,8 +490,8 @@ private:
     static CriticalSection s_csThreadContext;
 
     StackProber * GetStackProber() const { return this->stackProber; }
-    PBYTE GetStackLimitForCurrentThread() const;
-    void SetStackLimitForCurrentThread(PBYTE limit);
+    size_t GetStackLimitForCurrentThread() const;
+    void SetStackLimitForCurrentThread(size_t limit);
 
     // The current heap enumeration object being used during enumeration.
     IActiveScriptProfilerHeapEnum* heapEnum;
@@ -519,6 +521,7 @@ private:
 public:
     typedef JsUtil::BaseHashSet<const Js::PropertyRecord *, HeapAllocator, PrimeSizePolicy, const Js::PropertyRecord *,
         Js::PropertyRecordStringHashComparer, JsUtil::SimpleHashedEntry, JsUtil::AsymetricResizeLock> PropertyMap;
+    PropertyMap * m_propertyMap;
 
     typedef JsUtil::BaseHashSet<Js::CaseInvariantPropertyListWithHashCode*, Recycler, PowerOf2SizePolicy, Js::CaseInvariantPropertyListWithHashCode*, JsUtil::NoCaseComparer, JsUtil::SimpleDictionaryEntry>
         PropertyNoCaseSetType;
@@ -628,12 +631,11 @@ private:
 
     ThreadContextFlags threadContextFlags;
     DWORD currentThreadId;
-    mutable PBYTE stackLimitForCurrentThread;
+    mutable size_t stackLimitForCurrentThread;
     StackProber * stackProber;
     bool isThreadBound;
     bool hasThrownPendingException;
     bool callDispose;
-    bool isAllJITCodeInPreReservedRegion;
 
     AllocationPolicyManager * allocationPolicyManager;
 
@@ -662,7 +664,6 @@ private:
 
     static const Js::PropertyRecord * const builtInPropertyRecords[];
 
-    PropertyMap * propertyMap;
     PropertyNoCaseSetType * caseInvariantPropertySet;
 
     Js::ScriptContext * rootPendingClose;
@@ -775,7 +776,6 @@ private:
 #ifdef _CONTROL_FLOW_GUARD
     Js::DelayLoadWinCoreMemory delayLoadWinCoreMemoryLibrary;
 #endif
-    Js::DelayLoadWinCoreProcessThreads delayLoadWinCoreProcessThreads;
 #endif
 
     // Number of script context attached with probe manager.
@@ -848,9 +848,6 @@ public:
     CustomHeap::CodePageAllocators * GetCodePageAllocators() { return &codePageAllocators; }
 #endif // ENABLE_NATIVE_CODEGEN
 
-    void ResetIsAllJITCodeInPreReservedRegion() { isAllJITCodeInPreReservedRegion = false; }
-    bool IsAllJITCodeInPreReservedRegion() { return isAllJITCodeInPreReservedRegion; }
-
     CriticalSection* GetEtwRundownCriticalSection() { return &csEtwRundown; }
 
     UCrtC99MathApis* GetUCrtC99MathApis() { return &ucrtC99MathApis; }
@@ -875,7 +872,6 @@ public:
 #ifdef _CONTROL_FLOW_GUARD
     Js::DelayLoadWinCoreMemory * GetWinCoreMemoryLibrary();
 #endif
-    Js::DelayLoadWinCoreProcessThreads * GetWinCoreProcessThreads();
 #endif
 
 #ifdef ENABLE_BASIC_TELEMETRY
@@ -1060,7 +1056,10 @@ public:
 
     void ShutdownThreads()
     {
-        JITManager::GetJITManager()->CleanupThreadContext(m_remoteThreadContextInfo);
+        if (JITManager::GetJITManager()->IsOOPJITEnabled())
+        {
+            JITManager::GetJITManager()->CleanupThreadContext(m_remoteThreadContextInfo);
+        }
 #if ENABLE_NATIVE_CODEGEN
         if (jobProcessor)
         {
@@ -1209,6 +1208,7 @@ public:
     BOOL IsNativeAddress(void * pCodeAddr);
     JsUtil::JobProcessor *GetJobProcessor();
     Js::Var * GetBailOutRegisterSaveSpace() const { return bailOutRegisterSaveSpace; }
+    virtual intptr_t GetBailOutRegisterSaveSpaceAddr() const override { return (intptr_t)bailOutRegisterSaveSpace; }
     CodeGenNumberThreadAllocator * GetCodeGenNumberThreadAllocator() const
     {
         return codeGenNumberThreadAllocator;
@@ -1272,6 +1272,25 @@ public:
     void RegisterConstructorCache(Js::PropertyId propertyId, Js::ConstructorCache* cache);
 #endif
 
+    virtual size_t GetScriptStackLimit() const override;
+
+    virtual HANDLE GetProcessHandle() const override;
+
+    virtual intptr_t GetThreadStackLimitAddr() const override;
+
+    virtual intptr_t GetSimdTempAreaAddr(uint8 tempIndex) const override;
+
+    virtual intptr_t GetDisableImplicitFlagsAddr() const override;
+    virtual intptr_t GetImplicitCallFlagsAddr() const override;
+
+    virtual intptr_t GetDebuggingFlagsAddr() const override;
+    virtual intptr_t GetDebugStepTypeAddr() const override;
+    virtual intptr_t GetDebugFrameAddressAddr() const override;
+    virtual intptr_t GetDebugScriptIdWhenSetAddr() const override;
+
+    virtual ptrdiff_t GetChakraBaseAddressDifference() const override;
+    virtual ptrdiff_t GetCRTBaseAddressDifference() const override;
+
 private:
     void RegisterInlineCache(InlineCacheListMapByPropertyId& inlineCacheMap, Js::InlineCache* inlineCache, Js::PropertyId propertyId);
     static bool IsInlineCacheRegistered(InlineCacheListMapByPropertyId& inlineCacheMap, const Js::InlineCache* inlineCache, Js::PropertyId propertyId);

+ 15 - 188
lib/Backend/ThreadContextInfo.cpp → lib/Runtime/Base/ThreadContextInfo.cpp

@@ -2,31 +2,13 @@
 // Copyright (C) Microsoft. All rights reserved.
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
-#include "Backend.h"
-
-ThreadContextInfo::ThreadContextInfo(ThreadContextDataIDL * data) :
-    m_threadContextData(*data),
-    m_policyManager(true),
-    m_pageAlloc(&m_policyManager, Js::Configuration::Global.flags, PageAllocatorType_BGJIT,
-        AutoSystemInfo::Data.IsLowMemoryProcess() ?
-            PageAllocator::DefaultLowMaxFreePageCount :
-            PageAllocator::DefaultMaxFreePageCount),
-    m_preReservedVirtualAllocator(),
-    m_codePageAllocators(&m_policyManager, ALLOC_XDATA, &m_preReservedVirtualAllocator, (HANDLE)data->processHandle),
-    m_codeGenAlloc(&m_policyManager, nullptr, &m_codePageAllocators, (HANDLE)data->processHandle),
+
+#include "RuntimeBasePch.h"
+
+ThreadContextInfo::ThreadContextInfo() :
     m_isAllJITCodeInPreReservedRegion(true),
-    m_jitChakraBaseAddress((intptr_t)GetModuleHandle(L"Chakra.dll")), // TODO: OOP JIT, don't hardcode name
-    m_jitCRTBaseAddress((intptr_t)GetModuleHandle(UCrtC99MathApis::LibraryName)),
-    m_delayLoadWinCoreProcessThreads(),
     m_activeJITCount(0)
 {
-    m_propertyMap = HeapNew(JITPropertyMap, &HeapAllocator::Instance, TotalNumberOfBuiltInProperties + 700);
-}
-
-ThreadContextInfo::~ThreadContextInfo()
-{
-    // TODO: OOP JIT, clear out elements of map. maybe should arena alloc?
-    HeapDelete(m_propertyMap);
 }
 
 intptr_t
@@ -288,70 +270,15 @@ ThreadContextInfo::GetX86FourLanesMaskAddr(uint8 minorityLane) const
 }
 
 intptr_t
-ThreadContextInfo::GetSimdTempAreaAddr(uint8 tempIndex) const
-{
-    Assert(tempIndex < SIMD_TEMP_SIZE);
-    return m_threadContextData.simdTempAreaBaseAddr + tempIndex * sizeof(_x86_SIMDValue);
-}
-
-intptr_t
-ThreadContextInfo::GetThreadStackLimitAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.threadStackLimitAddr);
-}
-
-intptr_t
-ThreadContextInfo::GetDisableImplicitFlagsAddr() const
+ThreadContextInfo::GetStringReplaceNameAddr() const
 {
-    return static_cast<intptr_t>(m_threadContextData.disableImplicitFlagsAddr);
+    return SHIFT_ADDR(this, Js::Constants::StringReplace);
 }
 
 intptr_t
-ThreadContextInfo::GetImplicitCallFlagsAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.implicitCallFlagsAddr);
-}
-
-size_t
-ThreadContextInfo::GetScriptStackLimit() const
-{
-    return static_cast<size_t>(m_threadContextData.scriptStackLimit);
-}
-
-bool
-ThreadContextInfo::IsThreadBound() const
-{
-    return m_threadContextData.isThreadBound != FALSE;
-}
-
-PageAllocator *
-ThreadContextInfo::GetPageAllocator()
-{
-    return &m_pageAlloc;
-}
-
-CustomHeap::CodePageAllocators * 
-ThreadContextInfo::GetCodePageAllocators()
-{
-    return &m_codePageAllocators;
-}
-
-CodeGenAllocators *
-ThreadContextInfo::GetCodeGenAllocators()
-{
-    return &m_codeGenAlloc;
-}
-
-AllocationPolicyManager *
-ThreadContextInfo::GetAllocationPolicyManager()
-{
-    return &m_policyManager;
-}
-
-HANDLE
-ThreadContextInfo::GetProcessHandle() const
+ThreadContextInfo::GetStringMatchNameAddr() const
 {
-    return reinterpret_cast<HANDLE>(m_threadContextData.processHandle);
+    return SHIFT_ADDR(this, Js::Constants::StringMatch);
 }
 
 bool
@@ -366,71 +293,13 @@ ThreadContextInfo::ResetIsAllJITCodeInPreReservedRegion()
     m_isAllJITCodeInPreReservedRegion = false;
 }
 
-intptr_t
-ThreadContextInfo::GetRuntimeChakraBaseAddress() const
-{
-    return static_cast<intptr_t>(m_threadContextData.chakraBaseAddress);
-}
-
-intptr_t
-ThreadContextInfo::GetRuntimeCRTBaseAddress() const
-{
-    return static_cast<intptr_t>(m_threadContextData.crtBaseAddress);
-}
+#ifdef ENABLE_GLOBALIZATION
 
-intptr_t
-ThreadContextInfo::GetBailOutRegisterSaveSpace() const
+Js::DelayLoadWinCoreProcessThreads *
+ThreadContextInfo::GetWinCoreProcessThreads()
 {
-    return static_cast<intptr_t>(m_threadContextData.bailOutRegisterSaveSpace);
-}
-
-intptr_t
-ThreadContextInfo::GetStringReplaceNameAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.stringReplaceNameAddr);
-}
-
-intptr_t
-ThreadContextInfo::GetStringMatchNameAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.stringMatchNameAddr);
-}
-
-
-intptr_t
-ThreadContextInfo::GetDebuggingFlagsAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.debuggingFlagsAddr);
-}
-
-intptr_t
-ThreadContextInfo::GetDebugStepTypeAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.debugStepTypeAddr);
-}
-
-intptr_t
-ThreadContextInfo::GetDebugFrameAddressAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.debugFrameAddressAddr);
-}
-
-intptr_t
-ThreadContextInfo::GetDebugScriptIdWhenSetAddr() const
-{
-    return static_cast<intptr_t>(m_threadContextData.debugScriptIdWhenSetAddr);
-}
-
-ptrdiff_t
-ThreadContextInfo::GetChakraBaseAddressDifference() const
-{
-    return GetRuntimeChakraBaseAddress() - m_jitChakraBaseAddress;
-}
-
-ptrdiff_t
-ThreadContextInfo::GetCRTBaseAddressDifference() const
-{
-    return GetRuntimeCRTBaseAddress() - m_jitCRTBaseAddress;
+    m_delayLoadWinCoreProcessThreads.EnsureFromSystemDirOnly();
+    return &m_delayLoadWinCoreProcessThreads;
 }
 
 bool
@@ -448,8 +317,9 @@ ThreadContextInfo::IsCFGEnabled()
     return CfgPolicy.EnableControlFlowGuard && AutoSystemInfo::Data.IsCFGEnabled();
 #else
     return false;
-#endif
+#endif // _CONTROL_FLOW_GUARD
 }
+#endif // ENABLE_GLOBALIZATION
 
 void
 ThreadContextInfo::BeginJIT()
@@ -463,49 +333,6 @@ ThreadContextInfo::EndJIT()
     InterlockedExchangeSubtract(&m_activeJITCount, 1);
 }
 
-void
-ThreadContextInfo::AddToPropertyMap(const Js::PropertyRecord * origRecord)
-{
-
-    size_t allocLength = origRecord->byteCount + sizeof(char16) + (origRecord->isNumeric ? sizeof(uint32) : 0);
-    Js::PropertyRecord * record = HeapNewPlus(allocLength, Js::PropertyRecord, origRecord->byteCount, origRecord->isNumeric, origRecord->hash, origRecord->isSymbol);
-    record->isBound = origRecord->isBound;
-
-    char16* buffer = (char16 *)(record + 1);
-    js_memcpy_s(buffer, origRecord->byteCount, origRecord->GetBuffer(), origRecord->byteCount);
-
-    buffer[record->GetLength()] = _u('\0');
-
-    if (record->isNumeric)
-    {
-        *(uint32 *)(buffer + record->GetLength() + 1) = origRecord->GetNumericValue();
-        Assert(record->GetNumericValue() == origRecord->GetNumericValue());
-    }
-    record->pid = origRecord->pid;
-
-    m_propertyMap->Add(record);
-
-    PropertyRecordTrace(_u("Added JIT property '%s' at 0x%08x, pid = %d\n"), record->GetBuffer(), record, record->pid);
-}
-
-Js::PropertyRecord const *
-ThreadContextInfo::GetPropertyRecord(Js::PropertyId propertyId)
-{
-    if (propertyId >= 0 && Js::IsInternalPropertyId(propertyId))
-    {
-        return Js::InternalPropertyRecords::GetInternalPropertyName(propertyId);
-    }
-
-    const Js::PropertyRecord * propertyRecord = nullptr;
-    m_propertyMap->LockResize();
-    bool found = m_propertyMap->TryGetValue(propertyId, &propertyRecord);
-    m_propertyMap->UnlockResize();
-
-    AssertMsg(found && propertyRecord != nullptr, "using invalid propertyid");
-    return propertyRecord;
-}
-
-
 bool
 ThreadContextInfo::IsJITActive()
 {

+ 33 - 45
lib/Backend/ThreadContextInfo.h → lib/Runtime/Base/ThreadContextInfo.h

@@ -9,11 +9,10 @@
 class ThreadContextInfo
 {
 public:
-    ThreadContextInfo(ThreadContextDataIDL * data);
-    ~ThreadContextInfo();
+    ThreadContextInfo();
+
     intptr_t GetNullFrameDisplayAddr() const;
     intptr_t GetStrictNullFrameDisplayAddr() const;
-    intptr_t GetThreadStackLimitAddr() const;
 
     intptr_t GetAbsDoubleCstAddr() const;
     intptr_t GetAbsFloatCstAddr() const;
@@ -40,17 +39,6 @@ public:
     intptr_t GetMantissaMaskAddr() const;
     intptr_t GetExponentMaskAddr() const;
 
-    intptr_t GetDisableImplicitFlagsAddr() const;
-    intptr_t GetImplicitCallFlagsAddr() const;
-    intptr_t GetBailOutRegisterSaveSpace() const;
-    intptr_t GetStringReplaceNameAddr() const;
-    intptr_t GetStringMatchNameAddr() const;
-
-    intptr_t GetDebuggingFlagsAddr() const;
-    intptr_t GetDebugStepTypeAddr() const;
-    intptr_t GetDebugFrameAddressAddr() const;
-    intptr_t GetDebugScriptIdWhenSetAddr() const;
-
     intptr_t GetX86AbsMaskF4Addr() const;
     intptr_t GetX86AbsMaskD2Addr() const;
     intptr_t GetX86NegMaskF4Addr() const;
@@ -69,51 +57,51 @@ public:
     intptr_t GetX86TwoPower31I4Addr() const;
     intptr_t GetX86NegTwoPower31F4Addr() const;
     intptr_t GetX86FourLanesMaskAddr(uint8 minorityLane) const;
-    intptr_t GetSimdTempAreaAddr(uint8 tempIndex) const;
-
-    size_t GetScriptStackLimit() const;
 
-    bool IsThreadBound() const;
-
-    PageAllocator * GetPageAllocator();
-    CodeGenAllocators * GetCodeGenAllocators();
-    AllocationPolicyManager * GetAllocationPolicyManager();
-    CustomHeap::CodePageAllocators * GetCodePageAllocators();
-    HANDLE GetProcessHandle() const;
+    intptr_t GetStringReplaceNameAddr() const;
+    intptr_t GetStringMatchNameAddr() const;
 
     void ResetIsAllJITCodeInPreReservedRegion();
     bool IsAllJITCodeInPreReservedRegion() const;
 
-    ptrdiff_t GetChakraBaseAddressDifference() const;
-    ptrdiff_t GetCRTBaseAddressDifference() const;
+    virtual HANDLE GetProcessHandle() const = 0;
+
+    virtual bool IsThreadBound() const = 0;
+
+    virtual size_t GetScriptStackLimit() const = 0;
 
-    Js::PropertyRecord const * GetPropertyRecord(Js::PropertyId propertyId);
+    virtual intptr_t GetThreadStackLimitAddr() const = 0;
+
+    virtual intptr_t GetSimdTempAreaAddr(uint8 tempIndex) const = 0;
+
+    virtual intptr_t GetDisableImplicitFlagsAddr() const = 0;
+    virtual intptr_t GetImplicitCallFlagsAddr() const = 0;
+    virtual intptr_t GetBailOutRegisterSaveSpaceAddr() const = 0;
+
+    virtual intptr_t GetDebuggingFlagsAddr() const = 0;
+    virtual intptr_t GetDebugStepTypeAddr() const = 0;
+    virtual intptr_t GetDebugFrameAddressAddr() const = 0;
+    virtual intptr_t GetDebugScriptIdWhenSetAddr() const = 0;
+
+    virtual ptrdiff_t GetChakraBaseAddressDifference() const = 0;
+    virtual ptrdiff_t GetCRTBaseAddressDifference() const = 0;
+
+    virtual Js::PropertyRecord const * GetPropertyRecord(Js::PropertyId propertyId) = 0;
 
     bool IsCFGEnabled();
-    void AddToPropertyMap(const Js::PropertyRecord * propertyRecord);
     void BeginJIT();
     void EndJIT();
     bool IsJITActive();
 
-private:
-    intptr_t GetRuntimeChakraBaseAddress() const;
-    intptr_t GetRuntimeCRTBaseAddress() const;
-    uint m_activeJITCount;
+#ifdef ENABLE_GLOBALIZATION
+    Js::DelayLoadWinCoreProcessThreads * GetWinCoreProcessThreads();
 
     Js::DelayLoadWinCoreProcessThreads m_delayLoadWinCoreProcessThreads;
-    PreReservedVirtualAllocWrapper m_preReservedVirtualAllocator;
-    CustomHeap::CodePageAllocators m_codePageAllocators;
-    PageAllocator m_pageAlloc;
-    AllocationPolicyManager m_policyManager;
-    CodeGenAllocators m_codeGenAlloc;
-
-    ThreadContextDataIDL m_threadContextData;
-
-    typedef JsUtil::BaseHashSet<const Js::PropertyRecord *, HeapAllocator, PrimeSizePolicy, const Js::PropertyRecord *,
-        DefaultComparer, JsUtil::SimpleHashedEntry, JsUtil::AsymetricResizeLock> JITPropertyMap;
-    JITPropertyMap * m_propertyMap;
-    intptr_t m_jitChakraBaseAddress;
-    intptr_t m_jitCRTBaseAddress;
+#endif
+
+private:
+
+    uint m_activeJITCount;
     bool m_isAllJITCodeInPreReservedRegion;
 };
 

+ 4 - 4
lib/Runtime/Base/ThreadContextTlsEntry.cpp

@@ -56,7 +56,7 @@ bool ThreadContextTLSEntry::TrySetThreadContext(ThreadContext * threadContext)
     if (threadContextThreadId != ThreadContext::NoThread && threadContextThreadId != ::GetCurrentThreadId())
     {
         // the thread doesn't support rental thread and try to set on a different thread???
-        Assert(!threadContext->GetIsThreadBound());
+        Assert(!threadContext->IsThreadBound());
         return false;
     }
 
@@ -64,7 +64,7 @@ bool ThreadContextTLSEntry::TrySetThreadContext(ThreadContext * threadContext)
 
     if (entry == NULL)
     {
-        Assert(!threadContext->GetIsThreadBound());
+        Assert(!threadContext->IsThreadBound());
         entry = CreateEntryForCurrentThread();
     }
     else if (entry->threadContext != NULL && entry->threadContext != threadContext)
@@ -72,7 +72,7 @@ bool ThreadContextTLSEntry::TrySetThreadContext(ThreadContext * threadContext)
         // If the thread has an active thread context and either that thread context is thread
         // bound (in which case it cannot be moved off this thread), or if the thread context
         // is running script, you cannot move it off this thread.
-        if (entry->threadContext->GetIsThreadBound() || entry->threadContext->IsInScript())
+        if (entry->threadContext->IsThreadBound() || entry->threadContext->IsInScript())
         {
             return false;
         }
@@ -108,7 +108,7 @@ bool ThreadContextTLSEntry::ClearThreadContext(ThreadContextTLSEntry * entry, bo
             // If the thread has an active thread context and either that thread context is thread
             // bound (in which case it cannot be moved off this thread), or if the thread context
             // is running script, you cannot move it off this thread.
-            if (!force && (entry->threadContext->GetIsThreadBound() || entry->threadContext->IsInScript()))
+            if (!force && (entry->threadContext->IsThreadBound() || entry->threadContext->IsInScript()))
             {
                 return false;
             }

+ 1 - 1
lib/Runtime/Base/ThreadContextTlsEntry.h

@@ -40,7 +40,7 @@ class ThreadContextScope
 public:
     ThreadContextScope(ThreadContext * threadContext)
     {
-        if (!threadContext->GetIsThreadBound())
+        if (!threadContext->IsThreadBound())
         {
             originalContext = ThreadContextTLSEntry::GetEntryForCurrentThread() ?
                 ThreadContextTLSEntry::GetEntryForCurrentThread()->GetThreadContext() : NULL;

+ 5 - 0
lib/Runtime/Debug/DebugManager.cpp

@@ -56,6 +56,11 @@ namespace Js
         return &this->debuggingFlags;
     }
 
+    intptr_t DebugManager::GetDebuggingFlagsAddr() const
+    {
+        return (intptr_t)&this->debuggingFlags;
+    }
+
     ReferencedArenaAdapter* DebugManager::GetDiagnosticArena()
     {
         if (pCurrentInterpreterLocation)

+ 1 - 0
lib/Runtime/Debug/DebugManager.h

@@ -46,6 +46,7 @@ namespace Js
         void Close();
 
         DebuggingFlags* GetDebuggingFlags();
+        intptr_t GetDebuggingFlagsAddr() const;
 
         bool IsAtDispatchHalt() const { return this->isAtDispatchHalt; }
         void SetDispatchHalt(bool set) { this->isAtDispatchHalt = set; }

+ 1 - 1
lib/Runtime/Language/amd64/StackFrame.cpp

@@ -43,7 +43,7 @@ bool Js::Amd64StackFrame::InitializeByReturnAddress(void *returnAddress, ScriptC
 
     this->stackCheckCodeHeight =
         scriptContext->GetThreadContext()->DoInterruptProbe() ? stackCheckCodeHeightWithInterruptProbe
-        : scriptContext->GetThreadContext()->GetIsThreadBound() ? stackCheckCodeHeightThreadBound
+        : scriptContext->GetThreadContext()->IsThreadBound() ? stackCheckCodeHeightThreadBound
         : stackCheckCodeHeightNotThreadBound;
 
     // this is the context for the current function

+ 2 - 2
lib/Runtime/Language/i386/StackFrame.cpp

@@ -17,7 +17,7 @@ X86StackFrame::InitializeByFrameId(void * frame, ScriptContext* scriptContext)
 
     this->stackCheckCodeHeight =
         scriptContext->GetThreadContext()->DoInterruptProbe() ? stackCheckCodeHeightWithInterruptProbe
-        : scriptContext->GetThreadContext()->GetIsThreadBound() ? stackCheckCodeHeightThreadBound
+        : scriptContext->GetThreadContext()->IsThreadBound() ? stackCheckCodeHeightThreadBound
         : stackCheckCodeHeightNotThreadBound;
 
     return Next();
@@ -35,7 +35,7 @@ X86StackFrame::InitializeByReturnAddress(void * returnAddress, ScriptContext* sc
 
     this->stackCheckCodeHeight =
         scriptContext->GetThreadContext()->DoInterruptProbe() ? stackCheckCodeHeightWithInterruptProbe
-        : scriptContext->GetThreadContext()->GetIsThreadBound() ? stackCheckCodeHeightThreadBound
+        : scriptContext->GetThreadContext()->IsThreadBound() ? stackCheckCodeHeightThreadBound
         : stackCheckCodeHeightNotThreadBound;
 
     while (Next())

+ 2 - 0
lib/Runtime/Runtime.h

@@ -470,6 +470,7 @@ enum tagDEBUG_EVENT_INFO_TYPE
 #define CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(builtin)
 #define CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(feature, m_scriptContext)
 #endif
+#include "Base/ThreadContextInfo.h"
 #include "Base/ThreadContext.h"
 
 #include "Base/StackProber.h"
@@ -480,6 +481,7 @@ enum tagDEBUG_EVENT_INFO_TYPE
 
 #include "Base/ScriptContextOptimizationOverrideInfo.h"
 #include "Base/ScriptContextBase.h"
+#include "Base/ScriptContextInfo.h"
 #include "Base/ScriptContext.h"
 #include "Base/LeaveScriptObject.h"
 #include "Base/PropertyRecord.h"