Reviewers: Erik Corry,

Description:
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... ;-)


Please review this at http://codereview.chromium.org/9860028/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/lithium.h
  M src/lithium.cc
  M src/v8.cc


Index: src/lithium.cc
diff --git a/src/lithium.cc b/src/lithium.cc
index aefd8b6492c45c7af1859a10dc037a0b507cd26c..d072358ce9edbcf022cb4be61f5a4a04266428f3 100644
--- a/src/lithium.cc
+++ b/src/lithium.cc
@@ -96,6 +96,7 @@ void LOperand::PrintTo(StringStream* stream) {

 #define DEFINE_OPERAND_CACHE(name, type)                      \
   name* name::cache = NULL;                                   \
+                                                              \
   void name::SetUpCache() {                                   \
     if (cache) return;                                        \
     cache = new name[kNumCachedOperands];                     \
@@ -103,23 +104,28 @@ void LOperand::PrintTo(StringStream* stream) {
       cache[i].ConvertTo(type, i);                            \
     }                                                         \
   }                                                           \
+                                                              \
+  void 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) name::SetUpCache();
+  LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_SETUP)
+#undef LITHIUM_OPERAND_SETUP
+}
+
+
+void LOperand::TearDownCaches() {
+#define LITHIUM_OPERAND_TEARDOWN(name, type) 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;
Index: src/lithium.h
diff --git a/src/lithium.h b/src/lithium.h
index d1e2e3cdef2edc104f6e5831db0580694e869b45..6d765ae8304e3a1f6c6834284c394123138b10af 100644
--- a/src/lithium.h
+++ b/src/lithium.h
@@ -35,6 +35,14 @@
 namespace v8 {
 namespace internal {

+#define LITHIUM_OPERAND_LIST(V)          \
+  V(LConstantOperand, CONSTANT_OPERAND)  \
+  V(LStackSlot,       STACK_SLOT)        \
+  V(LDoubleStackSlot, DOUBLE_STACK_SLOT) \
+  V(LRegister,        REGISTER)          \
+  V(LDoubleRegister,  DOUBLE_REGISTER)
+
+
 class LOperand: public ZoneObject {
  public:
   enum Kind {
@@ -69,9 +77,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 +273,7 @@ class LConstantOperand: public LOperand {
   }

   static void SetUpCache();
+  static void TearDownCache();

  private:
   static const int kNumCachedOperands = 128;
@@ -300,6 +309,7 @@ class LStackSlot: public LOperand {
   }

   static void SetUpCache();
+  static void TearDownCache();

  private:
   static const int kNumCachedOperands = 128;
@@ -324,6 +334,7 @@ class LDoubleStackSlot: public LOperand {
   }

   static void SetUpCache();
+  static void TearDownCache();

  private:
   static const int kNumCachedOperands = 128;
@@ -348,6 +359,7 @@ class LRegister: public LOperand {
   }

   static void SetUpCache();
+  static void TearDownCache();

  private:
   static const int kNumCachedOperands = 16;
@@ -372,6 +384,7 @@ class LDoubleRegister: public LOperand {
   }

   static void SetUpCache();
+  static void TearDownCache();

  private:
   static const int kNumCachedOperands = 16;
Index: src/v8.cc
diff --git a/src/v8.cc b/src/v8.cc
index 506f3f66068bb2809d06fd4297d231fe602b20eb..b32c3cbf2350f0472dd57f68cc70f7844e2ea986 100644
--- a/src/v8.cc
+++ b/src/v8.cc
@@ -103,6 +103,9 @@ void V8::TearDown() {
   ASSERT(isolate->IsDefaultIsolate());

   if (!has_been_set_up_ || has_been_disposed_) return;
+
+  LOperand::TearDownCaches();
+
   isolate->TearDown();

   is_running_ = false;


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to