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 15 matching lines...) Expand all Loading... | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #if defined(V8_TARGET_ARCH_IA32) | 30 #if defined(V8_TARGET_ARCH_IA32) |
31 | 31 |
32 #include "codegen.h" | 32 #include "codegen.h" |
33 #include "deoptimizer.h" | 33 #include "deoptimizer.h" |
34 #include "full-codegen.h" | 34 #include "full-codegen.h" |
35 #include "safepoint-table.h" | 35 #include "safepoint-table.h" |
36 #include "utils.h" | |
36 | 37 |
37 namespace v8 { | 38 namespace v8 { |
38 namespace internal { | 39 namespace internal { |
39 | 40 |
40 | 41 |
41 int Deoptimizer::table_entry_size_ = 10; | 42 int Deoptimizer::table_entry_size_ = 10; |
42 | 43 |
43 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { | 44 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
44 AssertNoAllocation no_allocation; | 45 AssertNoAllocation no_allocation; |
45 | 46 |
46 if (!function->IsOptimized()) return; | 47 if (!function->IsOptimized()) return; |
47 | 48 |
48 // Get the optimized code. | 49 // Get the optimized code. |
49 Code* code = function->code(); | 50 Code* code = function->code(); |
50 | 51 |
51 // Invalidate the relocation information, as it will become invalid by the | |
52 // code patching below, and is not needed any more. | |
53 code->InvalidateRelocation(); | |
54 | |
55 // For each return after a safepoint insert a absolute call to the | 52 // For each return after a safepoint insert a absolute call to the |
56 // corresponding deoptimization entry. | 53 // corresponding deoptimization entry. |
57 unsigned last_pc_offset = 0; | 54 unsigned last_pc_offset = 0; |
58 SafepointTable table(function->code()); | 55 SafepointTable table(function->code()); |
56 | |
57 Address original_reloc_payload = code->relocation_start(); | |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
This needs a comment to the effect of "We will ove
Rico
2011/02/02 09:19:08
Done.
| |
58 Address reloc_end = | |
59 RoundUp(original_reloc_payload + code->relocation_size(), kPointerSize);; | |
60 RelocInfoWriter reloc_info_writer(reloc_end, code->instruction_start()); | |
61 | |
59 for (unsigned i = 0; i < table.length(); i++) { | 62 for (unsigned i = 0; i < table.length(); i++) { |
60 unsigned pc_offset = table.GetPcOffset(i); | 63 unsigned pc_offset = table.GetPcOffset(i); |
61 SafepointEntry safepoint_entry = table.GetEntry(i); | 64 SafepointEntry safepoint_entry = table.GetEntry(i); |
62 int deoptimization_index = safepoint_entry.deoptimization_index(); | 65 int deoptimization_index = safepoint_entry.deoptimization_index(); |
63 int gap_code_size = safepoint_entry.gap_code_size(); | 66 int gap_code_size = safepoint_entry.gap_code_size(); |
64 #ifdef DEBUG | 67 #ifdef DEBUG |
65 // Destroy the code which is not supposed to run again. | 68 // Destroy the code which is not supposed to run again. |
66 unsigned instructions = pc_offset - last_pc_offset; | 69 unsigned instructions = pc_offset - last_pc_offset; |
67 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 70 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
68 instructions); | 71 instructions); |
69 for (unsigned i = 0; i < instructions; i++) { | 72 for (unsigned i = 0; i < instructions; i++) { |
70 destroyer.masm()->int3(); | 73 destroyer.masm()->int3(); |
71 } | 74 } |
72 #endif | 75 #endif |
73 last_pc_offset = pc_offset; | 76 last_pc_offset = pc_offset; |
74 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { | 77 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { |
75 CodePatcher patcher( | 78 Address call_pc = code->instruction_start() + pc_offset + gap_code_size; |
76 code->instruction_start() + pc_offset + gap_code_size, | 79 CodePatcher patcher(call_pc, Assembler::kCallInstructionLength); |
77 Assembler::kCallInstructionLength); | 80 Address entry_address = |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
Does this fit on one line? What if you just call
Rico
2011/02/02 09:19:08
Done.
| |
78 patcher.masm()->call(GetDeoptimizationEntry(deoptimization_index, LAZY), | 81 GetDeoptimizationEntry(deoptimization_index, LAZY); |
79 RelocInfo::NONE); | 82 patcher.masm()->call(entry_address, RelocInfo::NONE); |
80 last_pc_offset += gap_code_size + Assembler::kCallInstructionLength; | 83 last_pc_offset += gap_code_size + Assembler::kCallInstructionLength; |
84 RelocInfo rinfo(call_pc + 1, RelocInfo::RUNTIME_ENTRY, | |
85 reinterpret_cast<intptr_t>(entry_address)); | |
86 reloc_info_writer.Write(&rinfo); | |
81 } | 87 } |
82 } | 88 } |
83 #ifdef DEBUG | 89 #ifdef DEBUG |
84 // Destroy the code which is not supposed to run again. | 90 // Destroy the code which is not supposed to run again. |
85 unsigned instructions = code->safepoint_table_start() - last_pc_offset; | 91 unsigned instructions = code->safepoint_table_start() - last_pc_offset; |
86 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 92 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
87 instructions); | 93 instructions); |
88 for (unsigned i = 0; i < instructions; i++) { | 94 for (unsigned i = 0; i < instructions; i++) { |
89 destroyer.masm()->int3(); | 95 destroyer.masm()->int3(); |
90 } | 96 } |
91 #endif | 97 #endif |
92 | 98 |
99 int reloc_size = reloc_end - reloc_info_writer.pos(); | |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
This needs a comment to the effect that we will no
Rico
2011/02/02 09:19:08
Done.
| |
100 memmove(original_reloc_payload, reloc_info_writer.pos(), reloc_size); | |
101 | |
102 // The relocation info is in place, update the size. | |
103 code->relocation_info()->set_length(reloc_size); | |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
Simply:
reloc_info->set_length(reloc_size);
if y
Rico
2011/02/02 09:19:08
Done.
| |
104 | |
105 Address new_reloc_end = | |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
This needs a comment to the effect that we'll put
Rico
2011/02/02 09:19:08
Done.
| |
106 RoundUp(code->relocation_start() + reloc_size, kPointerSize); | |
107 CHECK(new_reloc_end <= reloc_end); | |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
I'm a little uncomfortable with having this a CHEC
Rico
2011/02/02 09:19:08
Done.
| |
108 | |
109 // Handle the junk part after the new relocation info. | |
Vitaly Repeshko
2011/02/02 14:14:53
Can we use Heap::CreateFillerObjectAt() here?
| |
110 if (reloc_end - new_reloc_end <= ByteArray::kHeaderSize) { | |
111 // We get in here if there is not enough space for a ByteArray. | |
112 | |
113 // Both addresses are kPointerSize alligned. | |
114 CHECK((reloc_end -new_reloc_end) % 4 == 0); | |
115 while(reloc_end > new_reloc_end) { | |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
This is a little simpler if you decrement first.
Rico
2011/02/02 09:19:08
Well, it explicitly say one_POINTER_filler, not on
| |
116 Address filler = reloc_end - kPointerSize; | |
117 Memory::Object_at(filler) = Heap::one_pointer_filler_map(); | |
118 reloc_end -= kPointerSize; | |
119 } | |
120 } else { | |
121 Address junk_data_start = new_reloc_end + ByteArray::kHeaderSize; | |
Kevin Millikin (Chromium)
2011/02/02 08:33:31
I think this whole thing is
int size = end_addres
Rico
2011/02/02 09:19:08
Done.
| |
122 int junk_size = reloc_end - junk_data_start; | |
123 | |
124 // Since the reloc_end address and junk_data_start are both alligned, | |
125 // we shouild never have junk which is not a multipla of kPointerSize. | |
126 CHECK(junk_size % kPointerSize == 0); | |
127 CHECK(junk_size > 0); | |
128 ByteArray* junk_array = ByteArray::FromDataStartAddress(junk_data_start); | |
129 junk_array->set_map(Heap::byte_array_map()); | |
130 junk_array->set_length(junk_size); | |
131 } | |
132 | |
93 // Add the deoptimizing code to the list. | 133 // Add the deoptimizing code to the list. |
94 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code); | 134 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code); |
95 node->set_next(deoptimizing_code_list_); | 135 node->set_next(deoptimizing_code_list_); |
96 deoptimizing_code_list_ = node; | 136 deoptimizing_code_list_ = node; |
97 | 137 |
98 // Set the code for the function to non-optimized version. | 138 // Set the code for the function to non-optimized version. |
99 function->ReplaceCode(function->shared()->code()); | 139 function->ReplaceCode(function->shared()->code()); |
100 | 140 |
101 if (FLAG_trace_deopt) { | 141 if (FLAG_trace_deopt) { |
102 PrintF("[forced deoptimization: "); | 142 PrintF("[forced deoptimization: "); |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 } | 681 } |
642 __ bind(&done); | 682 __ bind(&done); |
643 } | 683 } |
644 | 684 |
645 #undef __ | 685 #undef __ |
646 | 686 |
647 | 687 |
648 } } // namespace v8::internal | 688 } } // namespace v8::internal |
649 | 689 |
650 #endif // V8_TARGET_ARCH_IA32 | 690 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |