| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 static bool AddressesMatch(void* key1, void* key2) { | 130 static bool AddressesMatch(void* key1, void* key2) { |
| 131 return key1 == key2; | 131 return key1 == key2; |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 // Check that snapshot has no unretained entries except root. | 135 // Check that snapshot has no unretained entries except root. |
| 136 static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth) { | 136 static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) { |
| 137 i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>( | 137 i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>( |
| 138 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); | 138 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 139 | 139 |
| 140 i::HashMap visited(AddressesMatch); | 140 i::HashMap visited(AddressesMatch); |
| 141 i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges(); | 141 i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges(); |
| 142 for (int i = 0; i < edges.length(); ++i) { | 142 for (int i = 0; i < edges.length(); ++i) { |
| 143 i::HashMap::Entry* entry = visited.Lookup( | 143 i::HashMap::Entry* entry = visited.Lookup( |
| 144 reinterpret_cast<void*>(edges[i].to()), | 144 reinterpret_cast<void*>(edges[i].to()), |
| 145 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to())), | 145 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to())), |
| 146 true); | 146 true); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 171 | 171 |
| 172 CompileRun( | 172 CompileRun( |
| 173 "function A2() {}\n" | 173 "function A2() {}\n" |
| 174 "function B2(x) { return function() { return typeof x; }; }\n" | 174 "function B2(x) { return function() { return typeof x; }; }\n" |
| 175 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" | 175 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" |
| 176 "var a2 = new A2();\n" | 176 "var a2 = new A2();\n" |
| 177 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" | 177 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" |
| 178 "var c2 = new C2(a2);"); | 178 "var c2 = new C2(a2);"); |
| 179 const v8::HeapSnapshot* snapshot_env2 = | 179 const v8::HeapSnapshot* snapshot_env2 = |
| 180 heap_profiler->TakeHeapSnapshot(v8_str("env2")); | 180 heap_profiler->TakeHeapSnapshot(v8_str("env2")); |
| 181 CHECK(ValidateSnapshot(snapshot_env2, 3)); | 181 CHECK(ValidateSnapshot(snapshot_env2)); |
| 182 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); | 182 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); |
| 183 | 183 |
| 184 // Verify, that JS global object of env2 has '..2' properties. | 184 // Verify, that JS global object of env2 has '..2' properties. |
| 185 const v8::HeapGraphNode* a2_node = | 185 const v8::HeapGraphNode* a2_node = |
| 186 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2"); | 186 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2"); |
| 187 CHECK_NE(NULL, a2_node); | 187 CHECK_NE(NULL, a2_node); |
| 188 CHECK_NE( | 188 CHECK_NE( |
| 189 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1")); | 189 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1")); |
| 190 CHECK_NE( | 190 CHECK_NE( |
| 191 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2")); | 191 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 207 | 207 |
| 208 // -a-> X1 --a | 208 // -a-> X1 --a |
| 209 // x -b-> X2 <-| | 209 // x -b-> X2 <-| |
| 210 CompileRun( | 210 CompileRun( |
| 211 "function X(a, b) { this.a = a; this.b = b; }\n" | 211 "function X(a, b) { this.a = a; this.b = b; }\n" |
| 212 "x = new X(new X(), new X());\n" | 212 "x = new X(new X(), new X());\n" |
| 213 "dummy = new X();\n" | 213 "dummy = new X();\n" |
| 214 "(function() { x.a.a = x.b; })();"); | 214 "(function() { x.a.a = x.b; })();"); |
| 215 const v8::HeapSnapshot* snapshot = | 215 const v8::HeapSnapshot* snapshot = |
| 216 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); | 216 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); |
| 217 CHECK(ValidateSnapshot(snapshot, 3)); | 217 CHECK(ValidateSnapshot(snapshot)); |
| 218 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 218 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 219 const v8::HeapGraphNode* x = | 219 const v8::HeapGraphNode* x = |
| 220 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); | 220 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); |
| 221 CHECK_NE(NULL, x); | 221 CHECK_NE(NULL, x); |
| 222 const v8::HeapGraphNode* x1 = | 222 const v8::HeapGraphNode* x1 = |
| 223 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); | 223 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); |
| 224 CHECK_NE(NULL, x1); | 224 CHECK_NE(NULL, x1); |
| 225 const v8::HeapGraphNode* x2 = | 225 const v8::HeapGraphNode* x2 = |
| 226 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); | 226 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); |
| 227 CHECK_NE(NULL, x2); | 227 CHECK_NE(NULL, x2); |
| 228 | 228 |
| 229 // Test sizes. | 229 // Test sizes. |
| 230 CHECK_NE(0, x->GetSelfSize()); | 230 CHECK_NE(0, x->GetSelfSize()); |
| 231 CHECK_NE(0, x1->GetSelfSize()); | 231 CHECK_NE(0, x1->GetSelfSize()); |
| 232 CHECK_NE(0, x2->GetSelfSize()); | 232 CHECK_NE(0, x2->GetSelfSize()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 | 235 |
| 236 TEST(BoundFunctionInSnapshot) { | 236 TEST(BoundFunctionInSnapshot) { |
| 237 LocalContext env; | 237 LocalContext env; |
| 238 v8::HandleScope scope(env->GetIsolate()); | 238 v8::HandleScope scope(env->GetIsolate()); |
| 239 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 239 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 240 CompileRun( | 240 CompileRun( |
| 241 "function myFunction(a, b) { this.a = a; this.b = b; }\n" | 241 "function myFunction(a, b) { this.a = a; this.b = b; }\n" |
| 242 "function AAAAA() {}\n" | 242 "function AAAAA() {}\n" |
| 243 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); | 243 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); |
| 244 const v8::HeapSnapshot* snapshot = | 244 const v8::HeapSnapshot* snapshot = |
| 245 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); | 245 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); |
| 246 CHECK(ValidateSnapshot(snapshot, 3)); | 246 CHECK(ValidateSnapshot(snapshot)); |
| 247 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 247 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 248 const v8::HeapGraphNode* f = | 248 const v8::HeapGraphNode* f = |
| 249 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); | 249 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); |
| 250 CHECK(f); | 250 CHECK(f); |
| 251 CHECK_EQ(v8::String::New("native_bind"), f->GetName()); | 251 CHECK_EQ(v8::String::New("native_bind"), f->GetName()); |
| 252 const v8::HeapGraphNode* bindings = | 252 const v8::HeapGraphNode* bindings = |
| 253 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); | 253 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); |
| 254 CHECK_NE(NULL, bindings); | 254 CHECK_NE(NULL, bindings); |
| 255 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType()); | 255 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType()); |
| 256 CHECK_EQ(4, bindings->GetChildrenCount()); | 256 CHECK_EQ(4, bindings->GetChildrenCount()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 275 TEST(HeapSnapshotEntryChildren) { | 275 TEST(HeapSnapshotEntryChildren) { |
| 276 LocalContext env; | 276 LocalContext env; |
| 277 v8::HandleScope scope(env->GetIsolate()); | 277 v8::HandleScope scope(env->GetIsolate()); |
| 278 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 278 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 279 | 279 |
| 280 CompileRun( | 280 CompileRun( |
| 281 "function A() { }\n" | 281 "function A() { }\n" |
| 282 "a = new A;"); | 282 "a = new A;"); |
| 283 const v8::HeapSnapshot* snapshot = | 283 const v8::HeapSnapshot* snapshot = |
| 284 heap_profiler->TakeHeapSnapshot(v8_str("children")); | 284 heap_profiler->TakeHeapSnapshot(v8_str("children")); |
| 285 CHECK(ValidateSnapshot(snapshot, 3)); | 285 CHECK(ValidateSnapshot(snapshot)); |
| 286 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 286 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 287 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { | 287 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { |
| 288 const v8::HeapGraphEdge* prop = global->GetChild(i); | 288 const v8::HeapGraphEdge* prop = global->GetChild(i); |
| 289 CHECK_EQ(global, prop->GetFromNode()); | 289 CHECK_EQ(global, prop->GetFromNode()); |
| 290 } | 290 } |
| 291 const v8::HeapGraphNode* a = | 291 const v8::HeapGraphNode* a = |
| 292 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); | 292 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); |
| 293 CHECK_NE(NULL, a); | 293 CHECK_NE(NULL, a); |
| 294 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { | 294 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { |
| 295 const v8::HeapGraphEdge* prop = a->GetChild(i); | 295 const v8::HeapGraphEdge* prop = a->GetChild(i); |
| 296 CHECK_EQ(a, prop->GetFromNode()); | 296 CHECK_EQ(a, prop->GetFromNode()); |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 | 299 |
| 300 | 300 |
| 301 TEST(HeapSnapshotCodeObjects) { | 301 TEST(HeapSnapshotCodeObjects) { |
| 302 LocalContext env; | 302 LocalContext env; |
| 303 v8::HandleScope scope(env->GetIsolate()); | 303 v8::HandleScope scope(env->GetIsolate()); |
| 304 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 304 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 305 | 305 |
| 306 CompileRun( | 306 CompileRun( |
| 307 "function lazy(x) { return x - 1; }\n" | 307 "function lazy(x) { return x - 1; }\n" |
| 308 "function compiled(x) { return x + 1; }\n" | 308 "function compiled(x) { return x + 1; }\n" |
| 309 "var anonymous = (function() { return function() { return 0; } })();\n" | 309 "var anonymous = (function() { return function() { return 0; } })();\n" |
| 310 "compiled(1)"); | 310 "compiled(1)"); |
| 311 const v8::HeapSnapshot* snapshot = | 311 const v8::HeapSnapshot* snapshot = |
| 312 heap_profiler->TakeHeapSnapshot(v8_str("code")); | 312 heap_profiler->TakeHeapSnapshot(v8_str("code")); |
| 313 CHECK(ValidateSnapshot(snapshot, 3)); | 313 CHECK(ValidateSnapshot(snapshot)); |
| 314 | 314 |
| 315 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 315 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 316 const v8::HeapGraphNode* compiled = | 316 const v8::HeapGraphNode* compiled = |
| 317 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); | 317 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); |
| 318 CHECK_NE(NULL, compiled); | 318 CHECK_NE(NULL, compiled); |
| 319 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); | 319 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); |
| 320 const v8::HeapGraphNode* lazy = | 320 const v8::HeapGraphNode* lazy = |
| 321 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy"); | 321 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy"); |
| 322 CHECK_NE(NULL, lazy); | 322 CHECK_NE(NULL, lazy); |
| 323 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType()); | 323 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 TEST(HeapSnapshotHeapNumbers) { | 368 TEST(HeapSnapshotHeapNumbers) { |
| 369 LocalContext env; | 369 LocalContext env; |
| 370 v8::HandleScope scope(env->GetIsolate()); | 370 v8::HandleScope scope(env->GetIsolate()); |
| 371 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 371 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 372 CompileRun( | 372 CompileRun( |
| 373 "a = 1; // a is Smi\n" | 373 "a = 1; // a is Smi\n" |
| 374 "b = 2.5; // b is HeapNumber"); | 374 "b = 2.5; // b is HeapNumber"); |
| 375 const v8::HeapSnapshot* snapshot = | 375 const v8::HeapSnapshot* snapshot = |
| 376 heap_profiler->TakeHeapSnapshot(v8_str("numbers")); | 376 heap_profiler->TakeHeapSnapshot(v8_str("numbers")); |
| 377 CHECK(ValidateSnapshot(snapshot, 3)); | 377 CHECK(ValidateSnapshot(snapshot)); |
| 378 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 378 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 379 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); | 379 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); |
| 380 const v8::HeapGraphNode* b = | 380 const v8::HeapGraphNode* b = |
| 381 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); | 381 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); |
| 382 CHECK_NE(NULL, b); | 382 CHECK_NE(NULL, b); |
| 383 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); | 383 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); |
| 384 } | 384 } |
| 385 | 385 |
| 386 | 386 |
| 387 TEST(HeapSnapshotSlicedString) { | 387 TEST(HeapSnapshotSlicedString) { |
| 388 LocalContext env; | 388 LocalContext env; |
| 389 v8::HandleScope scope(env->GetIsolate()); | 389 v8::HandleScope scope(env->GetIsolate()); |
| 390 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 390 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 391 CompileRun( | 391 CompileRun( |
| 392 "parent_string = \"123456789.123456789.123456789.123456789.123456789." | 392 "parent_string = \"123456789.123456789.123456789.123456789.123456789." |
| 393 "123456789.123456789.123456789.123456789.123456789." | 393 "123456789.123456789.123456789.123456789.123456789." |
| 394 "123456789.123456789.123456789.123456789.123456789." | 394 "123456789.123456789.123456789.123456789.123456789." |
| 395 "123456789.123456789.123456789.123456789.123456789.\";" | 395 "123456789.123456789.123456789.123456789.123456789.\";" |
| 396 "child_string = parent_string.slice(100);"); | 396 "child_string = parent_string.slice(100);"); |
| 397 const v8::HeapSnapshot* snapshot = | 397 const v8::HeapSnapshot* snapshot = |
| 398 heap_profiler->TakeHeapSnapshot(v8_str("strings")); | 398 heap_profiler->TakeHeapSnapshot(v8_str("strings")); |
| 399 CHECK(ValidateSnapshot(snapshot, 3)); | 399 CHECK(ValidateSnapshot(snapshot)); |
| 400 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 400 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 401 const v8::HeapGraphNode* parent_string = | 401 const v8::HeapGraphNode* parent_string = |
| 402 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); | 402 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); |
| 403 CHECK_NE(NULL, parent_string); | 403 CHECK_NE(NULL, parent_string); |
| 404 const v8::HeapGraphNode* child_string = | 404 const v8::HeapGraphNode* child_string = |
| 405 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); | 405 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); |
| 406 CHECK_NE(NULL, child_string); | 406 CHECK_NE(NULL, child_string); |
| 407 const v8::HeapGraphNode* parent = | 407 const v8::HeapGraphNode* parent = |
| 408 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); | 408 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); |
| 409 CHECK_EQ(parent_string, parent); | 409 CHECK_EQ(parent_string, parent); |
| 410 } | 410 } |
| 411 | 411 |
| 412 | 412 |
| 413 TEST(HeapSnapshotInternalReferences) { | 413 TEST(HeapSnapshotInternalReferences) { |
| 414 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 414 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 415 v8::HandleScope scope(isolate); | 415 v8::HandleScope scope(isolate); |
| 416 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 416 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 417 global_template->SetInternalFieldCount(2); | 417 global_template->SetInternalFieldCount(2); |
| 418 LocalContext env(NULL, global_template); | 418 LocalContext env(NULL, global_template); |
| 419 v8::Handle<v8::Object> global_proxy = env->Global(); | 419 v8::Handle<v8::Object> global_proxy = env->Global(); |
| 420 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 420 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
| 421 CHECK_EQ(2, global->InternalFieldCount()); | 421 CHECK_EQ(2, global->InternalFieldCount()); |
| 422 v8::Local<v8::Object> obj = v8::Object::New(); | 422 v8::Local<v8::Object> obj = v8::Object::New(); |
| 423 global->SetInternalField(0, v8_num(17)); | 423 global->SetInternalField(0, v8_num(17)); |
| 424 global->SetInternalField(1, obj); | 424 global->SetInternalField(1, obj); |
| 425 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 425 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
| 426 const v8::HeapSnapshot* snapshot = | 426 const v8::HeapSnapshot* snapshot = |
| 427 heap_profiler->TakeHeapSnapshot(v8_str("internals")); | 427 heap_profiler->TakeHeapSnapshot(v8_str("internals")); |
| 428 CHECK(ValidateSnapshot(snapshot, 3)); | 428 CHECK(ValidateSnapshot(snapshot)); |
| 429 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 429 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
| 430 // The first reference will not present, because it's a Smi. | 430 // The first reference will not present, because it's a Smi. |
| 431 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); | 431 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); |
| 432 // The second reference is to an object. | 432 // The second reference is to an object. |
| 433 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); | 433 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); |
| 434 } | 434 } |
| 435 | 435 |
| 436 | 436 |
| 437 // Trying to introduce a check helper for uint32_t causes many | 437 // Trying to introduce a check helper for uint32_t causes many |
| 438 // overloading ambiguities, so it seems easier just to cast | 438 // overloading ambiguities, so it seems easier just to cast |
| 439 // them to a signed type. | 439 // them to a signed type. |
| 440 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \ | 440 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \ |
| 441 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b)) | 441 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b)) |
| 442 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ | 442 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ |
| 443 CHECK((a) != (b)) // NOLINT | 443 CHECK((a) != (b)) // NOLINT |
| 444 | 444 |
| 445 TEST(HeapSnapshotAddressReuse) { | 445 TEST(HeapSnapshotAddressReuse) { |
| 446 LocalContext env; | 446 LocalContext env; |
| 447 v8::HandleScope scope(env->GetIsolate()); | 447 v8::HandleScope scope(env->GetIsolate()); |
| 448 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 448 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 449 | 449 |
| 450 CompileRun( | 450 CompileRun( |
| 451 "function A() {}\n" | 451 "function A() {}\n" |
| 452 "var a = [];\n" | 452 "var a = [];\n" |
| 453 "for (var i = 0; i < 10000; ++i)\n" | 453 "for (var i = 0; i < 10000; ++i)\n" |
| 454 " a[i] = new A();\n"); | 454 " a[i] = new A();\n"); |
| 455 const v8::HeapSnapshot* snapshot1 = | 455 const v8::HeapSnapshot* snapshot1 = |
| 456 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1")); | 456 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1")); |
| 457 CHECK(ValidateSnapshot(snapshot1, 3)); | 457 CHECK(ValidateSnapshot(snapshot1)); |
| 458 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); | 458 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); |
| 459 | 459 |
| 460 CompileRun( | 460 CompileRun( |
| 461 "for (var i = 0; i < 10000; ++i)\n" | 461 "for (var i = 0; i < 10000; ++i)\n" |
| 462 " a[i] = new A();\n"); | 462 " a[i] = new A();\n"); |
| 463 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 463 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 464 | 464 |
| 465 const v8::HeapSnapshot* snapshot2 = | 465 const v8::HeapSnapshot* snapshot2 = |
| 466 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2")); | 466 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2")); |
| 467 CHECK(ValidateSnapshot(snapshot2, 3)); | 467 CHECK(ValidateSnapshot(snapshot2)); |
| 468 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 468 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
| 469 | 469 |
| 470 const v8::HeapGraphNode* array_node = | 470 const v8::HeapGraphNode* array_node = |
| 471 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); | 471 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); |
| 472 CHECK_NE(NULL, array_node); | 472 CHECK_NE(NULL, array_node); |
| 473 int wrong_count = 0; | 473 int wrong_count = 0; |
| 474 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { | 474 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { |
| 475 const v8::HeapGraphEdge* prop = array_node->GetChild(i); | 475 const v8::HeapGraphEdge* prop = array_node->GetChild(i); |
| 476 if (prop->GetType() != v8::HeapGraphEdge::kElement) | 476 if (prop->GetType() != v8::HeapGraphEdge::kElement) |
| 477 continue; | 477 continue; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 491 CompileRun( | 491 CompileRun( |
| 492 "function AnObject() {\n" | 492 "function AnObject() {\n" |
| 493 " this.first = 'first';\n" | 493 " this.first = 'first';\n" |
| 494 " this.second = 'second';\n" | 494 " this.second = 'second';\n" |
| 495 "}\n" | 495 "}\n" |
| 496 "var a = new Array();\n" | 496 "var a = new Array();\n" |
| 497 "for (var i = 0; i < 10; ++i)\n" | 497 "for (var i = 0; i < 10; ++i)\n" |
| 498 " a.push(new AnObject());\n"); | 498 " a.push(new AnObject());\n"); |
| 499 const v8::HeapSnapshot* snapshot1 = | 499 const v8::HeapSnapshot* snapshot1 = |
| 500 heap_profiler->TakeHeapSnapshot(v8_str("s1")); | 500 heap_profiler->TakeHeapSnapshot(v8_str("s1")); |
| 501 CHECK(ValidateSnapshot(snapshot1, 3)); | 501 CHECK(ValidateSnapshot(snapshot1)); |
| 502 | 502 |
| 503 CompileRun( | 503 CompileRun( |
| 504 "for (var i = 0; i < 1; ++i)\n" | 504 "for (var i = 0; i < 1; ++i)\n" |
| 505 " a.shift();\n"); | 505 " a.shift();\n"); |
| 506 | 506 |
| 507 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 507 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 508 | 508 |
| 509 const v8::HeapSnapshot* snapshot2 = | 509 const v8::HeapSnapshot* snapshot2 = |
| 510 heap_profiler->TakeHeapSnapshot(v8_str("s2")); | 510 heap_profiler->TakeHeapSnapshot(v8_str("s2")); |
| 511 CHECK(ValidateSnapshot(snapshot2, 3)); | 511 CHECK(ValidateSnapshot(snapshot2)); |
| 512 | 512 |
| 513 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); | 513 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); |
| 514 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 514 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
| 515 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); | 515 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); |
| 516 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); | 516 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); |
| 517 | 517 |
| 518 const v8::HeapGraphNode* a1 = | 518 const v8::HeapGraphNode* a1 = |
| 519 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); | 519 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); |
| 520 CHECK_NE(NULL, a1); | 520 CHECK_NE(NULL, a1); |
| 521 const v8::HeapGraphNode* k1 = | 521 const v8::HeapGraphNode* k1 = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 540 | 540 |
| 541 CompileRun( | 541 CompileRun( |
| 542 "function A() {}\n" | 542 "function A() {}\n" |
| 543 "function B(x) { this.x = x; }\n" | 543 "function B(x) { this.x = x; }\n" |
| 544 "var a = new A();\n" | 544 "var a = new A();\n" |
| 545 "var b = new B(a);"); | 545 "var b = new B(a);"); |
| 546 v8::Local<v8::String> s1_str = v8_str("s1"); | 546 v8::Local<v8::String> s1_str = v8_str("s1"); |
| 547 v8::Local<v8::String> s2_str = v8_str("s2"); | 547 v8::Local<v8::String> s2_str = v8_str("s2"); |
| 548 const v8::HeapSnapshot* snapshot1 = | 548 const v8::HeapSnapshot* snapshot1 = |
| 549 heap_profiler->TakeHeapSnapshot(s1_str); | 549 heap_profiler->TakeHeapSnapshot(s1_str); |
| 550 CHECK(ValidateSnapshot(snapshot1, 3)); | 550 CHECK(ValidateSnapshot(snapshot1)); |
| 551 | 551 |
| 552 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 552 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 553 | 553 |
| 554 const v8::HeapSnapshot* snapshot2 = | 554 const v8::HeapSnapshot* snapshot2 = |
| 555 heap_profiler->TakeHeapSnapshot(s2_str); | 555 heap_profiler->TakeHeapSnapshot(s2_str); |
| 556 CHECK(ValidateSnapshot(snapshot2, 3)); | 556 CHECK(ValidateSnapshot(snapshot2)); |
| 557 | 557 |
| 558 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000); | 558 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000); |
| 559 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= | 559 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= |
| 560 snapshot2->GetMaxSnapshotJSObjectId()); | 560 snapshot2->GetMaxSnapshotJSObjectId()); |
| 561 | 561 |
| 562 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); | 562 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); |
| 563 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 563 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
| 564 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); | 564 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); |
| 565 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); | 565 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); |
| 566 const v8::HeapGraphNode* A1 = | 566 const v8::HeapGraphNode* A1 = |
| (...skipping 30 matching lines...) Expand all Loading... |
| 597 CHECK_EQ_SNAPSHOT_OBJECT_ID(b1->GetId(), b2->GetId()); | 597 CHECK_EQ_SNAPSHOT_OBJECT_ID(b1->GetId(), b2->GetId()); |
| 598 } | 598 } |
| 599 | 599 |
| 600 | 600 |
| 601 TEST(HeapSnapshotRootPreservedAfterSorting) { | 601 TEST(HeapSnapshotRootPreservedAfterSorting) { |
| 602 LocalContext env; | 602 LocalContext env; |
| 603 v8::HandleScope scope(env->GetIsolate()); | 603 v8::HandleScope scope(env->GetIsolate()); |
| 604 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 604 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 605 const v8::HeapSnapshot* snapshot = | 605 const v8::HeapSnapshot* snapshot = |
| 606 heap_profiler->TakeHeapSnapshot(v8_str("s")); | 606 heap_profiler->TakeHeapSnapshot(v8_str("s")); |
| 607 CHECK(ValidateSnapshot(snapshot, 3)); | 607 CHECK(ValidateSnapshot(snapshot)); |
| 608 const v8::HeapGraphNode* root1 = snapshot->GetRoot(); | 608 const v8::HeapGraphNode* root1 = snapshot->GetRoot(); |
| 609 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( | 609 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( |
| 610 snapshot))->GetSortedEntriesList(); | 610 snapshot))->GetSortedEntriesList(); |
| 611 const v8::HeapGraphNode* root2 = snapshot->GetRoot(); | 611 const v8::HeapGraphNode* root2 = snapshot->GetRoot(); |
| 612 CHECK_EQ(root1, root2); | 612 CHECK_EQ(root1, root2); |
| 613 } | 613 } |
| 614 | 614 |
| 615 | 615 |
| 616 namespace { | 616 namespace { |
| 617 | 617 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 665 |
| 666 #define STRING_LITERAL_FOR_TEST \ | 666 #define STRING_LITERAL_FOR_TEST \ |
| 667 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" | 667 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" |
| 668 CompileRun( | 668 CompileRun( |
| 669 "function A(s) { this.s = s; }\n" | 669 "function A(s) { this.s = s; }\n" |
| 670 "function B(x) { this.x = x; }\n" | 670 "function B(x) { this.x = x; }\n" |
| 671 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" | 671 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" |
| 672 "var b = new B(a);"); | 672 "var b = new B(a);"); |
| 673 const v8::HeapSnapshot* snapshot = | 673 const v8::HeapSnapshot* snapshot = |
| 674 heap_profiler->TakeHeapSnapshot(v8_str("json")); | 674 heap_profiler->TakeHeapSnapshot(v8_str("json")); |
| 675 CHECK(ValidateSnapshot(snapshot, 3)); | 675 CHECK(ValidateSnapshot(snapshot)); |
| 676 | 676 |
| 677 TestJSONStream stream; | 677 TestJSONStream stream; |
| 678 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 678 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
| 679 CHECK_GT(stream.size(), 0); | 679 CHECK_GT(stream.size(), 0); |
| 680 CHECK_EQ(1, stream.eos_signaled()); | 680 CHECK_EQ(1, stream.eos_signaled()); |
| 681 i::ScopedVector<char> json(stream.size()); | 681 i::ScopedVector<char> json(stream.size()); |
| 682 stream.WriteTo(json); | 682 stream.WriteTo(json); |
| 683 | 683 |
| 684 // Verify that snapshot string is valid JSON. | 684 // Verify that snapshot string is valid JSON. |
| 685 AsciiResource json_res(json); | 685 AsciiResource json_res(json); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 *v8::String::Utf8Value(string)); | 763 *v8::String::Utf8Value(string)); |
| 764 } | 764 } |
| 765 | 765 |
| 766 | 766 |
| 767 TEST(HeapSnapshotJSONSerializationAborting) { | 767 TEST(HeapSnapshotJSONSerializationAborting) { |
| 768 LocalContext env; | 768 LocalContext env; |
| 769 v8::HandleScope scope(env->GetIsolate()); | 769 v8::HandleScope scope(env->GetIsolate()); |
| 770 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 770 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 771 const v8::HeapSnapshot* snapshot = | 771 const v8::HeapSnapshot* snapshot = |
| 772 heap_profiler->TakeHeapSnapshot(v8_str("abort")); | 772 heap_profiler->TakeHeapSnapshot(v8_str("abort")); |
| 773 CHECK(ValidateSnapshot(snapshot, 3)); | 773 CHECK(ValidateSnapshot(snapshot)); |
| 774 TestJSONStream stream(5); | 774 TestJSONStream stream(5); |
| 775 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 775 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
| 776 CHECK_GT(stream.size(), 0); | 776 CHECK_GT(stream.size(), 0); |
| 777 CHECK_EQ(0, stream.eos_signaled()); | 777 CHECK_EQ(0, stream.eos_signaled()); |
| 778 } | 778 } |
| 779 | 779 |
| 780 namespace { | 780 namespace { |
| 781 | 781 |
| 782 class TestStatsStream : public v8::OutputStream { | 782 class TestStatsStream : public v8::OutputStream { |
| 783 public: | 783 public: |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 | 1005 |
| 1006 TEST(HeapSnapshotGetNodeById) { | 1006 TEST(HeapSnapshotGetNodeById) { |
| 1007 LocalContext env; | 1007 LocalContext env; |
| 1008 v8::HandleScope scope(env->GetIsolate()); | 1008 v8::HandleScope scope(env->GetIsolate()); |
| 1009 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1009 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1010 | 1010 |
| 1011 const v8::HeapSnapshot* snapshot = | 1011 const v8::HeapSnapshot* snapshot = |
| 1012 heap_profiler->TakeHeapSnapshot(v8_str("id")); | 1012 heap_profiler->TakeHeapSnapshot(v8_str("id")); |
| 1013 CHECK(ValidateSnapshot(snapshot, 3)); | 1013 CHECK(ValidateSnapshot(snapshot)); |
| 1014 const v8::HeapGraphNode* root = snapshot->GetRoot(); | 1014 const v8::HeapGraphNode* root = snapshot->GetRoot(); |
| 1015 CheckChildrenIds(snapshot, root, 0, 3); | 1015 CheckChildrenIds(snapshot, root, 0, 3); |
| 1016 // Check a big id, which should not exist yet. | 1016 // Check a big id, which should not exist yet. |
| 1017 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL)); | 1017 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL)); |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 | 1020 |
| 1021 TEST(HeapSnapshotGetSnapshotObjectId) { | 1021 TEST(HeapSnapshotGetSnapshotObjectId) { |
| 1022 LocalContext env; | 1022 LocalContext env; |
| 1023 v8::HandleScope scope(env->GetIsolate()); | 1023 v8::HandleScope scope(env->GetIsolate()); |
| 1024 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1024 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1025 CompileRun("globalObject = {};\n"); | 1025 CompileRun("globalObject = {};\n"); |
| 1026 const v8::HeapSnapshot* snapshot = | 1026 const v8::HeapSnapshot* snapshot = |
| 1027 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id")); | 1027 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id")); |
| 1028 CHECK(ValidateSnapshot(snapshot, 3)); | 1028 CHECK(ValidateSnapshot(snapshot)); |
| 1029 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1029 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1030 const v8::HeapGraphNode* global_object = | 1030 const v8::HeapGraphNode* global_object = |
| 1031 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); | 1031 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); |
| 1032 CHECK(global_object); | 1032 CHECK(global_object); |
| 1033 | 1033 |
| 1034 v8::Local<v8::Value> globalObjectHandle = | 1034 v8::Local<v8::Value> globalObjectHandle = |
| 1035 env->Global()->Get(v8::String::New("globalObject")); | 1035 env->Global()->Get(v8::String::New("globalObject")); |
| 1036 CHECK(!globalObjectHandle.IsEmpty()); | 1036 CHECK(!globalObjectHandle.IsEmpty()); |
| 1037 CHECK(globalObjectHandle->IsObject()); | 1037 CHECK(globalObjectHandle->IsObject()); |
| 1038 | 1038 |
| 1039 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle); | 1039 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle); |
| 1040 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId), | 1040 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId), |
| 1041 id); | 1041 id); |
| 1042 CHECK_EQ(static_cast<int>(id), global_object->GetId()); | 1042 CHECK_EQ(static_cast<int>(id), global_object->GetId()); |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 | 1045 |
| 1046 TEST(HeapSnapshotUnknownSnapshotObjectId) { | 1046 TEST(HeapSnapshotUnknownSnapshotObjectId) { |
| 1047 LocalContext env; | 1047 LocalContext env; |
| 1048 v8::HandleScope scope(env->GetIsolate()); | 1048 v8::HandleScope scope(env->GetIsolate()); |
| 1049 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1049 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1050 CompileRun("globalObject = {};\n"); | 1050 CompileRun("globalObject = {};\n"); |
| 1051 const v8::HeapSnapshot* snapshot = | 1051 const v8::HeapSnapshot* snapshot = |
| 1052 heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id")); | 1052 heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id")); |
| 1053 CHECK(ValidateSnapshot(snapshot, 3)); | 1053 CHECK(ValidateSnapshot(snapshot)); |
| 1054 const v8::HeapGraphNode* node = | 1054 const v8::HeapGraphNode* node = |
| 1055 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); | 1055 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); |
| 1056 CHECK_EQ(NULL, node); | 1056 CHECK_EQ(NULL, node); |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 | 1059 |
| 1060 namespace { | 1060 namespace { |
| 1061 | 1061 |
| 1062 class TestActivityControl : public v8::ActivityControl { | 1062 class TestActivityControl : public v8::ActivityControl { |
| 1063 public: | 1063 public: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1090 heap_profiler->TakeHeapSnapshot(v8_str("abort"), | 1090 heap_profiler->TakeHeapSnapshot(v8_str("abort"), |
| 1091 &aborting_control); | 1091 &aborting_control); |
| 1092 CHECK_EQ(NULL, no_snapshot); | 1092 CHECK_EQ(NULL, no_snapshot); |
| 1093 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount()); | 1093 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount()); |
| 1094 CHECK_GT(aborting_control.total(), aborting_control.done()); | 1094 CHECK_GT(aborting_control.total(), aborting_control.done()); |
| 1095 | 1095 |
| 1096 TestActivityControl control(-1); // Don't abort. | 1096 TestActivityControl control(-1); // Don't abort. |
| 1097 const v8::HeapSnapshot* snapshot = | 1097 const v8::HeapSnapshot* snapshot = |
| 1098 heap_profiler->TakeHeapSnapshot(v8_str("full"), | 1098 heap_profiler->TakeHeapSnapshot(v8_str("full"), |
| 1099 &control); | 1099 &control); |
| 1100 CHECK(ValidateSnapshot(snapshot, 3)); | 1100 CHECK(ValidateSnapshot(snapshot)); |
| 1101 | 1101 |
| 1102 CHECK_NE(NULL, snapshot); | 1102 CHECK_NE(NULL, snapshot); |
| 1103 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount()); | 1103 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount()); |
| 1104 CHECK_EQ(control.total(), control.done()); | 1104 CHECK_EQ(control.total(), control.done()); |
| 1105 CHECK_GT(control.total(), 0); | 1105 CHECK_GT(control.total(), 0); |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 | 1108 |
| 1109 namespace { | 1109 namespace { |
| 1110 | 1110 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 2, TestRetainedObjectInfo::WrapperInfoCallback); | 1202 2, TestRetainedObjectInfo::WrapperInfoCallback); |
| 1203 v8::Persistent<v8::String> p_AAA(isolate, v8_str("AAA")); | 1203 v8::Persistent<v8::String> p_AAA(isolate, v8_str("AAA")); |
| 1204 p_AAA.SetWrapperClassId(isolate, 1); | 1204 p_AAA.SetWrapperClassId(isolate, 1); |
| 1205 v8::Persistent<v8::String> p_BBB(isolate, v8_str("BBB")); | 1205 v8::Persistent<v8::String> p_BBB(isolate, v8_str("BBB")); |
| 1206 p_BBB.SetWrapperClassId(isolate, 1); | 1206 p_BBB.SetWrapperClassId(isolate, 1); |
| 1207 v8::Persistent<v8::String> p_CCC(isolate, v8_str("CCC")); | 1207 v8::Persistent<v8::String> p_CCC(isolate, v8_str("CCC")); |
| 1208 p_CCC.SetWrapperClassId(isolate, 2); | 1208 p_CCC.SetWrapperClassId(isolate, 2); |
| 1209 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); | 1209 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); |
| 1210 const v8::HeapSnapshot* snapshot = | 1210 const v8::HeapSnapshot* snapshot = |
| 1211 heap_profiler->TakeHeapSnapshot(v8_str("retained")); | 1211 heap_profiler->TakeHeapSnapshot(v8_str("retained")); |
| 1212 CHECK(ValidateSnapshot(snapshot, 3)); | 1212 CHECK(ValidateSnapshot(snapshot)); |
| 1213 | 1213 |
| 1214 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); | 1214 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); |
| 1215 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { | 1215 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { |
| 1216 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); | 1216 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); |
| 1217 delete TestRetainedObjectInfo::instances[i]; | 1217 delete TestRetainedObjectInfo::instances[i]; |
| 1218 } | 1218 } |
| 1219 | 1219 |
| 1220 const v8::HeapGraphNode* native_group_aaa = GetNode( | 1220 const v8::HeapGraphNode* native_group_aaa = GetNode( |
| 1221 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group"); | 1221 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group"); |
| 1222 CHECK_NE(NULL, native_group_aaa); | 1222 CHECK_NE(NULL, native_group_aaa); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 TEST(HeapSnapshotImplicitReferences) { | 1295 TEST(HeapSnapshotImplicitReferences) { |
| 1296 LocalContext env; | 1296 LocalContext env; |
| 1297 v8::HandleScope scope(env->GetIsolate()); | 1297 v8::HandleScope scope(env->GetIsolate()); |
| 1298 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1298 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1299 | 1299 |
| 1300 GraphWithImplicitRefs graph(&env); | 1300 GraphWithImplicitRefs graph(&env); |
| 1301 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); | 1301 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); |
| 1302 | 1302 |
| 1303 const v8::HeapSnapshot* snapshot = | 1303 const v8::HeapSnapshot* snapshot = |
| 1304 heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs")); | 1304 heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs")); |
| 1305 CHECK(ValidateSnapshot(snapshot, 3)); | 1305 CHECK(ValidateSnapshot(snapshot)); |
| 1306 | 1306 |
| 1307 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); | 1307 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); |
| 1308 const v8::HeapGraphNode* obj0 = GetProperty( | 1308 const v8::HeapGraphNode* obj0 = GetProperty( |
| 1309 global_object, v8::HeapGraphEdge::kProperty, "root_object"); | 1309 global_object, v8::HeapGraphEdge::kProperty, "root_object"); |
| 1310 CHECK(obj0); | 1310 CHECK(obj0); |
| 1311 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); | 1311 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); |
| 1312 const v8::HeapGraphNode* obj1 = GetProperty( | 1312 const v8::HeapGraphNode* obj1 = GetProperty( |
| 1313 obj0, v8::HeapGraphEdge::kInternal, "native"); | 1313 obj0, v8::HeapGraphEdge::kInternal, "native"); |
| 1314 CHECK(obj1); | 1314 CHECK(obj1); |
| 1315 int implicit_targets_count = 0; | 1315 int implicit_targets_count = 0; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 v8::HandleScope scope(env->GetIsolate()); | 1413 v8::HandleScope scope(env->GetIsolate()); |
| 1414 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1414 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1415 | 1415 |
| 1416 CompileRun("document = { URL:\"abcdefgh\" };"); | 1416 CompileRun("document = { URL:\"abcdefgh\" };"); |
| 1417 | 1417 |
| 1418 NameResolver name_resolver; | 1418 NameResolver name_resolver; |
| 1419 const v8::HeapSnapshot* snapshot = | 1419 const v8::HeapSnapshot* snapshot = |
| 1420 heap_profiler->TakeHeapSnapshot(v8_str("document"), | 1420 heap_profiler->TakeHeapSnapshot(v8_str("document"), |
| 1421 NULL, | 1421 NULL, |
| 1422 &name_resolver); | 1422 &name_resolver); |
| 1423 CHECK(ValidateSnapshot(snapshot, 3)); | 1423 CHECK(ValidateSnapshot(snapshot)); |
| 1424 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1424 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1425 CHECK_NE(NULL, global); | 1425 CHECK_NE(NULL, global); |
| 1426 CHECK_EQ("Object / Global object name" , | 1426 CHECK_EQ("Object / Global object name" , |
| 1427 const_cast<i::HeapEntry*>( | 1427 const_cast<i::HeapEntry*>( |
| 1428 reinterpret_cast<const i::HeapEntry*>(global))->name()); | 1428 reinterpret_cast<const i::HeapEntry*>(global))->name()); |
| 1429 } | 1429 } |
| 1430 | 1430 |
| 1431 | 1431 |
| 1432 TEST(NoHandleLeaks) { | 1432 TEST(NoHandleLeaks) { |
| 1433 LocalContext env; | 1433 LocalContext env; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1444 CHECK_EQ(count_before, count_after); | 1444 CHECK_EQ(count_before, count_after); |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 | 1447 |
| 1448 TEST(NodesIteration) { | 1448 TEST(NodesIteration) { |
| 1449 LocalContext env; | 1449 LocalContext env; |
| 1450 v8::HandleScope scope(env->GetIsolate()); | 1450 v8::HandleScope scope(env->GetIsolate()); |
| 1451 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1451 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1452 const v8::HeapSnapshot* snapshot = | 1452 const v8::HeapSnapshot* snapshot = |
| 1453 heap_profiler->TakeHeapSnapshot(v8_str("iteration")); | 1453 heap_profiler->TakeHeapSnapshot(v8_str("iteration")); |
| 1454 CHECK(ValidateSnapshot(snapshot, 3)); | 1454 CHECK(ValidateSnapshot(snapshot)); |
| 1455 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1455 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1456 CHECK_NE(NULL, global); | 1456 CHECK_NE(NULL, global); |
| 1457 // Verify that we can find this object by iteration. | 1457 // Verify that we can find this object by iteration. |
| 1458 const int nodes_count = snapshot->GetNodesCount(); | 1458 const int nodes_count = snapshot->GetNodesCount(); |
| 1459 int count = 0; | 1459 int count = 0; |
| 1460 for (int i = 0; i < nodes_count; ++i) { | 1460 for (int i = 0; i < nodes_count; ++i) { |
| 1461 if (snapshot->GetNode(i) == global) | 1461 if (snapshot->GetNode(i) == global) |
| 1462 ++count; | 1462 ++count; |
| 1463 } | 1463 } |
| 1464 CHECK_EQ(1, count); | 1464 CHECK_EQ(1, count); |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 | 1467 |
| 1468 TEST(GetHeapValue) { | 1468 TEST(GetHeapValue) { |
| 1469 LocalContext env; | 1469 LocalContext env; |
| 1470 v8::HandleScope scope(env->GetIsolate()); | 1470 v8::HandleScope scope(env->GetIsolate()); |
| 1471 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1471 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1472 | 1472 |
| 1473 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };"); | 1473 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };"); |
| 1474 const v8::HeapSnapshot* snapshot = | 1474 const v8::HeapSnapshot* snapshot = |
| 1475 heap_profiler->TakeHeapSnapshot(v8_str("value")); | 1475 heap_profiler->TakeHeapSnapshot(v8_str("value")); |
| 1476 CHECK(ValidateSnapshot(snapshot, 3)); | 1476 CHECK(ValidateSnapshot(snapshot)); |
| 1477 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1477 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1478 CHECK(global->GetHeapValue()->IsObject()); | 1478 CHECK(global->GetHeapValue()->IsObject()); |
| 1479 v8::Local<v8::Object> js_global = | 1479 v8::Local<v8::Object> js_global = |
| 1480 env->Global()->GetPrototype().As<v8::Object>(); | 1480 env->Global()->GetPrototype().As<v8::Object>(); |
| 1481 CHECK(js_global == global->GetHeapValue()); | 1481 CHECK(js_global == global->GetHeapValue()); |
| 1482 const v8::HeapGraphNode* obj = GetProperty( | 1482 const v8::HeapGraphNode* obj = GetProperty( |
| 1483 global, v8::HeapGraphEdge::kProperty, "a"); | 1483 global, v8::HeapGraphEdge::kProperty, "a"); |
| 1484 CHECK(obj->GetHeapValue()->IsObject()); | 1484 CHECK(obj->GetHeapValue()->IsObject()); |
| 1485 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); | 1485 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); |
| 1486 CHECK(js_obj == obj->GetHeapValue()); | 1486 CHECK(js_obj == obj->GetHeapValue()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1501 LocalContext env; | 1501 LocalContext env; |
| 1502 v8::HandleScope scope(env->GetIsolate()); | 1502 v8::HandleScope scope(env->GetIsolate()); |
| 1503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1504 | 1504 |
| 1505 // It is impossible to delete a global property, so we are about to delete a | 1505 // It is impossible to delete a global property, so we are about to delete a |
| 1506 // property of the "a" object. Also, the "p" object can't be an empty one | 1506 // property of the "a" object. Also, the "p" object can't be an empty one |
| 1507 // because the empty object is static and isn't actually deleted. | 1507 // because the empty object is static and isn't actually deleted. |
| 1508 CompileRun("a = { p: { r: {} } };"); | 1508 CompileRun("a = { p: { r: {} } };"); |
| 1509 const v8::HeapSnapshot* snapshot = | 1509 const v8::HeapSnapshot* snapshot = |
| 1510 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1510 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1511 CHECK(ValidateSnapshot(snapshot, 3)); | 1511 CHECK(ValidateSnapshot(snapshot)); |
| 1512 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1512 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1513 const v8::HeapGraphNode* obj = GetProperty( | 1513 const v8::HeapGraphNode* obj = GetProperty( |
| 1514 global, v8::HeapGraphEdge::kProperty, "a"); | 1514 global, v8::HeapGraphEdge::kProperty, "a"); |
| 1515 const v8::HeapGraphNode* prop = GetProperty( | 1515 const v8::HeapGraphNode* prop = GetProperty( |
| 1516 obj, v8::HeapGraphEdge::kProperty, "p"); | 1516 obj, v8::HeapGraphEdge::kProperty, "p"); |
| 1517 { | 1517 { |
| 1518 // Perform the check inside a nested local scope to avoid creating a | 1518 // Perform the check inside a nested local scope to avoid creating a |
| 1519 // reference to the object we are deleting. | 1519 // reference to the object we are deleting. |
| 1520 v8::HandleScope scope(env->GetIsolate()); | 1520 v8::HandleScope scope(env->GetIsolate()); |
| 1521 CHECK(prop->GetHeapValue()->IsObject()); | 1521 CHECK(prop->GetHeapValue()->IsObject()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 | 1588 |
| 1589 CompileRun("var obj1 = {};\n" | 1589 CompileRun("var obj1 = {};\n" |
| 1590 "obj1.__defineGetter__('propWithGetter', function Y() {\n" | 1590 "obj1.__defineGetter__('propWithGetter', function Y() {\n" |
| 1591 " return 42;\n" | 1591 " return 42;\n" |
| 1592 "});\n" | 1592 "});\n" |
| 1593 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" | 1593 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" |
| 1594 " return this.value_ = value;\n" | 1594 " return this.value_ = value;\n" |
| 1595 "});\n"); | 1595 "});\n"); |
| 1596 const v8::HeapSnapshot* snapshot = | 1596 const v8::HeapSnapshot* snapshot = |
| 1597 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors")); | 1597 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors")); |
| 1598 CHECK(ValidateSnapshot(snapshot, 3)); | 1598 CHECK(ValidateSnapshot(snapshot)); |
| 1599 | 1599 |
| 1600 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1600 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1601 CHECK_NE(NULL, global); | 1601 CHECK_NE(NULL, global); |
| 1602 const v8::HeapGraphNode* obj1 = | 1602 const v8::HeapGraphNode* obj1 = |
| 1603 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); | 1603 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); |
| 1604 CHECK_NE(NULL, obj1); | 1604 CHECK_NE(NULL, obj1); |
| 1605 const v8::HeapGraphNode* func; | 1605 const v8::HeapGraphNode* func; |
| 1606 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); | 1606 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); |
| 1607 CHECK_NE(NULL, func); | 1607 CHECK_NE(NULL, func); |
| 1608 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); | 1608 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1622 CompileRun("var obj1 = {};\n" | 1622 CompileRun("var obj1 = {};\n" |
| 1623 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};" | 1623 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};" |
| 1624 "obj1.__defineGetter__('propWithGetter', function Y() {\n" | 1624 "obj1.__defineGetter__('propWithGetter', function Y() {\n" |
| 1625 " return 42;\n" | 1625 " return 42;\n" |
| 1626 "});\n" | 1626 "});\n" |
| 1627 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" | 1627 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" |
| 1628 " return this.value_ = value;\n" | 1628 " return this.value_ = value;\n" |
| 1629 "});\n"); | 1629 "});\n"); |
| 1630 const v8::HeapSnapshot* snapshot = | 1630 const v8::HeapSnapshot* snapshot = |
| 1631 heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors")); | 1631 heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors")); |
| 1632 CHECK(ValidateSnapshot(snapshot, 3)); | 1632 CHECK(ValidateSnapshot(snapshot)); |
| 1633 | 1633 |
| 1634 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1634 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1635 CHECK_NE(NULL, global); | 1635 CHECK_NE(NULL, global); |
| 1636 const v8::HeapGraphNode* obj1 = | 1636 const v8::HeapGraphNode* obj1 = |
| 1637 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); | 1637 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); |
| 1638 CHECK_NE(NULL, obj1); | 1638 CHECK_NE(NULL, obj1); |
| 1639 const v8::HeapGraphNode* func; | 1639 const v8::HeapGraphNode* func; |
| 1640 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); | 1640 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); |
| 1641 CHECK_NE(NULL, func); | 1641 CHECK_NE(NULL, func); |
| 1642 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); | 1642 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); |
| 1643 CHECK_EQ(NULL, func); | 1643 CHECK_EQ(NULL, func); |
| 1644 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); | 1644 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); |
| 1645 CHECK_NE(NULL, func); | 1645 CHECK_NE(NULL, func); |
| 1646 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); | 1646 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); |
| 1647 CHECK_EQ(NULL, func); | 1647 CHECK_EQ(NULL, func); |
| 1648 } | 1648 } |
| 1649 | 1649 |
| 1650 | 1650 |
| 1651 TEST(HiddenPropertiesFastCase) { | 1651 TEST(HiddenPropertiesFastCase) { |
| 1652 LocalContext env; | 1652 LocalContext env; |
| 1653 v8::HandleScope scope(env->GetIsolate()); | 1653 v8::HandleScope scope(env->GetIsolate()); |
| 1654 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1654 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1655 | 1655 |
| 1656 CompileRun( | 1656 CompileRun( |
| 1657 "function C(x) { this.a = this; this.b = x; }\n" | 1657 "function C(x) { this.a = this; this.b = x; }\n" |
| 1658 "c = new C(2012);\n"); | 1658 "c = new C(2012);\n"); |
| 1659 const v8::HeapSnapshot* snapshot = | 1659 const v8::HeapSnapshot* snapshot = |
| 1660 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1")); | 1660 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1")); |
| 1661 CHECK(ValidateSnapshot(snapshot, 3)); | 1661 CHECK(ValidateSnapshot(snapshot)); |
| 1662 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1662 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1663 const v8::HeapGraphNode* c = | 1663 const v8::HeapGraphNode* c = |
| 1664 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); | 1664 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); |
| 1665 CHECK_NE(NULL, c); | 1665 CHECK_NE(NULL, c); |
| 1666 const v8::HeapGraphNode* hidden_props = | 1666 const v8::HeapGraphNode* hidden_props = |
| 1667 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); | 1667 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); |
| 1668 CHECK_EQ(NULL, hidden_props); | 1668 CHECK_EQ(NULL, hidden_props); |
| 1669 | 1669 |
| 1670 v8::Handle<v8::Value> cHandle = env->Global()->Get(v8::String::New("c")); | 1670 v8::Handle<v8::Value> cHandle = env->Global()->Get(v8::String::New("c")); |
| 1671 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); | 1671 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); |
| 1672 cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val")); | 1672 cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val")); |
| 1673 | 1673 |
| 1674 snapshot = heap_profiler->TakeHeapSnapshot( | 1674 snapshot = heap_profiler->TakeHeapSnapshot( |
| 1675 v8_str("HiddenPropertiesFastCase2")); | 1675 v8_str("HiddenPropertiesFastCase2")); |
| 1676 CHECK(ValidateSnapshot(snapshot, 3)); | 1676 CHECK(ValidateSnapshot(snapshot)); |
| 1677 global = GetGlobalObject(snapshot); | 1677 global = GetGlobalObject(snapshot); |
| 1678 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); | 1678 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); |
| 1679 CHECK_NE(NULL, c); | 1679 CHECK_NE(NULL, c); |
| 1680 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, | 1680 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, |
| 1681 "hidden_properties"); | 1681 "hidden_properties"); |
| 1682 CHECK_NE(NULL, hidden_props); | 1682 CHECK_NE(NULL, hidden_props); |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 | 1685 |
| 1686 bool HasWeakEdge(const v8::HeapGraphNode* node) { | 1686 bool HasWeakEdge(const v8::HeapGraphNode* node) { |
| 1687 for (int i = 0; i < node->GetChildrenCount(); ++i) { | 1687 for (int i = 0; i < node->GetChildrenCount(); ++i) { |
| 1688 const v8::HeapGraphEdge* handle_edge = node->GetChild(i); | 1688 const v8::HeapGraphEdge* handle_edge = node->GetChild(i); |
| 1689 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true; | 1689 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true; |
| 1690 } | 1690 } |
| 1691 return false; | 1691 return false; |
| 1692 } | 1692 } |
| 1693 | 1693 |
| 1694 | 1694 |
| 1695 bool HasWeakGlobalHandle() { | 1695 bool HasWeakGlobalHandle() { |
| 1696 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1696 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 1697 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 1697 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
| 1698 const v8::HeapSnapshot* snapshot = | 1698 const v8::HeapSnapshot* snapshot = |
| 1699 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); | 1699 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); |
| 1700 CHECK(ValidateSnapshot(snapshot, 3)); | 1700 CHECK(ValidateSnapshot(snapshot)); |
| 1701 const v8::HeapGraphNode* gc_roots = GetNode( | 1701 const v8::HeapGraphNode* gc_roots = GetNode( |
| 1702 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); | 1702 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); |
| 1703 CHECK_NE(NULL, gc_roots); | 1703 CHECK_NE(NULL, gc_roots); |
| 1704 const v8::HeapGraphNode* global_handles = GetNode( | 1704 const v8::HeapGraphNode* global_handles = GetNode( |
| 1705 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); | 1705 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); |
| 1706 CHECK_NE(NULL, global_handles); | 1706 CHECK_NE(NULL, global_handles); |
| 1707 return HasWeakEdge(global_handles); | 1707 return HasWeakEdge(global_handles); |
| 1708 } | 1708 } |
| 1709 | 1709 |
| 1710 | 1710 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 | 1730 |
| 1731 TEST(WeakNativeContextRefs) { | 1731 TEST(WeakNativeContextRefs) { |
| 1732 LocalContext env; | 1732 LocalContext env; |
| 1733 v8::HandleScope scope(env->GetIsolate()); | 1733 v8::HandleScope scope(env->GetIsolate()); |
| 1734 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1734 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1735 | 1735 |
| 1736 const v8::HeapSnapshot* snapshot = | 1736 const v8::HeapSnapshot* snapshot = |
| 1737 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); | 1737 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); |
| 1738 CHECK(ValidateSnapshot(snapshot, 3)); | 1738 CHECK(ValidateSnapshot(snapshot)); |
| 1739 const v8::HeapGraphNode* gc_roots = GetNode( | 1739 const v8::HeapGraphNode* gc_roots = GetNode( |
| 1740 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); | 1740 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); |
| 1741 CHECK_NE(NULL, gc_roots); | 1741 CHECK_NE(NULL, gc_roots); |
| 1742 const v8::HeapGraphNode* global_handles = GetNode( | 1742 const v8::HeapGraphNode* global_handles = GetNode( |
| 1743 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); | 1743 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); |
| 1744 CHECK_NE(NULL, global_handles); | 1744 CHECK_NE(NULL, global_handles); |
| 1745 const v8::HeapGraphNode* native_context = GetNode( | 1745 const v8::HeapGraphNode* native_context = GetNode( |
| 1746 global_handles, v8::HeapGraphNode::kHidden, "system / NativeContext"); | 1746 global_handles, v8::HeapGraphNode::kHidden, "system / NativeContext"); |
| 1747 CHECK_NE(NULL, native_context); | 1747 CHECK_NE(NULL, native_context); |
| 1748 CHECK(HasWeakEdge(native_context)); | 1748 CHECK(HasWeakEdge(native_context)); |
| 1749 } | 1749 } |
| 1750 | 1750 |
| 1751 | 1751 |
| 1752 TEST(SfiAndJsFunctionWeakRefs) { | 1752 TEST(SfiAndJsFunctionWeakRefs) { |
| 1753 LocalContext env; | 1753 LocalContext env; |
| 1754 v8::HandleScope scope(env->GetIsolate()); | 1754 v8::HandleScope scope(env->GetIsolate()); |
| 1755 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1755 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1756 | 1756 |
| 1757 CompileRun( | 1757 CompileRun( |
| 1758 "fun = (function (x) { return function () { return x + 1; } })(1);"); | 1758 "fun = (function (x) { return function () { return x + 1; } })(1);"); |
| 1759 const v8::HeapSnapshot* snapshot = | 1759 const v8::HeapSnapshot* snapshot = |
| 1760 heap_profiler->TakeHeapSnapshot(v8_str("fun")); | 1760 heap_profiler->TakeHeapSnapshot(v8_str("fun")); |
| 1761 CHECK(ValidateSnapshot(snapshot, 3)); | 1761 CHECK(ValidateSnapshot(snapshot)); |
| 1762 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1762 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1763 CHECK_NE(NULL, global); | 1763 CHECK_NE(NULL, global); |
| 1764 const v8::HeapGraphNode* fun = | 1764 const v8::HeapGraphNode* fun = |
| 1765 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); | 1765 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); |
| 1766 CHECK(HasWeakEdge(fun)); | 1766 CHECK(HasWeakEdge(fun)); |
| 1767 const v8::HeapGraphNode* shared = | 1767 const v8::HeapGraphNode* shared = |
| 1768 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); | 1768 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); |
| 1769 CHECK(HasWeakEdge(shared)); | 1769 CHECK(HasWeakEdge(shared)); |
| 1770 } | 1770 } |
| 1771 | 1771 |
| 1772 | 1772 |
| 1773 #ifdef ENABLE_DEBUGGER_SUPPORT | 1773 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1774 TEST(NoDebugObjectInSnapshot) { | 1774 TEST(NoDebugObjectInSnapshot) { |
| 1775 LocalContext env; | 1775 LocalContext env; |
| 1776 v8::HandleScope scope(env->GetIsolate()); | 1776 v8::HandleScope scope(env->GetIsolate()); |
| 1777 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1777 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1778 | 1778 |
| 1779 v8::internal::Isolate::Current()->debug()->Load(); | 1779 v8::internal::Isolate::Current()->debug()->Load(); |
| 1780 CompileRun("foo = {};"); | 1780 CompileRun("foo = {};"); |
| 1781 const v8::HeapSnapshot* snapshot = | 1781 const v8::HeapSnapshot* snapshot = |
| 1782 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1782 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1783 CHECK(ValidateSnapshot(snapshot, 3)); | 1783 CHECK(ValidateSnapshot(snapshot)); |
| 1784 const v8::HeapGraphNode* root = snapshot->GetRoot(); | 1784 const v8::HeapGraphNode* root = snapshot->GetRoot(); |
| 1785 int globals_count = 0; | 1785 int globals_count = 0; |
| 1786 for (int i = 0; i < root->GetChildrenCount(); ++i) { | 1786 for (int i = 0; i < root->GetChildrenCount(); ++i) { |
| 1787 const v8::HeapGraphEdge* edge = root->GetChild(i); | 1787 const v8::HeapGraphEdge* edge = root->GetChild(i); |
| 1788 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { | 1788 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { |
| 1789 ++globals_count; | 1789 ++globals_count; |
| 1790 const v8::HeapGraphNode* global = edge->GetToNode(); | 1790 const v8::HeapGraphNode* global = edge->GetToNode(); |
| 1791 const v8::HeapGraphNode* foo = | 1791 const v8::HeapGraphNode* foo = |
| 1792 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 1792 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
| 1793 CHECK_NE(NULL, foo); | 1793 CHECK_NE(NULL, foo); |
| 1794 } | 1794 } |
| 1795 } | 1795 } |
| 1796 CHECK_EQ(1, globals_count); | 1796 CHECK_EQ(1, globals_count); |
| 1797 } | 1797 } |
| 1798 #endif // ENABLE_DEBUGGER_SUPPORT | 1798 #endif // ENABLE_DEBUGGER_SUPPORT |
| 1799 | 1799 |
| 1800 | 1800 |
| 1801 TEST(AllStrongGcRootsHaveNames) { | 1801 TEST(AllStrongGcRootsHaveNames) { |
| 1802 LocalContext env; | 1802 LocalContext env; |
| 1803 v8::HandleScope scope(env->GetIsolate()); | 1803 v8::HandleScope scope(env->GetIsolate()); |
| 1804 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1804 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1805 | 1805 |
| 1806 CompileRun("foo = {};"); | 1806 CompileRun("foo = {};"); |
| 1807 const v8::HeapSnapshot* snapshot = | 1807 const v8::HeapSnapshot* snapshot = |
| 1808 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1808 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1809 CHECK(ValidateSnapshot(snapshot, 3)); | 1809 CHECK(ValidateSnapshot(snapshot)); |
| 1810 const v8::HeapGraphNode* gc_roots = GetNode( | 1810 const v8::HeapGraphNode* gc_roots = GetNode( |
| 1811 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); | 1811 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); |
| 1812 CHECK_NE(NULL, gc_roots); | 1812 CHECK_NE(NULL, gc_roots); |
| 1813 const v8::HeapGraphNode* strong_roots = GetNode( | 1813 const v8::HeapGraphNode* strong_roots = GetNode( |
| 1814 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)"); | 1814 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)"); |
| 1815 CHECK_NE(NULL, strong_roots); | 1815 CHECK_NE(NULL, strong_roots); |
| 1816 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { | 1816 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { |
| 1817 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); | 1817 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); |
| 1818 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); | 1818 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); |
| 1819 v8::String::Utf8Value name(edge->GetName()); | 1819 v8::String::Utf8Value name(edge->GetName()); |
| 1820 CHECK(isalpha(**name)); | 1820 CHECK(isalpha(**name)); |
| 1821 } | 1821 } |
| 1822 } | 1822 } |
| 1823 | 1823 |
| 1824 | 1824 |
| 1825 TEST(NoRefsToNonEssentialEntries) { | 1825 TEST(NoRefsToNonEssentialEntries) { |
| 1826 LocalContext env; | 1826 LocalContext env; |
| 1827 v8::HandleScope scope(env->GetIsolate()); | 1827 v8::HandleScope scope(env->GetIsolate()); |
| 1828 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1828 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1829 CompileRun("global_object = {};\n"); | 1829 CompileRun("global_object = {};\n"); |
| 1830 const v8::HeapSnapshot* snapshot = | 1830 const v8::HeapSnapshot* snapshot = |
| 1831 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1831 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1832 CHECK(ValidateSnapshot(snapshot, 3)); | 1832 CHECK(ValidateSnapshot(snapshot)); |
| 1833 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1833 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1834 const v8::HeapGraphNode* global_object = | 1834 const v8::HeapGraphNode* global_object = |
| 1835 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); | 1835 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); |
| 1836 CHECK_NE(NULL, global_object); | 1836 CHECK_NE(NULL, global_object); |
| 1837 const v8::HeapGraphNode* properties = | 1837 const v8::HeapGraphNode* properties = |
| 1838 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); | 1838 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); |
| 1839 CHECK_EQ(NULL, properties); | 1839 CHECK_EQ(NULL, properties); |
| 1840 const v8::HeapGraphNode* elements = | 1840 const v8::HeapGraphNode* elements = |
| 1841 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); | 1841 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); |
| 1842 CHECK_EQ(NULL, elements); | 1842 CHECK_EQ(NULL, elements); |
| 1843 } | 1843 } |
| 1844 | 1844 |
| 1845 | 1845 |
| 1846 TEST(MapHasDescriptorsAndTransitions) { | 1846 TEST(MapHasDescriptorsAndTransitions) { |
| 1847 LocalContext env; | 1847 LocalContext env; |
| 1848 v8::HandleScope scope(env->GetIsolate()); | 1848 v8::HandleScope scope(env->GetIsolate()); |
| 1849 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1849 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1850 CompileRun("obj = { a: 10 };\n"); | 1850 CompileRun("obj = { a: 10 };\n"); |
| 1851 const v8::HeapSnapshot* snapshot = | 1851 const v8::HeapSnapshot* snapshot = |
| 1852 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1852 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1853 CHECK(ValidateSnapshot(snapshot, 3)); | 1853 CHECK(ValidateSnapshot(snapshot)); |
| 1854 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1854 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1855 const v8::HeapGraphNode* global_object = | 1855 const v8::HeapGraphNode* global_object = |
| 1856 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); | 1856 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); |
| 1857 CHECK_NE(NULL, global_object); | 1857 CHECK_NE(NULL, global_object); |
| 1858 | 1858 |
| 1859 const v8::HeapGraphNode* map = | 1859 const v8::HeapGraphNode* map = |
| 1860 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); | 1860 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); |
| 1861 CHECK_NE(NULL, map); | 1861 CHECK_NE(NULL, map); |
| 1862 const v8::HeapGraphNode* own_descriptors = GetProperty( | 1862 const v8::HeapGraphNode* own_descriptors = GetProperty( |
| 1863 map, v8::HeapGraphEdge::kInternal, "descriptors"); | 1863 map, v8::HeapGraphEdge::kInternal, "descriptors"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1882 " if (i > 0)" | 1882 " if (i > 0)" |
| 1883 " f += 'f_' + (i - 1) + '();';" | 1883 " f += 'f_' + (i - 1) + '();';" |
| 1884 " f += ' }';" | 1884 " f += ' }';" |
| 1885 " result.push(f);" | 1885 " result.push(f);" |
| 1886 "}" | 1886 "}" |
| 1887 "result.push('return f_' + (n - 1) + ';');" | 1887 "result.push('return f_' + (n - 1) + ';');" |
| 1888 "result.push('})()');" | 1888 "result.push('})()');" |
| 1889 "var ok = eval(result.join('\\n'));"); | 1889 "var ok = eval(result.join('\\n'));"); |
| 1890 const v8::HeapSnapshot* snapshot = | 1890 const v8::HeapSnapshot* snapshot = |
| 1891 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1891 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1892 CHECK(ValidateSnapshot(snapshot, 3)); | 1892 CHECK(ValidateSnapshot(snapshot)); |
| 1893 | 1893 |
| 1894 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1894 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1895 CHECK_NE(NULL, global); | 1895 CHECK_NE(NULL, global); |
| 1896 const v8::HeapGraphNode* ok_object = | 1896 const v8::HeapGraphNode* ok_object = |
| 1897 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok"); | 1897 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok"); |
| 1898 CHECK_NE(NULL, ok_object); | 1898 CHECK_NE(NULL, ok_object); |
| 1899 const v8::HeapGraphNode* context_object = | 1899 const v8::HeapGraphNode* context_object = |
| 1900 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context"); | 1900 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context"); |
| 1901 CHECK_NE(NULL, context_object); | 1901 CHECK_NE(NULL, context_object); |
| 1902 // Check the objects are not duplicated in the context. | 1902 // Check the objects are not duplicated in the context. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1916 | 1916 |
| 1917 TEST(AllocationSitesAreVisible) { | 1917 TEST(AllocationSitesAreVisible) { |
| 1918 LocalContext env; | 1918 LocalContext env; |
| 1919 v8::HandleScope scope(env->GetIsolate()); | 1919 v8::HandleScope scope(env->GetIsolate()); |
| 1920 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1920 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1921 CompileRun( | 1921 CompileRun( |
| 1922 "fun = function () { var a = [3, 2, 1]; return a; }\n" | 1922 "fun = function () { var a = [3, 2, 1]; return a; }\n" |
| 1923 "fun();"); | 1923 "fun();"); |
| 1924 const v8::HeapSnapshot* snapshot = | 1924 const v8::HeapSnapshot* snapshot = |
| 1925 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1925 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1926 CHECK(ValidateSnapshot(snapshot, 3)); | 1926 CHECK(ValidateSnapshot(snapshot)); |
| 1927 | 1927 |
| 1928 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1928 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1929 CHECK_NE(NULL, global); | 1929 CHECK_NE(NULL, global); |
| 1930 const v8::HeapGraphNode* fun_code = | 1930 const v8::HeapGraphNode* fun_code = |
| 1931 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); | 1931 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); |
| 1932 CHECK_NE(NULL, fun_code); | 1932 CHECK_NE(NULL, fun_code); |
| 1933 const v8::HeapGraphNode* literals = | 1933 const v8::HeapGraphNode* literals = |
| 1934 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals"); | 1934 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals"); |
| 1935 CHECK_NE(NULL, literals); | 1935 CHECK_NE(NULL, literals); |
| 1936 CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType()); | 1936 CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1956 | 1956 |
| 1957 CHECK(transition_info->GetHeapValue()->IsArray()); | 1957 CHECK(transition_info->GetHeapValue()->IsArray()); |
| 1958 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast( | 1958 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast( |
| 1959 transition_info->GetHeapValue()); | 1959 transition_info->GetHeapValue()); |
| 1960 // Verify the array is "a" in the code above. | 1960 // Verify the array is "a" in the code above. |
| 1961 CHECK_EQ(3, array->Length()); | 1961 CHECK_EQ(3, array->Length()); |
| 1962 CHECK_EQ(v8::Integer::New(3), array->Get(v8::Integer::New(0))); | 1962 CHECK_EQ(v8::Integer::New(3), array->Get(v8::Integer::New(0))); |
| 1963 CHECK_EQ(v8::Integer::New(2), array->Get(v8::Integer::New(1))); | 1963 CHECK_EQ(v8::Integer::New(2), array->Get(v8::Integer::New(1))); |
| 1964 CHECK_EQ(v8::Integer::New(1), array->Get(v8::Integer::New(2))); | 1964 CHECK_EQ(v8::Integer::New(1), array->Get(v8::Integer::New(2))); |
| 1965 } | 1965 } |
| 1966 |
| 1967 |
| 1968 TEST(JSFunctionHasCodeLink) { |
| 1969 LocalContext env; |
| 1970 v8::HandleScope scope(env->GetIsolate()); |
| 1971 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1972 CompileRun("function foo(x, y) { return x + y; }\n"); |
| 1973 const v8::HeapSnapshot* snapshot = |
| 1974 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 1975 CHECK(ValidateSnapshot(snapshot)); |
| 1976 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1977 const v8::HeapGraphNode* foo_func = |
| 1978 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
| 1979 CHECK_NE(NULL, foo_func); |
| 1980 const v8::HeapGraphNode* code = |
| 1981 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); |
| 1982 CHECK_NE(NULL, code); |
| 1983 } |
| OLD | NEW |