Reviewers: yurys, loislo, Dmitry Lomov (chromium),
Message:
ptal
Description:
DevTools: Drop kSinTable dependency off the heap profiler ArrayBuffer
backing_store test
LOG=N
Please review this at https://codereview.chromium.org/170253008/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+47, -35 lines):
M test/cctest/test-heap-profiler.cc
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());
+ 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);
- 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);
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.