Bug 1264948 - Make it possible to use a placement-new with a fallible TempAllocator. r=h4writer

This commit is contained in:
Nicolas B. Pierron 2016-06-01 14:43:31 +00:00
parent e9b8a82345
commit 0619381333
2 changed files with 9 additions and 6 deletions

View File

@ -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 {

View File

@ -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);
}