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