mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1395509
- Add FreeOp methods to deal with releasing RefCounted types r=sfink
Differential Revision: https://phabricator.services.mozilla.com/D35484
This commit is contained in:
parent
928742d3ea
commit
532b9e4484
@ -10,6 +10,7 @@
|
|||||||
#include "gc/FreeOp.h"
|
#include "gc/FreeOp.h"
|
||||||
|
|
||||||
#include "gc/ZoneAllocator.h"
|
#include "gc/ZoneAllocator.h"
|
||||||
|
#include "js/RefCounted.h"
|
||||||
|
|
||||||
namespace js {
|
namespace js {
|
||||||
|
|
||||||
@ -42,6 +43,14 @@ inline void FreeOp::freeLater(void* p) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void FreeOp::release(gc::Cell* cell, T* p, size_t nbytes, MemoryUse use) {
|
||||||
|
if (p) {
|
||||||
|
RemoveCellMemory(cell, nbytes, use);
|
||||||
|
p->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace js
|
} // namespace js
|
||||||
|
|
||||||
#endif // gc_FreeOp_inl_h
|
#endif // gc_FreeOp_inl_h
|
||||||
|
@ -86,8 +86,8 @@ class FreeOp : public JSFreeOp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a C++ object that associated with a GC thing and update the memory
|
// Delete a C++ object that was associated with a GC thing and update the
|
||||||
// accounting. The size is determined by the type T.
|
// memory accounting. The size is determined by the type T.
|
||||||
//
|
//
|
||||||
// The memory should have been associated with the GC thing using
|
// The memory should have been associated with the GC thing using
|
||||||
// js::InitReservedSlot or js::InitObjectPrivate, or possibly
|
// js::InitReservedSlot or js::InitObjectPrivate, or possibly
|
||||||
@ -97,8 +97,8 @@ class FreeOp : public JSFreeOp {
|
|||||||
delete_(cell, p, sizeof(T), use);
|
delete_(cell, p, sizeof(T), use);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a C++ object that associated with a GC thing and update the memory
|
// Delete a C++ object that was associated with a GC thing and update the
|
||||||
// accounting.
|
// memory accounting.
|
||||||
//
|
//
|
||||||
// The memory should have been associated with the GC thing using
|
// The memory should have been associated with the GC thing using
|
||||||
// js::InitReservedSlot or js::InitObjectPrivate, or possibly
|
// js::InitReservedSlot or js::InitObjectPrivate, or possibly
|
||||||
@ -110,6 +110,31 @@ class FreeOp : public JSFreeOp {
|
|||||||
free_(cell, p, nbytes, use);
|
free_(cell, p, nbytes, use);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Release a RefCounted object that was associated with a GC thing and update
|
||||||
|
// the memory accounting.
|
||||||
|
//
|
||||||
|
// The memory should have been associated with the GC thing using
|
||||||
|
// js::InitReservedSlot or js::InitObjectPrivate, or possibly
|
||||||
|
// js::AddCellMemory.
|
||||||
|
//
|
||||||
|
// This counts the memory once per association with a GC thing. It's not
|
||||||
|
// expected that the same object is associated with more than one GC thing in
|
||||||
|
// each zone. If this is the case then some other form of accounting would be
|
||||||
|
// more appropriate.
|
||||||
|
template <class T>
|
||||||
|
void release(gc::Cell* cell, T* p, MemoryUse use) {
|
||||||
|
release(cell, p, sizeof(T), use);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release a RefCounted object and that was associated with a GC thing and
|
||||||
|
// update the memory accounting.
|
||||||
|
//
|
||||||
|
// The memory should have been associated with the GC thing using
|
||||||
|
// js::InitReservedSlot or js::InitObjectPrivate, or possibly
|
||||||
|
// js::AddCellMemory.
|
||||||
|
template <class T>
|
||||||
|
void release(gc::Cell* cell, T* p, size_t nbytes, MemoryUse use);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace js
|
} // namespace js
|
||||||
|
Loading…
Reference in New Issue
Block a user