Chromium Code Reviews| 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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3)); | 848 CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3)); |
| 849 const_cast<v8::HeapSnapshot*>(s2)->Delete(); | 849 const_cast<v8::HeapSnapshot*>(s2)->Delete(); |
| 850 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); | 850 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); |
| 851 CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid2)); | 851 CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid2)); |
| 852 CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3)); | 852 CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3)); |
| 853 const_cast<v8::HeapSnapshot*>(s3)->Delete(); | 853 const_cast<v8::HeapSnapshot*>(s3)->Delete(); |
| 854 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 854 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
| 855 CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid3)); | 855 CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid3)); |
| 856 } | 856 } |
| 857 | 857 |
| 858 class TestResource: public v8::String::ExternalStringResource { | |
| 859 public: | |
| 860 static const size_t max_length = 100; | |
|
mnaganov (inactive)
2012/01/11 18:50:23
kMaxLength
yurys
2012/01/11 19:50:13
Done.
| |
| 861 explicit TestResource(const char* data) | |
| 862 : data_(), length_(strlen(data)) { | |
| 863 if (length_ >= max_length) length_ = max_length - 1; | |
| 864 for (size_t i = 0; i < length_; i++) data_[i] = data[i]; | |
| 865 data_[length_ + 1] = 0; | |
| 866 } | |
| 867 | |
| 868 ~TestResource() {} | |
| 869 const uint16_t* data() const { return data_; } | |
| 870 size_t length() const { return length_; } | |
| 871 private: | |
| 872 uint16_t data_[max_length]; | |
| 873 size_t length_; | |
| 874 }; | |
| 875 | |
| 876 class VisitorImpl : public v8::HeapProfiler::ExternalResourceVisitor { | |
| 877 public: | |
| 878 VisitorImpl(TestResource* r1, TestResource* r2) | |
| 879 : resource1_(r1), | |
| 880 resource2_(r2) {} | |
| 881 virtual ~VisitorImpl() {} | |
| 882 virtual void VisitExternalString(v8::Handle<v8::String> string) { | |
| 883 if (!string->IsExternal()) { | |
| 884 CHECK(string->IsExternalAscii()); | |
| 885 return; | |
| 886 } | |
| 887 v8::String::ExternalStringResource* resource = | |
| 888 string->GetExternalStringResource(); | |
| 889 CHECK(resource); | |
| 890 if (resource1_ == resource) | |
|
mnaganov (inactive)
2012/01/11 18:50:23
Perhaps, just use boolean flags? Modifying referen
yurys
2012/01/11 19:50:13
Done.
| |
| 891 resource1_ = NULL; | |
| 892 if (resource2_ == resource) | |
| 893 resource2_ = NULL; | |
| 894 } | |
| 895 void CheckVisitedResources() { | |
| 896 CHECK_EQ(NULL, resource1_); | |
| 897 CHECK_EQ(NULL, resource2_); | |
| 898 } | |
| 899 | |
| 900 private: | |
| 901 v8::String::ExternalStringResource* resource1_; | |
| 902 v8::String::ExternalStringResource* resource2_; | |
| 903 }; | |
| 904 | |
| 905 TEST(VisitExternalStrings) { | |
| 906 v8::HandleScope scope; | |
| 907 LocalContext env; | |
| 908 TestResource* resource = new TestResource("Test string1"); | |
| 909 v8::Local<v8::String> string1 = v8::String::NewExternal(resource); | |
| 910 TestResource* resource2 = new TestResource("Test string2"); | |
| 911 v8::Local<v8::String> string2 = v8::String::NewExternal(resource2); | |
| 912 | |
| 913 VisitorImpl visitor(resource, resource2); | |
| 914 v8::HeapProfiler::VisitExternalResources(&visitor); | |
| 915 visitor.CheckVisitedResources(); | |
| 916 } | |
| 917 | |
| 858 | 918 |
| 859 TEST(DocumentURL) { | 919 TEST(DocumentURL) { |
| 860 v8::HandleScope scope; | 920 v8::HandleScope scope; |
| 861 LocalContext env; | 921 LocalContext env; |
| 862 | 922 |
| 863 CompileRun("document = { URL:\"abcdefgh\" };"); | 923 CompileRun("document = { URL:\"abcdefgh\" };"); |
| 864 | 924 |
| 865 const v8::HeapSnapshot* snapshot = | 925 const v8::HeapSnapshot* snapshot = |
| 866 v8::HeapProfiler::TakeSnapshot(v8_str("document")); | 926 v8::HeapProfiler::TakeSnapshot(v8_str("document")); |
| 867 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 927 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1148 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); | 1208 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); |
| 1149 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1209 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 1150 CHECK_NE(NULL, global); | 1210 CHECK_NE(NULL, global); |
| 1151 const v8::HeapGraphNode* fun = | 1211 const v8::HeapGraphNode* fun = |
| 1152 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); | 1212 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); |
| 1153 CHECK(HasWeakEdge(fun)); | 1213 CHECK(HasWeakEdge(fun)); |
| 1154 const v8::HeapGraphNode* shared = | 1214 const v8::HeapGraphNode* shared = |
| 1155 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); | 1215 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); |
| 1156 CHECK(HasWeakEdge(shared)); | 1216 CHECK(HasWeakEdge(shared)); |
| 1157 } | 1217 } |
| OLD | NEW |