Revision: 10960
Author: [email protected]
Date: Wed Mar 7 09:38:50 2012
Log: Add HeapProfiler::GetPersistentHandleCount to be able to track
the number of persistent handles
It turns out that an increasing number of persistent handles is a good
signal for bugs in the bindings layer
BUG=none
TEST=cctest/test-heap-profiler/PersistentHandleCount
Review URL: https://chromiumcodereview.appspot.com/9620007
Patch from Jochen Eisinger <[email protected]>.
http://code.google.com/p/v8/source/detail?r=10960
Modified:
/branches/bleeding_edge/include/v8-profiler.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/global-handles.cc
/branches/bleeding_edge/src/global-handles.h
/branches/bleeding_edge/test/cctest/test-heap-profiler.cc
=======================================
--- /branches/bleeding_edge/include/v8-profiler.h Mon Feb 27 07:42:36 2012
+++ /branches/bleeding_edge/include/v8-profiler.h Wed Mar 7 09:38:50 2012
@@ -430,6 +430,9 @@
* handle.
*/
static const uint16_t kPersistentHandleNoClassId = 0;
+
+ /** Returns the number of currently existing persistent handles. */
+ static int GetPersistentHandleCount();
};
=======================================
--- /branches/bleeding_edge/src/api.cc Mon Feb 27 07:42:36 2012
+++ /branches/bleeding_edge/src/api.cc Wed Mar 7 09:38:50 2012
@@ -6071,6 +6071,11 @@
}
+int HeapProfiler::GetPersistentHandleCount() {
+ i::Isolate* isolate = i::Isolate::Current();
+ return isolate->global_handles()->NumberOfGlobalHandles();
+}
+
v8::Testing::StressType internal::Testing::stress_type_ =
v8::Testing::kStressTypeOpt;
=======================================
--- /branches/bleeding_edge/src/global-handles.cc Mon Jan 16 04:38:59 2012
+++ /branches/bleeding_edge/src/global-handles.cc Wed Mar 7 09:38:50 2012
@@ -384,6 +384,7 @@
: 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),
first_free_(NULL),
@@ -403,6 +404,7 @@
Handle<Object> GlobalHandles::Create(Object* value) {
isolate_->counters()->global_handles()->Increment();
+ number_of_global_handles_++;
if (first_free_ == NULL) {
first_block_ = new NodeBlock(first_block_);
first_block_->PutNodesOnFreeList(&first_free_);
@@ -423,6 +425,7 @@
void GlobalHandles::Destroy(Object** location) {
isolate_->counters()->global_handles()->Decrement();
+ number_of_global_handles_--;
if (location == NULL) return;
Node::FromLocation(location)->Release(this);
}
=======================================
--- /branches/bleeding_edge/src/global-handles.h Mon Jun 6 09:18:59 2011
+++ /branches/bleeding_edge/src/global-handles.h Wed Mar 7 09:38:50 2012
@@ -142,6 +142,11 @@
int NumberOfGlobalObjectWeakHandles() {
return number_of_global_object_weak_handles_;
}
+
+ // Returns the current number of handles to global objects.
+ int NumberOfGlobalHandles() {
+ return number_of_global_handles_;
+ }
// Clear the weakness of a global handle.
void ClearWeakness(Object** location);
@@ -248,6 +253,9 @@
// 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_;
+
// List of all allocated node blocks.
NodeBlock* first_block_;
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Mon Feb 27
07:42:36 2012
+++ /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Wed Mar 7
09:38:50 2012
@@ -1279,3 +1279,37 @@
GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared");
CHECK(HasWeakEdge(shared));
}
+
+
+TEST(PersistentHandleCount) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ // V8 also uses global handles internally, so we can't test for an
absolute
+ // number.
+ int global_handle_count = v8::HeapProfiler::GetPersistentHandleCount();
+
+ // Create some persistent handles.
+ v8::Persistent<v8::String> p_AAA =
+ v8::Persistent<v8::String>::New(v8_str("AAA"));
+ CHECK_EQ(global_handle_count + 1,
+ v8::HeapProfiler::GetPersistentHandleCount());
+ v8::Persistent<v8::String> p_BBB =
+ v8::Persistent<v8::String>::New(v8_str("BBB"));
+ CHECK_EQ(global_handle_count + 2,
+ v8::HeapProfiler::GetPersistentHandleCount());
+ v8::Persistent<v8::String> p_CCC =
+ v8::Persistent<v8::String>::New(v8_str("CCC"));
+ CHECK_EQ(global_handle_count + 3,
+ v8::HeapProfiler::GetPersistentHandleCount());
+
+ // Dipose the persistent handles in a different order.
+ p_AAA.Dispose();
+ CHECK_EQ(global_handle_count + 2,
+ v8::HeapProfiler::GetPersistentHandleCount());
+ p_CCC.Dispose();
+ CHECK_EQ(global_handle_count + 1,
+ v8::HeapProfiler::GetPersistentHandleCount());
+ p_BBB.Dispose();
+ CHECK_EQ(global_handle_count,
v8::HeapProfiler::GetPersistentHandleCount());
+}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev