| 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // implicit pointers. | 440 // implicit pointers. |
| 441 HeapIterator iterator; | 441 HeapIterator iterator; |
| 442 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 442 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 443 obj->Iterate(&visitor); | 443 obj->Iterate(&visitor); |
| 444 } | 444 } |
| 445 | 445 |
| 446 visitor.Replace(substitution); | 446 visitor.Replace(substitution); |
| 447 } | 447 } |
| 448 | 448 |
| 449 | 449 |
| 450 // Check whether the code is natural function code (not a lazy-compile stub |
| 451 // code). |
| 452 static bool IsJSFunctionCode(Code* code) { |
| 453 return code->kind() == Code::FUNCTION; |
| 454 } |
| 455 |
| 456 |
| 450 void LiveEdit::ReplaceFunctionCode(Handle<JSArray> new_compile_info_array, | 457 void LiveEdit::ReplaceFunctionCode(Handle<JSArray> new_compile_info_array, |
| 451 Handle<JSArray> shared_info_array) { | 458 Handle<JSArray> shared_info_array) { |
| 452 HandleScope scope; | 459 HandleScope scope; |
| 453 | 460 |
| 454 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); | 461 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); |
| 455 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 462 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
| 456 | 463 |
| 457 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 464 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
| 458 | 465 |
| 459 ReplaceCodeObject(shared_info->code(), | 466 |
| 460 *(compile_info_wrapper.GetFunctionCode())); | 467 if (IsJSFunctionCode(shared_info->code())) { |
| 468 ReplaceCodeObject(shared_info->code(), |
| 469 *(compile_info_wrapper.GetFunctionCode())); |
| 470 } |
| 471 |
| 472 if (shared_info->debug_info()->IsDebugInfo()) { |
| 473 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); |
| 474 Handle<Code> new_original_code = |
| 475 Factory::CopyCode(compile_info_wrapper.GetFunctionCode()); |
| 476 debug_info->set_original_code(*new_original_code); |
| 477 } |
| 461 | 478 |
| 462 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); | 479 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); |
| 463 shared_info->set_end_position(compile_info_wrapper.GetEndPosition()); | 480 shared_info->set_end_position(compile_info_wrapper.GetEndPosition()); |
| 464 // update breakpoints, original code, constructor stub | 481 |
| 482 shared_info->set_construct_stub( |
| 483 Builtins::builtin(Builtins::JSConstructStubGeneric)); |
| 484 // update breakpoints |
| 465 } | 485 } |
| 466 | 486 |
| 467 | 487 |
| 488 // TODO(635): Eval caches its scripts (same text -- same compiled info). |
| 489 // Make sure we clear such caches. |
| 468 void LiveEdit::RelinkFunctionToScript(Handle<JSArray> shared_info_array, | 490 void LiveEdit::RelinkFunctionToScript(Handle<JSArray> shared_info_array, |
| 469 Handle<Script> script_handle) { | 491 Handle<Script> script_handle) { |
| 470 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 492 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
| 471 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 493 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
| 472 | 494 |
| 473 shared_info->set_script(*script_handle); | 495 shared_info->set_script(*script_handle); |
| 474 } | 496 } |
| 475 | 497 |
| 476 | 498 |
| 477 // For a script text change (defined as position_change_array), translates | 499 // For a script text change (defined as position_change_array), translates |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 int new_function_start = TranslatePosition(old_function_start, | 666 int new_function_start = TranslatePosition(old_function_start, |
| 645 position_change_array); | 667 position_change_array); |
| 646 info->set_start_position(new_function_start); | 668 info->set_start_position(new_function_start); |
| 647 info->set_end_position(TranslatePosition(info->end_position(), | 669 info->set_end_position(TranslatePosition(info->end_position(), |
| 648 position_change_array)); | 670 position_change_array)); |
| 649 | 671 |
| 650 info->set_function_token_position( | 672 info->set_function_token_position( |
| 651 TranslatePosition(info->function_token_position(), | 673 TranslatePosition(info->function_token_position(), |
| 652 position_change_array)); | 674 position_change_array)); |
| 653 | 675 |
| 654 // Patch relocation info section of the code. | 676 if (IsJSFunctionCode(info->code())) { |
| 655 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()), | 677 // Patch relocation info section of the code. |
| 656 position_change_array); | 678 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()), |
| 657 if (*patched_code != info->code()) { | 679 position_change_array); |
| 658 // Replace all references to the code across the heap. In particular, | 680 if (*patched_code != info->code()) { |
| 659 // some stubs may refer to this code and this code may be being executed | 681 // Replace all references to the code across the heap. In particular, |
| 660 // on stack (it is safe to substitute the code object on stack, because | 682 // some stubs may refer to this code and this code may be being executed |
| 661 // we only change the structure of rinfo and leave instructions untouched). | 683 // on stack (it is safe to substitute the code object on stack, because |
| 662 ReplaceCodeObject(info->code(), *patched_code); | 684 // we only change the structure of rinfo and leave instructions |
| 685 // untouched). |
| 686 ReplaceCodeObject(info->code(), *patched_code); |
| 687 } |
| 663 } | 688 } |
| 664 | 689 |
| 665 | 690 |
| 666 Handle<JSArray> result = Factory::NewJSArray(0); | 691 Handle<JSArray> result = Factory::NewJSArray(0); |
| 667 int result_len = 0; | 692 int result_len = 0; |
| 668 | 693 |
| 669 if (info->debug_info()->IsDebugInfo()) { | 694 if (info->debug_info()->IsDebugInfo()) { |
| 670 Handle<DebugInfo> debug_info(DebugInfo::cast(info->debug_info())); | 695 Handle<DebugInfo> debug_info(DebugInfo::cast(info->debug_info())); |
| 671 Handle<Code> patched_orig_code = | 696 Handle<Code> patched_orig_code = |
| 672 PatchPositionsInCode(Handle<Code>(debug_info->original_code()), | 697 PatchPositionsInCode(Handle<Code>(debug_info->original_code()), |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 | 1049 |
| 1025 bool LiveEditFunctionTracker::IsActive() { | 1050 bool LiveEditFunctionTracker::IsActive() { |
| 1026 return false; | 1051 return false; |
| 1027 } | 1052 } |
| 1028 | 1053 |
| 1029 #endif // ENABLE_DEBUGGER_SUPPORT | 1054 #endif // ENABLE_DEBUGGER_SUPPORT |
| 1030 | 1055 |
| 1031 | 1056 |
| 1032 | 1057 |
| 1033 } } // namespace v8::internal | 1058 } } // namespace v8::internal |
| OLD | NEW |