Removing exit time destructors by leaking static members.
authoryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 18 Nov 2011 08:59:33 +0000 (08:59 +0000)
committeryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 18 Nov 2011 08:59:33 +0000 (08:59 +0000)
Note that some cctests and d8 still contain statical members with exit time destructors.

BUG=v8:1828

Review URL: http://codereview.chromium.org/8586025

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10025 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/ast.cc
src/ast.h
src/elements.cc
src/extensions/gc-extension.cc
src/hashmap.cc
src/hashmap.h
src/parser.h
src/scopes.cc

index 91f4d9aabd750a9beb9ae85d2c5784a7f4d5d38c..6af15258a2f898db7b8c6ab67a72190215569e76 100644 (file)
@@ -897,8 +897,6 @@ FOR_EACH_REG_EXP_TREE_TYPE(MAKE_TYPE_CASE)
 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_TYPE_CASE)
 #undef MAKE_TYPE_CASE
 
-RegExpEmpty RegExpEmpty::kInstance;
-
 
 static Interval ListCaptureRegisters(ZoneList<RegExpTree*>* children) {
   Interval result = Interval::Empty();
index ab300db7fb5a6e96194ea809f4ea8ecaeb3f897d..c2d9412a90b227e59885504ed79effd08ad8dcdc 100644 (file)
--- a/src/ast.h
+++ b/src/ast.h
@@ -2131,9 +2131,10 @@ class RegExpEmpty: public RegExpTree {
   virtual bool IsEmpty();
   virtual int min_match() { return 0; }
   virtual int max_match() { return 0; }
-  static RegExpEmpty* GetInstance() { return &kInstance; }
- private:
-  static RegExpEmpty kInstance;
+  static RegExpEmpty* GetInstance() {
+    static RegExpEmpty* instance = ::new RegExpEmpty();
+    return instance;
+  }
 };
 
 
index 1d50099bca833af1c01e10a771d9a4ce02945cb4..4376df62c6460b3efa4509f71b63db7d3d538391 100644 (file)
@@ -801,42 +801,45 @@ ElementsAccessor* ElementsAccessor::ForArray(FixedArrayBase* array) {
 
 
 void ElementsAccessor::InitializeOncePerProcess() {
+  // First argument in list is the accessor class, the second argument is can
+  // be any arbitrary unique identifier, in this case chosen to be the
+  // corresponding enum.  Use the fast element handler for smi-only arrays.
+  // The implementation is currently identical.  Note that the order must match
+  // that of the ElementsKind enum for the |accessor_array[]| below to work.
+#define ELEMENTS_LIST(V)                                                       \
+  V(FastObjectElementsAccessor, FAST_SMI_ONLY_ELEMENTS)                        \
+  V(FastObjectElementsAccessor, FAST_ELEMENTS)                                 \
+  V(FastDoubleElementsAccessor, FAST_DOUBLE_ELEMENTS)                          \
+  V(DictionaryElementsAccessor, DICTIONARY_ELEMENTS)                           \
+  V(NonStrictArgumentsElementsAccessor, NON_STRICT_ARGUMENTS_ELEMENTS)         \
+  V(ExternalByteElementsAccessor, EXTERNAL_BYTE_ELEMENTS)                      \
+  V(ExternalUnsignedByteElementsAccessor, EXTERNAL_UNSIGNED_BYTE_ELEMENTS)     \
+  V(ExternalShortElementsAccessor, EXTERNAL_SHORT_ELEMENTS)                    \
+  V(ExternalUnsignedShortElementsAccessor, EXTERNAL_UNSIGNED_SHORT_ELEMENTS)   \
+  V(ExternalIntElementsAccessor, EXTERNAL_INT_ELEMENTS)                        \
+  V(ExternalUnsignedIntElementsAccessor, EXTERNAL_UNSIGNED_INT_ELEMENTS)       \
+  V(ExternalFloatElementsAccessor, EXTERNAL_FLOAT_ELEMENTS)                    \
+  V(ExternalDoubleElementsAccessor, EXTERNAL_DOUBLE_ELEMENTS)                  \
+  V(PixelElementsAccessor, EXTERNAL_PIXEL_ELEMENTS)
+
   static struct ConcreteElementsAccessors {
-    // Use the fast element handler for smi-only arrays. The implementation is
-    // currently identical.
-    FastObjectElementsAccessor fast_smi_elements_handler;
-    FastObjectElementsAccessor fast_elements_handler;
-    FastDoubleElementsAccessor fast_double_elements_handler;
-    DictionaryElementsAccessor dictionary_elements_handler;
-    NonStrictArgumentsElementsAccessor non_strict_arguments_elements_handler;
-    ExternalByteElementsAccessor byte_elements_handler;
-    ExternalUnsignedByteElementsAccessor unsigned_byte_elements_handler;
-    ExternalShortElementsAccessor short_elements_handler;
-    ExternalUnsignedShortElementsAccessor unsigned_short_elements_handler;
-    ExternalIntElementsAccessor int_elements_handler;
-    ExternalUnsignedIntElementsAccessor unsigned_int_elements_handler;
-    ExternalFloatElementsAccessor float_elements_handler;
-    ExternalDoubleElementsAccessor double_elements_handler;
-    PixelElementsAccessor pixel_elements_handler;
-  } element_accessors;
+#define ACCESSOR_STRUCT(Class, Name) Class* Name##_handler;
+    ELEMENTS_LIST(ACCESSOR_STRUCT)
+#undef ACCESSOR_STRUCT
+  } element_accessors = {
+#define ACCESSOR_INIT(Class, Name) ::new Class(),
+    ELEMENTS_LIST(ACCESSOR_INIT)
+#undef ACCESSOR_INIT
+  };
 
   static ElementsAccessor* accessor_array[] = {
-    &element_accessors.fast_smi_elements_handler,
-    &element_accessors.fast_elements_handler,
-    &element_accessors.fast_double_elements_handler,
-    &element_accessors.dictionary_elements_handler,
-    &element_accessors.non_strict_arguments_elements_handler,
-    &element_accessors.byte_elements_handler,
-    &element_accessors.unsigned_byte_elements_handler,
-    &element_accessors.short_elements_handler,
-    &element_accessors.unsigned_short_elements_handler,
-    &element_accessors.int_elements_handler,
-    &element_accessors.unsigned_int_elements_handler,
-    &element_accessors.float_elements_handler,
-    &element_accessors.double_elements_handler,
-    &element_accessors.pixel_elements_handler
+#define ACCESSOR_ARRAY(Class, Name) element_accessors.Name##_handler,
+    ELEMENTS_LIST(ACCESSOR_ARRAY)
+#undef ACCESSOR_ARRAY
   };
 
+#undef ELEMENTS_LIST
+
   STATIC_ASSERT((sizeof(accessor_array) / sizeof(*accessor_array)) ==
                 kElementsKindCount);
 
index 48e8c42057600530de93cd8b7a11714a96b57b64..238e305f3db712cbbb748dcec385077253b5516f 100644 (file)
@@ -46,8 +46,8 @@ v8::Handle<v8::Value> GCExtension::GC(const v8::Arguments& args) {
 
 
 void GCExtension::Register() {
-  static GCExtension gc_extension;
-  static v8::DeclareExtension gc_extension_declaration(&gc_extension);
+  static GCExtension* gc_extension = ::new GCExtension();
+  static v8::DeclareExtension gc_extension_declaration(gc_extension);
 }
 
 } }  // namespace v8::internal
index 37748a34f816282c27563570068c46fda792a30a..0b404a97e18667830198c2527ce86a792d751a82 100644 (file)
@@ -36,7 +36,7 @@
 namespace v8 {
 namespace internal {
 
-Allocator HashMap::DefaultAllocator;
+Allocator* HashMap::DefaultAllocator = ::new Allocator();
 
 
 HashMap::HashMap(MatchFun match,
index 4e6a454a3c9622cebb3e9dc1c609e4c39c31397d..d2d1fafa32480630622c6d831fac06d34a64f430 100644 (file)
@@ -46,14 +46,14 @@ class Allocator BASE_EMBEDDED {
 
 class HashMap {
  public:
-  static Allocator DefaultAllocator;
+  static Allocator* DefaultAllocator;
 
   typedef bool (*MatchFun) (void* key1, void* key2);
 
   // initial_capacity is the size of the initial hash map;
   // it must be a power of 2 (and thus must not be 0).
   explicit HashMap(MatchFun match,
-                   Allocator* allocator = &DefaultAllocator,
+                   Allocator* allocator = DefaultAllocator,
                    uint32_t initial_capacity = 8);
 
   ~HashMap();
index 1436bf9066c5d50b11c91ec44d1481fd0434d2a4..5e2c27a90fb8739f6f12c9cbf3e790cb178782c0 100644 (file)
@@ -681,8 +681,9 @@ class Parser {
   // Factory methods.
 
   Statement* EmptyStatement() {
-    static v8::internal::EmptyStatement empty;
-    return &empty;
+    static v8::internal::EmptyStatement* empty =
+        ::new v8::internal::EmptyStatement();
+    return empty;
   }
 
   Scope* NewScope(Scope* parent, ScopeType type);
index f9cd62065380ffc933058e9139599918b0c9b24a..60ea20f16d5ed94f8e8a6ab8f6e58db7aab1b4c6 100644 (file)
@@ -55,7 +55,7 @@ class ZoneAllocator: public Allocator {
 };
 
 
-static ZoneAllocator LocalsMapAllocator;
+static ZoneAllocator* LocalsMapAllocator = ::new ZoneAllocator();
 
 
 // ----------------------------------------------------------------------------
@@ -76,7 +76,7 @@ static bool Match(void* key1, void* key2) {
 }
 
 
-VariableMap::VariableMap() : HashMap(Match, &LocalsMapAllocator, 8) {}
+VariableMap::VariableMap() : HashMap(Match, LocalsMapAllocator, 8) {}
 VariableMap::~VariableMap() {}