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

Unified Diff: test/cctest/test-heap-profiler.cc

Issue 136643008: A64: Synchronize with r18256. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-macro-assembler-arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc
index e496673776ca9915f6cab21df9848c4183ff5603..7a27495695a68ce8f66e9fcf45d07bc804646f6e 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -1763,10 +1763,10 @@ bool HasWeakGlobalHandle() {
}
-static void PersistentHandleCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Value>* handle,
- void*) {
- handle->Reset();
+static void PersistentHandleCallback(
+ const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
+ data.GetParameter()->Reset();
+ delete data.GetParameter();
}
@@ -1776,8 +1776,9 @@ TEST(WeakGlobalHandle) {
CHECK(!HasWeakGlobalHandle());
- v8::Persistent<v8::Object> handle(env->GetIsolate(), v8::Object::New());
- handle.MakeWeak<v8::Value, void>(NULL, PersistentHandleCallback);
+ v8::Persistent<v8::Object>* handle =
+ new v8::Persistent<v8::Object>(env->GetIsolate(), v8::Object::New());
+ handle->SetWeak(handle, PersistentHandleCallback);
CHECK(HasWeakGlobalHandle());
}
@@ -2055,7 +2056,8 @@ void HeapProfilerExtension::FindUntrackedObjects(
const v8::FunctionCallbackInfo<v8::Value>& args) {
i::HeapProfiler* heap_profiler =
reinterpret_cast<i::HeapProfiler*>(args.GetIsolate()->GetHeapProfiler());
- int untracked_objects = heap_profiler->FindUntrackedObjects();
+ int untracked_objects =
+ heap_profiler->heap_object_map()->FindUntrackedObjects();
args.GetReturnValue().Set(untracked_objects);
CHECK_EQ(0, untracked_objects);
}
@@ -2066,26 +2068,6 @@ v8::DeclareExtension kHeapProfilerExtensionDeclaration(
&kHeapProfilerExtension);
-// This is an example of using checking of JS allocations tracking in a test.
-TEST(HeapObjectsTracker) {
- const char* extensions[] = { HeapProfilerExtension::kName };
- v8::ExtensionConfiguration config(1, extensions);
- LocalContext env(&config);
- v8::HandleScope scope(env->GetIsolate());
- HeapObjectsTracker tracker;
- CompileRun("var a = 1.2");
- CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;");
- CompileRun(
- "var a = [];\n"
- "for (var i = 0; i < 5; ++i)\n"
- " a[i] = i;\n"
- "findUntrackedObjects();\n"
- "for (var i = 0; i < 3; ++i)\n"
- " a.shift();\n"
- "findUntrackedObjects();\n");
-}
-
-
static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot,
const char* path[],
int depth) {
@@ -2181,12 +2163,6 @@ static const char* record_trace_tree_source =
"for (var i = 0; i < 100; i++) start();\n";
-static i::HeapSnapshot* ToInternal(const v8::HeapSnapshot* snapshot) {
- return const_cast<i::HeapSnapshot*>(
- reinterpret_cast<const i::HeapSnapshot*>(snapshot));
-}
-
-
static AllocationTraceNode* FindNode(
AllocationTracker* tracker, const Vector<const char*>& names) {
AllocationTraceNode* node = tracker->trace_tree()->root();
@@ -2207,19 +2183,48 @@ static AllocationTraceNode* FindNode(
}
+TEST(ArrayGrowLeftTrim) {
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
+ heap_profiler->StartTrackingHeapObjects(true);
+
+ CompileRun(
+ "var a = [];\n"
+ "for (var i = 0; i < 5; ++i)\n"
+ " a[i] = i;\n"
+ "for (var i = 0; i < 3; ++i)\n"
+ " a.shift();\n");
+
+ const char* names[] = { "(anonymous function)" };
+ AllocationTracker* tracker =
+ reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
+ CHECK_NE(NULL, tracker);
+ // Resolve all function locations.
+ tracker->PrepareForSerialization();
+ // Print for better diagnostics in case of failure.
+ tracker->trace_tree()->Print(tracker);
+
+ AllocationTraceNode* node =
+ FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
+ CHECK_NE(NULL, node);
+ CHECK_GE(node->allocation_count(), 2);
+ CHECK_GE(node->allocation_size(), 4 * 5);
+ heap_profiler->StopTrackingHeapObjects();
+}
+
+
TEST(TrackHeapAllocations) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
LocalContext env;
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
- heap_profiler->StartRecordingHeapAllocations();
+ heap_profiler->StartTrackingHeapObjects(true);
CompileRun(record_trace_tree_source);
- const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
- v8::String::NewFromUtf8(env->GetIsolate(), "Test"));
- i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
- AllocationTracker* tracker = collection->allocation_tracker();
+ AllocationTracker* tracker =
+ reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
CHECK_NE(NULL, tracker);
// Resolve all function locations.
tracker->PrepareForSerialization();
@@ -2233,7 +2238,7 @@ TEST(TrackHeapAllocations) {
CHECK_NE(NULL, node);
CHECK_GE(node->allocation_count(), 100);
CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
- heap_profiler->StopRecordingHeapAllocations();
+ heap_profiler->StopTrackingHeapObjects();
}
@@ -2265,14 +2270,12 @@ TEST(TrackBumpPointerAllocations) {
const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" };
// First check that normally all allocations are recorded.
{
- heap_profiler->StartRecordingHeapAllocations();
+ heap_profiler->StartTrackingHeapObjects(true);
CompileRun(inline_heap_allocation_source);
- const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
- v8::String::NewFromUtf8(env->GetIsolate(), "Test2"));
- i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
- AllocationTracker* tracker = collection->allocation_tracker();
+ AllocationTracker* tracker =
+ reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
CHECK_NE(NULL, tracker);
// Resolve all function locations.
tracker->PrepareForSerialization();
@@ -2284,11 +2287,11 @@ TEST(TrackBumpPointerAllocations) {
CHECK_NE(NULL, node);
CHECK_GE(node->allocation_count(), 100);
CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
- heap_profiler->StopRecordingHeapAllocations();
+ heap_profiler->StopTrackingHeapObjects();
}
{
- heap_profiler->StartRecordingHeapAllocations();
+ heap_profiler->StartTrackingHeapObjects(true);
// Now check that not all allocations are tracked if we manually reenable
// inline allocations.
@@ -2297,10 +2300,8 @@ TEST(TrackBumpPointerAllocations) {
CompileRun(inline_heap_allocation_source);
- const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
- v8::String::NewFromUtf8(env->GetIsolate(), "Test1"));
- i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
- AllocationTracker* tracker = collection->allocation_tracker();
+ AllocationTracker* tracker =
+ reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
CHECK_NE(NULL, tracker);
// Resolve all function locations.
tracker->PrepareForSerialization();
@@ -2313,6 +2314,6 @@ TEST(TrackBumpPointerAllocations) {
CHECK_LT(node->allocation_count(), 100);
CcTest::heap()->DisableInlineAllocation();
- heap_profiler->StopRecordingHeapAllocations();
+ heap_profiler->StopTrackingHeapObjects();
}
}
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-macro-assembler-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698