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() { ...@@ -151,8 +151,8 @@ assembler::GenericRegister ICSlotRewrite::returnRegister() {
ICSlotRewrite* ICInfo::startRewrite(const char* debug_name) { std::unique_ptr<ICSlotRewrite> ICInfo::startRewrite(const char* debug_name) {
return new ICSlotRewrite(this, debug_name); return std::unique_ptr<ICSlotRewrite>(new ICSlotRewrite(this, debug_name));
} }
ICSlotInfo* ICInfo::pickEntryForRewrite(const char* debug_name) { ICSlotInfo* ICInfo::pickEntryForRewrite(const char* debug_name) {
...@@ -236,11 +236,11 @@ std::unique_ptr<ICInfo> registerCompiledPatchpoint(uint8_t* start_addr, uint8_t* ...@@ -236,11 +236,11 @@ std::unique_ptr<ICInfo> registerCompiledPatchpoint(uint8_t* start_addr, uint8_t*
// writer->emitNop(); // writer->emitNop();
// writer->emitGuardFalse(); // writer->emitGuardFalse();
std::unique_ptr<Assembler> writer(new Assembler(start, ic->slot_size)); Assembler writer(start, ic->slot_size);
writer->nop(); writer.nop();
// writer->trap(); // writer.trap();
// writer->jmp(JumpDestination::fromStart(ic->slot_size * (ic->num_slots - i))); // writer.jmp(JumpDestination::fromStart(ic->slot_size * (ic->num_slots - i)));
writer->jmp(JumpDestination::fromStart(slowpath_start_addr - start)); 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, 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) { ...@@ -272,10 +272,10 @@ void ICInfo::clear(ICSlotInfo* icentry) {
if (VERBOSITY() >= 4) if (VERBOSITY() >= 4)
printf("clearing patchpoint %p, slot at %p\n", start_addr, start); printf("clearing patchpoint %p, slot at %p\n", start_addr, start);
std::unique_ptr<Assembler> writer(new Assembler(start, getSlotSize())); Assembler writer(start, getSlotSize());
writer->nop(); writer.nop();
writer->jmp(JumpDestination::fromStart(getSlotSize())); writer.jmp(JumpDestination::fromStart(getSlotSize()));
assert(writer->bytesWritten() <= IC_INVALDITION_HEADER_SIZE); assert(writer.bytesWritten() <= IC_INVALDITION_HEADER_SIZE);
// std::unique_ptr<MCWriter> writer(createMCWriter(start, getSlotSize(), 0)); // std::unique_ptr<MCWriter> writer(createMCWriter(start, getSlotSize(), 0));
// writer->emitNop(); // writer->emitNop();
......
...@@ -119,7 +119,7 @@ public: ...@@ -119,7 +119,7 @@ public:
llvm::CallingConv::ID getCallingConvention() { return calling_conv; } llvm::CallingConv::ID getCallingConvention() { return calling_conv; }
const std::vector<int>& getLiveOuts() { return live_outs; } 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); void clear(ICSlotInfo* entry);
bool shouldAttempt(); bool shouldAttempt();
......
...@@ -1676,11 +1676,11 @@ TypeRecorder* Rewriter::getTypeRecorder() { ...@@ -1676,11 +1676,11 @@ TypeRecorder* Rewriter::getTypeRecorder() {
return rewrite->getTypeRecorder(); return rewrite->getTypeRecorder();
} }
Rewriter::Rewriter(ICSlotRewrite* rewrite, int num_args, const std::vector<int>& live_outs) Rewriter::Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const std::vector<int>& live_outs)
: rewrite(rewrite), : rewrite(std::move(rewrite)),
assembler(rewrite->getAssembler()), assembler(this->rewrite->getAssembler()),
const_loader(this), const_loader(this),
return_location(rewrite->returnRegister()), return_location(this->rewrite->returnRegister()),
failed(false), failed(false),
added_changing_action(false), added_changing_action(false),
marked_inside_ic(false), marked_inside_ic(false),
......
...@@ -344,7 +344,7 @@ protected: ...@@ -344,7 +344,7 @@ protected:
std::vector<RewriterVar*> args; std::vector<RewriterVar*> args;
std::vector<RewriterVar*> live_outs; 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; std::vector<RewriterAction> actions;
void addAction(const std::function<void()>& action, std::vector<RewriterVar*> const& vars, ActionType type) { 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