Skip to content

Commit 9d947dd

Browse files
author
Jianchun Xu
committed
[MERGE #2364 @jianchun] swb: a few fixes (module namespace, Debugger)
Merge pull request #2364 from jianchun:swbmodule ### swb: fix module namespace annotation OP_StModuleSlot was changing slot without write barrier. Annotate all related code. (Credit to Lei for finding it is module namespace related.) ### Revert "fix a pal build issue on my machine" This reverts commit c49e4af. It should now work after Oguz removed wchar_t redef from PAL. ### pin Debugger::m_context Found under stress unit testing. Debugger::m_context was not pinned and could be GC collected when not in use.
2 parents 224e603 + 36659e8 commit 9d947dd

File tree

12 files changed

+30
-32
lines changed

12 files changed

+30
-32
lines changed

bin/ch/Debugger.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ Debugger::Debugger(JsRuntimeHandle runtime)
192192

193193
Debugger::~Debugger()
194194
{
195+
if (this->m_context != JS_INVALID_REFERENCE)
196+
{
197+
ChakraRTInterface::JsRelease(this->m_context, nullptr);
198+
this->m_context = JS_INVALID_REFERENCE;
199+
}
195200
this->m_runtime = JS_INVALID_RUNTIME_HANDLE;
196201
}
197202

@@ -225,7 +230,9 @@ bool Debugger::Initialize()
225230
// Create a new context and run dbgcontroller.js in that context
226231
// setup dbgcontroller.js callbacks
227232

233+
Assert(this->m_context == JS_INVALID_REFERENCE);
228234
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateContext(this->m_runtime, &this->m_context));
235+
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsAddRef(this->m_context, nullptr)); // Pin context
229236

230237
AutoRestoreContext autoRestoreContext(this->m_context);
231238

lib/Backend/IRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3823,7 +3823,7 @@ IRBuilder::BuildElementSlotI2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot r
38233823
case Js::OpCode::LdModuleSlot:
38243824
case Js::OpCode::StModuleSlot:
38253825
{
3826-
Js::Var* moduleExportVarArrayAddr = Js::JavascriptOperators::OP_GetModuleExportSlotArrayAddress(slotId1, slotId2, m_func->GetScriptContextInfo());
3826+
Field(Js::Var)* moduleExportVarArrayAddr = Js::JavascriptOperators::OP_GetModuleExportSlotArrayAddress(slotId1, slotId2, m_func->GetScriptContextInfo());
38273827
IR::AddrOpnd* addrOpnd = IR::AddrOpnd::New(moduleExportVarArrayAddr, IR::AddrOpndKindConstantAddress, m_func, true);
38283828
regOpnd = IR::RegOpnd::New(TyVar, m_func);
38293829
instr = IR::Instr::New(Js::OpCode::Ld_A, regOpnd, addrOpnd, m_func);

lib/Backend/ServerScriptContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ ServerScriptContext::Release()
351351
}
352352
}
353353

354-
Js::Var*
354+
Field(Js::Var)*
355355
ServerScriptContext::GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex)
356356
{
357357
Assert(m_moduleRecords.ContainsKey(moduleIndex));
@@ -370,7 +370,7 @@ ServerScriptContext::AddModuleRecordInfo(unsigned int moduleId, __int64 localExp
370370
{
371371
Js::ServerSourceTextModuleRecord* record = HeapNewStructZ(Js::ServerSourceTextModuleRecord);
372372
record->moduleId = moduleId;
373-
record->localExportSlotsAddr = (Js::Var*)localExportSlotsAddr;
373+
record->localExportSlotsAddr = (Field(Js::Var)*)localExportSlotsAddr;
374374
m_moduleRecords.Add(moduleId, record);
375375
}
376376

lib/Backend/ServerScriptContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ServerScriptContext : public ScriptContextInfo
7171
typedef JsUtil::BaseDictionary<uint, Js::ServerSourceTextModuleRecord*, Memory::HeapAllocator> ServerModuleRecords;
7272
ServerModuleRecords m_moduleRecords;
7373

74-
virtual Js::Var* GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex) override;
74+
virtual Field(Js::Var)* GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex) override;
7575

7676
void SetIsPRNGSeeded(bool value);
7777
void AddModuleRecordInfo(unsigned int moduleId, __int64 localExportSlotsAddr);

lib/Runtime/Base/ScriptContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5940,7 +5940,7 @@ void ScriptContext::RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertie
59405940
return nameLen;
59415941
}
59425942

5943-
Js::Var* ScriptContext::GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex)
5943+
Field(Js::Var)* ScriptContext::GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex)
59445944
{
59455945
Js::SourceTextModuleRecord* moduleRecord = this->GetModuleRecord(moduleIndex);
59465946
Assert(moduleRecord != nullptr);

lib/Runtime/Base/ScriptContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ namespace Js
17451745
virtual bool IsRecyclerVerifyEnabled() const override;
17461746
virtual uint GetRecyclerVerifyPad() const override;
17471747

1748-
virtual Js::Var* GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex) override;
1748+
virtual Field(Js::Var)* GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex) override;
17491749

