Bug 1052579 - Allow JS AllocPolicy to be assigned to an arena r=sfink

Several areas of JS code abstract their memory allocation logic behind an
AllocPolicy. Since these allocations may now need to be in different arenas,
each AllocPolicy will need to be assigned a Mozjemalloc arena that it will
use for all its allocations.

Differential Revision: https://phabricator.services.mozilla.com/D25705

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris Martin 2019-04-03 19:53:06 +00:00
Родитель 9bbc7930d4
Коммит 5c32fcd59d
2 изменённых файлов: 15 добавлений и 5 удалений

Просмотреть файл

@ -25,18 +25,26 @@ enum class AllocFunction { Malloc, Calloc, Realloc };
/* Base class allocation policies providing allocation methods. */
class AllocPolicyBase {
const arena_id_t& arenaId_;
protected:
arena_id_t getArenaId() { return arenaId_; }
public:
explicit AllocPolicyBase(const arena_id_t& arenaId = js::MallocArena)
: arenaId_(arenaId) {}
template <typename T>
T* maybe_pod_malloc(size_t numElems) {
return js_pod_malloc<T>(numElems);
return js_pod_arena_malloc<T>(getArenaId(), numElems);
}
template <typename T>
T* maybe_pod_calloc(size_t numElems) {
return js_pod_calloc<T>(numElems);
return js_pod_arena_calloc<T>(getArenaId(), numElems);
}
template <typename T>
T* maybe_pod_realloc(T* p, size_t oldSize, size_t newSize) {
return js_pod_realloc<T>(p, oldSize, newSize);
return js_pod_arena_realloc<T>(getArenaId(), p, oldSize, newSize);
}
template <typename T>
T* pod_malloc(size_t numElems) {
@ -95,7 +103,9 @@ class TempAllocPolicy : public AllocPolicyBase {
}
public:
MOZ_IMPLICIT TempAllocPolicy(JSContext* cx) : cx_(cx) {}
MOZ_IMPLICIT TempAllocPolicy(JSContext* cx,
const arena_id_t& arenaId = js::MallocArena)
: AllocPolicyBase(arenaId), cx_(cx) {}
template <typename T>
T* pod_malloc(size_t numElems) {

Просмотреть файл

@ -12,7 +12,7 @@ using namespace js;
void* TempAllocPolicy::onOutOfMemory(AllocFunction allocFunc, size_t nbytes,
void* reallocPtr) {
return cx_->onOutOfMemory(allocFunc, js::MallocArena, nbytes, reallocPtr);
return cx_->onOutOfMemory(allocFunc, this->getArenaId(), nbytes, reallocPtr);
}
void TempAllocPolicy::reportAllocOverflow() const {