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

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

Issue 1846723002: Gracefully handle unloaded scripts (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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
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 2854 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 v8::String::Utf8Value child_name(child->name); 2865 v8::String::Utf8Value child_name(child->name);
2866 if (strcmp(*child_name, name) == 0) { 2866 if (strcmp(*child_name, name) == 0) {
2867 node = child; 2867 node = child;
2868 break; 2868 break;
2869 } 2869 }
2870 } 2870 }
2871 } 2871 }
2872 return node; 2872 return node;
2873 } 2873 }
2874 2874
2875
2876 TEST(SamplingHeapProfiler) { 2875 TEST(SamplingHeapProfiler) {
2877 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2876 v8::HandleScope scope(v8::Isolate::GetCurrent());
2878 LocalContext env; 2877 LocalContext env;
2879 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2878 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2880 2879
2881 // Turn off always_opt. Inlining can cause stack traces to be shorter than 2880 // Turn off always_opt. Inlining can cause stack traces to be shorter than
2882 // what we expect in this test. 2881 // what we expect in this test.
2883 v8::internal::FLAG_always_opt = false; 2882 v8::internal::FLAG_always_opt = false;
2884 2883
2885 // Suppress randomness to avoid flakiness in tests. 2884 // Suppress randomness to avoid flakiness in tests.
2886 v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true; 2885 v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
2887 2886
2888 const char* script_source = 2887 const char* script_source =
2889 "var A = [];\n" 2888 "var A = [];\n"
2890 "function bar(size) { return new Array(size); }\n" 2889 "function bar(size) { return new Array(size); }\n"
2891 "var foo = function() {\n" 2890 "var foo = function() {\n"
2892 " for (var i = 0; i < 1024; ++i) {\n" 2891 " for (var i = 0; i < 1024; ++i) {\n"
2893 " A[i] = bar(1024);\n" 2892 " A[i] = bar(1024);\n"
2894 " }\n" 2893 " }\n"
2895 "}\n" 2894 "}\n"
2896 "foo();"; 2895 "foo();";
2897 2896
2897 const char* gced =
ofrobots 2016/03/30 22:35:35 Use a more descriptive name or, better, inline the
mattloring 2016/03/30 23:55:09 Done.
2898 "for (var i = 0; i < 1024; i++) {\n"
2899 " eval(\"new Array(100)\");\n"
2900 "}\n";
2901
2898 // Sample should be empty if requested before sampling has started. 2902 // Sample should be empty if requested before sampling has started.
2899 { 2903 {
2900 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile(); 2904 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile();
2901 CHECK(profile == nullptr); 2905 CHECK(profile == nullptr);
2902 } 2906 }
2903 2907
2904 int count_1024 = 0; 2908 int count_1024 = 0;
2905 { 2909 {
2906 heap_profiler->StartSamplingHeapProfiler(1024); 2910 heap_profiler->StartSamplingHeapProfiler(1024);
2907 CompileRun(script_source); 2911 CompileRun(script_source);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2978 *profile, Vector<const char*>(names1, arraysize(names1))); 2982 *profile, Vector<const char*>(names1, arraysize(names1)));
2979 CHECK(node1); 2983 CHECK(node1);
2980 2984
2981 const char* names2[] = {"", "generateFunctions"}; 2985 const char* names2[] = {"", "generateFunctions"};
2982 auto node2 = FindAllocationProfileNode( 2986 auto node2 = FindAllocationProfileNode(
2983 *profile, Vector<const char*>(names2, arraysize(names2))); 2987 *profile, Vector<const char*>(names2, arraysize(names2)));
2984 CHECK(node2); 2988 CHECK(node2);
2985 2989
2986 heap_profiler->StopSamplingHeapProfiler(); 2990 heap_profiler->StopSamplingHeapProfiler();
2987 } 2991 }
2992
2993 // A test case with scripts unloaded before profile gathered
2994 {
2995 heap_profiler->StartSamplingHeapProfiler(64);
2996 CompileRun(gced);
2997
2998 CcTest::heap()->CollectAllGarbage();
2999
3000 v8::base::SmartPointer<v8::AllocationProfile> profile(
3001 heap_profiler->GetAllocationProfile());
3002 CHECK(!profile.is_empty());
3003
3004 heap_profiler->StopSamplingHeapProfiler();
3005 }
2988 } 3006 }
2989 3007
2990 3008
2991 TEST(SamplingHeapProfilerApiAllocation) { 3009 TEST(SamplingHeapProfilerApiAllocation) {
2992 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3010 v8::HandleScope scope(v8::Isolate::GetCurrent());
2993 LocalContext env; 3011 LocalContext env;
2994 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 3012 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2995 3013
2996 // Suppress randomness to avoid flakiness in tests. 3014 // Suppress randomness to avoid flakiness in tests.
2997 v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true; 3015 v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
2998 3016
2999 heap_profiler->StartSamplingHeapProfiler(256); 3017 heap_profiler->StartSamplingHeapProfiler(256);
3000 3018
3001 for (int i = 0; i < 8 * 1024; ++i) v8::Object::New(env->GetIsolate()); 3019 for (int i = 0; i < 8 * 1024; ++i) v8::Object::New(env->GetIsolate());
3002 3020
3003 v8::base::SmartPointer<v8::AllocationProfile> profile( 3021 v8::base::SmartPointer<v8::AllocationProfile> profile(
3004 heap_profiler->GetAllocationProfile()); 3022 heap_profiler->GetAllocationProfile());
3005 CHECK(!profile.is_empty()); 3023 CHECK(!profile.is_empty());
3006 const char* names[] = {"(V8 API)"}; 3024 const char* names[] = {"(V8 API)"};
3007 auto node = FindAllocationProfileNode( 3025 auto node = FindAllocationProfileNode(
3008 *profile, Vector<const char*>(names, arraysize(names))); 3026 *profile, Vector<const char*>(names, arraysize(names)));
3009 CHECK(node); 3027 CHECK(node);
3010 3028
3011 heap_profiler->StopSamplingHeapProfiler(); 3029 heap_profiler->StopSamplingHeapProfiler();
3012 } 3030 }
OLDNEW
« src/profiler/sampling-heap-profiler.cc ('K') | « src/profiler/sampling-heap-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698