Fix JS incremental GC issue (destroyed realms are not collected).

Further work would be nice to be able to only collect zones that
probably have garbage to collect, but that likely requires splitting our
contexts in more zones.

0 A.D. had been running in incremental GC since 1.8.5. With the SM78
upgrade, I changed this to the new default "ZONE_INCREMENTAL", which GCs
specific zones.
However, I failed to realise that deleted scriptInterfaces and their
corresponding zones would no longer be collected.
This corrects for that.

Fixes d92a2118b0.

Refs #5861

Differential Revision: https://code.wildfiregames.com/D3220
This was SVN commit r24392.
This commit is contained in:
wraitii 2020-12-14 08:51:29 +00:00
parent 21fa835cff
commit b0c3037abc

View File

@ -130,6 +130,10 @@ void ScriptContext::RegisterRealm(JS::Realm* realm)
void ScriptContext::UnRegisterRealm(JS::Realm* realm)
{
// Schedule the zone for GC, which will destroy the realm.
if (JS::IsIncrementalGCInProgress(m_cx))
JS::FinishIncrementalGC(m_cx, JS::GCReason::API);
JS::PrepareZoneForGC(js::GetRealmZone(realm));
m_Realms.remove(realm);
}
@ -241,7 +245,7 @@ void ScriptContext::ShrinkingGC()
JS_SetGCParameter(m_cx, JSGC_MODE, JSGC_MODE_ZONE);
JS::PrepareForFullGC(m_cx);
JS::NonIncrementalGC(m_cx, GC_SHRINK, JS::GCReason::API);
JS_SetGCParameter(m_cx, JSGC_MODE, JSGC_MODE_INCREMENTAL);
JS_SetGCParameter(m_cx, JSGC_MODE, JSGC_MODE_ZONE_INCREMENTAL);
}
void ScriptContext::PrepareZonesForIncrementalGC() const