17501750
Js::SourceTextModuleRecord* GetModuleRecord(uint moduleId) const
17511751
{

lib/Runtime/Base/ScriptContextInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ScriptContextInfo
4848

4949
virtual bool IsClosed() const = 0;
5050

51-
virtual Js::Var* GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex) = 0;
51+
virtual Field(Js::Var)* GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex) = 0;
5252

5353
virtual intptr_t GetDebuggingFlagsAddr() const = 0;
5454
virtual intptr_t GetDebugStepTypeAddr() const = 0;

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6598,22 +6598,22 @@ namespace Js
65986598
return propertyId;
65996599
}
66006600

6601-
Var* JavascriptOperators::OP_GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex, ScriptContextInfo* scriptContext)
6601+
Field(Var)* JavascriptOperators::OP_GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex, ScriptContextInfo* scriptContext)
66026602
{
66036603
return scriptContext->GetModuleExportSlotArrayAddress(moduleIndex, slotIndex);
66046604
}
66056605

6606-
Var* JavascriptOperators::OP_GetModuleExportSlotAddress(uint moduleIndex, uint slotIndex, ScriptContext* scriptContext)
6606+
Field(Var)* JavascriptOperators::OP_GetModuleExportSlotAddress(uint moduleIndex, uint slotIndex, ScriptContext* scriptContext)
66076607
{
6608-
Var* moduleRecordSlots = OP_GetModuleExportSlotArrayAddress(moduleIndex, slotIndex, scriptContext);
6608+
Field(Var)* moduleRecordSlots = OP_GetModuleExportSlotArrayAddress(moduleIndex, slotIndex, scriptContext);
66096609
Assert(moduleRecordSlots != nullptr);
66106610

66116611
return &moduleRecordSlots[slotIndex];
66126612
}
66136613

66146614
Var JavascriptOperators::OP_LdModuleSlot(uint moduleIndex, uint slotIndex, ScriptContext* scriptContext)
66156615
{
6616-
Var* addr = OP_GetModuleExportSlotAddress(moduleIndex, slotIndex, scriptContext);
6616+
Field(Var)* addr = OP_GetModuleExportSlotAddress(moduleIndex, slotIndex, scriptContext);
66176617

66186618
Assert(addr != nullptr);
66196619

@@ -6624,7 +6624,7 @@ namespace Js
66246624
{
66256625
Assert(value != nullptr);
66266626

6627-
Var* addr = OP_GetModuleExportSlotAddress(moduleIndex, slotIndex, scriptContext);
6627+
Field(Var)* addr = OP_GetModuleExportSlotAddress(moduleIndex, slotIndex, scriptContext);
66286628

66296629
Assert(addr != nullptr);
66306630

lib/Runtime/Language/JavascriptOperators.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ namespace Js
292292
static void OP_InitClassMemberSet(Var object, PropertyId propertyId, Var setter);
293293
static void OP_InitClassMemberSetComputedName(Var object, Var elementName, Var getter, ScriptContext* scriptContext, PropertyOperationFlags flags = PropertyOperation_None);
294294

295-
static Var* OP_GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex, ScriptContextInfo* scriptContext);
296-
static Var* OP_GetModuleExportSlotAddress(uint moduleIndex, uint slotIndex, ScriptContext* scriptContext);
295+
static Field(Var)* OP_GetModuleExportSlotArrayAddress(uint moduleIndex, uint slotIndex, ScriptContextInfo* scriptContext);
296+
static Field(Var)* OP_GetModuleExportSlotAddress(uint moduleIndex, uint slotIndex, ScriptContext* scriptContext);
297297
static Var OP_LdModuleSlot(uint moduleIndex, uint slotIndex, ScriptContext* scriptContext);
298298
static void OP_StModuleSlot(uint moduleIndex, uint slotIndex, Var value, ScriptContext* scriptContext);
299299

lib/Runtime/Language/ModuleNamespace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace Js
9090
Field(ListForListIterator*) sortedExportedNames; // sorted exported names for both local and indirect exports; excludes symbols.
9191
Field(Field(Var)*) nsSlots;
9292

93-
void SetNSSlotsForModuleNS(Var* nsSlot) { this->nsSlots = (Field(Var)*)nsSlot; }
93+
void SetNSSlotsForModuleNS(Field(Var)* nsSlot) { this->nsSlots = nsSlot; }
9494
Var GetNSSlot(BigPropertyIndex propertyIndex);
9595
void AddUnambiguousNonLocalExport(PropertyId exportId, ModuleNameRecord* nonLocalExportNameRecord);
9696
UnambiguousExportMap* GetUnambiguousNonLocalExports() const { return unambiguousNonLocalExports; }

0 commit comments

Comments
 (0)