remove lots of unnecessary sizeof computations with a convenient 'operator new' overload

This commit is contained in:
Joshua Warner 2012-05-08 16:13:17 -06:00
parent fde7a3e7a1
commit fa9814b86d
7 changed files with 92 additions and 141 deletions

View File

@ -57,4 +57,8 @@ copy(Allocator* allocator, const char* a)
} // namespace vm } // namespace vm
inline void* operator new (size_t size, vm::Allocator* allocator) {
return allocator->allocate(size);
}
#endif//ALLOCATOR_H #endif//ALLOCATOR_H

View File

@ -228,7 +228,7 @@ class Context {
public: public:
Context(System* s, Allocator* a, Zone* zone): Context(System* s, Allocator* a, Zone* zone):
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0), s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
firstBlock(new (zone->allocate(sizeof(MyBlock))) MyBlock(this, 0)), firstBlock(new(zone) MyBlock(this, 0)),
lastBlock(firstBlock), poolOffsetHead(0), poolOffsetTail(0), lastBlock(firstBlock), poolOffsetHead(0), poolOffsetTail(0),
constantPool(0), constantPoolCount(0) constantPool(0), constantPoolCount(0)
{ } { }
@ -346,8 +346,7 @@ class Offset: public Promise {
Promise* Promise*
offset(Context* c, bool forTrace = false) offset(Context* c, bool forTrace = false)
{ {
return new (c->zone->allocate(sizeof(Offset))) return new(c->zone) Offset(c, c->lastBlock, c->code.length(), forTrace);
Offset(c, c->lastBlock, c->code.length(), forTrace);
} }
bool bool
@ -414,8 +413,7 @@ class OffsetTask: public Task {
void void
appendOffsetTask(Context* c, Promise* promise, Promise* instructionOffset) appendOffsetTask(Context* c, Promise* promise, Promise* instructionOffset)
{ {
c->tasks = new (c->zone->allocate(sizeof(OffsetTask))) OffsetTask c->tasks = new(c->zone) OffsetTask(c->tasks, promise, instructionOffset);
(c->tasks, promise, instructionOffset);
} }
inline unsigned inline unsigned
@ -628,17 +626,14 @@ appendConstantPoolEntry(Context* c, Promise* constant, Promise* callOffset)
if (constant->resolved()) { if (constant->resolved()) {
// make a copy, since the original might be allocated on the // make a copy, since the original might be allocated on the
// stack, and we need our copy to live until assembly is complete // stack, and we need our copy to live until assembly is complete
constant = new (c->zone->allocate(sizeof(ResolvedPromise))) constant = new(c->zone) ResolvedPromise(constant->value());
ResolvedPromise(constant->value());
} }
c->constantPool = new (c->zone->allocate(sizeof(ConstantPoolEntry))) c->constantPool = new(c->zone) ConstantPoolEntry(c, constant, c->constantPool, callOffset);
ConstantPoolEntry(c, constant, c->constantPool, callOffset);
++ c->constantPoolCount; ++ c->constantPoolCount;
PoolOffset* o = new (c->zone->allocate(sizeof(PoolOffset))) PoolOffset PoolOffset* o = new(c->zone) PoolOffset(c->lastBlock, c->constantPool, c->code.length() - c->lastBlock->offset);
(c->lastBlock, c->constantPool, c->code.length() - c->lastBlock->offset);
if (DebugPool) { if (DebugPool) {
fprintf(stderr, "add pool offset %p %d to block %p\n", fprintf(stderr, "add pool offset %p %d to block %p\n",
@ -657,8 +652,7 @@ void
appendPoolEvent(Context* c, MyBlock* b, unsigned offset, PoolOffset* head, appendPoolEvent(Context* c, MyBlock* b, unsigned offset, PoolOffset* head,
PoolOffset* tail) PoolOffset* tail)
{ {
PoolEvent* e = new (c->zone->allocate(sizeof(PoolEvent))) PoolEvent PoolEvent* e = new(c->zone) PoolEvent(head, tail, offset);
(head, tail, offset);
if (b->poolEventTail) { if (b->poolEventTail) {
b->poolEventTail->next = e; b->poolEventTail->next = e;
@ -1522,8 +1516,7 @@ branchCM(Context* c, TernaryOperation op, unsigned size,
ShiftMaskPromise* ShiftMaskPromise*
shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask) shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask)
{ {
return new (c->zone->allocate(sizeof(ShiftMaskPromise))) return new(c->zone) ShiftMaskPromise(base, shift, mask);
ShiftMaskPromise(base, shift, mask);
} }
void void
@ -2158,9 +2151,7 @@ class MyAssembler: public Assembler {
{ {
Register stack(StackRegister); Register stack(StackRegister);
Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread); Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread);
Constant handlerConstant Constant handlerConstant(new(c.zone) ResolvedPromise(handler));
(new (c.zone->allocate(sizeof(ResolvedPromise)))
ResolvedPromise(handler));
branchRM(&c, JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, branchRM(&c, JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit,
&handlerConstant); &handlerConstant);
} }
@ -2465,8 +2456,7 @@ class MyAssembler: public Assembler {
MyBlock* b = c.lastBlock; MyBlock* b = c.lastBlock;
b->size = c.code.length() - b->offset; b->size = c.code.length() - b->offset;
if (startNew) { if (startNew) {
c.lastBlock = new (c.zone->allocate(sizeof(MyBlock))) c.lastBlock = new (c.zone) MyBlock(&c, c.code.length());
MyBlock(&c, c.code.length());
} else { } else {
c.lastBlock = 0; c.lastBlock = 0;
} }
@ -2537,8 +2527,7 @@ Assembler*
makeAssembler(System* system, Allocator* allocator, Zone* zone, makeAssembler(System* system, Allocator* allocator, Zone* zone,
Assembler::Architecture* architecture) Assembler::Architecture* architecture)
{ {
return new (zone->allocate(sizeof(MyAssembler))) return new(zone) MyAssembler(system, allocator, zone,
MyAssembler(system, allocator, zone,
static_cast<MyArchitecture*>(architecture)); static_cast<MyArchitecture*>(architecture));
} }

View File

@ -1389,8 +1389,7 @@ class Frame {
Compiler::Operand* append(object o) { Compiler::Operand* append(object o) {
BootContext* bc = context->bootContext; BootContext* bc = context->bootContext;
if (bc) { if (bc) {
Promise* p = new (bc->zone->allocate(sizeof(ListenPromise))) Promise* p = new (bc->zone) ListenPromise(t->m->system, bc->zone);
ListenPromise(t->m->system, bc->zone);
PROTECT(t, o); PROTECT(t, o);
object pointer = makePointer(t, p); object pointer = makePointer(t, p);
@ -1408,9 +1407,7 @@ class Frame {
} }
} }
context->objectPool = new context->objectPool = new(&context->zone) PoolElement(t, o, context->objectPool);
(context->zone.allocate(sizeof(PoolElement)))
PoolElement(t, o, context->objectPool);
++ context->objectPoolCount; ++ context->objectPoolCount;
@ -1615,8 +1612,7 @@ class Frame {
Promise* addressPromise(Promise* p) { Promise* addressPromise(Promise* p) {
BootContext* bc = context->bootContext; BootContext* bc = context->bootContext;
if (bc) { if (bc) {
bc->addresses = new (bc->zone->allocate(sizeof(DelayedPromise))) bc->addresses = new(bc->zone) DelayedPromise(t->m->system, bc->zone, p, bc->addresses);
DelayedPromise(t->m->system, bc->zone, p, bc->addresses);
return bc->addresses; return bc->addresses;
} else { } else {
return p; return p;
@ -1633,7 +1629,7 @@ class Frame {
(TargetBytesPerWord, c->memory (TargetBytesPerWord, c->memory
(c->register_(t->arch->thread()), Compiler::AddressType, (c->register_(t->arch->thread()), Compiler::AddressType,
TargetThreadCodeImage), c->promiseConstant TargetThreadCodeImage), c->promiseConstant
(new (context->zone.allocate(sizeof(OffsetPromise))) (new(&context->zone)
OffsetPromise OffsetPromise
(p, - reinterpret_cast<intptr_t>(codeAllocator(t)->base)), (p, - reinterpret_cast<intptr_t>(codeAllocator(t)->base)),
Compiler::AddressType)) Compiler::AddressType))
@ -3417,8 +3413,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall)
and (not (TailCalls and tailCall and (not (TailCalls and tailCall
and (methodFlags(t, target) & ACC_NATIVE)))) and (methodFlags(t, target) & ACC_NATIVE))))
{ {
Promise* p = new (bc->zone->allocate(sizeof(ListenPromise))) Promise* p = new(bc->zone) ListenPromise(t->m->system, bc->zone);
ListenPromise(t->m->system, bc->zone);
PROTECT(t, target); PROTECT(t, target);
object pointer = makePointer(t, p); object pointer = makePointer(t, p);
@ -6636,7 +6631,7 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots,
} }
if (path == 0) { if (path == 0) {
path = new (context->zone.allocate(sizeof(SubroutinePath))) path = new(&context->zone)
SubroutinePath(call, subroutinePath, SubroutinePath(call, subroutinePath,
makeRootTable(t, &(context->zone), context->method)); makeRootTable(t, &(context->zone), context->method));
} }
@ -7061,8 +7056,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context)
p != bc->addressSentinal; p != bc->addressSentinal;
p = p->next) p = p->next)
{ {
p->basis = new (bc->zone->allocate(sizeof(ResolvedPromise))) p->basis = new(bc->zone) ResolvedPromise(p->basis->value());
ResolvedPromise(p->basis->value());
} }
} }
@ -9724,8 +9718,7 @@ compileCall(MyThread* t, Context* c, ThunkIndex index, bool call = true)
(call ? Call : Jump, TargetBytesPerWord, RegisterOperand, &scratch); (call ? Call : Jump, TargetBytesPerWord, RegisterOperand, &scratch);
} else { } else {
Assembler::Constant proc Assembler::Constant proc
(new (c->zone.allocate(sizeof(ResolvedPromise))) (new(&c->zone) ResolvedPromise(reinterpret_cast<intptr_t>(t->thunkTable[index])));
ResolvedPromise(reinterpret_cast<intptr_t>(t->thunkTable[index])));
a->apply a->apply
(call ? LongCall : LongJump, TargetBytesPerWord, ConstantOperand, &proc); (call ? LongCall : LongJump, TargetBytesPerWord, ConstantOperand, &proc);

View File

@ -576,7 +576,7 @@ count(Cell* c)
Cell* Cell*
cons(Context* c, void* value, Cell* next) cons(Context* c, void* value, Cell* next)
{ {
return new (c->zone->allocate(sizeof(Cell))) Cell(next, value); return new (c->zone) Cell(next, value);
} }
Cell* Cell*
@ -648,7 +648,7 @@ Link*
link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor, link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor,
Link* nextSuccessor, ForkState* forkState) Link* nextSuccessor, ForkState* forkState)
{ {
return new (c->zone->allocate(sizeof(Link))) Link return new(c->zone) Link
(predecessor, nextPredecessor, successor, nextSuccessor, forkState); (predecessor, nextPredecessor, successor, nextSuccessor, forkState);
} }
@ -1602,15 +1602,13 @@ constantSite(Context* c, Promise* value);
ShiftMaskPromise* ShiftMaskPromise*
shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask) shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask)
{ {
return new (c->zone->allocate(sizeof(ShiftMaskPromise))) return new(c->zone) ShiftMaskPromise(base, shift, mask);
ShiftMaskPromise(base, shift, mask);
} }
CombinedPromise* CombinedPromise*
combinedPromise(Context* c, Promise* low, Promise* high) combinedPromise(Context* c, Promise* low, Promise* high)
{ {
return new (c->zone->allocate(sizeof(CombinedPromise))) return new(c->zone) CombinedPromise(low, high);
CombinedPromise(low, high);
} }
class ConstantSite: public Site { class ConstantSite: public Site {
@ -1686,14 +1684,13 @@ class ConstantSite: public Site {
ConstantSite* ConstantSite*
constantSite(Context* c, Promise* value) constantSite(Context* c, Promise* value)
{ {
return new (c->zone->allocate(sizeof(ConstantSite))) ConstantSite(value); return new(c->zone) ConstantSite(value);
} }
ResolvedPromise* ResolvedPromise*
resolved(Context* c, int64_t value) resolved(Context* c, int64_t value)
{ {
return new (c->zone->allocate(sizeof(ResolvedPromise))) return new(c->zone) ResolvedPromise(value);
ResolvedPromise(value);
} }
ConstantSite* ConstantSite*
@ -1776,7 +1773,7 @@ class AddressSite: public Site {
AddressSite* AddressSite*
addressSite(Context* c, Promise* address) addressSite(Context* c, Promise* address)
{ {
return new (c->zone->allocate(sizeof(AddressSite))) AddressSite(address); return new(c->zone) AddressSite(address);
} }
RegisterSite* RegisterSite*
@ -1978,15 +1975,13 @@ registerSite(Context* c, int number)
assert(c, (1 << number) & (c->arch->generalRegisterMask() assert(c, (1 << number) & (c->arch->generalRegisterMask()
| c->arch->floatRegisterMask())); | c->arch->floatRegisterMask()));
return new (c->zone->allocate(sizeof(RegisterSite))) return new(c->zone) RegisterSite(1 << number, number);
RegisterSite(1 << number, number);
} }
RegisterSite* RegisterSite*
freeRegisterSite(Context* c, uint32_t mask) freeRegisterSite(Context* c, uint32_t mask)
{ {
return new (c->zone->allocate(sizeof(RegisterSite))) return new(c->zone) RegisterSite(mask, NoRegister);
RegisterSite(mask, NoRegister);
} }
MemorySite* MemorySite*
@ -2219,8 +2214,7 @@ class MemorySite: public Site {
MemorySite* MemorySite*
memorySite(Context* c, int base, int offset, int index, unsigned scale) memorySite(Context* c, int base, int offset, int index, unsigned scale)
{ {
return new (c->zone->allocate(sizeof(MemorySite))) return new(c->zone) MemorySite(base, offset, index, scale);
MemorySite(base, offset, index, scale);
} }
MemorySite* MemorySite*
@ -2341,8 +2335,7 @@ read(Context* c, const SiteMask& mask, Value* successor = 0)
{ {
assert(c, (mask.typeMask != 1 << MemoryOperand) or mask.frameIndex >= 0); assert(c, (mask.typeMask != 1 << MemoryOperand) or mask.frameIndex >= 0);
return new (c->zone->allocate(sizeof(SingleRead))) return new(c->zone) SingleRead(mask, successor);
SingleRead(mask, successor);
} }
bool bool
@ -2762,7 +2755,7 @@ class MultiRead: public Read {
MultiRead* MultiRead*
multiRead(Context* c) multiRead(Context* c)
{ {
return new (c->zone->allocate(sizeof(MultiRead))) MultiRead; return new(c->zone) MultiRead;
} }
class StubRead: public Read { class StubRead: public Read {
@ -2811,7 +2804,7 @@ class StubRead: public Read {
StubRead* StubRead*
stubRead(Context* c) stubRead(Context* c)
{ {
return new (c->zone->allocate(sizeof(StubRead))) StubRead; return new(c->zone) StubRead;
} }
Site* Site*
@ -3121,15 +3114,13 @@ clean(Context* c, Event* e, Stack* stack, Local* locals, Read* reads,
CodePromise* CodePromise*
codePromise(Context* c, Event* e) codePromise(Context* c, Event* e)
{ {
return e->promises = new (c->zone->allocate(sizeof(CodePromise))) return e->promises = new(c->zone) CodePromise(c, e->promises);
CodePromise(c, e->promises);
} }
CodePromise* CodePromise*
codePromise(Context* c, Promise* offset) codePromise(Context* c, Promise* offset)
{ {
return new (c->zone->allocate(sizeof(CodePromise))) return new (c->zone) CodePromise(c, offset);
CodePromise(c, offset);
} }
void void
@ -3467,7 +3458,7 @@ appendCall(Context* c, Value* address, unsigned flags,
Stack* argumentStack, unsigned argumentCount, Stack* argumentStack, unsigned argumentCount,
unsigned stackArgumentFootprint) unsigned stackArgumentFootprint)
{ {
append(c, new (c->zone->allocate(sizeof(CallEvent))) append(c, new(c->zone)
CallEvent(c, address, flags, traceHandler, result, CallEvent(c, address, flags, traceHandler, result,
resultSize, argumentStack, argumentCount, resultSize, argumentStack, argumentCount,
stackArgumentFootprint)); stackArgumentFootprint));
@ -3515,8 +3506,7 @@ class ReturnEvent: public Event {
void void
appendReturn(Context* c, unsigned size, Value* value) appendReturn(Context* c, unsigned size, Value* value)
{ {
append(c, new (c->zone->allocate(sizeof(ReturnEvent))) append(c, new(c->zone) ReturnEvent(c, size, value));
ReturnEvent(c, size, value));
} }
void void
@ -3714,7 +3704,7 @@ pickSiteOrMove(Context* c, Value* src, Value* dst, Site* nextWord,
Value* Value*
value(Context* c, ValueType type, Site* site = 0, Site* target = 0) value(Context* c, ValueType type, Site* site = 0, Site* target = 0)
{ {
return new (c->zone->allocate(sizeof(Value))) Value(site, target, type); return new(c->zone) Value(site, target, type);
} }
void void
@ -3914,7 +3904,7 @@ appendMove(Context* c, BinaryOperation type, unsigned srcSize,
assert(c, not thunk); assert(c, not thunk);
append(c, new (c->zone->allocate(sizeof(MoveEvent))) append(c, new(c->zone)
MoveEvent MoveEvent
(c, type, srcSize, srcSelectSize, src, dstSize, dst, (c, type, srcSize, srcSelectSize, src, dstSize, dst,
SiteMask(srcTypeMask, srcRegisterMask, AnyFrameIndex), SiteMask(srcTypeMask, srcRegisterMask, AnyFrameIndex),
@ -4173,7 +4163,7 @@ snapshot(Context* c, Value* value, Snapshot* next)
value, value->buddy, buffer); value, value->buddy, buffer);
} }
return new (c->zone->allocate(sizeof(Snapshot))) Snapshot(c, value, next); return new(c->zone) Snapshot(c, value, next);
} }
Snapshot* Snapshot*
@ -4189,8 +4179,7 @@ makeSnapshots(Context* c, Value* value, Snapshot* next)
Stack* Stack*
stack(Context* c, Value* value, Stack* next) stack(Context* c, Value* value, Stack* next)
{ {
return new (c->zone->allocate(sizeof(Stack))) return new(c->zone) Stack(next ? next->index + 1 : 0, value, next);
Stack(next ? next->index + 1 : 0, value, next);
} }
Value* Value*
@ -4450,7 +4439,7 @@ appendCombine(Context* c, TernaryOperation type,
resultSize, argumentStack, stackSize, 0); resultSize, argumentStack, stackSize, 0);
} else { } else {
append append
(c, new (c->zone->allocate(sizeof(CombineEvent))) (c, new(c->zone)
CombineEvent CombineEvent
(c, type, (c, type,
firstSize, first, firstSize, first,
@ -4568,7 +4557,7 @@ appendTranslate(Context* c, BinaryOperation type, unsigned firstSize,
0, 0, result, resultSize, argumentStack, 0, 0, result, resultSize, argumentStack,
ceiling(firstSize, TargetBytesPerWord), 0); ceiling(firstSize, TargetBytesPerWord), 0);
} else { } else {
append(c, new (c->zone->allocate(sizeof(TranslateEvent))) append(c, new(c->zone)
TranslateEvent TranslateEvent
(c, type, firstSize, first, resultSize, result, (c, type, firstSize, first, resultSize, result,
SiteMask(firstTypeMask, firstRegisterMask, AnyFrameIndex), SiteMask(firstTypeMask, firstRegisterMask, AnyFrameIndex),
@ -4597,7 +4586,7 @@ void
appendOperation(Context* c, Operation op) appendOperation(Context* c, Operation op)
{ {
append append
(c, new (c->zone->allocate(sizeof(OperationEvent))) OperationEvent(c, op)); (c, new(c->zone) OperationEvent(c, op));
} }
class MemoryEvent: public Event { class MemoryEvent: public Event {
@ -4677,7 +4666,7 @@ void
appendMemory(Context* c, Value* base, int displacement, Value* index, appendMemory(Context* c, Value* base, int displacement, Value* index,
unsigned scale, Value* result) unsigned scale, Value* result)
{ {
append(c, new (c->zone->allocate(sizeof(MemoryEvent))) append(c, new(c->zone)
MemoryEvent(c, base, displacement, index, scale, result)); MemoryEvent(c, base, displacement, index, scale, result));
} }
@ -4908,7 +4897,7 @@ appendBranch(Context* c, TernaryOperation type, unsigned size, Value* first,
result, address); result, address);
} else { } else {
append append
(c, new (c->zone->allocate(sizeof(BranchEvent))) (c, new(c->zone)
BranchEvent BranchEvent
(c, type, size, first, second, address, (c, type, size, first, second, address,
SiteMask(firstTypeMask, firstRegisterMask, AnyFrameIndex), SiteMask(firstTypeMask, firstRegisterMask, AnyFrameIndex),
@ -4972,8 +4961,7 @@ void
appendJump(Context* c, UnaryOperation type, Value* address, bool exit = false, appendJump(Context* c, UnaryOperation type, Value* address, bool exit = false,
bool cleanLocals = false) bool cleanLocals = false)
{ {
append(c, new (c->zone->allocate(sizeof(JumpEvent))) append(c, new(c->zone) JumpEvent(c, type, address, exit, cleanLocals));
JumpEvent(c, type, address, exit, cleanLocals));
} }
class BoundsCheckEvent: public Event { class BoundsCheckEvent: public Event {
@ -5051,8 +5039,7 @@ void
appendBoundsCheck(Context* c, Value* object, unsigned lengthOffset, appendBoundsCheck(Context* c, Value* object, unsigned lengthOffset,
Value* index, intptr_t handler) Value* index, intptr_t handler)
{ {
append(c, new (c->zone->allocate(sizeof(BoundsCheckEvent))) append(c, new(c->zone) BoundsCheckEvent(c, object, lengthOffset, index, handler));
BoundsCheckEvent(c, object, lengthOffset, index, handler));
} }
class FrameSiteEvent: public Event { class FrameSiteEvent: public Event {
@ -5078,8 +5065,7 @@ class FrameSiteEvent: public Event {
void void
appendFrameSite(Context* c, Value* value, int index) appendFrameSite(Context* c, Value* value, int index)
{ {
append(c, new (c->zone->allocate(sizeof(FrameSiteEvent))) append(c, new(c->zone) FrameSiteEvent(c, value, index));
FrameSiteEvent(c, value, index));
} }
unsigned unsigned
@ -5157,8 +5143,7 @@ class BuddyEvent: public Event {
void void
appendBuddy(Context* c, Value* original, Value* buddy) appendBuddy(Context* c, Value* original, Value* buddy)
{ {
append(c, new (c->zone->allocate(sizeof(BuddyEvent))) append(c, new(c->zone) BuddyEvent(c, original, buddy));
BuddyEvent(c, original, buddy));
} }
class SaveLocalsEvent: public Event { class SaveLocalsEvent: public Event {
@ -5183,8 +5168,7 @@ class SaveLocalsEvent: public Event {
void void
appendSaveLocals(Context* c) appendSaveLocals(Context* c)
{ {
append(c, new (c->zone->allocate(sizeof(SaveLocalsEvent))) append(c, new(c->zone) SaveLocalsEvent(c));
SaveLocalsEvent(c));
} }
class DummyEvent: public Event { class DummyEvent: public Event {
@ -5210,7 +5194,7 @@ appendDummy(Context* c)
c->stack = i->stack; c->stack = i->stack;
c->locals = i->locals; c->locals = i->locals;
append(c, new (c->zone->allocate(sizeof(DummyEvent))) DummyEvent(c)); append(c, new(c->zone) DummyEvent(c));
c->stack = stack; c->stack = stack;
c->locals = locals; c->locals = locals;
@ -5746,7 +5730,7 @@ class Block {
Block* Block*
block(Context* c, Event* head) block(Context* c, Event* head)
{ {
return new (c->zone->allocate(sizeof(Block))) Block(head); return new(c->zone) Block(head);
} }
void void
@ -6057,8 +6041,7 @@ class MyCompiler: public Compiler {
} }
virtual Subroutine* startSubroutine() { virtual Subroutine* startSubroutine() {
return c.subroutine = new (c.zone->allocate(sizeof(MySubroutine))) return c.subroutine = new(c.zone) MySubroutine;
MySubroutine;
} }
virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) { virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) {
@ -6199,7 +6182,7 @@ class MyCompiler: public Compiler {
} }
virtual Promise* machineIp(unsigned logicalIp) { virtual Promise* machineIp(unsigned logicalIp) {
return new (c.zone->allocate(sizeof(IpPromise))) IpPromise(&c, logicalIp); return new(c.zone) IpPromise(&c, logicalIp);
} }
virtual Promise* poolAppend(intptr_t value) { virtual Promise* poolAppend(intptr_t value) {
@ -6207,12 +6190,9 @@ class MyCompiler: public Compiler {
} }
virtual Promise* poolAppendPromise(Promise* value) { virtual Promise* poolAppendPromise(Promise* value) {
Promise* p = new (c.zone->allocate(sizeof(PoolPromise))) Promise* p = new(c.zone) PoolPromise(&c, c.constantCount);
PoolPromise(&c, c.constantCount);
ConstantPoolNode* constant ConstantPoolNode* constant = new (c.zone) ConstantPoolNode(value);
= new (c.zone->allocate(sizeof(ConstantPoolNode)))
ConstantPoolNode(value);
if (c.firstConstant) { if (c.firstConstant) {
c.lastConstant->next = constant; c.lastConstant->next = constant;
@ -6997,8 +6977,7 @@ Compiler*
makeCompiler(System* system, Assembler* assembler, Zone* zone, makeCompiler(System* system, Assembler* assembler, Zone* zone,
Compiler::Client* client) Compiler::Client* client)
{ {
return new (zone->allocate(sizeof(local::MyCompiler))) return new(zone) local::MyCompiler(system, assembler, zone, client);
local::MyCompiler(system, assembler, zone, client);
} }
} // namespace vm } // namespace vm

View File

@ -233,7 +233,7 @@ class Context {
public: public:
Context(System* s, Allocator* a, Zone* zone): Context(System* s, Allocator* a, Zone* zone):
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0), s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
firstBlock(new (zone->allocate(sizeof(MyBlock))) MyBlock(this, 0)), firstBlock(new(zone) MyBlock(this, 0)),
lastBlock(firstBlock), jumpOffsetHead(0), jumpOffsetTail(0), lastBlock(firstBlock), jumpOffsetHead(0), jumpOffsetTail(0),
constantPool(0), constantPoolCount(0) constantPool(0), constantPoolCount(0)
{ } { }
@ -349,8 +349,7 @@ class Offset: public Promise {
Promise* Promise*
offset(Context* c) offset(Context* c)
{ {
return new (c->zone->allocate(sizeof(Offset))) return new(c->zone) Offset(c, c->lastBlock, c->code.length());
Offset(c, c->lastBlock, c->code.length());
} }
bool bool
@ -468,14 +467,13 @@ void
appendOffsetTask(Context* c, Promise* promise, Promise* instructionOffset, appendOffsetTask(Context* c, Promise* promise, Promise* instructionOffset,
bool conditional) bool conditional)
{ {
OffsetTask* task = new (c->zone->allocate(sizeof(OffsetTask))) OffsetTask OffsetTask* task = new(c->zone) OffsetTask(c->tasks, promise, instructionOffset, conditional);
(c->tasks, promise, instructionOffset, conditional);
c->tasks = task; c->tasks = task;
if (conditional) { if (conditional) {
JumpOffset* offset = new (c->zone->allocate(sizeof(JumpOffset))) JumpOffset JumpOffset* offset =
(c->lastBlock, task, c->code.length() - c->lastBlock->offset); new(c->zone) JumpOffset(c->lastBlock, task, c->code.length() - c->lastBlock->offset);
if (c->lastBlock->jumpOffsetTail) { if (c->lastBlock->jumpOffsetTail) {
c->lastBlock->jumpOffsetTail->next = offset; c->lastBlock->jumpOffsetTail->next = offset;
@ -490,7 +488,7 @@ void
appendJumpEvent(Context* c, MyBlock* b, unsigned offset, JumpOffset* head, appendJumpEvent(Context* c, MyBlock* b, unsigned offset, JumpOffset* head,
JumpOffset* tail) JumpOffset* tail)
{ {
JumpEvent* e = new (c->zone->allocate(sizeof(JumpEvent))) JumpEvent JumpEvent* e = new(c->zone) JumpEvent
(head, tail, offset); (head, tail, offset);
if (b->jumpEventTail) { if (b->jumpEventTail) {
@ -858,8 +856,7 @@ void
appendImmediateTask(Context* c, Promise* promise, Promise* offset, appendImmediateTask(Context* c, Promise* promise, Promise* offset,
unsigned size, unsigned promiseOffset, bool address) unsigned size, unsigned promiseOffset, bool address)
{ {
c->tasks = new (c->zone->allocate(sizeof(ImmediateTask))) ImmediateTask c->tasks = new(c->zone) ImmediateTask(c->tasks, promise, offset, size, promiseOffset, address);
(c->tasks, promise, offset, size, promiseOffset, address);
} }
class ConstantPoolEntry: public Promise { class ConstantPoolEntry: public Promise {
@ -890,8 +887,7 @@ class ConstantPoolEntry: public Promise {
ConstantPoolEntry* ConstantPoolEntry*
appendConstantPoolEntry(Context* c, Promise* constant) appendConstantPoolEntry(Context* c, Promise* constant)
{ {
return new (c->zone->allocate(sizeof(ConstantPoolEntry))) return new (c->zone) ConstantPoolEntry(c, constant);
ConstantPoolEntry(c, constant);
} }
void void
@ -1785,8 +1781,7 @@ branchCM(Context* c, TernaryOperation op, unsigned size,
ShiftMaskPromise* ShiftMaskPromise*
shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask) shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask)
{ {
return new (c->zone->allocate(sizeof(ShiftMaskPromise))) return new (c->zone) ShiftMaskPromise(base, shift, mask);
ShiftMaskPromise(base, shift, mask);
} }
void void
@ -2462,8 +2457,7 @@ class MyAssembler: public Assembler {
Register stack(StackRegister); Register stack(StackRegister);
Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread); Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread);
Constant handlerConstant Constant handlerConstant
(new (c.zone->allocate(sizeof(ResolvedPromise))) (new(c.zone) ResolvedPromise(handler));
ResolvedPromise(handler));
branchRM(&c, JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, branchRM(&c, JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit,
&handlerConstant); &handlerConstant);
} }
@ -2783,8 +2777,7 @@ class MyAssembler: public Assembler {
MyBlock* b = c.lastBlock; MyBlock* b = c.lastBlock;
b->size = c.code.length() - b->offset; b->size = c.code.length() - b->offset;
if (startNew) { if (startNew) {
c.lastBlock = new (c.zone->allocate(sizeof(MyBlock))) c.lastBlock = new(c.zone) MyBlock(&c, c.code.length());
MyBlock(&c, c.code.length());
} else { } else {
c.lastBlock = 0; c.lastBlock = 0;
} }
@ -2855,9 +2848,9 @@ Assembler*
makeAssembler(System* system, Allocator* allocator, Zone* zone, makeAssembler(System* system, Allocator* allocator, Zone* zone,
Assembler::Architecture* architecture) Assembler::Architecture* architecture)
{ {
return new (zone->allocate(sizeof(MyAssembler))) return
MyAssembler(system, allocator, zone, new(zone) MyAssembler(system, allocator, zone,
static_cast<MyArchitecture*>(architecture)); static_cast<MyArchitecture*>(architecture));
} }
} // namespace vm } // namespace vm

View File

@ -58,8 +58,7 @@ class TreeContext {
TreeContext::Path* TreeContext::Path*
path(TreeContext* c, object node, TreeContext::Path* next) path(TreeContext* c, object node, TreeContext::Path* next)
{ {
return new (c->zone->allocate(sizeof(TreeContext::Path))) return new(c->zone) TreeContext::Path(node, next);
TreeContext::Path(node, next);
} }
inline object inline object

View File

@ -157,7 +157,7 @@ class Context {
public: public:
Context(System* s, Allocator* a, Zone* zone, ArchitectureContext* ac): Context(System* s, Allocator* a, Zone* zone, ArchitectureContext* ac):
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0), s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
firstBlock(new (zone->allocate(sizeof(MyBlock))) MyBlock(0)), firstBlock(new(zone) MyBlock(0)),
lastBlock(firstBlock), ac(ac) lastBlock(firstBlock), ac(ac)
{ } { }
@ -207,8 +207,7 @@ expect(Context* c, bool v)
ResolvedPromise* ResolvedPromise*
resolved(Context* c, int64_t value) resolved(Context* c, int64_t value)
{ {
return new (c->zone->allocate(sizeof(ResolvedPromise))) return new(c->zone) ResolvedPromise(value);
ResolvedPromise(value);
} }
class CodePromise: public Promise { class CodePromise: public Promise {
@ -234,7 +233,7 @@ class CodePromise: public Promise {
CodePromise* CodePromise*
codePromise(Context* c, unsigned offset) codePromise(Context* c, unsigned offset)
{ {
return new (c->zone->allocate(sizeof(CodePromise))) CodePromise(c, offset); return new (c->zone) CodePromise(c, offset);
} }
class Offset: public Promise { class Offset: public Promise {
@ -268,8 +267,7 @@ class Offset: public Promise {
Promise* Promise*
offset(Context* c) offset(Context* c)
{ {
return new (c->zone->allocate(sizeof(Offset))) return new(c->zone) Offset(c, c->lastBlock, c->code.length(), c->lastBlock->lastPadding);
Offset(c, c->lastBlock, c->code.length(), c->lastBlock->lastPadding);
} }
class Task { class Task {
@ -346,8 +344,8 @@ void
appendOffsetTask(Context* c, Promise* promise, Promise* instructionOffset, appendOffsetTask(Context* c, Promise* promise, Promise* instructionOffset,
unsigned instructionSize) unsigned instructionSize)
{ {
OffsetTask* task = new (c->zone->allocate(sizeof(OffsetTask))) OffsetTask OffsetTask* task =
(c->tasks, promise, instructionOffset, instructionSize); new(c->zone) OffsetTask(c->tasks, promise, instructionOffset, instructionSize);
c->tasks = task; c->tasks = task;
} }
@ -418,7 +416,7 @@ void
appendImmediateTask(Context* c, Promise* promise, Promise* offset, appendImmediateTask(Context* c, Promise* promise, Promise* offset,
unsigned size, unsigned promiseOffset = 0) unsigned size, unsigned promiseOffset = 0)
{ {
c->tasks = new (c->zone->allocate(sizeof(ImmediateTask))) ImmediateTask c->tasks = new(c->zone) ImmediateTask
(c->tasks, promise, offset, size, promiseOffset); (c->tasks, promise, offset, size, promiseOffset);
} }
@ -839,7 +837,7 @@ callM(Context* c, unsigned size UNUSED, Assembler::Memory* a)
void void
alignedCallC(Context* c, unsigned size, Assembler::Constant* a) alignedCallC(Context* c, unsigned size, Assembler::Constant* a)
{ {
new (c->zone->allocate(sizeof(AlignmentPadding))) AlignmentPadding(c, 1, 4); new(c->zone) AlignmentPadding(c, 1, 4);
callC(c, size, a); callC(c, size, a);
} }
@ -849,8 +847,7 @@ alignedLongCallC(Context* c, unsigned size, Assembler::Constant* a)
assert(c, size == TargetBytesPerWord); assert(c, size == TargetBytesPerWord);
if (TargetBytesPerWord == 8) { if (TargetBytesPerWord == 8) {
new (c->zone->allocate(sizeof(AlignmentPadding))) new (c->zone) AlignmentPadding(c, 2, 8);
AlignmentPadding(c, 2, 8);
longCallC(c, size, a); longCallC(c, size, a);
} else { } else {
alignedCallC(c, size, a); alignedCallC(c, size, a);
@ -860,7 +857,7 @@ alignedLongCallC(Context* c, unsigned size, Assembler::Constant* a)
void void
alignedJumpC(Context* c, unsigned size, Assembler::Constant* a) alignedJumpC(Context* c, unsigned size, Assembler::Constant* a)
{ {
new (c->zone->allocate(sizeof(AlignmentPadding))) AlignmentPadding(c, 1, 4); new (c->zone) AlignmentPadding(c, 1, 4);
jumpC(c, size, a); jumpC(c, size, a);
} }
@ -870,8 +867,7 @@ alignedLongJumpC(Context* c, unsigned size, Assembler::Constant* a)
assert(c, size == TargetBytesPerWord); assert(c, size == TargetBytesPerWord);
if (TargetBytesPerWord == 8) { if (TargetBytesPerWord == 8) {
new (c->zone->allocate(sizeof(AlignmentPadding))) new (c->zone) AlignmentPadding(c, 2, 8);
AlignmentPadding(c, 2, 8);
longJumpC(c, size, a); longJumpC(c, size, a);
} else { } else {
alignedJumpC(c, size, a); alignedJumpC(c, size, a);
@ -1296,8 +1292,7 @@ moveAR(Context* c, unsigned aSize, Assembler::Address* a,
ShiftMaskPromise* ShiftMaskPromise*
shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask) shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask)
{ {
return new (c->zone->allocate(sizeof(ShiftMaskPromise))) return new(c->zone) ShiftMaskPromise(base, shift, mask);
ShiftMaskPromise(base, shift, mask);
} }
void void
@ -3707,8 +3702,7 @@ class MyAssembler: public Assembler {
MyBlock* b = c.lastBlock; MyBlock* b = c.lastBlock;
b->size = c.code.length() - b->offset; b->size = c.code.length() - b->offset;
if (startNew) { if (startNew) {
c.lastBlock = new (c.zone->allocate(sizeof(MyBlock))) c.lastBlock = new(c.zone) MyBlock(c.code.length());
MyBlock(c.code.length());
} else { } else {
c.lastBlock = 0; c.lastBlock = 0;
} }
@ -3752,9 +3746,9 @@ Assembler*
makeAssembler(System* system, Allocator* allocator, Zone* zone, makeAssembler(System* system, Allocator* allocator, Zone* zone,
Assembler::Architecture* architecture) Assembler::Architecture* architecture)
{ {
return new (zone->allocate(sizeof(local::MyAssembler))) return
local::MyAssembler(system, allocator, zone, new(zone) local::MyAssembler(system, allocator, zone,
static_cast<local::MyArchitecture*>(architecture)); static_cast<local::MyArchitecture*>(architecture));
} }
} // namespace vm } // namespace vm