Chromium Code Reviews| Index: test/cctest/test-heap-profiler.cc |
| diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc |
| index b48e708ae31f62cef288c0ef001dba5068340ff2..5262fc6f65f066fd3a62137c1258f83f914f9269 100644 |
| --- a/test/cctest/test-heap-profiler.cc |
| +++ b/test/cctest/test-heap-profiler.cc |
| @@ -2389,48 +2389,60 @@ TEST(ArrayBufferAndArrayBufferView) { |
| } |
| -static int GetRetainersCount(const v8::HeapSnapshot* snapshot, |
| - const v8::HeapGraphNode* node) { |
| - int count = 0; |
| - for (int i = 0, l = snapshot->GetNodesCount(); i < l; ++i) { |
| - const v8::HeapGraphNode* parent = snapshot->GetNode(i); |
| - for (int j = 0, l2 = parent->GetChildrenCount(); j < l2; ++j) { |
| - if (parent->GetChild(j)->GetToNode() == node) { |
| - ++count; |
| - } |
| - } |
| - } |
| - return count; |
| -} |
| +class ScopedArrayBufferContents { |
| + public: |
| + explicit ScopedArrayBufferContents( |
| + const v8::ArrayBuffer::Contents& contents) |
| + : contents_(contents) {} |
| + ~ScopedArrayBufferContents() { free(contents_.Data()); } |
| + void* Data() const { return contents_.Data(); } |
| + size_t ByteLength() const { return contents_.ByteLength(); } |
| + private: |
| + const v8::ArrayBuffer::Contents contents_; |
| +}; |
| TEST(ArrayBufferSharedBackingStore) { |
| LocalContext env; |
| - v8::HandleScope scope(env->GetIsolate()); |
| - v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| - CompileRun("sin1 = Math.sin(1);"); |
| - LocalContext env2; |
| - CompileRun("sin2 = Math.sin(2);"); |
| + v8::Isolate* isolate = env->GetIsolate(); |
| + v8::HandleScope handle_scope(isolate); |
| + v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
| + |
| + v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024); |
| + CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); |
| + CHECK(!ab->IsExternal()); |
| + ScopedArrayBufferContents ab_contents(ab->Externalize()); |
| + CHECK(ab->IsExternal()); |
| + |
| + CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); |
| + 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.
|
| + ASSERT(data != NULL); |
| + v8::Local<v8::ArrayBuffer> ab2 = |
| + v8::ArrayBuffer::New(isolate, data, ab_contents.ByteLength()); |
| + CHECK(ab2->IsExternal()); |
| + env->Global()->Set(v8_str("ab1"), ab); |
| + env->Global()->Set(v8_str("ab2"), ab2); |
| + |
| + v8::Handle<v8::Value> result = CompileRun("ab2.byteLength"); |
| + CHECK_EQ(1024, result->Int32Value()); |
| + |
| const v8::HeapSnapshot* snapshot = |
| heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| CHECK(ValidateSnapshot(snapshot)); |
| - // The 0th-child is (GC Roots), 1st is the user root. |
| - const v8::HeapGraphNode* global = |
| - snapshot->GetRoot()->GetChild(1)->GetToNode(); |
| - const v8::HeapGraphNode* builtins = |
| - GetProperty(global, v8::HeapGraphEdge::kInternal, "builtins"); |
| - CHECK_NE(NULL, builtins); |
| - const v8::HeapGraphNode* sin_table = |
| - GetProperty(builtins, v8::HeapGraphEdge::kProperty, "kSinTable"); |
| - CHECK_NE(NULL, sin_table); |
| - const v8::HeapGraphNode* buffer = |
| - GetProperty(sin_table, v8::HeapGraphEdge::kInternal, "buffer"); |
| - CHECK_NE(NULL, buffer); |
| - const v8::HeapGraphNode* backing_store = |
| - GetProperty(buffer, v8::HeapGraphEdge::kInternal, "backing_store"); |
| - CHECK_NE(NULL, backing_store); |
| - 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.
|
| - CHECK_EQ(2, retainers); |
| + const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| + const v8::HeapGraphNode* ab1_node = |
| + GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1"); |
| + CHECK_NE(NULL, ab1_node); |
| + const v8::HeapGraphNode* ab1_data = |
| + GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store"); |
| + CHECK_NE(NULL, ab1_data); |
| + const v8::HeapGraphNode* ab2_node = |
| + GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2"); |
| + CHECK_NE(NULL, ab2_node); |
| + const v8::HeapGraphNode* ab2_data = |
| + GetProperty(ab2_node, v8::HeapGraphEdge::kInternal, "backing_store"); |
| + CHECK_NE(NULL, ab2_data); |
| + CHECK_EQ(ab1_data, ab2_data); |
| } |