OLD | NEW |
1 // Copyright 2010 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 18 matching lines...) Expand all Loading... |
30 #include "codegen.h" | 30 #include "codegen.h" |
31 #include "deoptimizer.h" | 31 #include "deoptimizer.h" |
32 #include "full-codegen.h" | 32 #include "full-codegen.h" |
33 #include "safepoint-table.h" | 33 #include "safepoint-table.h" |
34 | 34 |
35 namespace v8 { | 35 namespace v8 { |
36 namespace internal { | 36 namespace internal { |
37 | 37 |
38 int Deoptimizer::table_entry_size_ = 16; | 38 int Deoptimizer::table_entry_size_ = 16; |
39 | 39 |
| 40 |
| 41 int Deoptimizer::patch_size() { |
| 42 const int kCallInstructionSizeInWords = 3; |
| 43 return kCallInstructionSizeInWords * Assembler::kInstrSize; |
| 44 } |
| 45 |
| 46 |
| 47 |
40 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { | 48 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
41 AssertNoAllocation no_allocation; | 49 AssertNoAllocation no_allocation; |
42 | 50 |
43 if (!function->IsOptimized()) return; | 51 if (!function->IsOptimized()) return; |
44 | 52 |
45 // Get the optimized code. | 53 // Get the optimized code. |
46 Code* code = function->code(); | 54 Code* code = function->code(); |
47 | 55 |
48 // Invalidate the relocation information, as it will become invalid by the | 56 // Invalidate the relocation information, as it will become invalid by the |
49 // code patching below, and is not needed any more. | 57 // code patching below, and is not needed any more. |
50 code->InvalidateRelocation(); | 58 code->InvalidateRelocation(); |
51 | 59 |
52 // For each return after a safepoint insert an absolute call to the | 60 // For each return after a safepoint insert an absolute call to the |
53 // corresponding deoptimization entry. | 61 // corresponding deoptimization entry. |
| 62 ASSERT(patch_size() % Assembler::kInstrSize == 0); |
| 63 int call_size_in_words = patch_size() / Assembler::kInstrSize; |
54 unsigned last_pc_offset = 0; | 64 unsigned last_pc_offset = 0; |
55 SafepointTable table(function->code()); | 65 SafepointTable table(function->code()); |
56 for (unsigned i = 0; i < table.length(); i++) { | 66 for (unsigned i = 0; i < table.length(); i++) { |
57 unsigned pc_offset = table.GetPcOffset(i); | 67 unsigned pc_offset = table.GetPcOffset(i); |
58 SafepointEntry safepoint_entry = table.GetEntry(i); | 68 SafepointEntry safepoint_entry = table.GetEntry(i); |
59 int deoptimization_index = safepoint_entry.deoptimization_index(); | 69 int deoptimization_index = safepoint_entry.deoptimization_index(); |
60 int gap_code_size = safepoint_entry.gap_code_size(); | 70 int gap_code_size = safepoint_entry.gap_code_size(); |
61 // Check that we did not shoot past next safepoint. | 71 // Check that we did not shoot past next safepoint. |
62 // TODO(srdjan): How do we guarantee that safepoint code does not | 72 // TODO(srdjan): How do we guarantee that safepoint code does not |
63 // overlap other safepoint patching code? | 73 // overlap other safepoint patching code? |
64 CHECK(pc_offset >= last_pc_offset); | 74 CHECK(pc_offset >= last_pc_offset); |
65 #ifdef DEBUG | 75 #ifdef DEBUG |
66 // Destroy the code which is not supposed to be run again. | 76 // Destroy the code which is not supposed to be run again. |
67 int instructions = (pc_offset - last_pc_offset) / Assembler::kInstrSize; | 77 int instructions = (pc_offset - last_pc_offset) / Assembler::kInstrSize; |
68 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 78 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
69 instructions); | 79 instructions); |
70 for (int x = 0; x < instructions; x++) { | 80 for (int x = 0; x < instructions; x++) { |
71 destroyer.masm()->bkpt(0); | 81 destroyer.masm()->bkpt(0); |
72 } | 82 } |
73 #endif | 83 #endif |
74 last_pc_offset = pc_offset; | 84 last_pc_offset = pc_offset; |
75 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { | 85 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { |
76 const int kCallInstructionSizeInWords = 3; | 86 last_pc_offset += gap_code_size; |
77 CodePatcher patcher(code->instruction_start() + pc_offset + gap_code_size, | 87 CodePatcher patcher(code->instruction_start() + last_pc_offset, |
78 kCallInstructionSizeInWords); | 88 call_size_in_words); |
79 Address deoptimization_entry = Deoptimizer::GetDeoptimizationEntry( | 89 Address deoptimization_entry = Deoptimizer::GetDeoptimizationEntry( |
80 deoptimization_index, Deoptimizer::LAZY); | 90 deoptimization_index, Deoptimizer::LAZY); |
81 patcher.masm()->Call(deoptimization_entry, RelocInfo::NONE); | 91 patcher.masm()->Call(deoptimization_entry, RelocInfo::NONE); |
82 last_pc_offset += | 92 last_pc_offset += patch_size(); |
83 gap_code_size + kCallInstructionSizeInWords * Assembler::kInstrSize; | |
84 } | 93 } |
85 } | 94 } |
86 | 95 |
87 | 96 |
88 #ifdef DEBUG | 97 #ifdef DEBUG |
89 // Destroy the code which is not supposed to be run again. | 98 // Destroy the code which is not supposed to be run again. |
90 int instructions = | 99 int instructions = |
91 (code->safepoint_table_start() - last_pc_offset) / Assembler::kInstrSize; | 100 (code->safepoint_table_start() - last_pc_offset) / Assembler::kInstrSize; |
92 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 101 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
93 instructions); | 102 instructions); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 __ push(ip); | 507 __ push(ip); |
499 __ b(&done); | 508 __ b(&done); |
500 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 509 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
501 } | 510 } |
502 __ bind(&done); | 511 __ bind(&done); |
503 } | 512 } |
504 | 513 |
505 #undef __ | 514 #undef __ |
506 | 515 |
507 } } // namespace v8::internal | 516 } } // namespace v8::internal |
OLD | NEW |