Skip to content

Commit 9311f40

Browse files
committed
add JsEnableOOPJIT API
1 parent 8ca6279 commit 9311f40

File tree

7 files changed

+69
-8
lines changed

7 files changed

+69
-8
lines changed

lib/Jsrt/ChakraCoreWindows.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,24 @@
1313
#include <rpc.h>
1414

1515
/// <summary>
16-
/// Enables out-of-process JIT by connecting to a Chakra JIT process that was initialized by calling JsInitializeJITServer
16+
/// Globally enables out-of-process JIT.
1717
/// </summary>
1818
/// <remarks>
1919
/// Should be called before JS code is executed.
20+
/// Code in all runtimes will run in interpreter until JsConnectJITProcess is called.
21+
/// </remarks>
22+
/// <returns>
23+
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
24+
/// </returns>
25+
CHAKRA_API
26+
JsEnableOOPJIT();
27+
28+
/// <summary>
29+
/// Globally enables out-of-process JIT and connects to a Chakra JIT process that was initialized
30+
/// by calling JsInitializeJITServer
31+
/// </summary>
32+
/// <remarks>
33+
/// Out-of-process JIT should be enabled before JS code is executed.
2034
/// </remarks>
2135
/// <param name="processHandle">Handle to the JIT process</param>
2236
/// <param name="serverSecurityDescriptor">Optional pointer to an RPC SECURITY_DESCRIPTOR structure</param>

lib/Jsrt/Core/JsrtCore.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,16 +1509,30 @@ JsDiscardBackgroundParse_Experimental(
15091509
}
15101510

15111511
#ifdef _WIN32
1512+
CHAKRA_API
1513+
JsEnableOOPJIT()
1514+
{
1515+
#ifdef ENABLE_OOP_NATIVE_CODEGEN
1516+
JITManager::GetJITManager()->EnableOOPJIT();
1517+
return JsNoError;
1518+
#else
1519+
return JsErrorNotImplemented;
1520+
#endif
1521+
}
1522+
15121523
CHAKRA_API
15131524
JsConnectJITProcess(_In_ HANDLE processHandle, _In_opt_ void* serverSecurityDescriptor, _In_ UUID connectionId)
15141525
{
15151526
#ifdef ENABLE_OOP_NATIVE_CODEGEN
15161527
JITManager::GetJITManager()->EnableOOPJIT();
15171528
ThreadContext::SetJITConnectionInfo(processHandle, serverSecurityDescriptor, connectionId);
1518-
#endif
15191529
return JsNoError;
1530+
#else
1531+
return JsErrorNotImplemented;
1532+
#endif
15201533
}
15211534
#endif
1535+
15221536
CHAKRA_API
15231537
JsGetArrayBufferFreeFunction(
15241538
_In_ JsValueRef arrayBuffer,

lib/Runtime/Base/ScriptContext.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5412,11 +5412,36 @@ ScriptContext::GetJitFuncRangeCache()
54125412
allowPrereserveAlloc = false;
54135413
#endif
54145414
// The EnsureJITThreadContext() call could fail if the JIT Server process has died. In such cases, we should not try to do anything further in the client process.
5415-
if (this->GetThreadContext()->EnsureJITThreadContext(allowPrereserveAlloc))
5415+
if (!this->GetThreadContext()->EnsureJITThreadContext(allowPrereserveAlloc))
54165416
{
5417-
HRESULT hr = JITManager::GetJITManager()->InitializeScriptContext(&contextData, this->GetThreadContext()->GetRemoteThreadContextAddr(), &m_remoteScriptContextAddr);
5417+
return;
5418+
}
5419+
5420+
HRESULT hr = JITManager::GetJITManager()->InitializeScriptContext(&contextData, this->GetThreadContext()->GetRemoteThreadContextAddr(), &m_remoteScriptContextAddr);
5421+
JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
5422+
5423+
if (!m_remoteScriptContextAddr)
5424+
{
5425+
return;
5426+
}
5427+
5428+
// Initialize mutable ScriptContext state if needed
5429+
if (this->IsPRNGSeeded())
5430+
{
5431+
hr = JITManager::GetJITManager()->SetIsPRNGSeeded(m_remoteScriptContextAddr, TRUE);
54185432
JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
54195433
}
5434+
5435+
if (this->GetLibrary()->GetModuleRecordList())
5436+
{
5437+
this->GetLibrary()->GetModuleRecordList()->Map([this](int start, SourceTextModuleRecord* moduleRecord) {
5438+
HRESULT hr = JITManager::GetJITManager()->AddModuleRecordInfo(
5439+
m_remoteScriptContextAddr,
5440+
moduleRecord->GetModuleId(),
5441+
(intptr_t)moduleRecord->GetLocalExportSlots());
5442+
JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
5443+
});
5444+
}
54205445
}
54215446
#endif
54225447

