Skip to content

Commit 00eeadc

Browse files
committed
only use OOP CFG registration in release build
1 parent fb06fad commit 00eeadc

File tree

8 files changed

+44
-13
lines changed

8 files changed

+44
-13
lines changed

bin/ch/ChakraRtInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ class ChakraRTInterface
244244
#ifdef DEBUG
245245
static HRESULT SetCheckOpHelpersFlag(bool flag) { return CHECKED_CALL(SetCheckOpHelpersFlag, flag); }
246246
#endif
247+
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
248+
static HRESULT SetOOPCFGRegistrationFlag(bool flag) { return CHECKED_CALL(SetOOPCFGRegistrationFlag, flag); }
249+
#endif
247250

248251
static HRESULT GetCrashOnExceptionFlag(bool * flag)
249252
{

bin/ch/JITProcessManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ HRESULT JITProcessManager::CreateServerProcess(int argc, __in_ecount(argc) LPWST
6767
RPC_WSTR connectionUuidString = NULL;
6868

6969
#pragma warning(suppress: 6386) // buffer overrun
70+
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
71+
hr = StringCchCopyW(cmdLine, cmdLineSize, L"ch.exe -OOPCFGRegistration- -CheckOpHelpers -jitserver:");
72+
#else
7073
hr = StringCchCopyW(cmdLine, cmdLineSize, L"ch.exe -jitserver:");
74+
#endif
7175
if (FAILED(hr))
7276
{
7377
return hr;

bin/ch/ch.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ HRESULT ExecuteTest(const char* fileName)
537537
#ifdef DEBUG
538538
ChakraRTInterface::SetCheckOpHelpersFlag(true);
539539
#endif
540+
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
541+
ChakraRTInterface::SetOOPCFGRegistrationFlag(false);
542+
#endif
540543

541544
if (!WScriptJsrt::Initialize())
542545
{

lib/Backend/Encoder.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Encoder::Encode()
3333
m_offsetBuffer = AnewArray(m_tempAlloc, uint, instrCount);
3434
#endif
3535

36-
m_pragmaInstrToRecordMap = Anew(m_tempAlloc, PragmaInstrList, m_tempAlloc);
36+
m_pragmaInstrToRecordMap = Anew(m_tempAlloc, PragmaInstrList, m_tempAlloc);
3737
if (DoTrackAllStatementBoundary())
3838
{
3939
// Create a new list, if we are tracking all statement boundaries.
@@ -48,7 +48,7 @@ Encoder::Encode()
4848

4949
#if defined(_M_IX86) || defined(_M_X64)
5050
// for BR shortening
51-
m_inlineeFrameRecords = Anew(m_tempAlloc, InlineeFrameRecords, m_tempAlloc);
51+
m_inlineeFrameRecords = Anew(m_tempAlloc, InlineeFrameRecords, m_tempAlloc);
5252
#endif
5353

5454
m_pc = m_encodeBuffer;
@@ -72,7 +72,7 @@ Encoder::Encode()
7272
Fatal();
7373
}
7474

75-
uint bufferCRC = initialCRCSeed;
75+
uint bufferCRC = initialCRCSeed;
7676

7777
FOREACH_INSTR_IN_FUNC(instr, m_func)
7878
{
@@ -89,7 +89,7 @@ Encoder::Encode()
8989
#endif
9090
if (instr->IsPragmaInstr())
9191
{
92-
switch(instr->m_opcode)
92+
switch (instr->m_opcode)
9393
{
9494
#ifdef _M_X64
9595
case Js::OpCode::PrologStart:
@@ -143,9 +143,9 @@ Encoder::Encode()
143143
multiBranchInstr->MapMultiBrTargetByAddress([=](void ** offset) -> void
144144
{
145145
#if defined(_M_ARM32_OR_ARM64)
146-
encoderMD->AddLabelReloc((byte*) offset);
146+
encoderMD->AddLabelReloc((byte*)offset);
147147
#else
148-
encoderMD->AppendRelocEntry(RelocTypeLabelUse, (void*) (offset), *(IR::LabelInstr**)(offset));
148+
encoderMD->AppendRelocEntry(RelocTypeLabelUse, (void*)(offset), *(IR::LabelInstr**)(offset));
149149
*((size_t*)offset) = 0;
150150
#endif
151151
});
@@ -223,7 +223,7 @@ Encoder::Encode()
223223
#if defined(_M_IX86) || defined(_M_X64)
224224
// for BR shortening.
225225
if (instr->isInlineeEntryInstr)
226-
m_encoderMD.AppendRelocEntry(RelocType::RelocTypeInlineeEntryOffset, (void*) (m_pc - MachPtr));
226+
m_encoderMD.AppendRelocEntry(RelocType::RelocTypeInlineeEntryOffset, (void*)(m_pc - MachPtr));
227227
#endif
228228
if (isCallInstr)
229229
{
@@ -240,7 +240,7 @@ Encoder::Encode()
240240
Fatal();
241241
}
242242
} NEXT_INSTR_IN_FUNC;
243-
243+
244244
ptrdiff_t codeSize = m_pc - m_encodeBuffer + totalJmpTableSizeInBytes;
245245

246246
BOOL isSuccessBrShortAndLoopAlign = false;
@@ -371,7 +371,10 @@ Encoder::Encode()
371371
m_func->GetJITOutput()->SetCodeAddress(m_func->GetJITOutput()->GetCodeAddress() | 0x1); // Set thumb mode
372372
#endif
373373

374-
m_func->GetThreadContextInfo()->SetValidCallTargetForCFG((PVOID)m_func->GetJITOutput()->GetCodeAddress());
374+
if (CONFIG_FLAG(OOPCFGRegistration))
375+
{
376+
m_func->GetThreadContextInfo()->SetValidCallTargetForCFG((PVOID)m_func->GetJITOutput()->GetCodeAddress());
377+
}
375378

376379
const bool isSimpleJit = m_func->IsSimpleJit();
377380

lib/Backend/InterpreterThunkEmitter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,14 @@ void InterpreterThunkEmitter::NewOOPJITThunkBlock()
369369
);
370370
JITManager::HandleServerCallResult(hr);
371371

372+
372373
this->thunkBuffer = (BYTE*)thunkInfo.thunkBlockAddr;
373374

375+
if (!CONFIG_FLAG(OOPCFGRegistration))
376+
{
377+
this->scriptContext->GetThreadContext()->SetValidCallTargetForCFG(this->thunkBuffer);
378+
}
379+
374380
// Update object state only at the end when everything has succeeded - and no exceptions can be thrown.
375381
auto block = this->thunkBlocks.PrependNode(allocator, this->thunkBuffer);
376382
#if PDATA_ENABLED

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,11 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
10821082
}
10831083
#endif
10841084

1085+
if (!CONFIG_FLAG(OOPCFGRegistration))
1086+
{
1087+
scriptContext->GetThreadContext()->SetValidCallTargetForCFG((PVOID)jitWriteData.codeAddress);
1088+
}
1089+
10851090
workItem->SetCodeAddress((size_t)jitWriteData.codeAddress);
10861091

10871092
workItem->GetEntryPoint()->SetCodeGenRecorded((Js::JavascriptMethod)jitWriteData.codeAddress, jitWriteData.codeSize);
@@ -3180,7 +3185,7 @@ NativeCodeGenerator::QueueFreeNativeCodeGenAllocation(void* address)
31803185
return;
31813186
}
31823187

3183-
if (!JITManager::GetJITManager()->IsOOPJITEnabled())
3188+
if (!JITManager::GetJITManager()->IsOOPJITEnabled() || !CONFIG_FLAG(OOPCFGRegistration))
31843189
{
31853190
//DeRegister Entry Point for CFG
31863191
ThreadContext::GetContextForCurrentThread()->SetValidCallTargetForCFG(address, false);

lib/Common/ConfigFlagsList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ PHASE(All)
651651
#define DEFAULT_CONFIG_DumpHeap (false)
652652
#define DEFAULT_CONFIG_PerfHintLevel (1)
653653
#define DEFAULT_CONFIG_OOPJITMissingOpts (true)
654+
#define DEFAULT_CONFIG_OOPCFGRegistration (true)
654655

655656
#define DEFAULT_CONFIG_FailFastIfDisconnectedDelegate (false)
656657

@@ -1201,6 +1202,7 @@ FLAGNR(Number, FuncObjectInlineCacheThreshold , "Maximum number of inline cach
12011202
FLAGNR(Boolean, NoDeferParse , "Disable deferred parsing", false)
12021203
FLAGNR(Boolean, NoLogo , "No logo, which we don't display anyways", false)
12031204
FLAGNR(Boolean, OOPJITMissingOpts , "Use optimizations that are missing from OOP JIT", DEFAULT_CONFIG_OOPJITMissingOpts)
1205+
FLAGNR(Boolean, OOPCFGRegistration , "Do CFG registration OOP (under OOP JIT)", DEFAULT_CONFIG_OOPCFGRegistration)
12041206
#ifdef _ARM64_
12051207
FLAGR (Boolean, NoNative , "Disable native codegen", true)
12061208
#else

lib/JITServer/JITServer.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ ServerNewInterpreterThunkBlock(
435435
MemoryOperationLastError::CheckProcessAndThrowFatalError(threadContext->GetProcessHandle());
436436
}
437437

438-
// Call to set VALID flag for CFG check
439-
threadContext->SetValidCallTargetForCFG(remoteBuffer);
438+
if(CONFIG_FLAG(OOPCFGRegistration))
439+
{
440+
threadContext->SetValidCallTargetForCFG(remoteBuffer);
441+
}
440442

441443
thunkInfo->thunkBlockAddr = (intptr_t)remoteBuffer;
442444
thunkInfo->thunkCount = thunkCount;
@@ -465,7 +467,10 @@ ServerFreeAllocation(
465467

466468
return ServerCallWrapper(context, [&]()->HRESULT
467469
{
468-
context->SetValidCallTargetForCFG((PVOID)address, false);
470+
if (CONFIG_FLAG(OOPCFGRegistration))
471+
{
472+
context->SetValidCallTargetForCFG((PVOID)address, false);
473+
}
469474
context->GetCodeGenAllocators()->emitBufferManager.FreeAllocation((void*)address);
470475
return S_OK;
471476
});

0 commit comments

Comments
 (0)