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

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

Issue 170253008: DevTools: Drop kSinTable dependency off the heap profiler ArrayBuffer backing_store test (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 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 | « no previous file | no next file » | 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 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 const v8::HeapGraphNode* first_view = 2382 const v8::HeapGraphNode* first_view =
2383 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view"); 2383 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view");
2384 CHECK_NE(NULL, first_view); 2384 CHECK_NE(NULL, first_view);
2385 const v8::HeapGraphNode* backing_store = 2385 const v8::HeapGraphNode* backing_store =
2386 GetProperty(arr1_buffer, v8::HeapGraphEdge::kInternal, "backing_store"); 2386 GetProperty(arr1_buffer, v8::HeapGraphEdge::kInternal, "backing_store");
2387 CHECK_NE(NULL, backing_store); 2387 CHECK_NE(NULL, backing_store);
2388 CHECK_EQ(400, static_cast<int>(backing_store->GetShallowSize())); 2388 CHECK_EQ(400, static_cast<int>(backing_store->GetShallowSize()));
2389 } 2389 }
2390 2390
2391 2391
2392 static int GetRetainersCount(const v8::HeapSnapshot* snapshot, 2392 class ScopedArrayBufferContents {
2393 const v8::HeapGraphNode* node) { 2393 public:
2394 int count = 0; 2394 explicit ScopedArrayBufferContents(
2395 for (int i = 0, l = snapshot->GetNodesCount(); i < l; ++i) { 2395 const v8::ArrayBuffer::Contents& contents)
2396 const v8::HeapGraphNode* parent = snapshot->GetNode(i); 2396 : contents_(contents) {}
2397 for (int j = 0, l2 = parent->GetChildrenCount(); j < l2; ++j) { 2397 ~ScopedArrayBufferContents() { free(contents_.Data()); }
2398 if (parent->GetChild(j)->GetToNode() == node) { 2398 void* Data() const { return contents_.Data(); }
2399 ++count; 2399 size_t ByteLength() const { return contents_.ByteLength(); }
2400 } 2400 private:
2401 } 2401 const v8::ArrayBuffer::Contents contents_;
2402 } 2402 };
2403 return count;
2404 }
2405 2403
2406 2404
2407 TEST(ArrayBufferSharedBackingStore) { 2405 TEST(ArrayBufferSharedBackingStore) {
2408 LocalContext env; 2406 LocalContext env;
2409 v8::HandleScope scope(env->GetIsolate()); 2407 v8::Isolate* isolate = env->GetIsolate();
2410 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2408 v8::HandleScope handle_scope(isolate);
2411 CompileRun("sin1 = Math.sin(1);"); 2409 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
2412 LocalContext env2; 2410
2413 CompileRun("sin2 = Math.sin(2);"); 2411 v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024);
2412 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2413 CHECK(!ab->IsExternal());
2414 ScopedArrayBufferContents ab_contents(ab->Externalize());
2415 CHECK(ab->IsExternal());
2416
2417 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2418 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
Dmitry Lomov (no reviews) 2014/02/18 13:50:43 Nit: why uint8_t and not void*? Saves you a cast.
alph 2014/02/18 15:56:30 that was a copy-paste. fixed.
2419 ASSERT(data != NULL);
2420 v8::Local<v8::ArrayBuffer> ab2 =
2421 v8::ArrayBuffer::New(isolate, data, ab_contents.ByteLength());
2422 CHECK(ab2->IsExternal());
2423 env->Global()->Set(v8_str("ab1"), ab);
2424 env->Global()->Set(v8_str("ab2"), ab2);
2425
2426 v8::Handle<v8::Value> result = CompileRun("ab2.byteLength");
2427 CHECK_EQ(1024, result->Int32Value());
2428
2414 const v8::HeapSnapshot* snapshot = 2429 const v8::HeapSnapshot* snapshot =
2415 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2430 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2416 CHECK(ValidateSnapshot(snapshot)); 2431 CHECK(ValidateSnapshot(snapshot));
2417 // The 0th-child is (GC Roots), 1st is the user root. 2432 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2418 const v8::HeapGraphNode* global = 2433 const v8::HeapGraphNode* ab1_node =
2419 snapshot->GetRoot()->GetChild(1)->GetToNode(); 2434 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1");
2420 const v8::HeapGraphNode* builtins = 2435 CHECK_NE(NULL, ab1_node);
2421 GetProperty(global, v8::HeapGraphEdge::kInternal, "builtins"); 2436 const v8::HeapGraphNode* ab1_data =
2422 CHECK_NE(NULL, builtins); 2437 GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store");
2423 const v8::HeapGraphNode* sin_table = 2438 CHECK_NE(NULL, ab1_data);
2424 GetProperty(builtins, v8::HeapGraphEdge::kProperty, "kSinTable"); 2439 const v8::HeapGraphNode* ab2_node =
2425 CHECK_NE(NULL, sin_table); 2440 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2");
2426 const v8::HeapGraphNode* buffer = 2441 CHECK_NE(NULL, ab2_node);
2427 GetProperty(sin_table, v8::HeapGraphEdge::kInternal, "buffer"); 2442 const v8::HeapGraphNode* ab2_data =
2428 CHECK_NE(NULL, buffer); 2443 GetProperty(ab2_node, v8::HeapGraphEdge::kInternal, "backing_store");
2429 const v8::HeapGraphNode* backing_store = 2444 CHECK_NE(NULL, ab2_data);
2430 GetProperty(buffer, v8::HeapGraphEdge::kInternal, "backing_store"); 2445 CHECK_EQ(ab1_data, ab2_data);
2431 CHECK_NE(NULL, backing_store);
2432 int retainers = GetRetainersCount(snapshot, backing_store);
Dmitry Lomov (no reviews) 2014/02/18 13:50:43 Looks like coverage for GetRetainersCount is gone?
alph 2014/02/18 15:56:30 Thought it's redundant. Added back.
2433 CHECK_EQ(2, retainers);
2434 } 2446 }
2435 2447
2436 2448
2437 TEST(BoxObject) { 2449 TEST(BoxObject) {
2438 v8::Isolate* isolate = CcTest::isolate(); 2450 v8::Isolate* isolate = CcTest::isolate();
2439 v8::HandleScope scope(isolate); 2451 v8::HandleScope scope(isolate);
2440 LocalContext env; 2452 LocalContext env;
2441 v8::Handle<v8::Object> global_proxy = env->Global(); 2453 v8::Handle<v8::Object> global_proxy = env->Global();
2442 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 2454 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
2443 2455
(...skipping 10 matching lines...) Expand all
2454 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 2466 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
2455 const v8::HeapGraphNode* box_node = 2467 const v8::HeapGraphNode* box_node =
2456 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); 2468 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0");
2457 CHECK_NE(NULL, box_node); 2469 CHECK_NE(NULL, box_node);
2458 v8::String::Utf8Value box_node_name(box_node->GetName()); 2470 v8::String::Utf8Value box_node_name(box_node->GetName());
2459 CHECK_EQ("system / Box", *box_node_name); 2471 CHECK_EQ("system / Box", *box_node_name);
2460 const v8::HeapGraphNode* box_value = 2472 const v8::HeapGraphNode* box_value =
2461 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); 2473 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value");
2462 CHECK_NE(NULL, box_value); 2474 CHECK_NE(NULL, box_value);
2463 } 2475 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698