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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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)); | 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 CHECK_EQ(v8::HeapGraphNode::kSlicedString, child_string->GetType()); |
407 const v8::HeapGraphNode* parent = | 408 const v8::HeapGraphNode* parent = |
408 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); | 409 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); |
409 CHECK_EQ(parent_string, parent); | 410 CHECK_EQ(parent_string, parent); |
| 411 heap_profiler->DeleteAllHeapSnapshots(); |
410 } | 412 } |
411 | 413 |
412 | 414 |
| 415 TEST(HeapSnapshotConsString) { |
| 416 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 417 v8::HandleScope scope(isolate); |
| 418 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 419 global_template->SetInternalFieldCount(1); |
| 420 LocalContext env(NULL, global_template); |
| 421 v8::Handle<v8::Object> global_proxy = env->Global(); |
| 422 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
| 423 CHECK_EQ(1, global->InternalFieldCount()); |
| 424 |
| 425 i::Factory* factory = i::Isolate::Current()->factory(); |
| 426 i::Handle<i::String> first = |
| 427 factory->NewStringFromAscii(i::CStrVector("0123456789")); |
| 428 i::Handle<i::String> second = |
| 429 factory->NewStringFromAscii(i::CStrVector("0123456789")); |
| 430 i::Handle<i::String> cons_string = factory->NewConsString(first, second); |
| 431 |
| 432 global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string)); |
| 433 |
| 434 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
| 435 const v8::HeapSnapshot* snapshot = |
| 436 heap_profiler->TakeHeapSnapshot(v8_str("cons_strings")); |
| 437 CHECK(ValidateSnapshot(snapshot)); |
| 438 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
| 439 |
| 440 const v8::HeapGraphNode* string_node = |
| 441 GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"); |
| 442 CHECK_NE(NULL, string_node); |
| 443 CHECK_EQ(v8::HeapGraphNode::kConsString, string_node->GetType()); |
| 444 |
| 445 const v8::HeapGraphNode* first_node = |
| 446 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "first"); |
| 447 CHECK_EQ(v8::HeapGraphNode::kString, first_node->GetType()); |
| 448 |
| 449 const v8::HeapGraphNode* second_node = |
| 450 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "second"); |
| 451 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType()); |
| 452 |
| 453 heap_profiler->DeleteAllHeapSnapshots(); |
| 454 } |
| 455 |
| 456 |
| 457 |
413 TEST(HeapSnapshotInternalReferences) { | 458 TEST(HeapSnapshotInternalReferences) { |
414 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 459 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
415 v8::HandleScope scope(isolate); | 460 v8::HandleScope scope(isolate); |
416 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 461 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
417 global_template->SetInternalFieldCount(2); | 462 global_template->SetInternalFieldCount(2); |
418 LocalContext env(NULL, global_template); | 463 LocalContext env(NULL, global_template); |
419 v8::Handle<v8::Object> global_proxy = env->Global(); | 464 v8::Handle<v8::Object> global_proxy = env->Global(); |
420 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 465 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
421 CHECK_EQ(2, global->InternalFieldCount()); | 466 CHECK_EQ(2, global->InternalFieldCount()); |
422 v8::Local<v8::Object> obj = v8::Object::New(); | 467 v8::Local<v8::Object> obj = v8::Object::New(); |
(...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1953 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 1998 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
1954 CHECK(ValidateSnapshot(snapshot)); | 1999 CHECK(ValidateSnapshot(snapshot)); |
1955 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2000 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1956 const v8::HeapGraphNode* foo_func = | 2001 const v8::HeapGraphNode* foo_func = |
1957 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 2002 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
1958 CHECK_NE(NULL, foo_func); | 2003 CHECK_NE(NULL, foo_func); |
1959 const v8::HeapGraphNode* code = | 2004 const v8::HeapGraphNode* code = |
1960 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); | 2005 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); |
1961 CHECK_NE(NULL, code); | 2006 CHECK_NE(NULL, code); |
1962 } | 2007 } |
OLD | NEW |