From c52bf800a4906c7e6c659a0bfe55c43bdd841226 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Thu, 23 Aug 2018 16:59:01 +0100 Subject: [PATCH] Bug 1485615 - Move internal ZoneAllocPolicy to gc/Zone.h r=sfink --- js/public/AllocPolicy.h | 34 ---------------- js/src/builtin/ModuleObject.h | 1 + js/src/gc/WeakMap.h | 1 + js/src/gc/Zone.h | 75 ++++++++++++++++++----------------- js/src/vm/RegExpShared.h | 1 + 5 files changed, 42 insertions(+), 70 deletions(-) diff --git a/js/public/AllocPolicy.h b/js/public/AllocPolicy.h index 7df6d24c426b..0ab9417989bb 100644 --- a/js/public/AllocPolicy.h +++ b/js/public/AllocPolicy.h @@ -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 inline T* maybe_pod_malloc(size_t numElems); - template inline T* maybe_pod_calloc(size_t numElems); - template inline T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize); - template inline T* pod_malloc(size_t numElems); - template inline T* pod_calloc(size_t numElems); - template inline T* pod_realloc(T* p, size_t oldSize, size_t newSize); - - template 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 */ diff --git a/js/src/builtin/ModuleObject.h b/js/src/builtin/ModuleObject.h index 68b9607ff08c..b3e7090c45c9 100644 --- a/js/src/builtin/ModuleObject.h +++ b/js/src/builtin/ModuleObject.h @@ -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" diff --git a/js/src/gc/WeakMap.h b/js/src/gc/WeakMap.h index 176482fb0e88..f253985799a5 100644 --- a/js/src/gc/WeakMap.h +++ b/js/src/gc/WeakMap.h @@ -11,6 +11,7 @@ #include "gc/Barrier.h" #include "gc/DeletePolicy.h" +#include "gc/Zone.h" #include "js/HashTable.h" namespace JS { diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index b9d606dee6a7..61f03330934b 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -757,47 +757,50 @@ class Zone : public JS::shadow::Zone, namespace js { -template -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(numElems); -} + JS::Zone* const zone; -template -inline T* -ZoneAllocPolicy::maybe_pod_calloc(size_t numElems) -{ - return zone->maybe_pod_calloc(numElems); -} + public: + MOZ_IMPLICIT ZoneAllocPolicy(JS::Zone* z) : zone(z) {} -template -inline T* -ZoneAllocPolicy::maybe_pod_realloc(T* p, size_t oldSize, size_t newSize) -{ - return zone->maybe_pod_realloc(p, oldSize, newSize); -} + template T* maybe_pod_malloc(size_t numElems) { + return zone->maybe_pod_malloc(numElems); + } + template T* maybe_pod_calloc(size_t numElems) { + return zone->maybe_pod_calloc(numElems); + } + template T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize) { + return zone->maybe_pod_realloc(p, oldSize, newSize); + } + template T* pod_malloc(size_t numElems) { + return zone->pod_malloc(numElems); + } + template T* pod_calloc(size_t numElems) { + return zone->pod_calloc(numElems); + } + template T* pod_realloc(T* p, size_t oldSize, size_t newSize) { + return zone->pod_realloc(p, oldSize, newSize); + } -template -inline T* -ZoneAllocPolicy::pod_malloc(size_t numElems) -{ - return zone->pod_malloc(numElems); -} + template void free_(T* p, size_t numElems = 0) { js_free(p); } + void reportAllocOverflow() const {} -template -inline T* -ZoneAllocPolicy::pod_calloc(size_t numElems) -{ - return zone->pod_calloc(numElems); -} - -template -inline T* -ZoneAllocPolicy::pod_realloc(T* p, size_t oldSize, size_t newSize) -{ - return zone->pod_realloc(p, oldSize, newSize); -} + MOZ_MUST_USE bool checkSimulatedOOM() const { + return !js::oom::ShouldFailWithOOM(); + } +}; } // namespace js diff --git a/js/src/vm/RegExpShared.h b/js/src/vm/RegExpShared.h index 6348221deda6..6f935a670cfe 100644 --- a/js/src/vm/RegExpShared.h +++ b/js/src/vm/RegExpShared.h @@ -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"