зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1367795 - Refactor some use of WeakCache r=sfink
This commit is contained in:
Родитель
1d691b821d
Коммит
8fbc82a162
|
@ -1022,7 +1022,7 @@ WasmInstanceObject::create(JSContext* cx,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePtr<WeakScopeMap> scopes = js::MakeUnique<WeakScopeMap>(cx->zone());
|
UniquePtr<ScopeMap> scopes = js::MakeUnique<ScopeMap>(cx->zone());
|
||||||
if (!scopes || !scopes->init()) {
|
if (!scopes || !scopes->init()) {
|
||||||
ReportOutOfMemory(cx);
|
ReportOutOfMemory(cx);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -1143,10 +1143,10 @@ WasmInstanceObject::exports() const
|
||||||
return *(ExportMap*)getReservedSlot(EXPORTS_SLOT).toPrivate();
|
return *(ExportMap*)getReservedSlot(EXPORTS_SLOT).toPrivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
WasmInstanceObject::WeakScopeMap&
|
WasmInstanceObject::ScopeMap&
|
||||||
WasmInstanceObject::scopes() const
|
WasmInstanceObject::scopes() const
|
||||||
{
|
{
|
||||||
return *(WeakScopeMap*)getReservedSlot(SCOPES_SLOT).toPrivate();
|
return *(ScopeMap*)getReservedSlot(SCOPES_SLOT).toPrivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -1440,18 +1440,18 @@ WasmMemoryObject::hasObservers() const
|
||||||
return !getReservedSlot(OBSERVERS_SLOT).isUndefined();
|
return !getReservedSlot(OBSERVERS_SLOT).isUndefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
WasmMemoryObject::WeakInstanceSet&
|
WasmMemoryObject::InstanceSet&
|
||||||
WasmMemoryObject::observers() const
|
WasmMemoryObject::observers() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(hasObservers());
|
MOZ_ASSERT(hasObservers());
|
||||||
return *reinterpret_cast<WeakInstanceSet*>(getReservedSlot(OBSERVERS_SLOT).toPrivate());
|
return *reinterpret_cast<InstanceSet*>(getReservedSlot(OBSERVERS_SLOT).toPrivate());
|
||||||
}
|
}
|
||||||
|
|
||||||
WasmMemoryObject::WeakInstanceSet*
|
WasmMemoryObject::InstanceSet*
|
||||||
WasmMemoryObject::getOrCreateObservers(JSContext* cx)
|
WasmMemoryObject::getOrCreateObservers(JSContext* cx)
|
||||||
{
|
{
|
||||||
if (!hasObservers()) {
|
if (!hasObservers()) {
|
||||||
auto observers = MakeUnique<WeakInstanceSet>(cx->zone());
|
auto observers = MakeUnique<InstanceSet>(cx->zone());
|
||||||
if (!observers || !observers->init()) {
|
if (!observers || !observers->init()) {
|
||||||
ReportOutOfMemory(cx);
|
ReportOutOfMemory(cx);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -1478,7 +1478,7 @@ WasmMemoryObject::addMovingGrowObserver(JSContext* cx, WasmInstanceObject* insta
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(movingGrowable());
|
MOZ_ASSERT(movingGrowable());
|
||||||
|
|
||||||
WeakInstanceSet* observers = getOrCreateObservers(cx);
|
InstanceSet* observers = getOrCreateObservers(cx);
|
||||||
if (!observers)
|
if (!observers)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -167,12 +167,11 @@ class WasmInstanceObject : public NativeObject
|
||||||
// WeakScopeMap maps from function index to js::Scope. This maps is weak
|
// WeakScopeMap maps from function index to js::Scope. This maps is weak
|
||||||
// to avoid holding scope objects alive. The scopes are normally created
|
// to avoid holding scope objects alive. The scopes are normally created
|
||||||
// during debugging.
|
// during debugging.
|
||||||
using ScopeMap = GCHashMap<uint32_t,
|
using ScopeMap = JS::WeakCache<GCHashMap<uint32_t,
|
||||||
ReadBarriered<WasmFunctionScope*>,
|
ReadBarriered<WasmFunctionScope*>,
|
||||||
DefaultHasher<uint32_t>,
|
DefaultHasher<uint32_t>,
|
||||||
SystemAllocPolicy>;
|
SystemAllocPolicy>>;
|
||||||
using WeakScopeMap = JS::WeakCache<ScopeMap>;
|
ScopeMap& scopes() const;
|
||||||
WeakScopeMap& scopes() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const unsigned RESERVED_SLOTS = 4;
|
static const unsigned RESERVED_SLOTS = 4;
|
||||||
|
@ -222,13 +221,12 @@ class WasmMemoryObject : public NativeObject
|
||||||
static bool growImpl(JSContext* cx, const CallArgs& args);
|
static bool growImpl(JSContext* cx, const CallArgs& args);
|
||||||
static bool grow(JSContext* cx, unsigned argc, Value* vp);
|
static bool grow(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
|
||||||
using InstanceSet = GCHashSet<ReadBarrieredWasmInstanceObject,
|
using InstanceSet = JS::WeakCache<GCHashSet<ReadBarrieredWasmInstanceObject,
|
||||||
MovableCellHasher<ReadBarrieredWasmInstanceObject>,
|
MovableCellHasher<ReadBarrieredWasmInstanceObject>,
|
||||||
SystemAllocPolicy>;
|
SystemAllocPolicy>>;
|
||||||
using WeakInstanceSet = JS::WeakCache<InstanceSet>;
|
|
||||||
bool hasObservers() const;
|
bool hasObservers() const;
|
||||||
WeakInstanceSet& observers() const;
|
InstanceSet& observers() const;
|
||||||
WeakInstanceSet* getOrCreateObservers(JSContext* cx);
|
InstanceSet* getOrCreateObservers(JSContext* cx);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const unsigned RESERVED_SLOTS = 2;
|
static const unsigned RESERVED_SLOTS = 2;
|
||||||
|
|
|
@ -31,13 +31,13 @@ namespace wasm {
|
||||||
|
|
||||||
class Table : public ShareableBase<Table>
|
class Table : public ShareableBase<Table>
|
||||||
{
|
{
|
||||||
using InstanceSet = GCHashSet<ReadBarrieredWasmInstanceObject,
|
using InstanceSet = JS::WeakCache<GCHashSet<ReadBarrieredWasmInstanceObject,
|
||||||
MovableCellHasher<ReadBarrieredWasmInstanceObject>,
|
MovableCellHasher<ReadBarrieredWasmInstanceObject>,
|
||||||
SystemAllocPolicy>;
|
SystemAllocPolicy>>;
|
||||||
typedef UniquePtr<uint8_t[], JS::FreePolicy> UniqueByteArray;
|
using UniqueByteArray = UniquePtr<uint8_t[], JS::FreePolicy>;
|
||||||
|
|
||||||
ReadBarrieredWasmTableObject maybeObject_;
|
ReadBarrieredWasmTableObject maybeObject_;
|
||||||
JS::WeakCache<InstanceSet> observers_;
|
InstanceSet observers_;
|
||||||
UniqueByteArray array_;
|
UniqueByteArray array_;
|
||||||
const TableKind kind_;
|
const TableKind kind_;
|
||||||
uint32_t length_;
|
uint32_t length_;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче