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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 CHECK_EQ(x->GetSelfSize() * 3, x->GetRetainedSize(false)); | 140 CHECK_EQ(x->GetSelfSize() * 3, x->GetRetainedSize(false)); |
141 CHECK_EQ(x1->GetSelfSize(), x1->GetRetainedSize(false)); | 141 CHECK_EQ(x1->GetSelfSize(), x1->GetRetainedSize(false)); |
142 CHECK_EQ(x2->GetSelfSize(), x2->GetRetainedSize(false)); | 142 CHECK_EQ(x2->GetSelfSize(), x2->GetRetainedSize(false)); |
143 // Test exact sizes. | 143 // Test exact sizes. |
144 CHECK_EQ(x->GetSelfSize() * 3, x->GetRetainedSize(true)); | 144 CHECK_EQ(x->GetSelfSize() * 3, x->GetRetainedSize(true)); |
145 CHECK_EQ(x1->GetSelfSize(), x1->GetRetainedSize(true)); | 145 CHECK_EQ(x1->GetSelfSize(), x1->GetRetainedSize(true)); |
146 CHECK_EQ(x2->GetSelfSize(), x2->GetRetainedSize(true)); | 146 CHECK_EQ(x2->GetSelfSize(), x2->GetRetainedSize(true)); |
147 } | 147 } |
148 | 148 |
149 | 149 |
| 150 TEST(BoundFunctionInSnapshot) { |
| 151 v8::HandleScope scope; |
| 152 LocalContext env; |
| 153 CompileRun( |
| 154 "function myFunction(a, b) { this.a = a; this.b = b; }\n" |
| 155 "function AAAAA() {}\n" |
| 156 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); |
| 157 const v8::HeapSnapshot* snapshot = |
| 158 v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); |
| 159 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 160 const v8::HeapGraphNode* f = |
| 161 GetProperty(global, v8::HeapGraphEdge::kShortcut, "boundFunction"); |
| 162 CHECK(f); |
| 163 CHECK_EQ(v8::String::New("native_bind"), f->GetName()); |
| 164 const v8::HeapGraphNode* bindings = |
| 165 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); |
| 166 CHECK_NE(NULL, bindings); |
| 167 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType()); |
| 168 CHECK_EQ(4, bindings->GetChildrenCount()); |
| 169 |
| 170 const v8::HeapGraphNode* bound_this = GetProperty( |
| 171 f, v8::HeapGraphEdge::kShortcut, "bound_this"); |
| 172 CHECK(bound_this); |
| 173 CHECK_EQ(v8::HeapGraphNode::kObject, bound_this->GetType()); |
| 174 |
| 175 const v8::HeapGraphNode* bound_function = GetProperty( |
| 176 f, v8::HeapGraphEdge::kShortcut, "bound_function"); |
| 177 CHECK(bound_function); |
| 178 CHECK_EQ(v8::HeapGraphNode::kClosure, bound_function->GetType()); |
| 179 |
| 180 const v8::HeapGraphNode* bound_argument = GetProperty( |
| 181 f, v8::HeapGraphEdge::kShortcut, "bound_argument_1"); |
| 182 CHECK(bound_argument); |
| 183 CHECK_EQ(v8::HeapGraphNode::kObject, bound_argument->GetType()); |
| 184 } |
| 185 |
| 186 |
150 TEST(HeapSnapshotEntryChildren) { | 187 TEST(HeapSnapshotEntryChildren) { |
151 v8::HandleScope scope; | 188 v8::HandleScope scope; |
152 LocalContext env; | 189 LocalContext env; |
153 | 190 |
154 CompileRun( | 191 CompileRun( |
155 "function A() { }\n" | 192 "function A() { }\n" |
156 "a = new A;"); | 193 "a = new A;"); |
157 const v8::HeapSnapshot* snapshot = | 194 const v8::HeapSnapshot* snapshot = |
158 v8::HeapProfiler::TakeSnapshot(v8_str("children")); | 195 v8::HeapProfiler::TakeSnapshot(v8_str("children")); |
159 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 196 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); | 1261 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); |
1225 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1262 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1226 CHECK_NE(NULL, global); | 1263 CHECK_NE(NULL, global); |
1227 const v8::HeapGraphNode* fun = | 1264 const v8::HeapGraphNode* fun = |
1228 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); | 1265 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); |
1229 CHECK(HasWeakEdge(fun)); | 1266 CHECK(HasWeakEdge(fun)); |
1230 const v8::HeapGraphNode* shared = | 1267 const v8::HeapGraphNode* shared = |
1231 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); | 1268 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); |
1232 CHECK(HasWeakEdge(shared)); | 1269 CHECK(HasWeakEdge(shared)); |
1233 } | 1270 } |
OLD | NEW |