Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 8716009: Distinguish weak references in heap snapshots, group GC roots. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/profile-generator.cc ('K') | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // 2 //
3 // Tests for heap profiler 3 // Tests for heap profiler
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "cctest.h" 7 #include "cctest.h"
8 #include "heap-profiler.h" 8 #include "heap-profiler.h"
9 #include "snapshot.h" 9 #include "snapshot.h"
10 #include "utils-inl.h" 10 #include "utils-inl.h"
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 const v8::HeapGraphNode* obj1 = 1058 const v8::HeapGraphNode* obj1 =
1059 GetProperty(global, v8::HeapGraphEdge::kShortcut, "obj1"); 1059 GetProperty(global, v8::HeapGraphEdge::kShortcut, "obj1");
1060 CHECK_NE(NULL, obj1); 1060 CHECK_NE(NULL, obj1);
1061 const v8::HeapGraphNode* getterFunction = 1061 const v8::HeapGraphNode* getterFunction =
1062 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get-propWithGetter"); 1062 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get-propWithGetter");
1063 CHECK_NE(NULL, getterFunction); 1063 CHECK_NE(NULL, getterFunction);
1064 const v8::HeapGraphNode* setterFunction = 1064 const v8::HeapGraphNode* setterFunction =
1065 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set-propWithSetter"); 1065 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set-propWithSetter");
1066 CHECK_NE(NULL, setterFunction); 1066 CHECK_NE(NULL, setterFunction);
1067 } 1067 }
1068
1069
1070 static bool HasWeakEdge(const v8::HeapGraphNode* node) {
1071 for (int i = 0; i < node->GetChildrenCount(); ++i) {
1072 const v8::HeapGraphEdge* handle_edge = node->GetChild(i);
1073 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true;
1074 }
1075 return false;
1076 }
1077
1078
1079 static bool HasWeakGlobalHandle() {
1080 const v8::HeapSnapshot* snapshot =
1081 v8::HeapProfiler::TakeSnapshot(v8_str("weaks"));
1082 const v8::HeapGraphNode* gc_roots = GetNode(
1083 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
1084 CHECK_NE(NULL, gc_roots);
1085 const v8::HeapGraphNode* global_handles = GetNode(
1086 gc_roots, v8::HeapGraphNode::kObject, "(Global handles)");
1087 CHECK_NE(NULL, global_handles);
1088 return HasWeakEdge(global_handles);
1089 }
1090
1091
1092 static void PersistentHandleCallback(v8::Persistent<v8::Value> handle, void*) {
1093 handle.Dispose();
1094 }
1095
1096
1097 TEST(WeakGlobalHandle) {
1098 v8::HandleScope scope;
1099 LocalContext env;
1100
1101 CHECK(!HasWeakGlobalHandle());
1102
1103 v8::Persistent<v8::Object> handle =
1104 v8::Persistent<v8::Object>::New(v8::Object::New());
1105 handle.MakeWeak(NULL, PersistentHandleCallback);
1106
1107 CHECK(HasWeakGlobalHandle());
1108 }
1109
1110
1111 TEST(WeakGlobalContextRefs) {
1112 v8::HandleScope scope;
1113 LocalContext env;
1114
1115 const v8::HeapSnapshot* snapshot =
1116 v8::HeapProfiler::TakeSnapshot(v8_str("weaks"));
1117 const v8::HeapGraphNode* gc_roots = GetNode(
1118 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
1119 CHECK_NE(NULL, gc_roots);
1120 const v8::HeapGraphNode* global_handles = GetNode(
1121 gc_roots, v8::HeapGraphNode::kObject, "(Global handles)");
1122 CHECK_NE(NULL, global_handles);
1123 const v8::HeapGraphNode* global_context = GetNode(
1124 global_handles, v8::HeapGraphNode::kHidden, "system / GlobalContext");
1125 CHECK_NE(NULL, global_context);
1126 CHECK(HasWeakEdge(global_context));
1127 }
1128
1129
1130 TEST(SfiAndJsFunctionWeakRefs) {
1131 v8::HandleScope scope;
1132 LocalContext env;
1133
1134 CompileRun(
1135 "fun = (function (x) { return function () { return x + 1; } })(1);");
1136 const v8::HeapSnapshot* snapshot =
1137 v8::HeapProfiler::TakeSnapshot(v8_str("fun"));
1138 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1139 CHECK_NE(NULL, global);
1140 const v8::HeapGraphNode* fun =
1141 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun");
1142 CHECK(HasWeakEdge(fun));
1143 const v8::HeapGraphNode* shared =
1144 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared");
1145 CHECK(HasWeakEdge(shared));
1146 }
OLDNEW
« src/profile-generator.cc ('K') | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698