Commit 5281aab8 authored by Marius Wachtler's avatar Marius Wachtler

rewriter: clean up memory managment.

It deleted the passed ICSlotRewrite* and there was no way for a caller to know this without looking at the source.
Make the ownership explicit by using a std::unique_ptr
parent b1b07129
......@@ -151,8 +151,8 @@ assembler::GenericRegister ICSlotRewrite::returnRegister() {
ICSlotRewrite* ICInfo::startRewrite(const char* debug_name) {
return new ICSlotRewrite(this, debug_name);
std::unique_ptr<ICSlotRewrite> ICInfo::startRewrite(const char* debug_name) {
return std::unique_ptr<ICSlotRewrite>(new ICSlotRewrite(this, debug_name));
}
ICSlotInfo* ICInfo::pickEntryForRewrite(const char* debug_name) {
......@@ -236,11 +236,11 @@ std::unique_ptr<ICInfo> registerCompiledPatchpoint(uint8_t* start_addr, uint8_t*
// writer->emitNop();
// writer->emitGuardFalse();
std::unique_ptr<Assembler> writer(new Assembler(start, ic->slot_size));
writer->nop();
// writer->trap();
// writer->jmp(JumpDestination::fromStart(ic->slot_size * (ic->num_slots - i)));
writer->jmp(JumpDestination::fromStart(slowpath_start_addr - start));
Assembler writer(start, ic->slot_size);
writer.nop();
// writer.trap();
// writer.jmp(JumpDestination::fromStart(ic->slot_size * (ic->num_slots - i)));
writer.jmp(JumpDestination::fromStart(slowpath_start_addr - start));
}
ICInfo* icinfo = new ICInfo(start_addr, slowpath_rtn_addr, continue_addr, stack_info, ic->num_slots, ic->slot_size,
......@@ -272,10 +272,10 @@ void ICInfo::clear(ICSlotInfo* icentry) {
if (VERBOSITY() >= 4)
printf("clearing patchpoint %p, slot at %p\n", start_addr, start);
std::unique_ptr<Assembler> writer(new Assembler(start, getSlotSize()));
writer->nop();
writer->jmp(JumpDestination::fromStart(getSlotSize()));
assert(writer->bytesWritten() <= IC_INVALDITION_HEADER_SIZE);
Assembler writer(start, getSlotSize());
writer.nop();
writer.jmp(JumpDestination::fromStart(getSlotSize()));
assert(writer.bytesWritten() <= IC_INVALDITION_HEADER_SIZE);
// std::unique_ptr<MCWriter> writer(createMCWriter(start, getSlotSize(), 0));
// writer->emitNop();
......
......@@ -119,7 +119,7 @@ public:
llvm::CallingConv::ID getCallingConvention() { return calling_conv; }
const std::vector<int>& getLiveOuts() { return live_outs; }
ICSlotRewrite* startRewrite(const char* debug_name);
std::unique_ptr<ICSlotRewrite> startRewrite(const char* debug_name);
void clear(ICSlotInfo* entry);
bool shouldAttempt();
......
......@@ -1676,11 +1676,11 @@ TypeRecorder* Rewriter::getTypeRecorder() {
return rewrite->getTypeRecorder();
}
Rewriter::Rewriter(ICSlotRewrite* rewrite, int num_args, const std::vector<int>& live_outs)
: rewrite(rewrite),
assembler(rewrite->getAssembler()),
Rewriter::Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const std::vector<int>& live_outs)
: rewrite(std::move(rewrite)),
assembler(this->rewrite->getAssembler()),
const_loader(this),
return_location(rewrite->returnRegister()),
return_location(this->rewrite->returnRegister()),
failed(false),
added_changing_action(false),
marked_inside_ic(false),
......
......@@ -344,7 +344,7 @@ protected:
std::vector<RewriterVar*> args;
std::vector<RewriterVar*> live_outs;
Rewriter(ICSlotRewrite* rewrite, int num_args, const std::vector<int>& live_outs);
Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const std::vector<int>& live_outs);
std::vector<RewriterAction> actions;
void addAction(const std::function<void()>& action, std::vector<RewriterVar*> const& vars, ActionType type) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment