Skip to content

Commit f826899

Browse files
committed
[MERGE #1758 @MikeHolman] cache debugManager JIT addrs on new ScriptContext, instead of new ThreadContext
Merge pull request #1758 from MikeHolman:debugmanageroop In case primary ScriptContext is closed, threadContext->debugManager can be freed, and if new ScriptContext is later opened, a new debugManager is created. In this case, the address we initially cached on the JIT will be wrong.
2 parents 872864b + b9022dd commit f826899

File tree

12 files changed

+74
-77
lines changed

12 files changed

+74
-77
lines changed

lib/Backend/Lower.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11482,7 +11482,7 @@ Lowerer::LowerBailForDebugger(IR::Instr* instr, bool isInsideHelper /* = false *
1148211482

1148311483
if (!(bailOutKind & IR::BailOutExplicit))
1148411484
{
11485-
intptr_t flags = m_func->GetThreadContextInfo()->GetDebuggingFlagsAddr();
11485+
intptr_t flags = m_func->GetScriptContextInfo()->GetDebuggingFlagsAddr();
1148611486

1148711487
// Check 1 (do we need to bail out?)
1148811488
// JXX bailoutLabel
@@ -11556,13 +11556,13 @@ Lowerer::LowerBailForDebugger(IR::Instr* instr, bool isInsideHelper /* = false *
1155611556
{
1155711557
// TEST STEP_BAILOUT, [&stepController->StepType]
1155811558
// BNE BailoutLabel
11559-
IR::Opnd* opnd1 = IR::MemRefOpnd::New(m_func->GetThreadContextInfo()->GetDebugStepTypeAddr(), TyInt8, m_func);
11559+
IR::Opnd* opnd1 = IR::MemRefOpnd::New(m_func->GetScriptContextInfo()->GetDebugStepTypeAddr(), TyInt8, m_func);
1156011560
IR::Opnd* opnd2 = IR::IntConstOpnd::New(Js::STEP_BAILOUT, TyInt8, this->m_func, /*dontEncode*/ true);
1156111561
InsertTestBranch(opnd1, opnd2, Js::OpCode::BrNeq_A, bailOutLabel, continueBranchInstr);
1156211562

1156311563
// CMP STEP_DOCUMENT, [&stepController->StepType]
1156411564
// BEQ BailoutDocumentLabel
11565-
opnd1 = IR::MemRefOpnd::New(m_func->GetThreadContextInfo()->GetDebugStepTypeAddr(), TyInt8, m_func);
11565+
opnd1 = IR::MemRefOpnd::New(m_func->GetScriptContextInfo()->GetDebugStepTypeAddr(), TyInt8, m_func);
1156611566
opnd2 = IR::IntConstOpnd::New(Js::STEP_DOCUMENT, TyInt8, this->m_func, /*dontEncode*/ true);
1156711567
InsertCompareBranch(opnd1, opnd2, Js::OpCode::BrEq_A, /*isUnsigned*/ true, bailOutDocumentLabel, continueBranchInstr);
1156811568

@@ -11583,12 +11583,12 @@ Lowerer::LowerBailForDebugger(IR::Instr* instr, bool isInsideHelper /* = false *
1158311583
effectiveFrameBaseReg = m_lowererMD.GetRegFramePointer();
1158411584
#endif
1158511585
IR::Opnd* opnd1 = IR::RegOpnd::New(nullptr, effectiveFrameBaseReg, TyMachReg, m_func);
11586-
IR::Opnd* opnd2 = IR::MemRefOpnd::New(m_func->GetThreadContextInfo()->GetDebugFrameAddressAddr(), TyMachReg, m_func);
11586+
IR::Opnd* opnd2 = IR::MemRefOpnd::New(m_func->GetScriptContextInfo()->GetDebugFrameAddressAddr(), TyMachReg, m_func);
1158711587
this->InsertCompareBranch(opnd1, opnd2, Js::OpCode::BrGt_A, /*isUnsigned*/ true, bailOutLabel, continueBranchInstr);
1158811588

1158911589
// CMP STEP_DOCUMENT, [&stepController->StepType]
1159011590
// BEQ BailoutDocumentLabel
11591-
opnd1 = IR::MemRefOpnd::New(m_func->GetThreadContextInfo()->GetDebugStepTypeAddr(), TyInt8, m_func);
11591+
opnd1 = IR::MemRefOpnd::New(m_func->GetScriptContextInfo()->GetDebugStepTypeAddr(), TyInt8, m_func);
1159211592
opnd2 = IR::IntConstOpnd::New(Js::STEP_DOCUMENT, TyInt8, this->m_func, /*dontEncode*/ true);
1159311593
InsertCompareBranch(opnd1, opnd2, Js::OpCode::BrEq_A, /*isUnsigned*/ true, bailOutDocumentLabel, continueBranchInstr);
1159411594

@@ -11623,7 +11623,7 @@ Lowerer::LowerBailForDebugger(IR::Instr* instr, bool isInsideHelper /* = false *
1162311623
// bailOutLabel: // (fallthrough bailOutLabel)
1162411624
IR::Opnd* opnd1 = IR::MemRefOpnd::New(m_func->GetJITFunctionBody()->GetScriptIdAddr(), TyInt32, m_func);
1162511625

11626-
IR::Opnd* opnd2 = IR::MemRefOpnd::New(m_func->GetThreadContextInfo()->GetDebugScriptIdWhenSetAddr(), TyInt32, m_func);
11626+
IR::Opnd* opnd2 = IR::MemRefOpnd::New(m_func->GetScriptContextInfo()->GetDebugScriptIdWhenSetAddr(), TyInt32, m_func);
1162711627
IR::RegOpnd* reg1 = IR::RegOpnd::New(TyInt32, m_func);
1162811628
InsertMove(reg1, opnd2, bailOutLabel);
1162911629

lib/Backend/ServerScriptContext.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,30 @@ ServerScriptContext::IsPRNGSeeded() const
270270
return m_isPRNGSeeded;
271271
}
272272

273+
intptr_t
274+
ServerScriptContext::GetDebuggingFlagsAddr() const
275+
{
276+
return static_cast<intptr_t>(m_contextData.debuggingFlagsAddr);
277+
}
278+
279+
intptr_t
280+
ServerScriptContext::GetDebugStepTypeAddr() const
281+
{
282+
return static_cast<intptr_t>(m_contextData.debugStepTypeAddr);
283+
}
284+
285+
intptr_t
286+
ServerScriptContext::GetDebugFrameAddressAddr() const
287+
{
288+
return static_cast<intptr_t>(m_contextData.debugFrameAddressAddr);
289+
}
290+
291+
intptr_t
292+
ServerScriptContext::GetDebugScriptIdWhenSetAddr() const
293+
{
294+
return static_cast<intptr_t>(m_contextData.debugScriptIdWhenSetAddr);
295+
}
296+
273297
bool
274298
ServerScriptContext::IsClosed() const
275299
{

lib/Backend/ServerScriptContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class ServerScriptContext : public ScriptContextInfo
4242
virtual bool IsClosed() const override;
4343
virtual intptr_t GetBuiltinFunctionsBaseAddr() const override;
4444

45+
virtual intptr_t GetDebuggingFlagsAddr() const override;
46+
virtual intptr_t GetDebugStepTypeAddr() const override;
47+
virtual intptr_t GetDebugFrameAddressAddr() const override;
48+
virtual intptr_t GetDebugScriptIdWhenSetAddr() const override;
49+
4550
virtual intptr_t GetAddr() const override;
4651

4752
virtual intptr_t GetVTableAddress(VTableValue vtableType) const override;

lib/Backend/ServerThreadContext.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,6 @@ ServerThreadContext::GetBailOutRegisterSaveSpaceAddr() const
9494
return static_cast<intptr_t>(m_threadContextData.bailOutRegisterSaveSpaceAddr);
9595
}
9696

97-
intptr_t
98-
ServerThreadContext::GetDebuggingFlagsAddr() const
99-
{
100-
return static_cast<intptr_t>(m_threadContextData.debuggingFlagsAddr);
101-
}
102-
103-
intptr_t
104-
ServerThreadContext::GetDebugStepTypeAddr() const
105-
{
106-
return static_cast<intptr_t>(m_threadContextData.debugStepTypeAddr);
107-
}
108-
109-
intptr_t
110-
ServerThreadContext::GetDebugFrameAddressAddr() const
111-
{
112-
return static_cast<intptr_t>(m_threadContextData.debugFrameAddressAddr);
113-
}
114-
115-
intptr_t
116-
ServerThreadContext::GetDebugScriptIdWhenSetAddr() const
117-
{
118-
return static_cast<intptr_t>(m_threadContextData.debugScriptIdWhenSetAddr);
119-
}
120-
12197
ptrdiff_t
12298
ServerThreadContext::GetChakraBaseAddressDifference() const
12399
{

lib/Backend/ServerThreadContext.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class ServerThreadContext : public ThreadContextInfo
2727
virtual intptr_t GetImplicitCallFlagsAddr() const override;
2828
virtual intptr_t GetBailOutRegisterSaveSpaceAddr() const override;
2929

30-
virtual intptr_t GetDebuggingFlagsAddr() const override;
31-
virtual intptr_t GetDebugStepTypeAddr() const override;
32-
virtual intptr_t GetDebugFrameAddressAddr() const override;
33-
virtual intptr_t GetDebugScriptIdWhenSetAddr() const override;
34-
3530
ptrdiff_t GetChakraBaseAddressDifference() const;
3631
ptrdiff_t GetCRTBaseAddressDifference() const;
3732

lib/JITIDL/JITTypes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,6 @@ typedef struct ThreadContextDataIDL
283283
CHAKRA_PTR bailOutRegisterSaveSpaceAddr;
284284
CHAKRA_PTR disableImplicitFlagsAddr;
285285
CHAKRA_PTR implicitCallFlagsAddr;
286-
CHAKRA_PTR debuggingFlagsAddr;
287-
CHAKRA_PTR debugStepTypeAddr;
288-
CHAKRA_PTR debugFrameAddressAddr;
289-
CHAKRA_PTR debugScriptIdWhenSetAddr;
290286
CHAKRA_PTR stringReplaceNameAddr;
291287
CHAKRA_PTR stringMatchNameAddr;
292288
CHAKRA_PTR simdTempAreaBaseAddr;
@@ -328,6 +324,10 @@ typedef struct ScriptContextDataIDL
328324
CHAKRA_PTR numberAllocatorAddr;
329325
CHAKRA_PTR recyclerAddr;
330326
CHAKRA_PTR builtinFunctionsBaseAddr;
327+
CHAKRA_PTR debuggingFlagsAddr;
328+
CHAKRA_PTR debugStepTypeAddr;
329+
CHAKRA_PTR debugFrameAddressAddr;
330+
CHAKRA_PTR debugScriptIdWhenSetAddr;
331331
} ScriptContextDataIDL;
332332

333333
typedef struct SmallSpanSequenceIDL

lib/Runtime/Base/ScriptContext.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4488,6 +4488,11 @@ void ScriptContext::RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertie
44884488
contextData.isRecyclerVerifyEnabled = FALSE;
44894489
contextData.recyclerVerifyPad = 0;
44904490
#endif
4491+
contextData.debuggingFlagsAddr = GetDebuggingFlagsAddr();
4492+
contextData.debugStepTypeAddr = GetDebugStepTypeAddr();
4493+
contextData.debugFrameAddressAddr = GetDebugFrameAddressAddr();
4494+
contextData.debugScriptIdWhenSetAddr = GetDebugScriptIdWhenSetAddr();
4495+
44914496
contextData.numberAllocatorAddr = (intptr_t)GetNumberAllocator();
44924497
contextData.isSIMDEnabled = GetConfig()->IsSimdjsEnabled();
44934498
CompileAssert(VTableValue::Count == VTABLE_COUNT); // need to update idl when this changes
@@ -4650,6 +4655,26 @@ void ScriptContext::RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertie
46504655
return (intptr_t)GetRecycler();
46514656
}
46524657

4658+
intptr_t ScriptContext::GetDebuggingFlagsAddr() const
4659+
{
4660+
return this->threadContext->GetDebugManager()->GetDebuggingFlagsAddr();
4661+
}
4662+
4663+
intptr_t ScriptContext::GetDebugStepTypeAddr() const
4664+
{
4665+
return (intptr_t)this->threadContext->GetDebugManager()->stepController.GetAddressOfStepType();
4666+
}
4667+
4668+
intptr_t ScriptContext::GetDebugFrameAddressAddr() const
4669+
{
4670+
return (intptr_t)this->threadContext->GetDebugManager()->stepController.GetAddressOfFrameAddress();
4671+
}
4672+
4673+
intptr_t ScriptContext::GetDebugScriptIdWhenSetAddr() const
4674+
{
4675+
return (intptr_t)this->threadContext->GetDebugManager()->stepController.GetAddressOfScriptIdWhenSet();
4676+
}
4677+
46534678
bool ScriptContext::GetRecyclerAllowNativeCodeBumpAllocation() const
46544679
{
46554680
return GetRecycler()->AllowNativeCodeBumpAllocation();

lib/Runtime/Base/ScriptContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,11 @@ namespace Js
17601760
virtual bool IsPRNGSeeded() const override;
17611761
virtual intptr_t GetBuiltinFunctionsBaseAddr() const override;
17621762

1763+
virtual intptr_t GetDebuggingFlagsAddr() const override;
1764+
virtual intptr_t GetDebugStepTypeAddr() const override;
1765+
virtual intptr_t GetDebugFrameAddressAddr() const override;
1766+
virtual intptr_t GetDebugScriptIdWhenSetAddr() const override;
1767+
17631768
#if ENABLE_NATIVE_CODEGEN
17641769
virtual void AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper) override;
17651770
virtual IR::JnHelperMethod GetDOMFastPathHelper(intptr_t funcInfoAddr) override;

lib/Runtime/Base/ScriptContextInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class ScriptContextInfo
5050

5151
virtual Js::Var* GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex) = 0;
5252

53+
virtual intptr_t GetDebuggingFlagsAddr() const = 0;
54+
virtual intptr_t GetDebugStepTypeAddr() const = 0;
55+
virtual intptr_t GetDebugFrameAddressAddr() const = 0;
56+
virtual intptr_t GetDebugScriptIdWhenSetAddr() const = 0;
57+
5358
#if ENABLE_NATIVE_CODEGEN
5459
virtual void AddToDOMFastPathHelperMap(intptr_t funcInfoAddr, IR::JnHelperMethod helper) = 0;
5560
virtual IR::JnHelperMethod GetDOMFastPathHelper(intptr_t funcInfoAddr) = 0;

lib/Runtime/Base/ThreadContext.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -341,30 +341,6 @@ ThreadContext::GetImplicitCallFlagsAddr() const
341341
return (intptr_t)&implicitCallFlags;
342342
}
343343

344-
intptr_t
345-
ThreadContext::GetDebuggingFlagsAddr() const
346-
{
347-
return this->debugManager->GetDebuggingFlagsAddr();
348-
}
349-
350-
intptr_t
351-
ThreadContext::GetDebugStepTypeAddr() const
352-
{
353-
return (intptr_t)this->debugManager->stepController.GetAddressOfStepType();
354-
}
355-
356-
intptr_t
357-
ThreadContext::GetDebugFrameAddressAddr() const
358-
{
359-
return (intptr_t)this->debugManager->stepController.GetAddressOfFrameAddress();
360-
}
361-
362-
intptr_t
363-
ThreadContext::GetDebugScriptIdWhenSetAddr() const
364-
{
365-
return (intptr_t)this->debugManager->stepController.GetAddressOfScriptIdWhenSet();
366-
}
367-
368344
ptrdiff_t
369345
ThreadContext::GetChakraBaseAddressDifference() const
370346
{
@@ -1994,10 +1970,6 @@ ThreadContext::EnsureJITThreadContext(bool allowPrereserveAlloc)
19941970
contextData.bailOutRegisterSaveSpaceAddr = (intptr_t)bailOutRegisterSaveSpace;
19951971
contextData.disableImplicitFlagsAddr = (intptr_t)GetAddressOfDisableImplicitFlags();
19961972
contextData.implicitCallFlagsAddr = (intptr_t)GetAddressOfImplicitCallFlags();
1997-
contextData.debuggingFlagsAddr = (intptr_t)this->debugManager->GetDebuggingFlags();
1998-
contextData.debugStepTypeAddr = (intptr_t)this->debugManager->stepController.GetAddressOfStepType();
1999-
contextData.debugFrameAddressAddr = (intptr_t)this->debugManager->stepController.GetAddressOfFrameAddress();
2000-
contextData.debugScriptIdWhenSetAddr = (intptr_t)this->debugManager->stepController.GetAddressOfScriptIdWhenSet();
20011973
contextData.scriptStackLimit = GetScriptStackLimit();
20021974
contextData.isThreadBound = IsThreadBound();
20031975
contextData.allowPrereserveAlloc = allowPrereserveAlloc;

0 commit comments

Comments
 (0)