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

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

Issue 984773003: CpuProfiler: fix for GetDeoptReason code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: comments addressed Created 5 years, 9 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
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 1689
1690 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); 1690 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
1691 CHECK(outer_profile); 1691 CHECK(outer_profile);
1692 CHECK_EQ(1, iprofiler->GetProfilesCount()); 1692 CHECK_EQ(1, iprofiler->GetProfilesCount());
1693 outer_profile->Delete(); 1693 outer_profile->Delete();
1694 outer_profile = NULL; 1694 outer_profile = NULL;
1695 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1695 CHECK_EQ(0, iprofiler->GetProfilesCount());
1696 } 1696 }
1697 1697
1698 1698
1699 const char* GetBranchDeoptReason(i::CpuProfile* iprofile, const char* branch[],
1700 int length) {
1701 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
1702 const ProfileNode* iopt_function = NULL;
1703 iopt_function = GetSimpleBranch(profile, branch, length);
1704 CHECK_EQ(1, iopt_function->deopt_infos().length());
1705 return iopt_function->deopt_infos()[0].deopt_reason;
1706 }
1707
1708
1699 // deopt at top function 1709 // deopt at top function
1700 TEST(CollectDeoptEvents) { 1710 TEST(CollectDeoptEvents) {
1701 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 1711 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
1702 i::FLAG_allow_natives_syntax = true; 1712 i::FLAG_allow_natives_syntax = true;
1703 v8::HandleScope scope(CcTest::isolate()); 1713 v8::HandleScope scope(CcTest::isolate());
1704 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1714 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1705 v8::Context::Scope context_scope(env); 1715 v8::Context::Scope context_scope(env);
1706 v8::Isolate* isolate = env->GetIsolate(); 1716 v8::Isolate* isolate = env->GetIsolate();
1707 v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); 1717 v8::CpuProfiler* profiler = isolate->GetCpuProfiler();
1708 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 1718 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
1709 1719
1720 const char opt_source[] =
1721 "function opt_function%d(value, depth) {\n"
1722 " if (depth) return opt_function%d(value, depth - 1);\n"
1723 "\n"
1724 " return 10 / value;\n"
1725 "}\n"
1726 "\n";
1727
1728 for (int i = 0; i < 3; ++i) {
1729 i::EmbeddedVector<char, sizeof(opt_source) + 100> buffer;
1730 i::SNPrintF(buffer, opt_source, i, i);
1731 v8::Script::Compile(v8_str(buffer.start()))->Run();
1732 }
1733
1710 const char* source = 1734 const char* source =
1711 "function opt_function(left, right, depth) {\n"
1712 " if (depth) return opt_function(left, right, depth - 1);\n"
1713 "\n"
1714 " var k = left / 10;\n"
1715 " var r = 10 / right;\n"
1716 " return k + r;"
1717 "}\n"
1718 "\n"
1719 "function test(left, right) {\n"
1720 " return opt_function(left, right, 1);\n"
1721 "}\n"
1722 "\n"
1723 "startProfiling();\n" 1735 "startProfiling();\n"
1724 "\n" 1736 "\n"
1725 "test(10, 10);\n" 1737 "opt_function0(1, 1);\n"
1726 "\n" 1738 "\n"
1727 "%OptimizeFunctionOnNextCall(opt_function)\n" 1739 "%OptimizeFunctionOnNextCall(opt_function0)\n"
1728 "\n" 1740 "\n"
1729 "test(10, 10);\n" 1741 "opt_function0(1, 1);\n"
1730 "\n" 1742 "\n"
1731 "test(undefined, 10);\n" 1743 "opt_function0(undefined, 1);\n"
1732 "\n" 1744 "\n"
1733 "%OptimizeFunctionOnNextCall(opt_function)\n" 1745 "opt_function1(1, 1);\n"
1734 "\n" 1746 "\n"
1735 "test(10, 10);\n" 1747 "%OptimizeFunctionOnNextCall(opt_function1)\n"
1736 "\n" 1748 "\n"
1737 "test(10, 0);\n" 1749 "opt_function1(1, 1);\n"
1750 "\n"
1751 "opt_function1(NaN, 1);\n"
1752 "\n"
1753 "opt_function2(1, 1);\n"
1754 "\n"
1755 "%OptimizeFunctionOnNextCall(opt_function2)\n"
1756 "\n"
1757 "opt_function2(1, 1);\n"
1758 "\n"
1759 "opt_function2(0, 1);\n"
1738 "\n" 1760 "\n"
1739 "stopProfiling();\n" 1761 "stopProfiling();\n"
1740 "\n"; 1762 "\n";
1741 1763
1742 v8::Script::Compile(v8_str(source))->Run(); 1764 v8::Script::Compile(v8_str(source))->Run();
1743 i::CpuProfile* iprofile = iprofiler->GetProfile(0); 1765 i::CpuProfile* iprofile = iprofiler->GetProfile(0);
1744 iprofile->Print(); 1766 iprofile->Print();
1745 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 1767 {
1746 const char* branch[] = {"", "test", "opt_function", "opt_function"}; 1768 const char* branch[] = {"", "opt_function0", "opt_function0"};
1747 const ProfileNode* iopt_function = 1769 CHECK_EQ(reason(i::Deoptimizer::kNotAHeapNumber),
1748 GetSimpleBranch(profile, branch, arraysize(branch)); 1770 GetBranchDeoptReason(iprofile, branch, arraysize(branch)));
1749 CHECK_EQ(2, iopt_function->deopt_infos().length()); 1771 }
1750 CHECK_EQ(reason(i::Deoptimizer::kNotAHeapNumber), 1772 {
1751 iopt_function->deopt_infos()[0].deopt_reason); 1773 const char* branch[] = {"", "opt_function1", "opt_function1"};
1752 CHECK_EQ(reason(i::Deoptimizer::kDivisionByZero), 1774 CHECK_EQ(reason(i::Deoptimizer::kNaN),
1753 iopt_function->deopt_infos()[1].deopt_reason); 1775 GetBranchDeoptReason(iprofile, branch, arraysize(branch)));
1776 }
1777 {
1778 const char* branch[] = {"", "opt_function2", "opt_function2"};
1779 CHECK_EQ(reason(i::Deoptimizer::kDivisionByZero),
1780 GetBranchDeoptReason(iprofile, branch, arraysize(branch)));
1781 }
1754 iprofiler->DeleteProfile(iprofile); 1782 iprofiler->DeleteProfile(iprofile);
1755 } 1783 }
1756 1784
1757 1785
1758 TEST(SourceLocation) { 1786 TEST(SourceLocation) {
1759 i::FLAG_always_opt = true; 1787 i::FLAG_always_opt = true;
1760 i::FLAG_hydrogen_track_positions = true; 1788 i::FLAG_hydrogen_track_positions = true;
1761 LocalContext env; 1789 LocalContext env;
1762 v8::HandleScope scope(CcTest::isolate()); 1790 v8::HandleScope scope(CcTest::isolate());
1763 1791
1764 const char* source = 1792 const char* source =
1765 "function CompareStatementWithThis() {\n" 1793 "function CompareStatementWithThis() {\n"
1766 " if (this === 1) {}\n" 1794 " if (this === 1) {}\n"
1767 "}\n" 1795 "}\n"
1768 "CompareStatementWithThis();\n"; 1796 "CompareStatementWithThis();\n";
1769 1797
1770 v8::Script::Compile(v8_str(source))->Run(); 1798 v8::Script::Compile(v8_str(source))->Run();
1771 } 1799 }
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698