Index: test/cctest/test-heap-profiler.cc |
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc |
index 1e9cb7355773ff2d9e32054807cf64a3e10658f3..b199507d70a1e20f88dae2db0d24aceffc74a554 100644 |
--- a/test/cctest/test-heap-profiler.cc |
+++ b/test/cctest/test-heap-profiler.cc |
@@ -74,13 +74,12 @@ TEST(ConstructorProfile) { |
} |
-static JSObjectsCluster AddHeapObjectToTree( |
- JSObjectsRetainerTree* tree, |
- i::String* constructor, |
- int instance, |
- JSObjectsCluster* ref1 = NULL, |
- JSObjectsCluster* ref2 = NULL, |
- JSObjectsCluster* ref3 = NULL) { |
+static JSObjectsCluster AddHeapObjectToTree(JSObjectsRetainerTree* tree, |
+ i::String* constructor, |
+ int instance, |
+ JSObjectsCluster* ref1 = NULL, |
+ JSObjectsCluster* ref2 = NULL, |
+ JSObjectsCluster* ref3 = NULL) { |
JSObjectsCluster o(constructor, reinterpret_cast<i::Object*>(instance)); |
JSObjectsClusterTree* o_tree = new JSObjectsClusterTree(); |
JSObjectsClusterTree::Locator o_loc; |
@@ -94,6 +93,16 @@ static JSObjectsCluster AddHeapObjectToTree( |
} |
+static void AddSelfReferenceToTree(JSObjectsRetainerTree* tree, |
+ JSObjectsCluster* self_ref) { |
+ JSObjectsRetainerTree::Locator loc; |
+ CHECK(tree->Find(*self_ref, &loc)); |
+ JSObjectsClusterTree::Locator o_loc; |
+ CHECK_NE(NULL, loc.value()); |
+ loc.value()->Insert(*self_ref, &o_loc); |
+} |
+ |
+ |
static inline void CheckEqualsHelper(const char* file, int line, |
const char* expected_source, |
const JSObjectsCluster& expected, |
@@ -121,7 +130,7 @@ static inline void CheckNonEqualsHelper(const char* file, int line, |
if (JSObjectsCluster::Compare(expected, value) == 0) { |
i::HeapStringAllocator allocator; |
i::StringStream stream(&allocator); |
- stream.Add("# Expected: "); |
+ stream.Add("# !Expected: "); |
expected.DebugPrint(&stream); |
stream.Add("\n# Found: "); |
value.DebugPrint(&stream); |
@@ -243,9 +252,11 @@ TEST(ClustersCoarserPathsTraversal) { |
coarser.Process(&tree); |
CHECK_EQ(JSObjectsCluster(), coarser.GetCoarseEquivalent(o)); |
+ CHECK_NE(JSObjectsCluster(), coarser.GetCoarseEquivalent(o11)); |
CHECK_EQ(coarser.GetCoarseEquivalent(o11), coarser.GetCoarseEquivalent(o12)); |
CHECK_EQ(coarser.GetCoarseEquivalent(o21), coarser.GetCoarseEquivalent(o22)); |
CHECK_NE(coarser.GetCoarseEquivalent(o11), coarser.GetCoarseEquivalent(o21)); |
+ CHECK_NE(JSObjectsCluster(), coarser.GetCoarseEquivalent(p)); |
CHECK_EQ(coarser.GetCoarseEquivalent(p), coarser.GetCoarseEquivalent(q)); |
CHECK_EQ(coarser.GetCoarseEquivalent(q), coarser.GetCoarseEquivalent(r)); |
CHECK_NE(coarser.GetCoarseEquivalent(o11), coarser.GetCoarseEquivalent(p)); |
@@ -253,6 +264,54 @@ TEST(ClustersCoarserPathsTraversal) { |
} |
+TEST(ClustersCoarserSelf) { |
+ v8::HandleScope scope; |
+ v8::Handle<v8::Context> env = v8::Context::New(); |
+ env->Enter(); |
+ |
+ i::ZoneScope zn_scope(i::DELETE_ON_EXIT); |
+ |
+ JSObjectsRetainerTree tree; |
+ |
+ // On the following graph: |
+ // |
+ // p (self-referencing) |
+ // <- o1 <- |
+ // q (self-referencing) o |
+ // <- o2 <- |
+ // r (self-referencing) |
+ // |
+ // we expect that coarser will deduce equivalences: p ~ q ~ r, o1 ~ o2; |
+ |
+ JSObjectsCluster o = |
+ AddHeapObjectToTree(&tree, i::Heap::Object_symbol(), 0x100); |
+ JSObjectsCluster o1 = |
+ AddHeapObjectToTree(&tree, i::Heap::Object_symbol(), 0x110, &o); |
+ JSObjectsCluster o2 = |
+ AddHeapObjectToTree(&tree, i::Heap::Object_symbol(), 0x120, &o); |
+ JSObjectsCluster p = |
+ AddHeapObjectToTree(&tree, i::Heap::Object_symbol(), 0x300, &o1); |
+ AddSelfReferenceToTree(&tree, &p); |
+ JSObjectsCluster q = |
+ AddHeapObjectToTree(&tree, i::Heap::Object_symbol(), 0x310, &o1, &o2); |
+ AddSelfReferenceToTree(&tree, &q); |
+ JSObjectsCluster r = |
+ AddHeapObjectToTree(&tree, i::Heap::Object_symbol(), 0x320, &o2); |
+ AddSelfReferenceToTree(&tree, &r); |
+ |
+ ClustersCoarser coarser; |
+ coarser.Process(&tree); |
+ |
+ CHECK_EQ(JSObjectsCluster(), coarser.GetCoarseEquivalent(o)); |
+ CHECK_NE(JSObjectsCluster(), coarser.GetCoarseEquivalent(o1)); |
+ CHECK_EQ(coarser.GetCoarseEquivalent(o1), coarser.GetCoarseEquivalent(o2)); |
+ CHECK_NE(JSObjectsCluster(), coarser.GetCoarseEquivalent(p)); |
+ CHECK_EQ(coarser.GetCoarseEquivalent(p), coarser.GetCoarseEquivalent(q)); |
+ CHECK_EQ(coarser.GetCoarseEquivalent(q), coarser.GetCoarseEquivalent(r)); |
+ CHECK_NE(coarser.GetCoarseEquivalent(o1), coarser.GetCoarseEquivalent(p)); |
+} |
+ |
+ |
namespace { |
class RetainerProfilePrinter : public RetainerHeapProfile::Printer { |