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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 CHECK_EQ(is_lazy ? 0 : 4, | 690 CHECK_EQ(is_lazy ? 0 : 4, |
691 GetFunctionLineNumber(profiler, env, "lazy_func_at_forth_line")); | 691 GetFunctionLineNumber(profiler, env, "lazy_func_at_forth_line")); |
692 CHECK_EQ(2, GetFunctionLineNumber(profiler, env, "bar_at_the_second_line")); | 692 CHECK_EQ(2, GetFunctionLineNumber(profiler, env, "bar_at_the_second_line")); |
693 CHECK_EQ(is_lazy ? 0 : 6, | 693 CHECK_EQ(is_lazy ? 0 : 6, |
694 GetFunctionLineNumber(profiler, env, "lazy_func_at_6th_line")); | 694 GetFunctionLineNumber(profiler, env, "lazy_func_at_6th_line")); |
695 | 695 |
696 profiler.StopProfiling("LineNumber"); | 696 profiler.StopProfiling("LineNumber"); |
697 } | 697 } |
698 | 698 |
699 TEST(BailoutReason) { | 699 TEST(BailoutReason) { |
700 i::FLAG_allow_natives_syntax = true; | |
701 i::FLAG_always_opt = false; | |
702 v8::HandleScope scope(CcTest::isolate()); | 700 v8::HandleScope scope(CcTest::isolate()); |
703 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); | 701 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
704 v8::Context::Scope context_scope(env); | 702 v8::Context::Scope context_scope(env); |
705 std::unique_ptr<CpuProfiler> iprofiler(new CpuProfiler(CcTest::i_isolate())); | 703 std::unique_ptr<CpuProfiler> iprofiler(new CpuProfiler(CcTest::i_isolate())); |
706 i::ProfilerExtension::set_profiler(iprofiler.get()); | 704 i::ProfilerExtension::set_profiler(iprofiler.get()); |
707 | 705 |
708 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 706 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
709 v8::Local<v8::Function> function = CompileRun( | 707 v8::Local<v8::Script> script = |
710 "function Debugger() {\n" | 708 v8_compile(v8_str("function Debugger() {\n" |
711 " startProfiling();\n" | 709 " debugger;\n" |
712 "}" | 710 " startProfiling();\n" |
713 "Debugger") | 711 "}\n" |
714 .As<v8::Function>(); | 712 "Debugger();\n" |
715 i::Handle<i::JSFunction> i_function = | 713 "stopProfiling();")); |
716 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function)); | 714 script->Run(v8::Isolate::GetCurrent()->GetCurrentContext()).ToLocalChecked(); |
717 // Set a high opt count to trigger bail out. | |
718 i_function->shared()->set_opt_count(10000); | |
719 | |
720 CompileRun( | |
721 "%OptimizeFunctionOnNextCall(Debugger);" | |
722 "Debugger();" | |
723 "stopProfiling()"); | |
724 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 715 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
725 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile; | 716 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile; |
726 CHECK(profile); | 717 CHECK(profile); |
727 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); | 718 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); |
728 reinterpret_cast<ProfileNode*>( | 719 reinterpret_cast<ProfileNode*>( |
729 const_cast<v8::CpuProfileNode*>(current))->Print(0); | 720 const_cast<v8::CpuProfileNode*>(current))->Print(0); |
730 // The tree should look like this: | 721 // The tree should look like this: |
731 // (root) | 722 // (root) |
732 // "" | 723 // "" |
733 // kFunctionBeingDebugged | 724 // kDebuggerStatement |
734 current = PickChild(current, ""); | 725 current = PickChild(current, ""); |
735 CHECK(const_cast<v8::CpuProfileNode*>(current)); | 726 CHECK(const_cast<v8::CpuProfileNode*>(current)); |
736 | 727 |
737 current = PickChild(current, "Debugger"); | 728 current = PickChild(current, "Debugger"); |
738 CHECK(const_cast<v8::CpuProfileNode*>(current)); | 729 CHECK(const_cast<v8::CpuProfileNode*>(current)); |
739 CHECK(!strcmp("Deoptimized too many times", current->GetBailoutReason())); | 730 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); |
740 } | 731 } |
OLD | NEW |