| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 | 40 |
| 41 int Deoptimizer::patch_size() { | 41 int Deoptimizer::patch_size() { |
| 42 const int kCallInstructionSizeInWords = 3; | 42 const int kCallInstructionSizeInWords = 3; |
| 43 return kCallInstructionSizeInWords * Assembler::kInstrSize; | 43 return kCallInstructionSizeInWords * Assembler::kInstrSize; |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 | 47 |
| 48 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { | 48 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
| 49 HandleScope scope; |
| 49 AssertNoAllocation no_allocation; | 50 AssertNoAllocation no_allocation; |
| 50 | 51 |
| 51 if (!function->IsOptimized()) return; | 52 if (!function->IsOptimized()) return; |
| 52 | 53 |
| 53 // Get the optimized code. | 54 // Get the optimized code. |
| 54 Code* code = function->code(); | 55 Code* code = function->code(); |
| 55 | 56 |
| 56 // Invalidate the relocation information, as it will become invalid by the | 57 // Invalidate the relocation information, as it will become invalid by the |
| 57 // code patching below, and is not needed any more. | 58 // code patching below, and is not needed any more. |
| 58 code->InvalidateRelocation(); | 59 code->InvalidateRelocation(); |
| 59 | 60 |
| 60 // For each return after a safepoint insert an absolute call to the | 61 // For each return after a safepoint insert an absolute call to the |
| 61 // corresponding deoptimization entry. | 62 // corresponding deoptimization entry. |
| 62 ASSERT(patch_size() % Assembler::kInstrSize == 0); | 63 ASSERT(patch_size() % Assembler::kInstrSize == 0); |
| 63 int call_size_in_words = patch_size() / Assembler::kInstrSize; | 64 int call_size_in_words = patch_size() / Assembler::kInstrSize; |
| 64 unsigned last_pc_offset = 0; | 65 unsigned last_pc_offset = 0; |
| 65 SafepointTable table(function->code()); | 66 SafepointTable table(function->code()); |
| 66 for (unsigned i = 0; i < table.length(); i++) { | 67 for (unsigned i = 0; i < table.length(); i++) { |
| 67 unsigned pc_offset = table.GetPcOffset(i); | 68 unsigned pc_offset = table.GetPcOffset(i); |
| 68 SafepointEntry safepoint_entry = table.GetEntry(i); | 69 SafepointEntry safepoint_entry = table.GetEntry(i); |
| 69 int deoptimization_index = safepoint_entry.deoptimization_index(); | 70 int deoptimization_index = safepoint_entry.deoptimization_index(); |
| 70 int gap_code_size = safepoint_entry.gap_code_size(); | 71 int gap_code_size = safepoint_entry.gap_code_size(); |
| 71 // Check that we did not shoot past next safepoint. | 72 // Check that we did not shoot past next safepoint. |
| 72 // TODO(srdjan): How do we guarantee that safepoint code does not | |
| 73 // overlap other safepoint patching code? | |
| 74 CHECK(pc_offset >= last_pc_offset); | 73 CHECK(pc_offset >= last_pc_offset); |
| 75 #ifdef DEBUG | 74 #ifdef DEBUG |
| 76 // Destroy the code which is not supposed to be run again. | 75 // Destroy the code which is not supposed to be run again. |
| 77 int instructions = (pc_offset - last_pc_offset) / Assembler::kInstrSize; | 76 int instructions = (pc_offset - last_pc_offset) / Assembler::kInstrSize; |
| 78 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 77 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
| 79 instructions); | 78 instructions); |
| 80 for (int x = 0; x < instructions; x++) { | 79 for (int x = 0; x < instructions; x++) { |
| 81 destroyer.masm()->bkpt(0); | 80 destroyer.masm()->bkpt(0); |
| 82 } | 81 } |
| 83 #endif | 82 #endif |
| (...skipping 26 matching lines...) Expand all Loading... |
| 110 node->set_next(deoptimizing_code_list_); | 109 node->set_next(deoptimizing_code_list_); |
| 111 deoptimizing_code_list_ = node; | 110 deoptimizing_code_list_ = node; |
| 112 | 111 |
| 113 // Set the code for the function to non-optimized version. | 112 // Set the code for the function to non-optimized version. |
| 114 function->ReplaceCode(function->shared()->code()); | 113 function->ReplaceCode(function->shared()->code()); |
| 115 | 114 |
| 116 if (FLAG_trace_deopt) { | 115 if (FLAG_trace_deopt) { |
| 117 PrintF("[forced deoptimization: "); | 116 PrintF("[forced deoptimization: "); |
| 118 function->PrintName(); | 117 function->PrintName(); |
| 119 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); | 118 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); |
| 119 #ifdef DEBUG |
| 120 if (FLAG_print_code) { |
| 121 code->PrintLn(); |
| 122 } |
| 123 #endif |
| 120 } | 124 } |
| 121 } | 125 } |
| 122 | 126 |
| 123 | 127 |
| 124 void Deoptimizer::PatchStackCheckCodeAt(Address pc_after, | 128 void Deoptimizer::PatchStackCheckCodeAt(Address pc_after, |
| 125 Code* check_code, | 129 Code* check_code, |
| 126 Code* replacement_code) { | 130 Code* replacement_code) { |
| 127 const int kInstrSize = Assembler::kInstrSize; | 131 const int kInstrSize = Assembler::kInstrSize; |
| 128 // The call of the stack guard check has the following form: | 132 // The call of the stack guard check has the following form: |
| 129 // e1 5d 00 0c cmp sp, <limit> | 133 // e1 5d 00 0c cmp sp, <limit> |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 __ push(ip); | 695 __ push(ip); |
| 692 __ b(&done); | 696 __ b(&done); |
| 693 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 697 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
| 694 } | 698 } |
| 695 __ bind(&done); | 699 __ bind(&done); |
| 696 } | 700 } |
| 697 | 701 |
| 698 #undef __ | 702 #undef __ |
| 699 | 703 |
| 700 } } // namespace v8::internal | 704 } } // namespace v8::internal |
| OLD | NEW |