Bug 1485615 - Move internal ZoneAllocPolicy to gc/Zone.h r=sfink

This commit is contained in:
Jon Coppeard 2018-08-23 16:59:01 +01:00
parent 4da01fd496
commit c52bf800a4
5 changed files with 42 additions and 70 deletions

View File

@ -128,40 +128,6 @@ class TempAllocPolicy : public AllocPolicyBase
}
};
/*
* Allocation policy that uses Zone::pod_malloc and friends, so that memory
* pressure is accounted for on the zone. This is suitable for memory associated
* with GC things allocated in the zone.
*
* Since it doesn't hold a JSContext (those may not live long enough), it can't
* report out-of-memory conditions itself; the caller must check for OOM and
* take the appropriate action.
*
* FIXME bug 647103 - replace these *AllocPolicy names.
*/
class ZoneAllocPolicy
{
JS::Zone* const zone;
public:
MOZ_IMPLICIT ZoneAllocPolicy(JS::Zone* z) : zone(z) {}
// These methods are defined in gc/Zone.h.
template <typename T> inline T* maybe_pod_malloc(size_t numElems);
template <typename T> inline T* maybe_pod_calloc(size_t numElems);
template <typename T> inline T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize);
template <typename T> inline T* pod_malloc(size_t numElems);
template <typename T> inline T* pod_calloc(size_t numElems);
template <typename T> inline T* pod_realloc(T* p, size_t oldSize, size_t newSize);
template <typename T> void free_(T* p, size_t numElems = 0) { js_free(p); }
void reportAllocOverflow() const {}
MOZ_MUST_USE bool checkSimulatedOOM() const {
return !js::oom::ShouldFailWithOOM();
}
};
} /* namespace js */
#endif /* js_AllocPolicy_h */

View File

@ -12,6 +12,7 @@
#include "jsapi.h"
#include "builtin/SelfHostingDefines.h"
#include "gc/Zone.h"
#include "js/GCVector.h"
#include "js/Id.h"
#include "js/UniquePtr.h"

View File

@ -11,6 +11,7 @@
#include "gc/Barrier.h"
#include "gc/DeletePolicy.h"
#include "gc/Zone.h"
#include "js/HashTable.h"
namespace JS {

View File

@ -757,47 +757,50 @@ class Zone : public JS::shadow::Zone,
namespace js {
template <typename T>
inline T*
ZoneAllocPolicy::maybe_pod_malloc(size_t numElems)
/*
* Allocation policy that uses Zone::pod_malloc and friends, so that memory
* pressure is accounted for on the zone. This is suitable for memory associated
* with GC things allocated in the zone.
*
* Since it doesn't hold a JSContext (those may not live long enough), it can't
* report out-of-memory conditions itself; the caller must check for OOM and
* take the appropriate action.
*
* FIXME bug 647103 - replace these *AllocPolicy names.
*/
class ZoneAllocPolicy
{
return zone->maybe_pod_malloc<T>(numElems);
}
JS::Zone* const zone;
template <typename T>
inline T*
ZoneAllocPolicy::maybe_pod_calloc(size_t numElems)
{
return zone->maybe_pod_calloc<T>(numElems);
}
public:
MOZ_IMPLICIT ZoneAllocPolicy(JS::Zone* z) : zone(z) {}
template <typename T>
inline T*
ZoneAllocPolicy::maybe_pod_realloc(T* p, size_t oldSize, size_t newSize)
{
return zone->maybe_pod_realloc<T>(p, oldSize, newSize);
}
template <typename T> T* maybe_pod_malloc(size_t numElems) {
return zone->maybe_pod_malloc<T>(numElems);
}
template <typename T> T* maybe_pod_calloc(size_t numElems) {
return zone->maybe_pod_calloc<T>(numElems);
}
template <typename T> T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize) {
return zone->maybe_pod_realloc<T>(p, oldSize, newSize);
}
template <typename T> T* pod_malloc(size_t numElems) {
return zone->pod_malloc<T>(numElems);
}
template <typename T> T* pod_calloc(size_t numElems) {
return zone->pod_calloc<T>(numElems);
}
template <typename T> T* pod_realloc(T* p, size_t oldSize, size_t newSize) {
return zone->pod_realloc<T>(p, oldSize, newSize);
}
template <typename T>
inline T*
ZoneAllocPolicy::pod_malloc(size_t numElems)
{
return zone->pod_malloc<T>(numElems);
}
template <typename T> void free_(T* p, size_t numElems = 0) { js_free(p); }
void reportAllocOverflow() const {}
template <typename T>
inline T*
ZoneAllocPolicy::pod_calloc(size_t numElems)
{
return zone->pod_calloc<T>(numElems);
}
template <typename T>
inline T*
ZoneAllocPolicy::pod_realloc(T* p, size_t oldSize, size_t newSize)
{
return zone->pod_realloc<T>(p, oldSize, newSize);
}
MOZ_MUST_USE bool checkSimulatedOOM() const {
return !js::oom::ShouldFailWithOOM();
}
};
} // namespace js

View File

@ -19,6 +19,7 @@
#include "gc/Barrier.h"
#include "gc/Heap.h"
#include "gc/Marking.h"
#include "gc/Zone.h"
#include "js/AllocPolicy.h"
#include "js/UbiNode.h"
#include "js/Vector.h"