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

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

Issue 2503393002: [cpu-profiler] use new source position information for deoptimization in cpu profiler (Closed)
Patch Set: removed CodeDeoptEvent::position Created 4 years, 1 month 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 "}\n" 1899 "}\n"
1900 "CompareStatementWithThis();\n"; 1900 "CompareStatementWithThis();\n";
1901 1901
1902 v8::Script::Compile(env.local(), v8_str(source)) 1902 v8::Script::Compile(env.local(), v8_str(source))
1903 .ToLocalChecked() 1903 .ToLocalChecked()
1904 ->Run(env.local()) 1904 ->Run(env.local())
1905 .ToLocalChecked(); 1905 .ToLocalChecked();
1906 } 1906 }
1907 1907
1908 static const char* inlined_source = 1908 static const char* inlined_source =
1909 "function opt_function(f) { return f()*f(); }\n"; 1909 "function opt_function(left, right) { var k = left * right; return k + 1; "
1910 "}\n";
1910 // 0.........1.........2.........3.........4....*....5.........6......*..7 1911 // 0.........1.........2.........3.........4....*....5.........6......*..7
1911 1912
1912 1913
1913 // deopt at the first level inlined function 1914 // deopt at the first level inlined function
1914 TEST(DeoptAtFirstLevelInlinedSource) { 1915 TEST(DeoptAtFirstLevelInlinedSource) {
1915 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 1916 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
1916 i::FLAG_allow_natives_syntax = true; 1917 i::FLAG_allow_natives_syntax = true;
1917 v8::HandleScope scope(CcTest::isolate()); 1918 v8::HandleScope scope(CcTest::isolate());
1918 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1919 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1919 v8::Context::Scope context_scope(env); 1920 v8::Context::Scope context_scope(env);
1920 ProfilerHelper helper(env); 1921 ProfilerHelper helper(env);
1921 i::CpuProfiler* iprofiler = 1922 i::CpuProfiler* iprofiler =
1922 reinterpret_cast<i::CpuProfiler*>(helper.profiler()); 1923 reinterpret_cast<i::CpuProfiler*>(helper.profiler());
1923 1924
1924 // 0.........1.........2.........3.........4.........5.........6.........7 1925 // 0.........1.........2.........3.........4.........5.........6.........7
1925 const char* source = 1926 const char* source =
1926 "function test(f) { return opt_function(f); }\n" 1927 "function test(left, right) { return opt_function(left, right); }\n"
1927 "\n" 1928 "\n"
1928 "startProfiling();\n" 1929 "startProfiling();\n"
1929 "\n" 1930 "\n"
1930 "test(function(){return 10});test(function(){return 12});\n" 1931 "test(10, 10);\n"
1931 "\n" 1932 "\n"
1932 "%SetForceInlineFlag(opt_function);\n"
1933 "%OptimizeFunctionOnNextCall(test)\n" 1933 "%OptimizeFunctionOnNextCall(test)\n"
1934 "\n" 1934 "\n"
1935 "test(function(){return 100000000000});\n" 1935 "test(10, 10);\n"
1936 "\n"
1937 "test(undefined, 1e9);\n"
1936 "\n" 1938 "\n"
1937 "stopProfiling();\n" 1939 "stopProfiling();\n"
1938 "\n"; 1940 "\n";
1939 1941
1940 v8::Local<v8::Script> inlined_script = v8_compile(inlined_source); 1942 v8::Local<v8::Script> inlined_script = v8_compile(inlined_source);
1941 inlined_script->Run(env).ToLocalChecked(); 1943 inlined_script->Run(env).ToLocalChecked();
1942 int inlined_script_id = inlined_script->GetUnboundScript()->GetId(); 1944 int inlined_script_id = inlined_script->GetUnboundScript()->GetId();
1943 1945
1944 v8::Local<v8::Script> script = v8_compile(source); 1946 v8::Local<v8::Script> script = v8_compile(source);
1945 script->Run(env).ToLocalChecked(); 1947 script->Run(env).ToLocalChecked();
(...skipping 14 matching lines...) Expand all
1960 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 1962 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
1961 1963
1962 const char* branch[] = {"", "test"}; 1964 const char* branch[] = {"", "test"};
1963 const ProfileNode* itest_node = 1965 const ProfileNode* itest_node =
1964 GetSimpleBranch(env, profile, branch, arraysize(branch)); 1966 GetSimpleBranch(env, profile, branch, arraysize(branch));
1965 const std::vector<v8::CpuProfileDeoptInfo>& deopt_infos = 1967 const std::vector<v8::CpuProfileDeoptInfo>& deopt_infos =
1966 itest_node->deopt_infos(); 1968 itest_node->deopt_infos();
1967 CHECK_EQ(1U, deopt_infos.size()); 1969 CHECK_EQ(1U, deopt_infos.size());
1968 1970
1969 const v8::CpuProfileDeoptInfo& info = deopt_infos[0]; 1971 const v8::CpuProfileDeoptInfo& info = deopt_infos[0];
1970 CHECK_EQ(reason(i::DeoptimizeReason::kNotASmi), info.deopt_reason); 1972 CHECK(reason(i::DeoptimizeReason::kNotASmi) == info.deopt_reason ||
1973 reason(i::DeoptimizeReason::kNotAHeapNumber) == info.deopt_reason);
1971 CHECK_EQ(2U, info.stack.size()); 1974 CHECK_EQ(2U, info.stack.size());
1972 CHECK_EQ(inlined_script_id, info.stack[0].script_id); 1975 CHECK_EQ(inlined_script_id, info.stack[0].script_id);
1973 CHECK(abs(static_cast<int>(offset(inlined_source, "*f()")) - 1976 CHECK(static_cast<int>(offset(inlined_source, "* right")) -
alph 2016/11/17 00:09:44 Please keep the abs otherwise any big enough value
1974 static_cast<int>(info.stack[0].position)) <= 1); 1977 static_cast<int>(info.stack[0].position) <=
1978 2);
1975 CHECK_EQ(script_id, info.stack[1].script_id); 1979 CHECK_EQ(script_id, info.stack[1].script_id);
1976 CHECK_EQ(offset(source, "opt_function(f)"), info.stack[1].position); 1980 CHECK_EQ(offset(source, "opt_function(left,"), info.stack[1].position);
1977 1981
1978 iprofiler->DeleteProfile(iprofile); 1982 iprofiler->DeleteProfile(iprofile);
1979 } 1983 }
1980 1984
1981 1985
1982 // deopt at the second level inlined function 1986 // deopt at the second level inlined function
1983 TEST(DeoptAtSecondLevelInlinedSource) { 1987 TEST(DeoptAtSecondLevelInlinedSource) {
1984 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 1988 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
1985 i::FLAG_allow_natives_syntax = true; 1989 i::FLAG_allow_natives_syntax = true;
1986 v8::HandleScope scope(CcTest::isolate()); 1990 v8::HandleScope scope(CcTest::isolate());
1987 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1991 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1988 v8::Context::Scope context_scope(env); 1992 v8::Context::Scope context_scope(env);
1989 ProfilerHelper helper(env); 1993 ProfilerHelper helper(env);
1990 i::CpuProfiler* iprofiler = 1994 i::CpuProfiler* iprofiler =
1991 reinterpret_cast<i::CpuProfiler*>(helper.profiler()); 1995 reinterpret_cast<i::CpuProfiler*>(helper.profiler());
1992 1996
1993 // 0.........1.........2.........3.........4.........5.........6.........7 1997 // 0.........1.........2.........3.........4.........5.........6.........7
1994 const char* source = 1998 const char* source =
1995 "function test2(f) { return opt_function(f); }\n" 1999 "function test2(left, right) { return opt_function(left, right); }\n"
1996 "function test1(f) { return test2(f); }\n" 2000 "function test1(left, right) { return test2(left, right); } \n"
1997 "\n" 2001 "\n"
1998 "startProfiling();\n" 2002 "startProfiling();\n"
1999 "\n" 2003 "\n"
2000 "test1(function(){return 10});\n" 2004 "test1(10, 10);\n"
2001 "test1(function(){return 11});\n"
2002 "\n" 2005 "\n"
2003 "%SetForceInlineFlag(test2);\n"
2004 "%SetForceInlineFlag(opt_function);\n"
2005 "%OptimizeFunctionOnNextCall(test1)\n" 2006 "%OptimizeFunctionOnNextCall(test1)\n"
2006 "\n" 2007 "\n"
2007 "test1(function(){return 12});\n" 2008 "test1(10, 10);\n"
2008 "\n" 2009 "\n"
2009 "test1(function(){return 100000000000});\n" 2010 "test1(undefined, 1e9);\n"
2010 "\n" 2011 "\n"
2011 "stopProfiling();\n" 2012 "stopProfiling();\n"
2012 "\n"; 2013 "\n";
2013 2014
2014 v8::Local<v8::Script> inlined_script = v8_compile(inlined_source); 2015 v8::Local<v8::Script> inlined_script = v8_compile(inlined_source);
2015 inlined_script->Run(env).ToLocalChecked(); 2016 inlined_script->Run(env).ToLocalChecked();
2016 int inlined_script_id = inlined_script->GetUnboundScript()->GetId(); 2017 int inlined_script_id = inlined_script->GetUnboundScript()->GetId();
2017 2018
2018 v8::Local<v8::Script> script = v8_compile(source); 2019 v8::Local<v8::Script> script = v8_compile(source);
2019 script->Run(env).ToLocalChecked(); 2020 script->Run(env).ToLocalChecked();
(...skipping 17 matching lines...) Expand all
2037 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 2038 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
2038 2039
2039 const char* branch[] = {"", "test1"}; 2040 const char* branch[] = {"", "test1"};
2040 const ProfileNode* itest_node = 2041 const ProfileNode* itest_node =
2041 GetSimpleBranch(env, profile, branch, arraysize(branch)); 2042 GetSimpleBranch(env, profile, branch, arraysize(branch));
2042 const std::vector<v8::CpuProfileDeoptInfo>& deopt_infos = 2043 const std::vector<v8::CpuProfileDeoptInfo>& deopt_infos =
2043 itest_node->deopt_infos(); 2044 itest_node->deopt_infos();
2044 CHECK_EQ(1U, deopt_infos.size()); 2045 CHECK_EQ(1U, deopt_infos.size());
2045 2046
2046 const v8::CpuProfileDeoptInfo info = deopt_infos[0]; 2047 const v8::CpuProfileDeoptInfo info = deopt_infos[0];
2047 CHECK_EQ(reason(i::DeoptimizeReason::kNotASmi), info.deopt_reason); 2048 CHECK(reason(i::DeoptimizeReason::kNotASmi) == info.deopt_reason ||
2049 reason(i::DeoptimizeReason::kNotAHeapNumber) == info.deopt_reason);
2048 CHECK_EQ(3U, info.stack.size()); 2050 CHECK_EQ(3U, info.stack.size());
2049 CHECK_EQ(inlined_script_id, info.stack[0].script_id); 2051 CHECK_EQ(inlined_script_id, info.stack[0].script_id);
2050 CHECK(abs(static_cast<int>(offset(inlined_source, "*f()")) - 2052 CHECK(static_cast<int>(offset(inlined_source, "* right")) -
alph 2016/11/17 00:09:44 ditto
2051 static_cast<int>(info.stack[0].position)) <= 1); 2053 static_cast<int>(info.stack[0].position) <=
2054 2);
2052 CHECK_EQ(script_id, info.stack[1].script_id); 2055 CHECK_EQ(script_id, info.stack[1].script_id);
2053 CHECK_EQ(offset(source, "opt_function(f)"), info.stack[1].position); 2056 CHECK_EQ(offset(source, "opt_function(left,"), info.stack[1].position);
2054 CHECK_EQ(offset(source, "test2(f);"), info.stack[2].position); 2057 CHECK_EQ(offset(source, "test2(left, right);"), info.stack[2].position);
2055 2058
2056 iprofiler->DeleteProfile(iprofile); 2059 iprofiler->DeleteProfile(iprofile);
2057 } 2060 }
2058 2061
2059 2062
2060 // deopt in untracked function 2063 // deopt in untracked function
2061 TEST(DeoptUntrackedFunction) { 2064 TEST(DeoptUntrackedFunction) {
2062 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 2065 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
2063 i::FLAG_allow_natives_syntax = true; 2066 i::FLAG_allow_natives_syntax = true;
2064 v8::HandleScope scope(CcTest::isolate()); 2067 v8::HandleScope scope(CcTest::isolate());
2065 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 2068 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
2066 v8::Context::Scope context_scope(env); 2069 v8::Context::Scope context_scope(env);
2067 ProfilerHelper helper(env); 2070 ProfilerHelper helper(env);
2068 i::CpuProfiler* iprofiler = 2071 i::CpuProfiler* iprofiler =
2069 reinterpret_cast<i::CpuProfiler*>(helper.profiler()); 2072 reinterpret_cast<i::CpuProfiler*>(helper.profiler());
2070 2073
2071 // 0.........1.........2.........3.........4.........5.........6.........7 2074 // 0.........1.........2.........3.........4.........5.........6.........7
2072 const char* source = 2075 const char* source =
2073 "function test(left, right) { return opt_function(left, right); }\n" 2076 "function test(left, right) { return opt_function(left, right); }\n"
2074 "\n" 2077 "\n"
2075 "test(function(){return 10});\n" 2078 "test(10, 10);\n"
2076 "test(function(){return 11});\n"
2077 "\n" 2079 "\n"
2078 "%SetForceInlineFlag(opt_function);\n"
2079 "%OptimizeFunctionOnNextCall(test)\n" 2080 "%OptimizeFunctionOnNextCall(test)\n"
2080 "\n" 2081 "\n"
2081 "test(function(){return 10});\n" 2082 "test(10, 10);\n"
2082 "\n" 2083 "\n"
2083 "startProfiling();\n" // profiler started after compilation. 2084 "startProfiling();\n" // profiler started after compilation.
2084 "\n" 2085 "\n"
2085 "test(function(){return 100000000000});\n" 2086 "test(undefined, 10);\n"
2086 "\n" 2087 "\n"
2087 "stopProfiling();\n" 2088 "stopProfiling();\n"
2088 "\n"; 2089 "\n";
2089 2090
2090 v8::Local<v8::Script> inlined_script = v8_compile(inlined_source); 2091 v8::Local<v8::Script> inlined_script = v8_compile(inlined_source);
2091 inlined_script->Run(env).ToLocalChecked(); 2092 inlined_script->Run(env).ToLocalChecked();
2092 2093
2093 v8::Local<v8::Script> script = v8_compile(source); 2094 v8::Local<v8::Script> script = v8_compile(source);
2094 script->Run(env).ToLocalChecked(); 2095 script->Run(env).ToLocalChecked();
2095 2096
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 printf("Profile JSON: %s\n", profile_json.c_str()); 2174 printf("Profile JSON: %s\n", profile_json.c_str());
2174 std::string code = profile_checker + profile_json + ")"; 2175 std::string code = profile_checker + profile_json + ")";
2175 v8::Local<v8::Value> result = 2176 v8::Local<v8::Value> result =
2176 CompileRunChecked(CcTest::isolate(), code.c_str()); 2177 CompileRunChecked(CcTest::isolate(), code.c_str());
2177 v8::String::Utf8Value value(result); 2178 v8::String::Utf8Value value(result);
2178 printf("Check result: %*s\n", value.length(), *value); 2179 printf("Check result: %*s\n", value.length(), *value);
2179 CHECK_EQ(0, value.length()); 2180 CHECK_EQ(0, value.length());
2180 2181
2181 i::V8::SetPlatformForTesting(old_platform); 2182 i::V8::SetPlatformForTesting(old_platform);
2182 } 2183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698