| 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 10 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 #include "safepoint-table.h" | 30 #include "safepoint-table.h" |
| 31 | 31 |
| 32 #include "deoptimizer.h" |
| 32 #include "disasm.h" | 33 #include "disasm.h" |
| 33 #include "macro-assembler.h" | 34 #include "macro-assembler.h" |
| 34 #include "zone-inl.h" | 35 #include "zone-inl.h" |
| 35 | 36 |
| 36 namespace v8 { | 37 namespace v8 { |
| 37 namespace internal { | 38 namespace internal { |
| 38 | 39 |
| 39 | 40 |
| 40 bool SafepointEntry::HasRegisters() const { | 41 bool SafepointEntry::HasRegisters() const { |
| 41 ASSERT(is_valid()); | 42 ASSERT(is_valid()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 ASSERT(reg_index >= 0 && reg_index < kNumSafepointRegisters); | 54 ASSERT(reg_index >= 0 && reg_index < kNumSafepointRegisters); |
| 54 int byte_index = reg_index >> kBitsPerByteLog2; | 55 int byte_index = reg_index >> kBitsPerByteLog2; |
| 55 int bit_index = reg_index & (kBitsPerByte - 1); | 56 int bit_index = reg_index & (kBitsPerByte - 1); |
| 56 return (bits_[byte_index] & (1 << bit_index)) != 0; | 57 return (bits_[byte_index] & (1 << bit_index)) != 0; |
| 57 } | 58 } |
| 58 | 59 |
| 59 | 60 |
| 60 SafepointTable::SafepointTable(Code* code) { | 61 SafepointTable::SafepointTable(Code* code) { |
| 61 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); | 62 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 62 code_ = code; | 63 code_ = code; |
| 63 Address header = code->instruction_start() + code->safepoint_table_start(); | 64 Address header = code->instruction_start() + code->safepoint_table_offset(); |
| 64 length_ = Memory::uint32_at(header + kLengthOffset); | 65 length_ = Memory::uint32_at(header + kLengthOffset); |
| 65 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset); | 66 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset); |
| 66 pc_and_deoptimization_indexes_ = header + kHeaderSize; | 67 pc_and_deoptimization_indexes_ = header + kHeaderSize; |
| 67 entries_ = pc_and_deoptimization_indexes_ + | 68 entries_ = pc_and_deoptimization_indexes_ + |
| 68 (length_ * kPcAndDeoptimizationIndexSize); | 69 (length_ * kPcAndDeoptimizationIndexSize); |
| 69 ASSERT(entry_size_ > 0); | 70 ASSERT(entry_size_ > 0); |
| 70 ASSERT_EQ(SafepointEntry::DeoptimizationIndexField::max(), | 71 ASSERT_EQ(SafepointEntry::DeoptimizationIndexField::max(), |
| 71 Safepoint::kNoDeoptimizationIndex); | 72 Safepoint::kNoDeoptimizationIndex); |
| 72 } | 73 } |
| 73 | 74 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 PrintF("%c", ((byte & (1 << i)) == 0) ? '0' : '1'); | 114 PrintF("%c", ((byte & (1 << i)) == 0) ? '0' : '1'); |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 117 | 118 |
| 118 void Safepoint::DefinePointerRegister(Register reg) { | 119 void Safepoint::DefinePointerRegister(Register reg) { |
| 119 registers_->Add(reg.code()); | 120 registers_->Add(reg.code()); |
| 120 } | 121 } |
| 121 | 122 |
| 122 | 123 |
| 123 Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler, | 124 Safepoint SafepointTableBuilder::DefineSafepoint( |
| 124 int deoptimization_index) { | 125 Assembler* assembler, Safepoint::Kind kind, int arguments, |
| 125 ASSERT(deoptimization_index != -1); | 126 int deoptimization_index) { |
| 126 DeoptimizationInfo pc_and_deoptimization_index; | |
| 127 pc_and_deoptimization_index.pc = assembler->pc_offset(); | |
| 128 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; | |
| 129 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); | |
| 130 pc_and_deoptimization_index.arguments = 0; | |
| 131 pc_and_deoptimization_index.has_doubles = false; | |
| 132 deoptimization_info_.Add(pc_and_deoptimization_index); | |
| 133 indexes_.Add(new ZoneList<int>(8)); | |
| 134 registers_.Add(NULL); | |
| 135 return Safepoint(indexes_.last(), registers_.last()); | |
| 136 } | |
| 137 | |
| 138 | |
| 139 Safepoint SafepointTableBuilder::DefineSafepointWithRegisters( | |
| 140 Assembler* assembler, int arguments, int deoptimization_index) { | |
| 141 ASSERT(deoptimization_index != -1); | 127 ASSERT(deoptimization_index != -1); |
| 142 ASSERT(arguments >= 0); | 128 ASSERT(arguments >= 0); |
| 143 DeoptimizationInfo pc_and_deoptimization_index; | 129 DeoptimizationInfo pc_and_deoptimization_index; |
| 144 pc_and_deoptimization_index.pc = assembler->pc_offset(); | 130 pc_and_deoptimization_index.pc = assembler->pc_offset(); |
| 145 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; | 131 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; |
| 146 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); | 132 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); |
| 147 pc_and_deoptimization_index.arguments = arguments; | 133 pc_and_deoptimization_index.arguments = arguments; |
| 148 pc_and_deoptimization_index.has_doubles = false; | 134 pc_and_deoptimization_index.has_doubles = (kind & Safepoint::kWithDoubles); |
| 149 deoptimization_info_.Add(pc_and_deoptimization_index); | 135 deoptimization_info_.Add(pc_and_deoptimization_index); |
| 150 indexes_.Add(new ZoneList<int>(8)); | 136 indexes_.Add(new ZoneList<int>(8)); |
| 151 registers_.Add(new ZoneList<int>(4)); | 137 registers_.Add((kind & Safepoint::kWithRegisters) |
| 138 ? new ZoneList<int>(4) |
| 139 : NULL); |
| 152 return Safepoint(indexes_.last(), registers_.last()); | 140 return Safepoint(indexes_.last(), registers_.last()); |
| 153 } | 141 } |
| 154 | 142 |
| 155 | 143 |
| 156 Safepoint SafepointTableBuilder::DefineSafepointWithRegistersAndDoubles( | |
| 157 Assembler* assembler, int arguments, int deoptimization_index) { | |
| 158 ASSERT(deoptimization_index != -1); | |
| 159 ASSERT(arguments >= 0); | |
| 160 DeoptimizationInfo pc_and_deoptimization_index; | |
| 161 pc_and_deoptimization_index.pc = assembler->pc_offset(); | |
| 162 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; | |
| 163 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); | |
| 164 pc_and_deoptimization_index.arguments = arguments; | |
| 165 pc_and_deoptimization_index.has_doubles = true; | |
| 166 deoptimization_info_.Add(pc_and_deoptimization_index); | |
| 167 indexes_.Add(new ZoneList<int>(8)); | |
| 168 registers_.Add(new ZoneList<int>(4)); | |
| 169 return Safepoint(indexes_.last(), registers_.last()); | |
| 170 } | |
| 171 | |
| 172 unsigned SafepointTableBuilder::GetCodeOffset() const { | 144 unsigned SafepointTableBuilder::GetCodeOffset() const { |
| 173 ASSERT(emitted_); | 145 ASSERT(emitted_); |
| 174 return offset_; | 146 return offset_; |
| 175 } | 147 } |
| 176 | 148 |
| 177 | 149 |
| 178 void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { | 150 void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { |
| 151 // For lazy deoptimization we need space to patch a call after every call. |
| 152 // Ensure there is always space for such patching, even if the code ends |
| 153 // in a call. |
| 154 int target_offset = assembler->pc_offset() + Deoptimizer::patch_size(); |
| 155 while (assembler->pc_offset() < target_offset) { |
| 156 assembler->nop(); |
| 157 } |
| 158 |
| 179 // Make sure the safepoint table is properly aligned. Pad with nops. | 159 // Make sure the safepoint table is properly aligned. Pad with nops. |
| 180 assembler->Align(kIntSize); | 160 assembler->Align(kIntSize); |
| 181 assembler->RecordComment(";;; Safepoint table."); | 161 assembler->RecordComment(";;; Safepoint table."); |
| 182 offset_ = assembler->pc_offset(); | 162 offset_ = assembler->pc_offset(); |
| 183 | 163 |
| 184 // Take the register bits into account. | 164 // Take the register bits into account. |
| 185 bits_per_entry += kNumSafepointRegisters; | 165 bits_per_entry += kNumSafepointRegisters; |
| 186 | 166 |
| 187 // Compute the number of bytes per safepoint entry. | 167 // Compute the number of bytes per safepoint entry. |
| 188 int bytes_per_entry = | 168 int bytes_per_entry = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 unsigned index = info.deoptimization_index; | 226 unsigned index = info.deoptimization_index; |
| 247 unsigned gap_size = info.pc_after_gap - info.pc; | 227 unsigned gap_size = info.pc_after_gap - info.pc; |
| 248 uint32_t encoding = SafepointEntry::DeoptimizationIndexField::encode(index); | 228 uint32_t encoding = SafepointEntry::DeoptimizationIndexField::encode(index); |
| 249 encoding |= SafepointEntry::GapCodeSizeField::encode(gap_size); | 229 encoding |= SafepointEntry::GapCodeSizeField::encode(gap_size); |
| 250 encoding |= SafepointEntry::ArgumentsField::encode(info.arguments); | 230 encoding |= SafepointEntry::ArgumentsField::encode(info.arguments); |
| 251 encoding |= SafepointEntry::SaveDoublesField::encode(info.has_doubles); | 231 encoding |= SafepointEntry::SaveDoublesField::encode(info.has_doubles); |
| 252 return encoding; | 232 return encoding; |
| 253 } | 233 } |
| 254 | 234 |
| 255 | 235 |
| 236 int SafepointTableBuilder::CountShortDeoptimizationIntervals(unsigned limit) { |
| 237 int result = 0; |
| 238 if (!deoptimization_info_.is_empty()) { |
| 239 unsigned previous_gap_end = deoptimization_info_[0].pc_after_gap; |
| 240 for (int i = 1, n = deoptimization_info_.length(); i < n; i++) { |
| 241 DeoptimizationInfo info = deoptimization_info_[i]; |
| 242 if (static_cast<int>(info.deoptimization_index) != |
| 243 Safepoint::kNoDeoptimizationIndex) { |
| 244 if (previous_gap_end + limit > info.pc) { |
| 245 result++; |
| 246 } |
| 247 previous_gap_end = info.pc_after_gap; |
| 248 } |
| 249 } |
| 250 } |
| 251 return result; |
| 252 } |
| 253 |
| 254 |
| 255 |
| 256 } } // namespace v8::internal | 256 } } // namespace v8::internal |
| OLD | NEW |