| OLD | NEW |
| 1 | 1 |
| 2 // Copyright 2011 the V8 project authors. All rights reserved. | 2 // Copyright 2011 the V8 project authors. All rights reserved. |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
| 5 // met: | 5 // met: |
| 6 // | 6 // |
| 7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following | 10 // copyright notice, this list of conditions and the following |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 38 | 38 |
| 39 | 39 |
| 40 int Deoptimizer::patch_size() { | 40 int Deoptimizer::patch_size() { |
| 41 const int kCallInstructionSizeInWords = 4; | 41 const int kCallInstructionSizeInWords = 4; |
| 42 return kCallInstructionSizeInWords * Assembler::kInstrSize; | 42 return kCallInstructionSizeInWords * Assembler::kInstrSize; |
| 43 } | 43 } |
| 44 | 44 |
| 45 | 45 |
| 46 void Deoptimizer::DeoptimizeFunctionWithPreparedFunctionList( | 46 void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { |
| 47 JSFunction* function) { | |
| 48 Isolate* isolate = function->GetIsolate(); | |
| 49 HandleScope scope(isolate); | |
| 50 DisallowHeapAllocation nha; | |
| 51 | |
| 52 ASSERT(function->IsOptimized()); | |
| 53 ASSERT(function->FunctionsInFunctionListShareSameCode()); | |
| 54 | |
| 55 // Get the optimized code. | |
| 56 Code* code = function->code(); | |
| 57 Address code_start_address = code->instruction_start(); | 47 Address code_start_address = code->instruction_start(); |
| 58 | |
| 59 // The optimized code is going to be patched, so we cannot use it any more. | |
| 60 function->shared()->EvictFromOptimizedCodeMap(code, "deoptimized function"); | |
| 61 | |
| 62 // Invalidate the relocation information, as it will become invalid by the | 48 // Invalidate the relocation information, as it will become invalid by the |
| 63 // code patching below, and is not needed any more. | 49 // code patching below, and is not needed any more. |
| 64 code->InvalidateRelocation(); | 50 code->InvalidateRelocation(); |
| 65 | 51 |
| 66 // For each LLazyBailout instruction insert a call to the corresponding | 52 // For each LLazyBailout instruction insert a call to the corresponding |
| 67 // deoptimization entry. | 53 // deoptimization entry. |
| 68 DeoptimizationInputData* deopt_data = | 54 DeoptimizationInputData* deopt_data = |
| 69 DeoptimizationInputData::cast(code->deoptimization_data()); | 55 DeoptimizationInputData::cast(code->deoptimization_data()); |
| 70 #ifdef DEBUG | 56 #ifdef DEBUG |
| 71 Address prev_call_address = NULL; | 57 Address prev_call_address = NULL; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 CodePatcher patcher(call_address, call_size_in_words); | 68 CodePatcher patcher(call_address, call_size_in_words); |
| 83 patcher.masm()->Call(deopt_entry, RelocInfo::NONE32); | 69 patcher.masm()->Call(deopt_entry, RelocInfo::NONE32); |
| 84 ASSERT(prev_call_address == NULL || | 70 ASSERT(prev_call_address == NULL || |
| 85 call_address >= prev_call_address + patch_size()); | 71 call_address >= prev_call_address + patch_size()); |
| 86 ASSERT(call_address + patch_size() <= code->instruction_end()); | 72 ASSERT(call_address + patch_size() <= code->instruction_end()); |
| 87 | 73 |
| 88 #ifdef DEBUG | 74 #ifdef DEBUG |
| 89 prev_call_address = call_address; | 75 prev_call_address = call_address; |
| 90 #endif | 76 #endif |
| 91 } | 77 } |
| 92 | |
| 93 // Add the deoptimizing code to the list. | |
| 94 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code); | |
| 95 DeoptimizerData* data = isolate->deoptimizer_data(); | |
| 96 node->set_next(data->deoptimizing_code_list_); | |
| 97 data->deoptimizing_code_list_ = node; | |
| 98 | |
| 99 // We might be in the middle of incremental marking with compaction. | |
| 100 // Tell collector to treat this code object in a special way and | |
| 101 // ignore all slots that might have been recorded on it. | |
| 102 isolate->heap()->mark_compact_collector()->InvalidateCode(code); | |
| 103 | |
| 104 ReplaceCodeForRelatedFunctions(function, code); | |
| 105 | |
| 106 if (FLAG_trace_deopt) { | |
| 107 PrintF("[forced deoptimization: "); | |
| 108 function->PrintName(); | |
| 109 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); | |
| 110 #ifdef DEBUG | |
| 111 if (FLAG_print_code) { | |
| 112 code->PrintLn(); | |
| 113 } | |
| 114 #endif | |
| 115 } | |
| 116 } | 78 } |
| 117 | 79 |
| 118 | 80 |
| 119 // This structure comes from FullCodeGenerator::EmitBackEdgeBookkeeping. | 81 // This structure comes from FullCodeGenerator::EmitBackEdgeBookkeeping. |
| 120 // The back edge bookkeeping code matches the pattern: | 82 // The back edge bookkeeping code matches the pattern: |
| 121 // | 83 // |
| 122 // sltu at, sp, t0 / slt at, a3, zero_reg (in case of count based interrupts) | 84 // sltu at, sp, t0 / slt at, a3, zero_reg (in case of count based interrupts) |
| 123 // beq at, zero_reg, ok | 85 // beq at, zero_reg, ok |
| 124 // lui t9, <interrupt stub address> upper | 86 // lui t9, <interrupt stub address> upper |
| 125 // ori t9, <interrupt stub address> lower | 87 // ori t9, <interrupt stub address> lower |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 } | 607 } |
| 646 | 608 |
| 647 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), | 609 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), |
| 648 count() * table_entry_size_); | 610 count() * table_entry_size_); |
| 649 } | 611 } |
| 650 | 612 |
| 651 #undef __ | 613 #undef __ |
| 652 | 614 |
| 653 | 615 |
| 654 } } // namespace v8::internal | 616 } } // namespace v8::internal |
| OLD | NEW |