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