OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/safepoint-table.h" | 7 #include "src/safepoint-table.h" |
8 | 8 |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/disasm.h" | 10 #include "src/disasm.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 SafepointTable::SafepointTable(Code* code) { | 39 SafepointTable::SafepointTable(Code* code) { |
40 DCHECK(code->is_crankshafted()); | 40 DCHECK(code->is_crankshafted()); |
41 code_ = code; | 41 code_ = code; |
42 Address header = code->instruction_start() + code->safepoint_table_offset(); | 42 Address header = code->instruction_start() + code->safepoint_table_offset(); |
43 length_ = Memory::uint32_at(header + kLengthOffset); | 43 length_ = Memory::uint32_at(header + kLengthOffset); |
44 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset); | 44 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset); |
45 pc_and_deoptimization_indexes_ = header + kHeaderSize; | 45 pc_and_deoptimization_indexes_ = header + kHeaderSize; |
46 entries_ = | 46 entries_ = pc_and_deoptimization_indexes_ + |
47 pc_and_deoptimization_indexes_ + (length_ * kPcAndDeoptimizationInfoSize); | 47 (length_ * kPcAndDeoptimizationIndexSize); |
48 DCHECK(entry_size_ > 0); | 48 DCHECK(entry_size_ > 0); |
49 STATIC_ASSERT(SafepointEntry::DeoptimizationIndexField::kMax == | 49 STATIC_ASSERT(SafepointEntry::DeoptimizationIndexField::kMax == |
50 Safepoint::kNoDeoptimizationIndex); | 50 Safepoint::kNoDeoptimizationIndex); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 SafepointEntry SafepointTable::FindEntry(Address pc) const { | 54 SafepointEntry SafepointTable::FindEntry(Address pc) const { |
55 unsigned pc_offset = static_cast<unsigned>(pc - code_->instruction_start()); | 55 unsigned pc_offset = static_cast<unsigned>(pc - code_->instruction_start()); |
56 for (unsigned i = 0; i < length(); i++) { | 56 for (unsigned i = 0; i < length(); i++) { |
57 // TODO(kasperl): Replace the linear search with binary search. | 57 // TODO(kasperl): Replace the linear search with binary search. |
58 if (GetPcOffset(i) == pc_offset) return GetEntry(i); | 58 if (GetPcOffset(i) == pc_offset) return GetEntry(i); |
59 if (GetDeoptimizationPcOffset(i) == pc_offset) return GetEntry(i); | |
60 } | 59 } |
61 return SafepointEntry(); | 60 return SafepointEntry(); |
62 } | 61 } |
63 | 62 |
64 | 63 |
65 void SafepointTable::PrintEntry(unsigned index, OStream& os) const { // NOLINT | 64 void SafepointTable::PrintEntry(unsigned index, OStream& os) const { // NOLINT |
66 disasm::NameConverter converter; | 65 disasm::NameConverter converter; |
67 SafepointEntry entry = GetEntry(index); | 66 SafepointEntry entry = GetEntry(index); |
68 uint8_t* bits = entry.bits(); | 67 uint8_t* bits = entry.bits(); |
69 | 68 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 Safepoint SafepointTableBuilder::DefineSafepoint( | 103 Safepoint SafepointTableBuilder::DefineSafepoint( |
105 Assembler* assembler, | 104 Assembler* assembler, |
106 Safepoint::Kind kind, | 105 Safepoint::Kind kind, |
107 int arguments, | 106 int arguments, |
108 Safepoint::DeoptMode deopt_mode) { | 107 Safepoint::DeoptMode deopt_mode) { |
109 DCHECK(arguments >= 0); | 108 DCHECK(arguments >= 0); |
110 DeoptimizationInfo info; | 109 DeoptimizationInfo info; |
111 info.pc = assembler->pc_offset(); | 110 info.pc = assembler->pc_offset(); |
112 info.arguments = arguments; | 111 info.arguments = arguments; |
113 info.has_doubles = (kind & Safepoint::kWithDoubles); | 112 info.has_doubles = (kind & Safepoint::kWithDoubles); |
114 info.deoptimization_pc = Safepoint::kNoDeoptimizationPc; | |
115 int safepoint_id = deoptimization_info_.length(); | |
116 deoptimization_info_.Add(info, zone_); | 113 deoptimization_info_.Add(info, zone_); |
117 deopt_index_list_.Add(Safepoint::kNoDeoptimizationIndex, zone_); | 114 deopt_index_list_.Add(Safepoint::kNoDeoptimizationIndex, zone_); |
118 if (deopt_mode == Safepoint::kNoLazyDeopt) { | 115 if (deopt_mode == Safepoint::kNoLazyDeopt) { |
119 last_lazy_safepoint_ = deopt_index_list_.length(); | 116 last_lazy_safepoint_ = deopt_index_list_.length(); |
120 } | 117 } |
121 indexes_.Add(new(zone_) ZoneList<int>(8, zone_), zone_); | 118 indexes_.Add(new(zone_) ZoneList<int>(8, zone_), zone_); |
122 registers_.Add((kind & Safepoint::kWithRegisters) | 119 registers_.Add((kind & Safepoint::kWithRegisters) |
123 ? new(zone_) ZoneList<int>(4, zone_) | 120 ? new(zone_) ZoneList<int>(4, zone_) |
124 : NULL, | 121 : NULL, |
125 zone_); | 122 zone_); |
126 return Safepoint(safepoint_id, indexes_.last(), registers_.last()); | 123 return Safepoint(indexes_.last(), registers_.last()); |
127 } | 124 } |
128 | 125 |
129 | 126 |
130 void SafepointTableBuilder::RecordLazyDeoptimizationIndex(int index) { | 127 void SafepointTableBuilder::RecordLazyDeoptimizationIndex(int index) { |
131 while (last_lazy_safepoint_ < deopt_index_list_.length()) { | 128 while (last_lazy_safepoint_ < deopt_index_list_.length()) { |
132 deopt_index_list_[last_lazy_safepoint_++] = index; | 129 deopt_index_list_[last_lazy_safepoint_++] = index; |
133 } | 130 } |
134 } | 131 } |
135 | 132 |
136 unsigned SafepointTableBuilder::GetCodeOffset() const { | 133 unsigned SafepointTableBuilder::GetCodeOffset() const { |
(...skipping 18 matching lines...) Expand all Loading... |
155 // Emit the table header. | 152 // Emit the table header. |
156 int length = deoptimization_info_.length(); | 153 int length = deoptimization_info_.length(); |
157 assembler->dd(length); | 154 assembler->dd(length); |
158 assembler->dd(bytes_per_entry); | 155 assembler->dd(bytes_per_entry); |
159 | 156 |
160 // Emit sorted table of pc offsets together with deoptimization indexes. | 157 // Emit sorted table of pc offsets together with deoptimization indexes. |
161 for (int i = 0; i < length; i++) { | 158 for (int i = 0; i < length; i++) { |
162 assembler->dd(deoptimization_info_[i].pc); | 159 assembler->dd(deoptimization_info_[i].pc); |
163 assembler->dd(EncodeExceptPC(deoptimization_info_[i], | 160 assembler->dd(EncodeExceptPC(deoptimization_info_[i], |
164 deopt_index_list_[i])); | 161 deopt_index_list_[i])); |
165 assembler->dd(deoptimization_info_[i].deoptimization_pc); | |
166 } | 162 } |
167 | 163 |
168 // Emit table of bitmaps. | 164 // Emit table of bitmaps. |
169 ZoneList<uint8_t> bits(bytes_per_entry, zone_); | 165 ZoneList<uint8_t> bits(bytes_per_entry, zone_); |
170 for (int i = 0; i < length; i++) { | 166 for (int i = 0; i < length; i++) { |
171 ZoneList<int>* indexes = indexes_[i]; | 167 ZoneList<int>* indexes = indexes_[i]; |
172 ZoneList<int>* registers = registers_[i]; | 168 ZoneList<int>* registers = registers_[i]; |
173 bits.Clear(); | 169 bits.Clear(); |
174 bits.AddBlock(0, bytes_per_entry, zone_); | 170 bits.AddBlock(0, bytes_per_entry, zone_); |
175 | 171 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 unsigned index) { | 207 unsigned index) { |
212 uint32_t encoding = SafepointEntry::DeoptimizationIndexField::encode(index); | 208 uint32_t encoding = SafepointEntry::DeoptimizationIndexField::encode(index); |
213 encoding |= SafepointEntry::ArgumentsField::encode(info.arguments); | 209 encoding |= SafepointEntry::ArgumentsField::encode(info.arguments); |
214 encoding |= SafepointEntry::SaveDoublesField::encode(info.has_doubles); | 210 encoding |= SafepointEntry::SaveDoublesField::encode(info.has_doubles); |
215 return encoding; | 211 return encoding; |
216 } | 212 } |
217 | 213 |
218 | 214 |
219 | 215 |
220 } } // namespace v8::internal | 216 } } // namespace v8::internal |
OLD | NEW |