| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 const int Deoptimizer::table_entry_size_ = 12; | 38 const int Deoptimizer::table_entry_size_ = 12; |
| 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 void Deoptimizer::DeoptimizeFunctionWithPreparedFunctionList( | 47 void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { |
| 48 JSFunction* function) { | |
| 49 Isolate* isolate = function->GetIsolate(); | |
| 50 HandleScope scope(isolate); | |
| 51 DisallowHeapAllocation no_allocation; | |
| 52 | |
| 53 ASSERT(function->IsOptimized()); | |
| 54 ASSERT(function->FunctionsInFunctionListShareSameCode()); | |
| 55 | |
| 56 // Get the optimized code. | |
| 57 Code* code = function->code(); | |
| 58 Address code_start_address = code->instruction_start(); | 48 Address code_start_address = code->instruction_start(); |
| 59 | |
| 60 // The optimized code is going to be patched, so we cannot use it any more. | |
| 61 function->shared()->EvictFromOptimizedCodeMap(code, "deoptimized function"); | |
| 62 | |
| 63 // Invalidate the relocation information, as it will become invalid by the | 49 // Invalidate the relocation information, as it will become invalid by the |
| 64 // code patching below, and is not needed any more. | 50 // code patching below, and is not needed any more. |
| 65 code->InvalidateRelocation(); | 51 code->InvalidateRelocation(); |
| 66 | 52 |
| 67 // For each LLazyBailout instruction insert a call to the corresponding | 53 // For each LLazyBailout instruction insert a call to the corresponding |
| 68 // deoptimization entry. | 54 // deoptimization entry. |
| 69 DeoptimizationInputData* deopt_data = | 55 DeoptimizationInputData* deopt_data = |
| 70 DeoptimizationInputData::cast(code->deoptimization_data()); | 56 DeoptimizationInputData::cast(code->deoptimization_data()); |
| 71 #ifdef DEBUG | 57 #ifdef DEBUG |
| 72 Address prev_call_address = NULL; | 58 Address prev_call_address = NULL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 85 ASSERT(call_size_in_bytes <= patch_size()); | 71 ASSERT(call_size_in_bytes <= patch_size()); |
| 86 CodePatcher patcher(call_address, call_size_in_words); | 72 CodePatcher patcher(call_address, call_size_in_words); |
| 87 patcher.masm()->Call(deopt_entry, RelocInfo::NONE32); | 73 patcher.masm()->Call(deopt_entry, RelocInfo::NONE32); |
| 88 ASSERT(prev_call_address == NULL || | 74 ASSERT(prev_call_address == NULL || |
| 89 call_address >= prev_call_address + patch_size()); | 75 call_address >= prev_call_address + patch_size()); |
| 90 ASSERT(call_address + patch_size() <= code->instruction_end()); | 76 ASSERT(call_address + patch_size() <= code->instruction_end()); |
| 91 #ifdef DEBUG | 77 #ifdef DEBUG |
| 92 prev_call_address = call_address; | 78 prev_call_address = call_address; |
| 93 #endif | 79 #endif |
| 94 } | 80 } |
| 95 | |
| 96 // Add the deoptimizing code to the list. | |
| 97 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code); | |
| 98 DeoptimizerData* data = isolate->deoptimizer_data(); | |
| 99 node->set_next(data->deoptimizing_code_list_); | |
| 100 data->deoptimizing_code_list_ = node; | |
| 101 | |
| 102 // We might be in the middle of incremental marking with compaction. | |
| 103 // Tell collector to treat this code object in a special way and | |
| 104 // ignore all slots that might have been recorded on it. | |
| 105 isolate->heap()->mark_compact_collector()->InvalidateCode(code); | |
| 106 | |
| 107 ReplaceCodeForRelatedFunctions(function, code); | |
| 108 | |
| 109 if (FLAG_trace_deopt) { | |
| 110 PrintF("[forced deoptimization: "); | |
| 111 function->PrintName(); | |
| 112 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); | |
| 113 } | |
| 114 } | 81 } |
| 115 | 82 |
| 116 | 83 |
| 117 static const int32_t kBranchBeforeInterrupt = 0x5a000004; | 84 static const int32_t kBranchBeforeInterrupt = 0x5a000004; |
| 118 | 85 |
| 119 // The back edge bookkeeping code matches the pattern: | 86 // The back edge bookkeeping code matches the pattern: |
| 120 // | 87 // |
| 121 // <decrement profiling counter> | 88 // <decrement profiling counter> |
| 122 // 2a 00 00 01 bpl ok | 89 // 2a 00 00 01 bpl ok |
| 123 // e5 9f c? ?? ldr ip, [pc, <interrupt stub address>] | 90 // e5 9f c? ?? ldr ip, [pc, <interrupt stub address>] |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 __ push(ip); | 598 __ push(ip); |
| 632 __ b(&done); | 599 __ b(&done); |
| 633 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 600 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
| 634 } | 601 } |
| 635 __ bind(&done); | 602 __ bind(&done); |
| 636 } | 603 } |
| 637 | 604 |
| 638 #undef __ | 605 #undef __ |
| 639 | 606 |
| 640 } } // namespace v8::internal | 607 } } // namespace v8::internal |
| OLD | NEW |