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

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

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

Powered by Google App Engine
This is Rietveld 408576698