OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 | 778 |
779 // Find source and name for the requested script. | 779 // Find source and name for the requested script. |
780 Handle<String> source_code = | 780 Handle<String> source_code = |
781 isolate->bootstrapper()->NativesSourceLookup(index); | 781 isolate->bootstrapper()->NativesSourceLookup(index); |
782 Vector<const char> name = Natives::GetScriptName(index); | 782 Vector<const char> name = Natives::GetScriptName(index); |
783 Handle<String> script_name = factory->NewStringFromAscii(name); | 783 Handle<String> script_name = factory->NewStringFromAscii(name); |
784 Handle<Context> context = isolate->native_context(); | 784 Handle<Context> context = isolate->native_context(); |
785 | 785 |
786 // Compile the script. | 786 // Compile the script. |
787 Handle<SharedFunctionInfo> function_info; | 787 Handle<SharedFunctionInfo> function_info; |
788 function_info = Compiler::Compile(source_code, | 788 function_info = Compiler::CompileScript(source_code, |
789 script_name, | 789 script_name, 0, 0, |
790 0, 0, | 790 false, |
791 false, | 791 context, |
792 context, | 792 NULL, NULL, |
793 NULL, NULL, | 793 Handle<String>::null(), |
794 Handle<String>::null(), | 794 NATIVES_CODE); |
795 NATIVES_CODE); | |
796 | 795 |
797 // Silently ignore stack overflows during compilation. | 796 // Silently ignore stack overflows during compilation. |
798 if (function_info.is_null()) { | 797 if (function_info.is_null()) { |
799 ASSERT(isolate->has_pending_exception()); | 798 ASSERT(isolate->has_pending_exception()); |
800 isolate->clear_pending_exception(); | 799 isolate->clear_pending_exception(); |
801 return false; | 800 return false; |
802 } | 801 } |
803 | 802 |
804 // Execute the shared function in the debugger context. | 803 // Execute the shared function in the debugger context. |
805 bool caught_exception; | 804 bool caught_exception; |
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 } | 1863 } |
1865 | 1864 |
1866 | 1865 |
1867 void Debug::ClearStepNext() { | 1866 void Debug::ClearStepNext() { |
1868 thread_local_.last_step_action_ = StepNone; | 1867 thread_local_.last_step_action_ = StepNone; |
1869 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 1868 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
1870 thread_local_.last_fp_ = 0; | 1869 thread_local_.last_fp_ = 0; |
1871 } | 1870 } |
1872 | 1871 |
1873 | 1872 |
1874 // Helper function to compile full code for debugging. This code will | |
1875 // have debug break slots and deoptimization information. Deoptimization | |
1876 // information is required in case that an optimized version of this | |
1877 // function is still activated on the stack. It will also make sure that | |
1878 // the full code is compiled with the same flags as the previous version, | |
1879 // that is flags which can change the code generated. The current method | |
1880 // of mapping from already compiled full code without debug break slots | |
1881 // to full code with debug break slots depends on the generated code is | |
1882 // otherwise exactly the same. | |
1883 static bool CompileFullCodeForDebugging(Handle<JSFunction> function, | |
1884 Handle<Code> current_code) { | |
1885 ASSERT(!current_code->has_debug_break_slots()); | |
1886 | |
1887 CompilationInfoWithZone info(function); | |
1888 info.MarkCompilingForDebugging(current_code); | |
1889 ASSERT(!info.shared_info()->is_compiled()); | |
1890 ASSERT(!info.isolate()->has_pending_exception()); | |
1891 | |
1892 // Use compile lazy which will end up compiling the full code in the | |
1893 // configuration configured above. | |
1894 bool result = Compiler::CompileLazy(&info); | |
1895 ASSERT(result != info.isolate()->has_pending_exception()); | |
1896 info.isolate()->clear_pending_exception(); | |
1897 #if DEBUG | |
1898 if (result) { | |
1899 Handle<Code> new_code(function->shared()->code()); | |
1900 ASSERT(new_code->has_debug_break_slots()); | |
1901 ASSERT(current_code->is_compiled_optimizable() == | |
1902 new_code->is_compiled_optimizable()); | |
1903 } | |
1904 #endif | |
1905 return result; | |
1906 } | |
1907 | |
1908 | |
1909 static void CollectActiveFunctionsFromThread( | 1873 static void CollectActiveFunctionsFromThread( |
1910 Isolate* isolate, | 1874 Isolate* isolate, |
1911 ThreadLocalTop* top, | 1875 ThreadLocalTop* top, |
1912 List<Handle<JSFunction> >* active_functions, | 1876 List<Handle<JSFunction> >* active_functions, |
1913 Object* active_code_marker) { | 1877 Object* active_code_marker) { |
1914 // Find all non-optimized code functions with activation frames | 1878 // Find all non-optimized code functions with activation frames |
1915 // on the stack. This includes functions which have optimized | 1879 // on the stack. This includes functions which have optimized |
1916 // activations (including inlined functions) on the stack as the | 1880 // activations (including inlined functions) on the stack as the |
1917 // non-optimized code is needed for the lazy deoptimization. | 1881 // non-optimized code is needed for the lazy deoptimization. |
1918 for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) { | 1882 for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 if (!shared->script()->IsScript()) continue; | 2072 if (!shared->script()->IsScript()) continue; |
2109 if (function->IsBuiltin()) continue; | 2073 if (function->IsBuiltin()) continue; |
2110 if (shared->code()->gc_metadata() == active_code_marker) continue; | 2074 if (shared->code()->gc_metadata() == active_code_marker) continue; |
2111 | 2075 |
2112 Code::Kind kind = function->code()->kind(); | 2076 Code::Kind kind = function->code()->kind(); |
2113 if (kind == Code::FUNCTION && | 2077 if (kind == Code::FUNCTION && |
2114 !function->code()->has_debug_break_slots()) { | 2078 !function->code()->has_debug_break_slots()) { |
2115 function->set_code(*lazy_compile); | 2079 function->set_code(*lazy_compile); |
2116 function->shared()->set_code(*lazy_compile); | 2080 function->shared()->set_code(*lazy_compile); |
2117 } else if (kind == Code::BUILTIN && | 2081 } else if (kind == Code::BUILTIN && |
2118 (function->IsInRecompileQueue() || | 2082 (function->IsInOptimizationQueue() || |
2119 function->IsMarkedForLazyRecompilation() || | 2083 function->IsMarkedForCompileOptimized() || |
2120 function->IsMarkedForConcurrentRecompilation())) { | 2084 function->IsMarkedForCompileOptimizedConcurrent())) { |
2121 // Abort in-flight compilation. | 2085 // Abort in-flight compilation. |
2122 Code* shared_code = function->shared()->code(); | 2086 Code* shared_code = function->shared()->code(); |
2123 if (shared_code->kind() == Code::FUNCTION && | 2087 if (shared_code->kind() == Code::FUNCTION && |
2124 shared_code->has_debug_break_slots()) { | 2088 shared_code->has_debug_break_slots()) { |
2125 function->set_code(shared_code); | 2089 function->set_code(shared_code); |
2126 } else { | 2090 } else { |
2127 function->set_code(*lazy_compile); | 2091 function->set_code(*lazy_compile); |
2128 function->shared()->set_code(*lazy_compile); | 2092 function->shared()->set_code(*lazy_compile); |
2129 } | 2093 } |
2130 } | 2094 } |
(...skipping 24 matching lines...) Expand all Loading... |
2155 !shared->allows_lazy_compilation() || | 2119 !shared->allows_lazy_compilation() || |
2156 shared->code()->kind() == Code::BUILTIN) { | 2120 shared->code()->kind() == Code::BUILTIN) { |
2157 continue; | 2121 continue; |
2158 } | 2122 } |
2159 | 2123 |
2160 // Make sure that the shared full code is compiled with debug | 2124 // Make sure that the shared full code is compiled with debug |
2161 // break slots. | 2125 // break slots. |
2162 if (!shared->code()->has_debug_break_slots()) { | 2126 if (!shared->code()->has_debug_break_slots()) { |
2163 // Try to compile the full code with debug break slots. If it | 2127 // Try to compile the full code with debug break slots. If it |
2164 // fails just keep the current code. | 2128 // fails just keep the current code. |
2165 Handle<Code> current_code(function->shared()->code()); | |
2166 shared->set_code(*lazy_compile); | |
2167 bool prev_force_debugger_active = | 2129 bool prev_force_debugger_active = |
2168 isolate_->debugger()->force_debugger_active(); | 2130 isolate_->debugger()->force_debugger_active(); |
2169 isolate_->debugger()->set_force_debugger_active(true); | 2131 isolate_->debugger()->set_force_debugger_active(true); |
2170 ASSERT(current_code->kind() == Code::FUNCTION); | 2132 function->ReplaceCode(*Compiler::GetCodeForDebugging(function)); |
2171 CompileFullCodeForDebugging(function, current_code); | |
2172 isolate_->debugger()->set_force_debugger_active( | 2133 isolate_->debugger()->set_force_debugger_active( |
2173 prev_force_debugger_active); | 2134 prev_force_debugger_active); |
2174 if (!shared->is_compiled()) { | |
2175 shared->set_code(*current_code); | |
2176 continue; | |
2177 } | |
2178 } | 2135 } |
2179 | 2136 |
2180 // Keep function code in sync with shared function info. | 2137 // Keep function code in sync with shared function info. |
2181 function->set_code(shared->code()); | 2138 function->set_code(shared->code()); |
2182 } | 2139 } |
2183 | 2140 |
2184 RedirectActivationsToRecompiledCodeOnThread(isolate_, | 2141 RedirectActivationsToRecompiledCodeOnThread(isolate_, |
2185 isolate_->thread_local_top()); | 2142 isolate_->thread_local_top()); |
2186 | 2143 |
2187 ActiveFunctionsRedirector active_functions_redirector; | 2144 ActiveFunctionsRedirector active_functions_redirector; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 has_break_points_ = true; | 2237 has_break_points_ = true; |
2281 | 2238 |
2282 // If the candidate found is compiled we are done. | 2239 // If the candidate found is compiled we are done. |
2283 done = target->is_compiled(); | 2240 done = target->is_compiled(); |
2284 if (!done) { | 2241 if (!done) { |
2285 // If the candidate is not compiled, compile it to reveal any inner | 2242 // If the candidate is not compiled, compile it to reveal any inner |
2286 // functions which might contain the requested source position. This | 2243 // functions which might contain the requested source position. This |
2287 // will compile all inner functions that cannot be compiled without a | 2244 // will compile all inner functions that cannot be compiled without a |
2288 // context, because Compiler::BuildFunctionInfo checks whether the | 2245 // context, because Compiler::BuildFunctionInfo checks whether the |
2289 // debugger is active. | 2246 // debugger is active. |
2290 if (target_function.is_null()) { | 2247 Handle<Code> result = target_function.is_null() |
2291 SharedFunctionInfo::CompileLazy(target, KEEP_EXCEPTION); | 2248 ? Compiler::GetUnoptimizedCode(target) |
2292 } else { | 2249 : Compiler::GetUnoptimizedCode(target_function); |
2293 JSFunction::CompileLazy(target_function, KEEP_EXCEPTION); | 2250 if (result.is_null()) return isolate_->heap()->undefined_value(); |
2294 } | |
2295 } | 2251 } |
2296 } // End while loop. | 2252 } // End while loop. |
2297 | 2253 |
2298 return *target; | 2254 return *target; |
2299 } | 2255 } |
2300 | 2256 |
2301 | 2257 |
2302 // Ensures the debug information is present for shared. | 2258 // Ensures the debug information is present for shared. |
2303 bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared, | 2259 bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared, |
2304 Handle<JSFunction> function) { | 2260 Handle<JSFunction> function) { |
2305 Isolate* isolate = shared->GetIsolate(); | 2261 Isolate* isolate = shared->GetIsolate(); |
2306 | 2262 |
2307 // Return if we already have the debug info for shared. | 2263 // Return if we already have the debug info for shared. |
2308 if (HasDebugInfo(shared)) { | 2264 if (HasDebugInfo(shared)) { |
2309 ASSERT(shared->is_compiled()); | 2265 ASSERT(shared->is_compiled()); |
2310 return true; | 2266 return true; |
2311 } | 2267 } |
2312 | 2268 |
2313 // There will be at least one break point when we are done. | 2269 // There will be at least one break point when we are done. |
2314 has_break_points_ = true; | 2270 has_break_points_ = true; |
2315 | 2271 |
2316 // Ensure function is compiled. Return false if this failed. | 2272 // Ensure function is compiled. Return false if this failed. |
2317 if (!function.is_null() && | 2273 if (!function.is_null() && |
2318 !JSFunction::EnsureCompiled(function, CLEAR_EXCEPTION)) { | 2274 !Compiler::EnsureCompiled(function, CLEAR_EXCEPTION)) { |
2319 return false; | 2275 return false; |
2320 } | 2276 } |
2321 | 2277 |
2322 // Create the debug info object. | 2278 // Create the debug info object. |
2323 Handle<DebugInfo> debug_info = isolate->factory()->NewDebugInfo(shared); | 2279 Handle<DebugInfo> debug_info = isolate->factory()->NewDebugInfo(shared); |
2324 | 2280 |
2325 // Add debug info to the list. | 2281 // Add debug info to the list. |
2326 DebugInfoListNode* node = new DebugInfoListNode(*debug_info); | 2282 DebugInfoListNode* node = new DebugInfoListNode(*debug_info); |
2327 node->set_next(debug_info_list_); | 2283 node->set_next(debug_info_list_); |
2328 debug_info_list_ = node; | 2284 debug_info_list_ = node; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2594 // Perform GC to get unreferenced scripts evicted from the cache before | 2550 // Perform GC to get unreferenced scripts evicted from the cache before |
2595 // returning the content. | 2551 // returning the content. |
2596 isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 2552 isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
2597 "Debug::GetLoadedScripts"); | 2553 "Debug::GetLoadedScripts"); |
2598 | 2554 |
2599 // Get the scripts from the cache. | 2555 // Get the scripts from the cache. |
2600 return script_cache_->GetScripts(); | 2556 return script_cache_->GetScripts(); |
2601 } | 2557 } |
2602 | 2558 |
2603 | 2559 |
| 2560 void Debug::RecordEvalCaller(Handle<Script> script) { |
| 2561 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
| 2562 // For eval scripts add information on the function from which eval was |
| 2563 // called. |
| 2564 StackTraceFrameIterator it(script->GetIsolate()); |
| 2565 if (!it.done()) { |
| 2566 script->set_eval_from_shared(it.frame()->function()->shared()); |
| 2567 Code* code = it.frame()->LookupCode(); |
| 2568 int offset = static_cast<int>( |
| 2569 it.frame()->pc() - code->instruction_start()); |
| 2570 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); |
| 2571 } |
| 2572 } |
| 2573 |
| 2574 |
2604 void Debug::AfterGarbageCollection() { | 2575 void Debug::AfterGarbageCollection() { |
2605 // Generate events for collected scripts. | 2576 // Generate events for collected scripts. |
2606 if (script_cache_ != NULL) { | 2577 if (script_cache_ != NULL) { |
2607 script_cache_->ProcessCollectedScripts(); | 2578 script_cache_->ProcessCollectedScripts(); |
2608 } | 2579 } |
2609 } | 2580 } |
2610 | 2581 |
2611 | 2582 |
2612 Debugger::Debugger(Isolate* isolate) | 2583 Debugger::Debugger(Isolate* isolate) |
2613 : debugger_access_(isolate->debugger_access()), | 2584 : debugger_access_(isolate->debugger_access()), |
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3854 { | 3825 { |
3855 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); | 3826 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); |
3856 isolate_->debugger()->CallMessageDispatchHandler(); | 3827 isolate_->debugger()->CallMessageDispatchHandler(); |
3857 } | 3828 } |
3858 } | 3829 } |
3859 } | 3830 } |
3860 | 3831 |
3861 #endif // ENABLE_DEBUGGER_SUPPORT | 3832 #endif // ENABLE_DEBUGGER_SUPPORT |
3862 | 3833 |
3863 } } // namespace v8::internal | 3834 } } // namespace v8::internal |
OLD | NEW |