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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 // implicit pointers. | 439 // implicit pointers. |
440 HeapIterator iterator; | 440 HeapIterator iterator; |
441 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 441 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
442 obj->Iterate(&visitor); | 442 obj->Iterate(&visitor); |
443 } | 443 } |
444 | 444 |
445 visitor.Replace(substitution); | 445 visitor.Replace(substitution); |
446 } | 446 } |
447 | 447 |
448 | 448 |
| 449 // Check whether the code is natural function code (not a lazy-compile stub |
| 450 // code). |
| 451 static bool IsJSFunctionCode(Code* code) { |
| 452 return code->kind() == Code::FUNCTION; |
| 453 } |
| 454 |
| 455 |
449 void LiveEdit::ReplaceFunctionCode(Handle<JSArray> new_compile_info_array, | 456 void LiveEdit::ReplaceFunctionCode(Handle<JSArray> new_compile_info_array, |
450 Handle<JSArray> shared_info_array) { | 457 Handle<JSArray> shared_info_array) { |
451 HandleScope scope; | 458 HandleScope scope; |
452 | 459 |
453 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); | 460 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); |
454 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 461 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
455 | 462 |
456 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 463 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
457 | 464 |
458 ReplaceCodeObject(shared_info->code(), | 465 |
459 *(compile_info_wrapper.GetFunctionCode())); | 466 if (IsJSFunctionCode(shared_info->code())) { |
| 467 ReplaceCodeObject(shared_info->code(), |
| 468 *(compile_info_wrapper.GetFunctionCode())); |
| 469 } |
| 470 |
| 471 if (shared_info->debug_info()->IsDebugInfo()) { |
| 472 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); |
| 473 Handle<Code> new_original_code = |
| 474 Factory::CopyCode(compile_info_wrapper.GetFunctionCode()); |
| 475 debug_info->set_original_code(*new_original_code); |
| 476 } |
460 | 477 |
461 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); | 478 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); |
462 shared_info->set_end_position(compile_info_wrapper.GetEndPosition()); | 479 shared_info->set_end_position(compile_info_wrapper.GetEndPosition()); |
463 // update breakpoints, original code, constructor stub | 480 |
| 481 shared_info->set_construct_stub( |
| 482 Builtins::builtin(Builtins::JSConstructStubGeneric)); |
| 483 // update breakpoints |
464 } | 484 } |
465 | 485 |
466 | 486 |
| 487 // TODO(635): Eval caches its scripts (same text -- same compiled info). |
| 488 // Make sure we clear such caches. |
467 void LiveEdit::RelinkFunctionToScript(Handle<JSArray> shared_info_array, | 489 void LiveEdit::RelinkFunctionToScript(Handle<JSArray> shared_info_array, |
468 Handle<Script> script_handle) { | 490 Handle<Script> script_handle) { |
469 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 491 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
470 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 492 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
471 | 493 |
472 shared_info->set_script(*script_handle); | 494 shared_info->set_script(*script_handle); |
473 } | 495 } |
474 | 496 |
475 | 497 |
476 // For a script text change (defined as position_change_array), translates | 498 // For a script text change (defined as position_change_array), translates |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 | 650 |
629 info->set_start_position(TranslatePosition(info->start_position(), | 651 info->set_start_position(TranslatePosition(info->start_position(), |
630 position_change_array)); | 652 position_change_array)); |
631 info->set_end_position(TranslatePosition(info->end_position(), | 653 info->set_end_position(TranslatePosition(info->end_position(), |
632 position_change_array)); | 654 position_change_array)); |
633 | 655 |
634 info->set_function_token_position( | 656 info->set_function_token_position( |
635 TranslatePosition(info->function_token_position(), | 657 TranslatePosition(info->function_token_position(), |
636 position_change_array)); | 658 position_change_array)); |
637 | 659 |
638 // Patch relocation info section of the code. | 660 if (IsJSFunctionCode(info->code())) { |
639 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()), | 661 // Patch relocation info section of the code. |
640 position_change_array); | 662 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()), |
641 if (*patched_code != info->code()) { | 663 position_change_array); |
642 // Replace all references to the code across the heap. In particular, | 664 if (*patched_code != info->code()) { |
643 // some stubs may refer to this code and this code may be being executed | 665 // Replace all references to the code across the heap. In particular, |
644 // on stack (it is safe to substitute the code object on stack, because | 666 // some stubs may refer to this code and this code may be being executed |
645 // we only change the structure of rinfo and leave instructions untouched). | 667 // on stack (it is safe to substitute the code object on stack, because |
646 ReplaceCodeObject(info->code(), *patched_code); | 668 // we only change the structure of rinfo and leave instructions |
| 669 // untouched). |
| 670 ReplaceCodeObject(info->code(), *patched_code); |
| 671 } |
647 } | 672 } |
648 | 673 |
649 if (info->debug_info()->IsDebugInfo()) { | 674 if (info->debug_info()->IsDebugInfo()) { |
650 Handle<DebugInfo> debug_info(DebugInfo::cast(info->debug_info())); | 675 Handle<DebugInfo> debug_info(DebugInfo::cast(info->debug_info())); |
651 Handle<Code> patched_orig_code = | 676 Handle<Code> patched_orig_code = |
652 PatchPositionsInCode(Handle<Code>(debug_info->original_code()), | 677 PatchPositionsInCode(Handle<Code>(debug_info->original_code()), |
653 position_change_array); | 678 position_change_array); |
654 if (*patched_orig_code != debug_info->original_code()) { | 679 if (*patched_orig_code != debug_info->original_code()) { |
655 // Do not use expensive ReplaceCodeObject for original_code, because we | 680 // Do not use expensive ReplaceCodeObject for original_code, because we |
656 // do not expect any other references except this one. | 681 // do not expect any other references except this one. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 | 753 |
729 bool LiveEditFunctionTracker::IsActive() { | 754 bool LiveEditFunctionTracker::IsActive() { |
730 return false; | 755 return false; |
731 } | 756 } |
732 | 757 |
733 #endif // ENABLE_DEBUGGER_SUPPORT | 758 #endif // ENABLE_DEBUGGER_SUPPORT |
734 | 759 |
735 | 760 |
736 | 761 |
737 } } // namespace v8::internal | 762 } } // namespace v8::internal |
OLD | NEW |