lib/Runtime/Base/ThreadContext.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,13 @@ ThreadContext::EnsureJITThreadContext(bool allowPrereserveAlloc)
20052005
&m_jitThunkStartAddr);
20062006
JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
20072007

2008+
// Initialize mutable ThreadContext state if needed
2009+
Js::TypeId wellKnownType = this->wellKnownHostTypeIds[WellKnownHostType_HTMLAllCollection];
2010+
if (m_remoteThreadContextInfo && wellKnownType != Js::TypeIds_Undefined)
2011+
{
2012+
hr = JITManager::GetJITManager()->SetWellKnownHostTypeId(m_remoteThreadContextInfo, wellKnownType);
2013+
JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
2014+
}
20082015
return m_remoteThreadContextInfo != nullptr;
20092016
#endif
20102017
}

lib/Runtime/Language/SourceTextModuleRecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ namespace Js
12041204
#if ENABLE_NATIVE_CODEGEN
12051205
if (JITManager::GetJITManager()->IsOOPJITEnabled() && JITManager::GetJITManager()->IsConnected())
12061206
{
1207-
PSCRIPTCONTEXT_HANDLE remoteScriptContext = this->scriptContext->GetRemoteScriptAddr();
1207+
PSCRIPTCONTEXT_HANDLE remoteScriptContext = this->scriptContext->GetRemoteScriptAddr(false);
12081208
if (remoteScriptContext)
12091209
{
12101210
HRESULT hr = JITManager::GetJITManager()->AddModuleRecordInfo(

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7045,12 +7045,12 @@ namespace Js
70457045
#if ENABLE_NATIVE_CODEGEN
70467046
if (JITManager::GetJITManager()->IsOOPJITEnabled() && JITManager::GetJITManager()->IsConnected())
70477047
{
7048-
PSCRIPTCONTEXT_HANDLE remoteScriptContext = this->scriptContext->GetRemoteScriptAddr();
7048+
PSCRIPTCONTEXT_HANDLE remoteScriptContext = this->scriptContext->GetRemoteScriptAddr(false);
70497049
if (remoteScriptContext)
70507050
{
70517051
HRESULT hr = JITManager::GetJITManager()->SetIsPRNGSeeded(remoteScriptContext, val);
7052-
JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
7053-
}
7052+
JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
7053+
}
70547054
}
70557055
#endif
70567056
}

lib/Runtime/Library/JavascriptLibrary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ namespace Js
11981198
void SetFakeGlobalFuncForUndefer(FunctionBody* functionBody) { this->fakeGlobalFuncForUndefer = functionBody; }
11991199

12001200
ModuleRecordList* EnsureModuleRecordList();
1201+
ModuleRecordList* GetModuleRecordList() const { return this->moduleRecordList; }
12011202
SourceTextModuleRecord* GetModuleRecord(uint moduleId);
12021203

12031204
private:

0 commit comments

Comments
 (0)