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

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

Issue 10086006: External references should not affect dominance relation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 8 months 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 "var c2 = new C2(a2);"); 102 "var c2 = new C2(a2);");
103 const v8::HeapSnapshot* snapshot_env2 = 103 const v8::HeapSnapshot* snapshot_env2 =
104 v8::HeapProfiler::TakeSnapshot(v8_str("env2")); 104 v8::HeapProfiler::TakeSnapshot(v8_str("env2"));
105 i::HeapSnapshot* i_snapshot_env2 = 105 i::HeapSnapshot* i_snapshot_env2 =
106 const_cast<i::HeapSnapshot*>( 106 const_cast<i::HeapSnapshot*>(
107 reinterpret_cast<const i::HeapSnapshot*>(snapshot_env2)); 107 reinterpret_cast<const i::HeapSnapshot*>(snapshot_env2));
108 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); 108 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2);
109 109
110 // Verify, that JS global object of env2 has '..2' properties. 110 // Verify, that JS global object of env2 has '..2' properties.
111 const v8::HeapGraphNode* a2_node = 111 const v8::HeapGraphNode* a2_node =
112 GetProperty(global_env2, v8::HeapGraphEdge::kShortcut, "a2"); 112 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2");
113 CHECK_NE(NULL, a2_node); 113 CHECK_NE(NULL, a2_node);
114 CHECK_NE( 114 CHECK_NE(
115 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kShortcut, "b2_1")); 115 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1"));
116 CHECK_NE( 116 CHECK_NE(
117 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kShortcut, "b2_2")); 117 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2"));
118 CHECK_NE(NULL, GetProperty(global_env2, v8::HeapGraphEdge::kShortcut, "c2")); 118 CHECK_NE(NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "c2"));
119 119
120 // Paint all nodes reachable from global object. 120 // Paint all nodes reachable from global object.
121 NamedEntriesDetector det; 121 NamedEntriesDetector det;
122 i_snapshot_env2->ClearPaint(); 122 i_snapshot_env2->ClearPaint();
123 det.CheckAllReachables(const_cast<i::HeapEntry*>( 123 det.CheckAllReachables(const_cast<i::HeapEntry*>(
124 reinterpret_cast<const i::HeapEntry*>(global_env2))); 124 reinterpret_cast<const i::HeapEntry*>(global_env2)));
125 CHECK(det.has_A2); 125 CHECK(det.has_A2);
126 CHECK(det.has_B2); 126 CHECK(det.has_B2);
127 CHECK(det.has_C2); 127 CHECK(det.has_C2);
128 } 128 }
129 129
130 130
131 TEST(HeapSnapshotObjectSizes) { 131 TEST(HeapSnapshotObjectSizes) {
132 v8::HandleScope scope; 132 v8::HandleScope scope;
133 LocalContext env; 133 LocalContext env;
134 134
135 // -a-> X1 --a 135 // -a-> X1 --a
136 // x -b-> X2 <-| 136 // x -b-> X2 <-|
137 CompileRun( 137 CompileRun(
138 "function X(a, b) { this.a = a; this.b = b; }\n" 138 "function X(a, b) { this.a = a; this.b = b; }\n"
139 "x = new X(new X(), new X());\n" 139 "x = new X(new X(), new X());\n"
140 "dummy = new X();\n"
140 "(function() { x.a.a = x.b; })();"); 141 "(function() { x.a.a = x.b; })();");
141 const v8::HeapSnapshot* snapshot = 142 const v8::HeapSnapshot* snapshot =
142 v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); 143 v8::HeapProfiler::TakeSnapshot(v8_str("sizes"));
143 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 144 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
144 const v8::HeapGraphNode* x = 145 const v8::HeapGraphNode* x =
145 GetProperty(global, v8::HeapGraphEdge::kShortcut, "x"); 146 GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
146 CHECK_NE(NULL, x); 147 CHECK_NE(NULL, x);
147 const v8::HeapGraphNode* x1 = 148 const v8::HeapGraphNode* x1 =
148 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); 149 GetProperty(x, v8::HeapGraphEdge::kProperty, "a");
149 CHECK_NE(NULL, x1); 150 CHECK_NE(NULL, x1);
150 const v8::HeapGraphNode* x2 = 151 const v8::HeapGraphNode* x2 =
151 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); 152 GetProperty(x, v8::HeapGraphEdge::kProperty, "b");
152 CHECK_NE(NULL, x2); 153 CHECK_NE(NULL, x2);
153 154
154 // Test sizes. 155 // Test sizes.
156 printf("ALF: %d %d %d %d\n", x->GetSelfSize(), x1->GetSelfSize(), x2->GetSelfS ize(), x->GetRetainedSize());
mnaganov (inactive) 2012/04/16 08:40:26 Do you need this printf? Also, please mind the lin
alexeif 2012/04/16 10:49:11 oops. fixed.
155 CHECK_EQ(x->GetSelfSize() * 3, x->GetRetainedSize()); 157 CHECK_EQ(x->GetSelfSize() * 3, x->GetRetainedSize());
156 CHECK_EQ(x1->GetSelfSize(), x1->GetRetainedSize()); 158 CHECK_EQ(x1->GetSelfSize(), x1->GetRetainedSize());
157 CHECK_EQ(x2->GetSelfSize(), x2->GetRetainedSize()); 159 CHECK_EQ(x2->GetSelfSize(), x2->GetRetainedSize());
158 } 160 }
159 161
160 162
161 TEST(BoundFunctionInSnapshot) { 163 TEST(BoundFunctionInSnapshot) {
162 v8::HandleScope scope; 164 v8::HandleScope scope;
163 LocalContext env; 165 LocalContext env;
164 CompileRun( 166 CompileRun(
165 "function myFunction(a, b) { this.a = a; this.b = b; }\n" 167 "function myFunction(a, b) { this.a = a; this.b = b; }\n"
166 "function AAAAA() {}\n" 168 "function AAAAA() {}\n"
167 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); 169 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n");
168 const v8::HeapSnapshot* snapshot = 170 const v8::HeapSnapshot* snapshot =
169 v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); 171 v8::HeapProfiler::TakeSnapshot(v8_str("sizes"));
170 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 172 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
171 const v8::HeapGraphNode* f = 173 const v8::HeapGraphNode* f =
172 GetProperty(global, v8::HeapGraphEdge::kShortcut, "boundFunction"); 174 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction");
173 CHECK(f); 175 CHECK(f);
174 CHECK_EQ(v8::String::New("native_bind"), f->GetName()); 176 CHECK_EQ(v8::String::New("native_bind"), f->GetName());
175 const v8::HeapGraphNode* bindings = 177 const v8::HeapGraphNode* bindings =
176 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); 178 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings");
177 CHECK_NE(NULL, bindings); 179 CHECK_NE(NULL, bindings);
178 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType()); 180 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType());
179 CHECK_EQ(4, bindings->GetChildrenCount()); 181 CHECK_EQ(4, bindings->GetChildrenCount());
180 182
181 const v8::HeapGraphNode* bound_this = GetProperty( 183 const v8::HeapGraphNode* bound_this = GetProperty(
182 f, v8::HeapGraphEdge::kShortcut, "bound_this"); 184 f, v8::HeapGraphEdge::kShortcut, "bound_this");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 CompileRun( 228 CompileRun(
227 "function lazy(x) { return x - 1; }\n" 229 "function lazy(x) { return x - 1; }\n"
228 "function compiled(x) { return x + 1; }\n" 230 "function compiled(x) { return x + 1; }\n"
229 "var anonymous = (function() { return function() { return 0; } })();\n" 231 "var anonymous = (function() { return function() { return 0; } })();\n"
230 "compiled(1)"); 232 "compiled(1)");
231 const v8::HeapSnapshot* snapshot = 233 const v8::HeapSnapshot* snapshot =
232 v8::HeapProfiler::TakeSnapshot(v8_str("code")); 234 v8::HeapProfiler::TakeSnapshot(v8_str("code"));
233 235
234 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 236 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
235 const v8::HeapGraphNode* compiled = 237 const v8::HeapGraphNode* compiled =
236 GetProperty(global, v8::HeapGraphEdge::kShortcut, "compiled"); 238 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled");
237 CHECK_NE(NULL, compiled); 239 CHECK_NE(NULL, compiled);
238 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); 240 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType());
239 const v8::HeapGraphNode* lazy = 241 const v8::HeapGraphNode* lazy =
240 GetProperty(global, v8::HeapGraphEdge::kShortcut, "lazy"); 242 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy");
241 CHECK_NE(NULL, lazy); 243 CHECK_NE(NULL, lazy);
242 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType()); 244 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType());
243 const v8::HeapGraphNode* anonymous = 245 const v8::HeapGraphNode* anonymous =
244 GetProperty(global, v8::HeapGraphEdge::kShortcut, "anonymous"); 246 GetProperty(global, v8::HeapGraphEdge::kProperty, "anonymous");
245 CHECK_NE(NULL, anonymous); 247 CHECK_NE(NULL, anonymous);
246 CHECK_EQ(v8::HeapGraphNode::kClosure, anonymous->GetType()); 248 CHECK_EQ(v8::HeapGraphNode::kClosure, anonymous->GetType());
247 v8::String::AsciiValue anonymous_name(anonymous->GetName()); 249 v8::String::AsciiValue anonymous_name(anonymous->GetName());
248 CHECK_EQ("", *anonymous_name); 250 CHECK_EQ("", *anonymous_name);
249 251
250 // Find references to code. 252 // Find references to code.
251 const v8::HeapGraphNode* compiled_code = 253 const v8::HeapGraphNode* compiled_code =
252 GetProperty(compiled, v8::HeapGraphEdge::kInternal, "shared"); 254 GetProperty(compiled, v8::HeapGraphEdge::kInternal, "shared");
253 CHECK_NE(NULL, compiled_code); 255 CHECK_NE(NULL, compiled_code);
254 const v8::HeapGraphNode* lazy_code = 256 const v8::HeapGraphNode* lazy_code =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 288
287 TEST(HeapSnapshotHeapNumbers) { 289 TEST(HeapSnapshotHeapNumbers) {
288 v8::HandleScope scope; 290 v8::HandleScope scope;
289 LocalContext env; 291 LocalContext env;
290 CompileRun( 292 CompileRun(
291 "a = 1; // a is Smi\n" 293 "a = 1; // a is Smi\n"
292 "b = 2.5; // b is HeapNumber"); 294 "b = 2.5; // b is HeapNumber");
293 const v8::HeapSnapshot* snapshot = 295 const v8::HeapSnapshot* snapshot =
294 v8::HeapProfiler::TakeSnapshot(v8_str("numbers")); 296 v8::HeapProfiler::TakeSnapshot(v8_str("numbers"));
295 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 297 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
296 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kShortcut, "a")); 298 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a"));
297 const v8::HeapGraphNode* b = 299 const v8::HeapGraphNode* b =
298 GetProperty(global, v8::HeapGraphEdge::kShortcut, "b"); 300 GetProperty(global, v8::HeapGraphEdge::kProperty, "b");
299 CHECK_NE(NULL, b); 301 CHECK_NE(NULL, b);
300 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); 302 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType());
301 } 303 }
302 304
303 TEST(HeapSnapshotSlicedString) { 305 TEST(HeapSnapshotSlicedString) {
304 v8::HandleScope scope; 306 v8::HandleScope scope;
305 LocalContext env; 307 LocalContext env;
306 CompileRun( 308 CompileRun(
307 "parent_string = \"123456789.123456789.123456789.123456789.123456789." 309 "parent_string = \"123456789.123456789.123456789.123456789.123456789."
308 "123456789.123456789.123456789.123456789.123456789." 310 "123456789.123456789.123456789.123456789.123456789."
309 "123456789.123456789.123456789.123456789.123456789." 311 "123456789.123456789.123456789.123456789.123456789."
310 "123456789.123456789.123456789.123456789.123456789.\";" 312 "123456789.123456789.123456789.123456789.123456789.\";"
311 "child_string = parent_string.slice(100);"); 313 "child_string = parent_string.slice(100);");
312 const v8::HeapSnapshot* snapshot = 314 const v8::HeapSnapshot* snapshot =
313 v8::HeapProfiler::TakeSnapshot(v8_str("strings")); 315 v8::HeapProfiler::TakeSnapshot(v8_str("strings"));
314 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 316 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
315 const v8::HeapGraphNode* parent_string = 317 const v8::HeapGraphNode* parent_string =
316 GetProperty(global, v8::HeapGraphEdge::kShortcut, "parent_string"); 318 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string");
317 CHECK_NE(NULL, parent_string); 319 CHECK_NE(NULL, parent_string);
318 const v8::HeapGraphNode* child_string = 320 const v8::HeapGraphNode* child_string =
319 GetProperty(global, v8::HeapGraphEdge::kShortcut, "child_string"); 321 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string");
320 CHECK_NE(NULL, child_string); 322 CHECK_NE(NULL, child_string);
321 const v8::HeapGraphNode* parent = 323 const v8::HeapGraphNode* parent =
322 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); 324 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent");
323 CHECK_EQ(parent_string, parent); 325 CHECK_EQ(parent_string, parent);
324 } 326 }
325 327
326 TEST(HeapSnapshotInternalReferences) { 328 TEST(HeapSnapshotInternalReferences) {
327 v8::HandleScope scope; 329 v8::HandleScope scope;
328 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 330 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
329 global_template->SetInternalFieldCount(2); 331 global_template->SetInternalFieldCount(2);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 v8::HeapProfiler::TakeSnapshot(v8_str("s2")); 379 v8::HeapProfiler::TakeSnapshot(v8_str("s2"));
378 380
379 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); 381 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
380 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 382 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
381 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); 383 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId());
382 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); 384 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId());
383 385
384 const v8::HeapGraphNode* a1 = 386 const v8::HeapGraphNode* a1 =
385 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); 387 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a");
386 CHECK_NE(NULL, a1); 388 CHECK_NE(NULL, a1);
387 const v8::HeapGraphNode* e1 =
388 GetProperty(a1, v8::HeapGraphEdge::kHidden, "1");
389 CHECK_NE(NULL, e1);
390 const v8::HeapGraphNode* k1 = 389 const v8::HeapGraphNode* k1 =
391 GetProperty(e1, v8::HeapGraphEdge::kInternal, "elements"); 390 GetProperty(a1, v8::HeapGraphEdge::kInternal, "elements");
392 CHECK_NE(NULL, k1); 391 CHECK_NE(NULL, k1);
393 const v8::HeapGraphNode* a2 = 392 const v8::HeapGraphNode* a2 =
394 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); 393 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a");
395 CHECK_NE(NULL, a2); 394 CHECK_NE(NULL, a2);
396 const v8::HeapGraphNode* e2 =
397 GetProperty(a2, v8::HeapGraphEdge::kHidden, "1");
398 CHECK_NE(NULL, e2);
399 const v8::HeapGraphNode* k2 = 395 const v8::HeapGraphNode* k2 =
400 GetProperty(e2, v8::HeapGraphEdge::kInternal, "elements"); 396 GetProperty(a2, v8::HeapGraphEdge::kInternal, "elements");
401 CHECK_NE(NULL, k2); 397 CHECK_NE(NULL, k2);
402 398
403 CHECK_EQ_SNAPSHOT_OBJECT_ID(a1->GetId(), a2->GetId()); 399 CHECK_EQ_SNAPSHOT_OBJECT_ID(a1->GetId(), a2->GetId());
404 CHECK_EQ_SNAPSHOT_OBJECT_ID(e1->GetId(), e2->GetId());
405 CHECK_EQ_SNAPSHOT_OBJECT_ID(k1->GetId(), k2->GetId()); 400 CHECK_EQ_SNAPSHOT_OBJECT_ID(k1->GetId(), k2->GetId());
406 } 401 }
407 402
408 TEST(HeapEntryIdsAndGC) { 403 TEST(HeapEntryIdsAndGC) {
409 v8::HandleScope scope; 404 v8::HandleScope scope;
410 LocalContext env; 405 LocalContext env;
411 406
412 CompileRun( 407 CompileRun(
413 "function A() {}\n" 408 "function A() {}\n"
414 "function B(x) { this.x = x; }\n" 409 "function B(x) { this.x = x; }\n"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 "node6.b.a.b = node6.b.b; // node2 -> node3\n" 502 "node6.b.a.b = node6.b.b; // node2 -> node3\n"
508 "node6.b.b.a = node6.b.a; // node3 -> node2\n" 503 "node6.b.b.a = node6.b.a; // node3 -> node2\n"
509 "})();"); 504 "})();");
510 505
511 const v8::HeapSnapshot* snapshot = 506 const v8::HeapSnapshot* snapshot =
512 v8::HeapProfiler::TakeSnapshot(v8_str("dominators")); 507 v8::HeapProfiler::TakeSnapshot(v8_str("dominators"));
513 508
514 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 509 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
515 CHECK_NE(NULL, global); 510 CHECK_NE(NULL, global);
516 const v8::HeapGraphNode* node6 = 511 const v8::HeapGraphNode* node6 =
517 GetProperty(global, v8::HeapGraphEdge::kShortcut, "node6"); 512 GetProperty(global, v8::HeapGraphEdge::kProperty, "node6");
518 CHECK_NE(NULL, node6); 513 CHECK_NE(NULL, node6);
519 const v8::HeapGraphNode* node5 = 514 const v8::HeapGraphNode* node5 =
520 GetProperty(node6, v8::HeapGraphEdge::kProperty, "a"); 515 GetProperty(node6, v8::HeapGraphEdge::kProperty, "a");
521 CHECK_NE(NULL, node5); 516 CHECK_NE(NULL, node5);
522 const v8::HeapGraphNode* node4 = 517 const v8::HeapGraphNode* node4 =
523 GetProperty(node6, v8::HeapGraphEdge::kProperty, "b"); 518 GetProperty(node6, v8::HeapGraphEdge::kProperty, "b");
524 CHECK_NE(NULL, node4); 519 CHECK_NE(NULL, node4);
525 const v8::HeapGraphNode* node3 = 520 const v8::HeapGraphNode* node3 =
526 GetProperty(node4, v8::HeapGraphEdge::kProperty, "b"); 521 GetProperty(node4, v8::HeapGraphEdge::kProperty, "b");
527 CHECK_NE(NULL, node3); 522 CHECK_NE(NULL, node3);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 " }\n" 647 " }\n"
653 " return null;\n" 648 " return null;\n"
654 "}\n"); 649 "}\n");
655 // Get the string index using the path: <root> -> <global>.b.x.s 650 // Get the string index using the path: <root> -> <global>.b.x.s
656 v8::Local<v8::Value> string_obj_pos_val = CompileRun( 651 v8::Local<v8::Value> string_obj_pos_val = CompileRun(
657 "GetChildPosByProperty(\n" 652 "GetChildPosByProperty(\n"
658 " GetChildPosByProperty(\n" 653 " GetChildPosByProperty(\n"
659 " GetChildPosByProperty(" 654 " GetChildPosByProperty("
660 " parsed.edges[parsed.nodes[edges_index_offset]" 655 " parsed.edges[parsed.nodes[edges_index_offset]"
661 " + edge_to_node_offset]," 656 " + edge_to_node_offset],"
662 " \"b\", shortcut_type),\n" 657 " \"b\", property_type),\n"
663 " \"x\", property_type)," 658 " \"x\", property_type),"
664 " \"s\", property_type)"); 659 " \"s\", property_type)");
665 CHECK(!string_obj_pos_val.IsEmpty()); 660 CHECK(!string_obj_pos_val.IsEmpty());
666 int string_obj_pos = 661 int string_obj_pos =
667 static_cast<int>(string_obj_pos_val->ToNumber()->Value()); 662 static_cast<int>(string_obj_pos_val->ToNumber()->Value());
668 v8::Local<v8::Object> nodes_array = 663 v8::Local<v8::Object> nodes_array =
669 parsed_snapshot->Get(v8_str("nodes"))->ToObject(); 664 parsed_snapshot->Get(v8_str("nodes"))->ToObject();
670 int string_index = static_cast<int>( 665 int string_index = static_cast<int>(
671 nodes_array->Get(string_obj_pos + 1)->ToNumber()->Value()); 666 nodes_array->Get(string_obj_pos + 1)->ToNumber()->Value());
672 CHECK_GT(string_index, 0); 667 CHECK_GT(string_index, 0);
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 v8::HandleScope scope; 1096 v8::HandleScope scope;
1102 LocalContext env; 1097 LocalContext env;
1103 1098
1104 GraphWithImplicitRefs graph(&env); 1099 GraphWithImplicitRefs graph(&env);
1105 v8::V8::SetGlobalGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); 1100 v8::V8::SetGlobalGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
1106 1101
1107 const v8::HeapSnapshot* snapshot = 1102 const v8::HeapSnapshot* snapshot =
1108 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs")); 1103 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs"));
1109 1104
1110 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); 1105 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
1111 // Use kShortcut type to skip intermediate JSGlobalPropertyCell
1112 const v8::HeapGraphNode* obj0 = GetProperty( 1106 const v8::HeapGraphNode* obj0 = GetProperty(
1113 global_object, v8::HeapGraphEdge::kShortcut, "root_object"); 1107 global_object, v8::HeapGraphEdge::kProperty, "root_object");
1114 CHECK(obj0); 1108 CHECK(obj0);
1115 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); 1109 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType());
1116 const v8::HeapGraphNode* obj1 = GetProperty( 1110 const v8::HeapGraphNode* obj1 = GetProperty(
1117 obj0, v8::HeapGraphEdge::kInternal, "native"); 1111 obj0, v8::HeapGraphEdge::kInternal, "native");
1118 CHECK(obj1); 1112 CHECK(obj1);
1119 int implicit_targets_count = 0; 1113 int implicit_targets_count = 0;
1120 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) { 1114 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) {
1121 const v8::HeapGraphEdge* prop = obj1->GetChild(i); 1115 const v8::HeapGraphEdge* prop = obj1->GetChild(i);
1122 v8::String::AsciiValue prop_name(prop->GetName()); 1116 v8::String::AsciiValue prop_name(prop->GetName());
1123 if (prop->GetType() == v8::HeapGraphEdge::kInternal && 1117 if (prop->GetType() == v8::HeapGraphEdge::kInternal &&
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 1270
1277 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };"); 1271 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };");
1278 const v8::HeapSnapshot* snapshot = 1272 const v8::HeapSnapshot* snapshot =
1279 v8::HeapProfiler::TakeSnapshot(v8_str("value")); 1273 v8::HeapProfiler::TakeSnapshot(v8_str("value"));
1280 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1274 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1281 CHECK(global->GetHeapValue()->IsObject()); 1275 CHECK(global->GetHeapValue()->IsObject());
1282 v8::Local<v8::Object> js_global = 1276 v8::Local<v8::Object> js_global =
1283 env->Global()->GetPrototype().As<v8::Object>(); 1277 env->Global()->GetPrototype().As<v8::Object>();
1284 CHECK(js_global == global->GetHeapValue()); 1278 CHECK(js_global == global->GetHeapValue());
1285 const v8::HeapGraphNode* obj = GetProperty( 1279 const v8::HeapGraphNode* obj = GetProperty(
1286 global, v8::HeapGraphEdge::kShortcut, "a"); 1280 global, v8::HeapGraphEdge::kProperty, "a");
1287 CHECK(obj->GetHeapValue()->IsObject()); 1281 CHECK(obj->GetHeapValue()->IsObject());
1288 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); 1282 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>();
1289 CHECK(js_obj == obj->GetHeapValue()); 1283 CHECK(js_obj == obj->GetHeapValue());
1290 const v8::HeapGraphNode* s_prop = 1284 const v8::HeapGraphNode* s_prop =
1291 GetProperty(obj, v8::HeapGraphEdge::kProperty, "s_prop"); 1285 GetProperty(obj, v8::HeapGraphEdge::kProperty, "s_prop");
1292 v8::Local<v8::String> js_s_prop = 1286 v8::Local<v8::String> js_s_prop =
1293 js_obj->Get(v8_str("s_prop")).As<v8::String>(); 1287 js_obj->Get(v8_str("s_prop")).As<v8::String>();
1294 CHECK(js_s_prop == s_prop->GetHeapValue()); 1288 CHECK(js_s_prop == s_prop->GetHeapValue());
1295 const v8::HeapGraphNode* n_prop = 1289 const v8::HeapGraphNode* n_prop =
1296 GetProperty(obj, v8::HeapGraphEdge::kProperty, "n_prop"); 1290 GetProperty(obj, v8::HeapGraphEdge::kProperty, "n_prop");
1297 v8::Local<v8::Number> js_n_prop = 1291 v8::Local<v8::Number> js_n_prop =
1298 js_obj->Get(v8_str("n_prop")).As<v8::Number>(); 1292 js_obj->Get(v8_str("n_prop")).As<v8::Number>();
1299 CHECK(js_n_prop == n_prop->GetHeapValue()); 1293 CHECK(js_n_prop == n_prop->GetHeapValue());
1300 } 1294 }
1301 1295
1302 1296
1303 TEST(GetHeapValueForDeletedObject) { 1297 TEST(GetHeapValueForDeletedObject) {
1304 v8::HandleScope scope; 1298 v8::HandleScope scope;
1305 LocalContext env; 1299 LocalContext env;
1306 1300
1307 // It is impossible to delete a global property, so we are about to delete a 1301 // It is impossible to delete a global property, so we are about to delete a
1308 // property of the "a" object. Also, the "p" object can't be an empty one 1302 // property of the "a" object. Also, the "p" object can't be an empty one
1309 // because the empty object is static and isn't actually deleted. 1303 // because the empty object is static and isn't actually deleted.
1310 CompileRun("a = { p: { r: {} } };"); 1304 CompileRun("a = { p: { r: {} } };");
1311 const v8::HeapSnapshot* snapshot = 1305 const v8::HeapSnapshot* snapshot =
1312 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); 1306 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot"));
1313 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1307 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1314 const v8::HeapGraphNode* obj = GetProperty( 1308 const v8::HeapGraphNode* obj = GetProperty(
1315 global, v8::HeapGraphEdge::kShortcut, "a"); 1309 global, v8::HeapGraphEdge::kProperty, "a");
1316 const v8::HeapGraphNode* prop = GetProperty( 1310 const v8::HeapGraphNode* prop = GetProperty(
1317 obj, v8::HeapGraphEdge::kProperty, "p"); 1311 obj, v8::HeapGraphEdge::kProperty, "p");
1318 { 1312 {
1319 // Perform the check inside a nested local scope to avoid creating a 1313 // Perform the check inside a nested local scope to avoid creating a
1320 // reference to the object we are deleting. 1314 // reference to the object we are deleting.
1321 v8::HandleScope scope; 1315 v8::HandleScope scope;
1322 CHECK(prop->GetHeapValue()->IsObject()); 1316 CHECK(prop->GetHeapValue()->IsObject());
1323 } 1317 }
1324 CompileRun("delete a.p;"); 1318 CompileRun("delete a.p;");
1325 CHECK(prop->GetHeapValue()->IsUndefined()); 1319 CHECK(prop->GetHeapValue()->IsUndefined());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 "});\n" 1386 "});\n"
1393 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" 1387 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n"
1394 " return this.value_ = value;\n" 1388 " return this.value_ = value;\n"
1395 "});\n"); 1389 "});\n");
1396 const v8::HeapSnapshot* snapshot = 1390 const v8::HeapSnapshot* snapshot =
1397 v8::HeapProfiler::TakeSnapshot(v8_str("fastCaseGetter")); 1391 v8::HeapProfiler::TakeSnapshot(v8_str("fastCaseGetter"));
1398 1392
1399 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1393 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1400 CHECK_NE(NULL, global); 1394 CHECK_NE(NULL, global);
1401 const v8::HeapGraphNode* obj1 = 1395 const v8::HeapGraphNode* obj1 =
1402 GetProperty(global, v8::HeapGraphEdge::kShortcut, "obj1"); 1396 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1");
1403 CHECK_NE(NULL, obj1); 1397 CHECK_NE(NULL, obj1);
1404 const v8::HeapGraphNode* getterFunction = 1398 const v8::HeapGraphNode* getterFunction =
1405 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get-propWithGetter"); 1399 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get-propWithGetter");
1406 CHECK_NE(NULL, getterFunction); 1400 CHECK_NE(NULL, getterFunction);
1407 const v8::HeapGraphNode* setterFunction = 1401 const v8::HeapGraphNode* setterFunction =
1408 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set-propWithSetter"); 1402 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set-propWithSetter");
1409 CHECK_NE(NULL, setterFunction); 1403 CHECK_NE(NULL, setterFunction);
1410 } 1404 }
1411 1405
1412 1406
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 v8::HandleScope scope; 1468 v8::HandleScope scope;
1475 LocalContext env; 1469 LocalContext env;
1476 1470
1477 CompileRun( 1471 CompileRun(
1478 "fun = (function (x) { return function () { return x + 1; } })(1);"); 1472 "fun = (function (x) { return function () { return x + 1; } })(1);");
1479 const v8::HeapSnapshot* snapshot = 1473 const v8::HeapSnapshot* snapshot =
1480 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); 1474 v8::HeapProfiler::TakeSnapshot(v8_str("fun"));
1481 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1475 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1482 CHECK_NE(NULL, global); 1476 CHECK_NE(NULL, global);
1483 const v8::HeapGraphNode* fun = 1477 const v8::HeapGraphNode* fun =
1484 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); 1478 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun");
1485 CHECK(HasWeakEdge(fun)); 1479 CHECK(HasWeakEdge(fun));
1486 const v8::HeapGraphNode* shared = 1480 const v8::HeapGraphNode* shared =
1487 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); 1481 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared");
1488 CHECK(HasWeakEdge(shared)); 1482 CHECK(HasWeakEdge(shared));
1489 } 1483 }
1490 1484
1491 1485
1492 TEST(PersistentHandleCount) { 1486 TEST(PersistentHandleCount) {
1493 v8::HandleScope scope; 1487 v8::HandleScope scope;
1494 LocalContext env; 1488 LocalContext env;
(...skipping 19 matching lines...) Expand all
1514 // Dipose the persistent handles in a different order. 1508 // Dipose the persistent handles in a different order.
1515 p_AAA.Dispose(); 1509 p_AAA.Dispose();
1516 CHECK_EQ(global_handle_count + 2, 1510 CHECK_EQ(global_handle_count + 2,
1517 v8::HeapProfiler::GetPersistentHandleCount()); 1511 v8::HeapProfiler::GetPersistentHandleCount());
1518 p_CCC.Dispose(); 1512 p_CCC.Dispose();
1519 CHECK_EQ(global_handle_count + 1, 1513 CHECK_EQ(global_handle_count + 1,
1520 v8::HeapProfiler::GetPersistentHandleCount()); 1514 v8::HeapProfiler::GetPersistentHandleCount());
1521 p_BBB.Dispose(); 1515 p_BBB.Dispose();
1522 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount()); 1516 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount());
1523 } 1517 }
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