Fixed various simulator-related space leaks.

Alas, this involved quite a bit of copy-n-paste between the
architectures, but this is caused by the very convoluted
relationships, lifetimes and distribution of responsibilities. This
should really be cleaned up by moving code around and using STL maps,
but that's not really a priority right now.

Bonus: Fixed leaks in the ARM64 disassembler tests.

Review URL: https://codereview.chromium.org/1132943007

Cr-Commit-Position: refs/heads/master@{#28496}
This commit is contained in:
svenpanne 2015-05-19 22:56:06 -07:00 committed by Commit bot
parent 31fb502474
commit 84aa494ebc
12 changed files with 123 additions and 11 deletions

View File

@ -774,8 +774,7 @@ Simulator::Simulator(Isolate* isolate) : isolate_(isolate) {
}
Simulator::~Simulator() {
}
Simulator::~Simulator() { free(stack_); }
// When the generated code calls an external reference we need to catch that in
@ -834,6 +833,14 @@ class Redirection {
return redirection->external_function();
}
static void DeleteChain(Redirection* redirection) {
while (redirection != nullptr) {
Redirection* next = redirection->next_;
delete redirection;
redirection = next;
}
}
private:
void* external_function_;
uint32_t swi_instruction_;
@ -842,6 +849,19 @@ class Redirection {
};
// static
void Simulator::TearDown(HashMap* i_cache, Redirection* first) {
Redirection::DeleteChain(first);
if (i_cache != nullptr) {
for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr;
entry = i_cache->Next(entry)) {
delete static_cast<CachePage*>(entry->value);
}
delete i_cache;
}
}
void* Simulator::RedirectExternalReference(void* external_function,
ExternalReference::Type type) {
Redirection* redirection = Redirection::Get(external_function, type);

View File

@ -194,6 +194,8 @@ class Simulator {
// Call on program start.
static void Initialize(Isolate* isolate);
static void TearDown(HashMap* i_cache, Redirection* first);
// V8 generally calls into generated JS code with 5 parameters and into
// generated RegExp code with 7 parameters. This is a convenience function,
// which sets up the simulator state and grabs the result on return.

View File

@ -500,6 +500,14 @@ class Redirection {
return redirection->external_function<void*>();
}
static void DeleteChain(Redirection* redirection) {
while (redirection != nullptr) {
Redirection* next = redirection->next_;
delete redirection;
redirection = next;
}
}
private:
void* external_function_;
Instruction redirect_call_;
@ -508,6 +516,12 @@ class Redirection {
};
// static
void Simulator::TearDown(HashMap* i_cache, Redirection* first) {
Redirection::DeleteChain(first);
}
// Calls into the V8 runtime are based on this very simple interface.
// Note: To be able to return two values from some calls the code in runtime.cc
// uses the ObjectPair structure.

View File

@ -163,6 +163,8 @@ class Simulator : public DecoderVisitor {
static void Initialize(Isolate* isolate);
static void TearDown(HashMap* i_cache, Redirection* first);
static Simulator* current(v8::internal::Isolate* isolate);
class CallArgument;

View File

@ -2001,6 +2001,12 @@ Isolate::~Isolate() {
delete debug_;
debug_ = NULL;
#if USE_SIMULATOR
Simulator::TearDown(simulator_i_cache_, simulator_redirection_);
simulator_i_cache_ = nullptr;
simulator_redirection_ = nullptr;
#endif
}

View File

@ -989,8 +989,7 @@ Simulator::Simulator(Isolate* isolate) : isolate_(isolate) {
}
Simulator::~Simulator() {
}
Simulator::~Simulator() { free(stack_); }
// When the generated code calls an external reference we need to catch that in
@ -1046,6 +1045,14 @@ class Redirection {
return redirection->external_function();
}
static void DeleteChain(Redirection* redirection) {
while (redirection != nullptr) {
Redirection* next = redirection->next_;
delete redirection;
redirection = next;
}
}
private:
void* external_function_;
uint32_t swi_instruction_;
@ -1054,6 +1061,19 @@ class Redirection {
};
// static
void Simulator::TearDown(HashMap* i_cache, Redirection* first) {
Redirection::DeleteChain(first);
if (i_cache != nullptr) {
for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr;
entry = i_cache->Next(entry)) {
delete static_cast<CachePage*>(entry->value);
}
delete i_cache;
}
}
void* Simulator::RedirectExternalReference(void* external_function,
ExternalReference::Type type) {
Redirection* redirection = Redirection::Get(external_function, type);

View File

@ -200,6 +200,8 @@ class Simulator {
// Call on program start.
static void Initialize(Isolate* isolate);
static void TearDown(HashMap* i_cache, Redirection* first);
// V8 generally calls into generated JS code with 5 parameters and into
// generated RegExp code with 7 parameters. This is a convenience function,
// which sets up the simulator state and grabs the result on return.

View File

@ -920,8 +920,7 @@ Simulator::Simulator(Isolate* isolate) : isolate_(isolate) {
}
Simulator::~Simulator() {
}
Simulator::~Simulator() { free(stack_); }
// When the generated code calls an external reference we need to catch that in
@ -977,6 +976,14 @@ class Redirection {
return redirection->external_function();
}
static void DeleteChain(Redirection* redirection) {
while (redirection != nullptr) {
Redirection* next = redirection->next_;
delete redirection;
redirection = next;
}
}
private:
void* external_function_;
uint32_t swi_instruction_;
@ -985,6 +992,19 @@ class Redirection {
};
// static
void Simulator::TearDown(HashMap* i_cache, Redirection* first) {
Redirection::DeleteChain(first);
if (i_cache != nullptr) {
for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr;
entry = i_cache->Next(entry)) {
delete static_cast<CachePage*>(entry->value);
}
delete i_cache;
}
}
void* Simulator::RedirectExternalReference(void* external_function,
ExternalReference::Type type) {
Redirection* redirection = Redirection::Get(external_function, type);

View File

@ -232,6 +232,8 @@ class Simulator {
// Call on program start.
static void Initialize(Isolate* isolate);
static void TearDown(HashMap* i_cache, Redirection* first);
// V8 generally calls into generated JS code with 5 parameters and into
// generated RegExp code with 7 parameters. This is a convenience function,
// which sets up the simulator state and grabs the result on return.

View File

@ -830,7 +830,7 @@ Simulator::Simulator(Isolate* isolate) : isolate_(isolate) {
}
Simulator::~Simulator() {}
Simulator::~Simulator() { free(stack_); }
// When the generated code calls an external reference we need to catch that in
@ -888,6 +888,14 @@ class Redirection {
return redirection->external_function();
}
static void DeleteChain(Redirection* redirection) {
while (redirection != nullptr) {
Redirection* next = redirection->next_;
delete redirection;
redirection = next;
}
}
private:
void* external_function_;
uint32_t swi_instruction_;
@ -896,6 +904,19 @@ class Redirection {
};
// static
void Simulator::TearDown(HashMap* i_cache, Redirection* first) {
Redirection::DeleteChain(first);
if (i_cache != nullptr) {
for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr;
entry = i_cache->Next(entry)) {
delete static_cast<CachePage*>(entry->value);
}
delete i_cache;
}
}
void* Simulator::RedirectExternalReference(void* external_function,
ExternalReference::Type type) {
Redirection* redirection = Redirection::Get(external_function, type);

View File

@ -212,6 +212,8 @@ class Simulator {
// Call on program start.
static void Initialize(Isolate* isolate);
static void TearDown(HashMap* i_cache, Redirection* first);
// V8 generally calls into generated JS code with 5 parameters and into
// generated RegExp code with 7 parameters. This is a convenience function,
// which sets up the simulator state and grabs the result on return.

View File

@ -83,10 +83,11 @@ using namespace v8::internal;
abort(); \
}
#define CLEANUP() \
delete disasm; \
delete decoder; \
delete assm
#define CLEANUP() \
delete disasm; \
delete decoder; \
delete assm; \
free(buf)
static bool vm_initialized = false;