OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/debug/debug.h" | 5 #include "src/debug/debug.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 while (SharedFunctionInfo* shared = iterator.Next()) { | 1276 while (SharedFunctionInfo* shared = iterator.Next()) { |
1277 shared->ClearCodeFromOptimizedCodeMap(); | 1277 shared->ClearCodeFromOptimizedCodeMap(); |
1278 } | 1278 } |
1279 } | 1279 } |
1280 | 1280 |
1281 // Make sure we abort incremental marking. | 1281 // Make sure we abort incremental marking. |
1282 isolate_->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask, | 1282 isolate_->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
1283 "prepare for break points"); | 1283 "prepare for break points"); |
1284 | 1284 |
1285 DCHECK(shared->is_compiled()); | 1285 DCHECK(shared->is_compiled()); |
1286 bool is_interpreted = shared->HasBytecodeArray(); | 1286 bool baseline_exists = shared->HasBaselineCode(); |
1287 | 1287 |
1288 { | 1288 { |
1289 // TODO(yangguo): with bytecode, we still walk the heap to find all | 1289 // TODO(yangguo): with bytecode, we still walk the heap to find all |
1290 // optimized code for the function to deoptimize. We can probably be | 1290 // optimized code for the function to deoptimize. We can probably be |
1291 // smarter here and avoid the heap walk. | 1291 // smarter here and avoid the heap walk. |
1292 HeapIterator iterator(isolate_->heap()); | 1292 HeapIterator iterator(isolate_->heap()); |
1293 HeapObject* obj; | 1293 HeapObject* obj; |
1294 bool find_resumables = !is_interpreted && shared->is_resumable(); | 1294 // Continuation from old-style generators need to be recomputed. |
| 1295 bool find_resumables = baseline_exists && shared->is_resumable(); |
1295 | 1296 |
1296 while ((obj = iterator.next())) { | 1297 while ((obj = iterator.next())) { |
1297 if (obj->IsJSFunction()) { | 1298 if (obj->IsJSFunction()) { |
1298 JSFunction* function = JSFunction::cast(obj); | 1299 JSFunction* function = JSFunction::cast(obj); |
1299 if (!function->Inlines(*shared)) continue; | 1300 if (!function->Inlines(*shared)) continue; |
1300 if (function->code()->kind() == Code::OPTIMIZED_FUNCTION) { | 1301 if (function->code()->kind() == Code::OPTIMIZED_FUNCTION) { |
1301 Deoptimizer::DeoptimizeFunction(function); | 1302 Deoptimizer::DeoptimizeFunction(function); |
1302 } | 1303 } |
1303 if (is_interpreted) continue; | 1304 if (baseline_exists && function->shared() == *shared) { |
1304 if (function->shared() == *shared) functions.Add(handle(function)); | 1305 functions.Add(handle(function)); |
| 1306 } |
1305 } else if (find_resumables && obj->IsJSGeneratorObject()) { | 1307 } else if (find_resumables && obj->IsJSGeneratorObject()) { |
1306 // This case handles async functions as well, as they use generator | 1308 // This case handles async functions as well, as they use generator |
1307 // objects for in-progress async function execution. | 1309 // objects for in-progress async function execution. |
1308 JSGeneratorObject* generator_obj = JSGeneratorObject::cast(obj); | 1310 JSGeneratorObject* generator_obj = JSGeneratorObject::cast(obj); |
1309 if (!generator_obj->is_suspended()) continue; | 1311 if (!generator_obj->is_suspended()) continue; |
1310 JSFunction* function = generator_obj->function(); | 1312 JSFunction* function = generator_obj->function(); |
1311 if (!function->Inlines(*shared)) continue; | 1313 if (!function->Inlines(*shared)) continue; |
1312 int pc_offset = generator_obj->continuation(); | 1314 int pc_offset = generator_obj->continuation(); |
1313 int index = | 1315 int index = |
1314 ComputeContinuationIndexFromPcOffset(function->code(), pc_offset); | 1316 ComputeContinuationIndexFromPcOffset(function->code(), pc_offset); |
1315 generator_obj->set_continuation(index); | 1317 generator_obj->set_continuation(index); |
1316 suspended_generators.Add(handle(generator_obj)); | 1318 suspended_generators.Add(handle(generator_obj)); |
1317 } | 1319 } |
1318 } | 1320 } |
1319 } | 1321 } |
1320 | 1322 |
1321 // We do not need to replace code to debug bytecode. | 1323 // We do not need to replace code to debug bytecode. |
1322 DCHECK(!is_interpreted || functions.length() == 0); | 1324 DCHECK(baseline_exists || functions.is_empty()); |
1323 DCHECK(!is_interpreted || suspended_generators.length() == 0); | 1325 DCHECK(baseline_exists || suspended_generators.is_empty()); |
1324 | 1326 |
1325 // We do not need to recompile to debug bytecode. | 1327 // We do not need to recompile to debug bytecode. |
1326 if (!is_interpreted && !shared->HasDebugCode()) { | 1328 if (baseline_exists && !shared->HasDebugCode()) { |
1327 DCHECK(functions.length() > 0); | 1329 DCHECK(functions.length() > 0); |
1328 if (!Compiler::CompileDebugCode(functions.first())) return false; | 1330 if (!Compiler::CompileDebugCode(functions.first())) return false; |
1329 } | 1331 } |
1330 | 1332 |
1331 for (Handle<JSFunction> const function : functions) { | 1333 for (Handle<JSFunction> const function : functions) { |
1332 function->ReplaceCode(shared->code()); | 1334 function->ReplaceCode(shared->code()); |
1333 JSFunction::EnsureLiterals(function); | 1335 JSFunction::EnsureLiterals(function); |
1334 } | 1336 } |
1335 | 1337 |
1336 for (Handle<JSGeneratorObject> const generator_obj : suspended_generators) { | 1338 for (Handle<JSGeneratorObject> const generator_obj : suspended_generators) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 | 1497 |
1496 // Return if we already have the debug info for shared. | 1498 // Return if we already have the debug info for shared. |
1497 if (shared->HasDebugInfo()) return true; | 1499 if (shared->HasDebugInfo()) return true; |
1498 | 1500 |
1499 if (function.is_null()) { | 1501 if (function.is_null()) { |
1500 DCHECK(shared->HasDebugCode()); | 1502 DCHECK(shared->HasDebugCode()); |
1501 } else if (!Compiler::Compile(function, Compiler::CLEAR_EXCEPTION)) { | 1503 } else if (!Compiler::Compile(function, Compiler::CLEAR_EXCEPTION)) { |
1502 return false; | 1504 return false; |
1503 } | 1505 } |
1504 | 1506 |
1505 if (shared->HasBytecodeArray()) { | 1507 // To prepare bytecode for debugging, we already need to have the debug |
1506 // To prepare bytecode for debugging, we already need to have the debug | 1508 // info (containing the debug copy) upfront, but since we do not recompile, |
1507 // info (containing the debug copy) upfront, but since we do not recompile, | 1509 // preparing for break points cannot fail. |
1508 // preparing for break points cannot fail. | 1510 CreateDebugInfo(shared); |
1509 CreateDebugInfo(shared); | 1511 CHECK(PrepareFunctionForBreakPoints(shared)); |
1510 CHECK(PrepareFunctionForBreakPoints(shared)); | |
1511 } else { | |
1512 if (!PrepareFunctionForBreakPoints(shared)) return false; | |
1513 CreateDebugInfo(shared); | |
1514 } | |
1515 return true; | 1512 return true; |
1516 } | 1513 } |
1517 | 1514 |
1518 | 1515 |
1519 void Debug::CreateDebugInfo(Handle<SharedFunctionInfo> shared) { | 1516 void Debug::CreateDebugInfo(Handle<SharedFunctionInfo> shared) { |
1520 // Create the debug info object. | 1517 // Create the debug info object. |
1521 DCHECK(shared->HasDebugCode()); | |
1522 Handle<DebugInfo> debug_info = isolate_->factory()->NewDebugInfo(shared); | 1518 Handle<DebugInfo> debug_info = isolate_->factory()->NewDebugInfo(shared); |
1523 | 1519 |
1524 // Add debug info to the list. | 1520 // Add debug info to the list. |
1525 DebugInfoListNode* node = new DebugInfoListNode(*debug_info); | 1521 DebugInfoListNode* node = new DebugInfoListNode(*debug_info); |
1526 node->set_next(debug_info_list_); | 1522 node->set_next(debug_info_list_); |
1527 debug_info_list_ = node; | 1523 debug_info_list_ = node; |
1528 } | 1524 } |
1529 | 1525 |
1530 | 1526 |
1531 void Debug::RemoveDebugInfoAndClearFromShared(Handle<DebugInfo> debug_info) { | 1527 void Debug::RemoveDebugInfoAndClearFromShared(Handle<DebugInfo> debug_info) { |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2569 } | 2565 } |
2570 | 2566 |
2571 | 2567 |
2572 void LockingCommandMessageQueue::Clear() { | 2568 void LockingCommandMessageQueue::Clear() { |
2573 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2569 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2574 queue_.Clear(); | 2570 queue_.Clear(); |
2575 } | 2571 } |
2576 | 2572 |
2577 } // namespace internal | 2573 } // namespace internal |
2578 } // namespace v8 | 2574 } // namespace v8 |
OLD | NEW |