Valgrind cleanliness, part 2: Delete lithium operand caches on exit.

This fixes 5 leaks, returning 1.6kB of lost memory.

Shocking news: I've actually introduced a 2nd-order macro for myself. I guess
I've been assimilated... ;-)

Review URL: https://chromiumcodereview.appspot.com/9860028

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11179 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fa91d25e
...@@ -95,31 +95,37 @@ void LOperand::PrintTo(StringStream* stream) { ...@@ -95,31 +95,37 @@ void LOperand::PrintTo(StringStream* stream) {
} }
#define DEFINE_OPERAND_CACHE(name, type) \ #define DEFINE_OPERAND_CACHE(name, type) \
name* name::cache = NULL; \ L##name* L##name::cache = NULL; \
void name::SetUpCache() { \ \
void L##name::SetUpCache() { \
if (cache) return; \ if (cache) return; \
cache = new name[kNumCachedOperands]; \ cache = new L##name[kNumCachedOperands]; \
for (int i = 0; i < kNumCachedOperands; i++) { \ for (int i = 0; i < kNumCachedOperands; i++) { \
cache[i].ConvertTo(type, i); \ cache[i].ConvertTo(type, i); \
} \ } \
} \ } \
\
void L##name::TearDownCache() { \
delete[] cache; \
}
DEFINE_OPERAND_CACHE(LConstantOperand, CONSTANT_OPERAND) LITHIUM_OPERAND_LIST(DEFINE_OPERAND_CACHE)
DEFINE_OPERAND_CACHE(LStackSlot, STACK_SLOT)
DEFINE_OPERAND_CACHE(LDoubleStackSlot, DOUBLE_STACK_SLOT)
DEFINE_OPERAND_CACHE(LRegister, REGISTER)
DEFINE_OPERAND_CACHE(LDoubleRegister, DOUBLE_REGISTER)
#undef DEFINE_OPERAND_CACHE #undef DEFINE_OPERAND_CACHE
void LOperand::SetUpCaches() { void LOperand::SetUpCaches() {
LConstantOperand::SetUpCache(); #define LITHIUM_OPERAND_SETUP(name, type) L##name::SetUpCache();
LStackSlot::SetUpCache(); LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_SETUP)
LDoubleStackSlot::SetUpCache(); #undef LITHIUM_OPERAND_SETUP
LRegister::SetUpCache(); }
LDoubleRegister::SetUpCache();
void LOperand::TearDownCaches() {
#define LITHIUM_OPERAND_TEARDOWN(name, type) L##name::TearDownCache();
LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_TEARDOWN)
#undef LITHIUM_OPERAND_TEARDOWN
} }
bool LParallelMove::IsRedundant() const { bool LParallelMove::IsRedundant() const {
for (int i = 0; i < move_operands_.length(); ++i) { for (int i = 0; i < move_operands_.length(); ++i) {
if (!move_operands_[i].IsRedundant()) return false; if (!move_operands_[i].IsRedundant()) return false;
......
...@@ -35,6 +35,14 @@ ...@@ -35,6 +35,14 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
#define LITHIUM_OPERAND_LIST(V) \
V(ConstantOperand, CONSTANT_OPERAND) \
V(StackSlot, STACK_SLOT) \
V(DoubleStackSlot, DOUBLE_STACK_SLOT) \
V(Register, REGISTER) \
V(DoubleRegister, DOUBLE_REGISTER)
class LOperand: public ZoneObject { class LOperand: public ZoneObject {
public: public:
enum Kind { enum Kind {
...@@ -52,14 +60,13 @@ class LOperand: public ZoneObject { ...@@ -52,14 +60,13 @@ class LOperand: public ZoneObject {
Kind kind() const { return KindField::decode(value_); } Kind kind() const { return KindField::decode(value_); }
int index() const { return static_cast<int>(value_) >> kKindFieldWidth; } int index() const { return static_cast<int>(value_) >> kKindFieldWidth; }
bool IsConstantOperand() const { return kind() == CONSTANT_OPERAND; } #define LITHIUM_OPERAND_PREDICATE(name, type) \
bool IsStackSlot() const { return kind() == STACK_SLOT; } bool Is##name() const { return kind() == type; }
bool IsDoubleStackSlot() const { return kind() == DOUBLE_STACK_SLOT; } LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE)
bool IsRegister() const { return kind() == REGISTER; } LITHIUM_OPERAND_PREDICATE(Argument, ARGUMENT)
bool IsDoubleRegister() const { return kind() == DOUBLE_REGISTER; } LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED)
bool IsArgument() const { return kind() == ARGUMENT; } LITHIUM_OPERAND_PREDICATE(Ignored, INVALID)
bool IsUnallocated() const { return kind() == UNALLOCATED; } #undef LITHIUM_OPERAND_PREDICATE
bool IsIgnored() const { return kind() == INVALID; }
bool Equals(LOperand* other) const { return value_ == other->value_; } bool Equals(LOperand* other) const { return value_ == other->value_; }
void PrintTo(StringStream* stream); void PrintTo(StringStream* stream);
...@@ -69,9 +76,9 @@ class LOperand: public ZoneObject { ...@@ -69,9 +76,9 @@ class LOperand: public ZoneObject {
ASSERT(this->index() == index); ASSERT(this->index() == index);
} }
// Calls SetUpCache() for each subclass. Don't forget to update this method // Calls SetUpCache()/TearDownCache() for each subclass.
// if you add a new LOperand subclass.
static void SetUpCaches(); static void SetUpCaches();
static void TearDownCaches();
protected: protected:
static const int kKindFieldWidth = 3; static const int kKindFieldWidth = 3;
...@@ -265,6 +272,7 @@ class LConstantOperand: public LOperand { ...@@ -265,6 +272,7 @@ class LConstantOperand: public LOperand {
} }
static void SetUpCache(); static void SetUpCache();
static void TearDownCache();
private: private:
static const int kNumCachedOperands = 128; static const int kNumCachedOperands = 128;
...@@ -300,6 +308,7 @@ class LStackSlot: public LOperand { ...@@ -300,6 +308,7 @@ class LStackSlot: public LOperand {
} }
static void SetUpCache(); static void SetUpCache();
static void TearDownCache();
private: private:
static const int kNumCachedOperands = 128; static const int kNumCachedOperands = 128;
...@@ -324,6 +333,7 @@ class LDoubleStackSlot: public LOperand { ...@@ -324,6 +333,7 @@ class LDoubleStackSlot: public LOperand {
} }
static void SetUpCache(); static void SetUpCache();
static void TearDownCache();
private: private:
static const int kNumCachedOperands = 128; static const int kNumCachedOperands = 128;
...@@ -348,6 +358,7 @@ class LRegister: public LOperand { ...@@ -348,6 +358,7 @@ class LRegister: public LOperand {
} }
static void SetUpCache(); static void SetUpCache();
static void TearDownCache();
private: private:
static const int kNumCachedOperands = 16; static const int kNumCachedOperands = 16;
...@@ -372,6 +383,7 @@ class LDoubleRegister: public LOperand { ...@@ -372,6 +383,7 @@ class LDoubleRegister: public LOperand {
} }
static void SetUpCache(); static void SetUpCache();
static void TearDownCache();
private: private:
static const int kNumCachedOperands = 16; static const int kNumCachedOperands = 16;
......
...@@ -105,6 +105,7 @@ void V8::TearDown() { ...@@ -105,6 +105,7 @@ void V8::TearDown() {
if (!has_been_set_up_ || has_been_disposed_) return; if (!has_been_set_up_ || has_been_disposed_) return;
ElementsAccessor::TearDown(); ElementsAccessor::TearDown();
LOperand::TearDownCaches();
isolate->TearDown(); isolate->TearDown();
delete isolate; delete isolate;
......
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