From 061938133384f7e623c1939caa1292b711fef0a3 Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Wed, 1 Jun 2016 14:43:31 +0000 Subject: [PATCH] Bug 1264948 - Make it possible to use a placement-new with a fallible TempAllocator. r=h4writer --- js/src/jit/BacktrackingAllocator.h | 8 ++------ js/src/jit/JitAllocPolicy.h | 7 +++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/js/src/jit/BacktrackingAllocator.h b/js/src/jit/BacktrackingAllocator.h index 97c0158c4ef8..7542c1f78fa9 100644 --- a/js/src/jit/BacktrackingAllocator.h +++ b/js/src/jit/BacktrackingAllocator.h @@ -272,9 +272,7 @@ class LiveRange : public TempObject static LiveRange* FallibleNew(TempAllocator& alloc, uint32_t vreg, CodePosition from, CodePosition to) { - if (!alloc.ensureBallast()) - return nullptr; - return new(alloc) LiveRange(vreg, Range(from, to)); + return new(alloc.fallible()) LiveRange(vreg, Range(from, to)); } uint32_t vreg() const { @@ -422,9 +420,7 @@ class LiveBundle : public TempObject public: static LiveBundle* FallibleNew(TempAllocator& alloc, SpillSet* spill, LiveBundle* spillParent) { - if (!alloc.ensureBallast()) - return nullptr; - return new(alloc) LiveBundle(spill, spillParent); + return new(alloc.fallible()) LiveBundle(spill, spillParent); } SpillSet* spillSet() const { diff --git a/js/src/jit/JitAllocPolicy.h b/js/src/jit/JitAllocPolicy.h index 39c66498f478..84508b94df76 100644 --- a/js/src/jit/JitAllocPolicy.h +++ b/js/src/jit/JitAllocPolicy.h @@ -60,6 +60,10 @@ class TempAllocator return p; } + // View this allocator as a fallible allocator. + struct Fallible { TempAllocator& alloc; }; + Fallible fallible() { return { *this }; } + LifoAlloc* lifoAlloc() { return &lifoScope_.alloc(); @@ -145,6 +149,9 @@ class AutoJitContextAlloc struct TempObject { + inline void* operator new(size_t nbytes, TempAllocator::Fallible view) noexcept { + return view.alloc.allocate(nbytes); + } inline void* operator new(size_t nbytes, TempAllocator& alloc) { return alloc.allocateInfallible(nbytes); }