Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 178223011: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-javascript-a64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); 227 GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
228 CHECK_NE(NULL, x); 228 CHECK_NE(NULL, x);
229 const v8::HeapGraphNode* x1 = 229 const v8::HeapGraphNode* x1 =
230 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); 230 GetProperty(x, v8::HeapGraphEdge::kProperty, "a");
231 CHECK_NE(NULL, x1); 231 CHECK_NE(NULL, x1);
232 const v8::HeapGraphNode* x2 = 232 const v8::HeapGraphNode* x2 =
233 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); 233 GetProperty(x, v8::HeapGraphEdge::kProperty, "b");
234 CHECK_NE(NULL, x2); 234 CHECK_NE(NULL, x2);
235 235
236 // Test sizes. 236 // Test sizes.
237 CHECK_NE(0, static_cast<int>(x->GetShallowSize())); 237 CHECK_NE(0, x->GetSelfSize());
238 CHECK_NE(0, static_cast<int>(x1->GetShallowSize())); 238 CHECK_NE(0, x1->GetSelfSize());
239 CHECK_NE(0, static_cast<int>(x2->GetShallowSize())); 239 CHECK_NE(0, x2->GetSelfSize());
240 } 240 }
241 241
242 242
243 TEST(BoundFunctionInSnapshot) { 243 TEST(BoundFunctionInSnapshot) {
244 LocalContext env; 244 LocalContext env;
245 v8::HandleScope scope(env->GetIsolate()); 245 v8::HandleScope scope(env->GetIsolate());
246 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 246 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
247 CompileRun( 247 CompileRun(
248 "function myFunction(a, b) { this.a = a; this.b = b; }\n" 248 "function myFunction(a, b) { this.a = a; this.b = b; }\n"
249 "function AAAAA() {}\n" 249 "function AAAAA() {}\n"
(...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 const v8::HeapGraphNode* transition_info = 2060 const v8::HeapGraphNode* transition_info =
2061 GetProperty(allocation_site, v8::HeapGraphEdge::kInternal, 2061 GetProperty(allocation_site, v8::HeapGraphEdge::kInternal,
2062 "transition_info"); 2062 "transition_info");
2063 CHECK_NE(NULL, transition_info); 2063 CHECK_NE(NULL, transition_info);
2064 2064
2065 const v8::HeapGraphNode* elements = 2065 const v8::HeapGraphNode* elements =
2066 GetProperty(transition_info, v8::HeapGraphEdge::kInternal, 2066 GetProperty(transition_info, v8::HeapGraphEdge::kInternal,
2067 "elements"); 2067 "elements");
2068 CHECK_NE(NULL, elements); 2068 CHECK_NE(NULL, elements);
2069 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType()); 2069 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType());
2070 CHECK_EQ(v8::internal::FixedArray::SizeFor(3), 2070 CHECK_EQ(v8::internal::FixedArray::SizeFor(3), elements->GetSelfSize());
2071 static_cast<int>(elements->GetShallowSize()));
2072 2071
2073 v8::Handle<v8::Value> array_val = 2072 v8::Handle<v8::Value> array_val =
2074 heap_profiler->FindObjectById(transition_info->GetId()); 2073 heap_profiler->FindObjectById(transition_info->GetId());
2075 CHECK(array_val->IsArray()); 2074 CHECK(array_val->IsArray());
2076 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val); 2075 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val);
2077 // Verify the array is "a" in the code above. 2076 // Verify the array is "a" in the code above.
2078 CHECK_EQ(3, array->Length()); 2077 CHECK_EQ(3, array->Length());
2079 CHECK_EQ(v8::Integer::New(isolate, 3), 2078 CHECK_EQ(v8::Integer::New(isolate, 3),
2080 array->Get(v8::Integer::New(isolate, 0))); 2079 array->Get(v8::Integer::New(isolate, 0)));
2081 CHECK_EQ(v8::Integer::New(isolate, 2), 2080 CHECK_EQ(v8::Integer::New(isolate, 2),
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2374 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2376 const v8::HeapGraphNode* arr1_obj = 2375 const v8::HeapGraphNode* arr1_obj =
2377 GetProperty(global, v8::HeapGraphEdge::kProperty, "arr1"); 2376 GetProperty(global, v8::HeapGraphEdge::kProperty, "arr1");
2378 CHECK_NE(NULL, arr1_obj); 2377 CHECK_NE(NULL, arr1_obj);
2379 const v8::HeapGraphNode* arr1_buffer = 2378 const v8::HeapGraphNode* arr1_buffer =
2380 GetProperty(arr1_obj, v8::HeapGraphEdge::kInternal, "buffer"); 2379 GetProperty(arr1_obj, v8::HeapGraphEdge::kInternal, "buffer");
2381 CHECK_NE(NULL, arr1_buffer); 2380 CHECK_NE(NULL, arr1_buffer);
2382 const v8::HeapGraphNode* first_view = 2381 const v8::HeapGraphNode* first_view =
2383 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view"); 2382 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view");
2384 CHECK_NE(NULL, first_view); 2383 CHECK_NE(NULL, first_view);
2385 const v8::HeapGraphNode* backing_store =
2386 GetProperty(arr1_buffer, v8::HeapGraphEdge::kInternal, "backing_store");
2387 CHECK_NE(NULL, backing_store);
2388 CHECK_EQ(400, static_cast<int>(backing_store->GetShallowSize()));
2389 } 2384 }
2390 2385
2391 2386
2392 static int GetRetainersCount(const v8::HeapSnapshot* snapshot,
2393 const v8::HeapGraphNode* node) {
2394 int count = 0;
2395 for (int i = 0, l = snapshot->GetNodesCount(); i < l; ++i) {
2396 const v8::HeapGraphNode* parent = snapshot->GetNode(i);
2397 for (int j = 0, l2 = parent->GetChildrenCount(); j < l2; ++j) {
2398 if (parent->GetChild(j)->GetToNode() == node) {
2399 ++count;
2400 }
2401 }
2402 }
2403 return count;
2404 }
2405
2406
2407 TEST(ArrayBufferSharedBackingStore) {
2408 LocalContext env;
2409 v8::Isolate* isolate = env->GetIsolate();
2410 v8::HandleScope handle_scope(isolate);
2411 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
2412
2413 v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024);
2414 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2415 CHECK(!ab->IsExternal());
2416 v8::ArrayBuffer::Contents ab_contents = ab->Externalize();
2417 CHECK(ab->IsExternal());
2418
2419 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2420 void* data = ab_contents.Data();
2421 ASSERT(data != NULL);
2422 v8::Local<v8::ArrayBuffer> ab2 =
2423 v8::ArrayBuffer::New(isolate, data, ab_contents.ByteLength());
2424 CHECK(ab2->IsExternal());
2425 env->Global()->Set(v8_str("ab1"), ab);
2426 env->Global()->Set(v8_str("ab2"), ab2);
2427
2428 v8::Handle<v8::Value> result = CompileRun("ab2.byteLength");
2429 CHECK_EQ(1024, result->Int32Value());
2430
2431 const v8::HeapSnapshot* snapshot =
2432 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2433 CHECK(ValidateSnapshot(snapshot));
2434 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2435 const v8::HeapGraphNode* ab1_node =
2436 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1");
2437 CHECK_NE(NULL, ab1_node);
2438 const v8::HeapGraphNode* ab1_data =
2439 GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store");
2440 CHECK_NE(NULL, ab1_data);
2441 const v8::HeapGraphNode* ab2_node =
2442 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2");
2443 CHECK_NE(NULL, ab2_node);
2444 const v8::HeapGraphNode* ab2_data =
2445 GetProperty(ab2_node, v8::HeapGraphEdge::kInternal, "backing_store");
2446 CHECK_NE(NULL, ab2_data);
2447 CHECK_EQ(ab1_data, ab2_data);
2448 CHECK_EQ(2, GetRetainersCount(snapshot, ab1_data));
2449 free(data);
2450 }
2451
2452
2453 TEST(BoxObject) { 2387 TEST(BoxObject) {
2454 v8::Isolate* isolate = CcTest::isolate(); 2388 v8::Isolate* isolate = CcTest::isolate();
2455 v8::HandleScope scope(isolate); 2389 v8::HandleScope scope(isolate);
2456 LocalContext env; 2390 LocalContext env;
2457 v8::Handle<v8::Object> global_proxy = env->Global(); 2391 v8::Handle<v8::Object> global_proxy = env->Global();
2458 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 2392 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
2459 2393
2460 i::Factory* factory = CcTest::i_isolate()->factory(); 2394 i::Factory* factory = CcTest::i_isolate()->factory();
2461 i::Handle<i::String> string = 2395 i::Handle<i::String> string =
2462 factory->NewStringFromAscii(i::CStrVector("string")); 2396 factory->NewStringFromAscii(i::CStrVector("string"));
2463 i::Handle<i::Object> box = factory->NewBox(string); 2397 i::Handle<i::Object> box = factory->NewBox(string);
2464 global->Set(0, v8::ToApiHandle<v8::Object>(box)); 2398 global->Set(0, v8::ToApiHandle<v8::Object>(box));
2465 2399
2466 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 2400 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
2467 const v8::HeapSnapshot* snapshot = 2401 const v8::HeapSnapshot* snapshot =
2468 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2402 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2469 CHECK(ValidateSnapshot(snapshot)); 2403 CHECK(ValidateSnapshot(snapshot));
2470 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 2404 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
2471 const v8::HeapGraphNode* box_node = 2405 const v8::HeapGraphNode* box_node =
2472 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); 2406 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0");
2473 CHECK_NE(NULL, box_node); 2407 CHECK_NE(NULL, box_node);
2474 v8::String::Utf8Value box_node_name(box_node->GetName()); 2408 v8::String::Utf8Value box_node_name(box_node->GetName());
2475 CHECK_EQ("system / Box", *box_node_name); 2409 CHECK_EQ("system / Box", *box_node_name);
2476 const v8::HeapGraphNode* box_value = 2410 const v8::HeapGraphNode* box_value =
2477 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); 2411 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value");
2478 CHECK_NE(NULL, box_value); 2412 CHECK_NE(NULL, box_value);
2479 } 2413 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-javascript-a64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698