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