From 0f5b5dd3115ab599a8d953fd625f03efae5036fb Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Mon, 21 Jan 2013 12:15:31 +0000 Subject: [PATCH] Remove GlobalHandles::number_of_weak_handles_ and number_of_global_object_weak_handles_ This is a preparation patch for inlining MakeWeak() and Clear(). Given that NumberOfWeakHandles() is used only by CHECK_EQ() in serialized.cc and that NumberOfGlobalObjectWeakHandles is unused, it is wasteful to keep track of number_of_weak_handles_ and number_of_global_object_weak_handles_ at every MakeWeak() and Clear(). Instead, we can count the number at the point where NumberOfWeakHandles() or NumberOfGlobalObjectWeakHandles() is called. BUG= Review URL: https://codereview.chromium.org/11958015 Patch from Kentaro Hara . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13443 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/global-handles.cc | 43 +++++++++++++++++++++++-------------------- src/global-handles.h | 18 ++++-------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/global-handles.cc b/src/global-handles.cc index 94ccc28..aae680d 100644 --- a/src/global-handles.cc +++ b/src/global-handles.cc @@ -106,12 +106,6 @@ class GlobalHandles::Node { void Release(GlobalHandles* global_handles) { ASSERT(state() != FREE); - if (IsWeakRetainer()) { - global_handles->number_of_weak_handles_--; - if (object_->IsJSGlobalObject()) { - global_handles->number_of_global_object_weak_handles_--; - } - } set_state(FREE); parameter_or_next_free_.next_free = global_handles->first_free_; global_handles->first_free_ = this; @@ -221,12 +215,6 @@ class GlobalHandles::Node { void* parameter, WeakReferenceCallback callback) { ASSERT(state() != FREE); - if (!IsWeakRetainer()) { - global_handles->number_of_weak_handles_++; - if (object_->IsJSGlobalObject()) { - global_handles->number_of_global_object_weak_handles_++; - } - } set_state(WEAK); set_parameter(parameter); callback_ = callback; @@ -234,12 +222,6 @@ class GlobalHandles::Node { void ClearWeakness(GlobalHandles* global_handles) { ASSERT(state() != FREE); - if (IsWeakRetainer()) { - global_handles->number_of_weak_handles_--; - if (object_->IsJSGlobalObject()) { - global_handles->number_of_global_object_weak_handles_--; - } - } set_state(NORMAL); set_parameter(NULL); } @@ -421,8 +403,6 @@ class GlobalHandles::NodeIterator { GlobalHandles::GlobalHandles(Isolate* isolate) : isolate_(isolate), - number_of_weak_handles_(0), - number_of_global_object_weak_handles_(0), number_of_global_handles_(0), first_block_(NULL), first_used_block_(NULL), @@ -712,6 +692,29 @@ void GlobalHandles::IterateAllRootsWithClassIds(ObjectVisitor* v) { } +int GlobalHandles::NumberOfWeakHandles() { + int count = 0; + for (NodeIterator it(this); !it.done(); it.Advance()) { + if (it.node()->IsWeakRetainer()) { + count++; + } + } + return count; +} + + +int GlobalHandles::NumberOfGlobalObjectWeakHandles() { + int count = 0; + for (NodeIterator it(this); !it.done(); it.Advance()) { + if (it.node()->IsWeakRetainer() && + it.node()->object()->IsJSGlobalObject()) { + count++; + } + } + return count; +} + + void GlobalHandles::RecordStats(HeapStats* stats) { *stats->global_handle_count = 0; *stats->weak_global_handle_count = 0; diff --git a/src/global-handles.h b/src/global-handles.h index a28a96f..4508bff 100644 --- a/src/global-handles.h +++ b/src/global-handles.h @@ -130,16 +130,14 @@ class GlobalHandles { void* parameter, WeakReferenceCallback callback); - // Returns the current number of weak handles. - int NumberOfWeakHandles() { return number_of_weak_handles_; } - void RecordStats(HeapStats* stats); + // Returns the current number of weak handles. + int NumberOfWeakHandles(); + // Returns the current number of weak handles to global objects. // These handles are also included in NumberOfWeakHandles(). - int NumberOfGlobalObjectWeakHandles() { - return number_of_global_object_weak_handles_; - } + int NumberOfGlobalObjectWeakHandles(); // Returns the current number of handles to global objects. int NumberOfGlobalHandles() { @@ -255,14 +253,6 @@ class GlobalHandles { Isolate* isolate_; - // Field always containing the number of weak and near-death handles. - int number_of_weak_handles_; - - // Field always containing the number of weak and near-death handles - // to global objects. These objects are also included in - // number_of_weak_handles_. - int number_of_global_object_weak_handles_; - // Field always containing the number of handles to global objects. int number_of_global_handles_; -- 2.7.4