OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
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 "safepoint-table.h" | 28 #include "safepoint-table.h" |
29 | |
29 #include "disasm.h" | 30 #include "disasm.h" |
31 #include "macro-assembler.h" | |
30 | 32 |
31 namespace v8 { | 33 namespace v8 { |
32 namespace internal { | 34 namespace internal { |
33 | 35 |
36 | |
37 bool SafepointEntry::HasRegisters() const { | |
38 ASSERT(is_valid()); | |
39 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte)); | |
40 const int num_reg_bytes = kNumSafepointRegisters >> kBitsPerByteLog2; | |
41 for (int i = 0; i < num_reg_bytes; i++) { | |
42 if (bits_[i] != SafepointTable::kNoRegisters) return true; | |
43 } | |
44 return false; | |
45 } | |
46 | |
47 | |
48 bool SafepointEntry::HasRegisterAt(int reg_index) const { | |
49 ASSERT(is_valid()); | |
50 ASSERT(reg_index >= 0 && reg_index < kNumSafepointRegisters); | |
51 int byte_index = reg_index >> kBitsPerByteLog2; | |
52 int bit_index = reg_index & (kBitsPerByte - 1); | |
53 return (bits_[byte_index] & (1 << bit_index)) != 0; | |
54 } | |
55 | |
56 | |
34 SafepointTable::SafepointTable(Code* code) { | 57 SafepointTable::SafepointTable(Code* code) { |
35 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); | 58 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
36 code_ = code; | 59 code_ = code; |
37 Address header = code->instruction_start() + code->safepoint_table_start(); | 60 Address header = code->instruction_start() + code->safepoint_table_start(); |
38 length_ = Memory::uint32_at(header + kLengthOffset); | 61 length_ = Memory::uint32_at(header + kLengthOffset); |
39 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset); | 62 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset); |
40 pc_and_deoptimization_indexes_ = header + kHeaderSize; | 63 pc_and_deoptimization_indexes_ = header + kHeaderSize; |
41 entries_ = pc_and_deoptimization_indexes_ + | 64 entries_ = pc_and_deoptimization_indexes_ + |
42 (length_ * kPcAndDeoptimizationIndexSize); | 65 (length_ * kPcAndDeoptimizationIndexSize); |
43 ASSERT(entry_size_ > 0); | 66 ASSERT(entry_size_ > 0); |
44 ASSERT_EQ(DeoptimizationIndexField::max(), Safepoint::kNoDeoptimizationIndex); | 67 ASSERT_EQ(SafepointEntry::DeoptimizationIndexField::max(), |
68 Safepoint::kNoDeoptimizationIndex); | |
45 } | 69 } |
46 | 70 |
47 | 71 |
48 bool SafepointTable::HasRegisters(uint8_t* entry) { | 72 SafepointEntry SafepointTable::FindEntry(Address pc) const { |
49 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte)); | 73 unsigned pc_offset = static_cast<unsigned>(pc - code_->instruction_start()); |
50 const int num_reg_bytes = kNumSafepointRegisters >> kBitsPerByteLog2; | 74 for (unsigned i = 0; i < length(); i++) { |
51 for (int i = 0; i < num_reg_bytes; i++) { | 75 // TODO(kasperl): Replace the linear search with binary search. |
52 if (entry[i] != kNoRegisters) return true; | 76 if (GetPcOffset(i) == pc_offset) return GetEntry(i); |
53 } | 77 } |
54 return false; | 78 return SafepointEntry(); |
55 } | |
56 | |
57 | |
58 bool SafepointTable::HasRegisterAt(uint8_t* entry, int reg_index) { | |
59 ASSERT(reg_index >= 0 && reg_index < kNumSafepointRegisters); | |
60 int byte_index = reg_index >> kBitsPerByteLog2; | |
61 int bit_index = reg_index & (kBitsPerByte - 1); | |
62 return (entry[byte_index] & (1 << bit_index)) != 0; | |
63 } | 79 } |
64 | 80 |
65 | 81 |
66 void SafepointTable::PrintEntry(unsigned index) const { | 82 void SafepointTable::PrintEntry(unsigned index) const { |
67 disasm::NameConverter converter; | 83 disasm::NameConverter converter; |
68 uint8_t* entry = GetEntry(index); | 84 SafepointEntry entry = GetEntry(index); |
85 uint8_t* bits = entry.bits(); | |
69 | 86 |
70 // Print the stack slot bits. | 87 // Print the stack slot bits. |
71 if (entry_size_ > 0) { | 88 if (entry_size_ > 0) { |
72 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte)); | 89 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte)); |
73 const int first = kNumSafepointRegisters >> kBitsPerByteLog2; | 90 const int first = kNumSafepointRegisters >> kBitsPerByteLog2; |
74 int last = entry_size_ - 1; | 91 int last = entry_size_ - 1; |
75 for (int i = first; i < last; i++) PrintBits(entry[i], kBitsPerByte); | 92 for (int i = first; i < last; i++) PrintBits(bits[i], kBitsPerByte); |
76 int last_bits = code_->stack_slots() - ((last - first) * kBitsPerByte); | 93 int last_bits = code_->stack_slots() - ((last - first) * kBitsPerByte); |
77 PrintBits(entry[last], last_bits); | 94 PrintBits(bits[last], last_bits); |
78 | 95 |
79 // Print the registers (if any). | 96 // Print the registers (if any). |
80 if (!HasRegisters(entry)) return; | 97 if (!entry.HasRegisters()) return; |
81 for (int j = 0; j < kNumSafepointRegisters; j++) { | 98 for (int j = 0; j < kNumSafepointRegisters; j++) { |
82 if (HasRegisterAt(entry, j)) { | 99 if (entry.HasRegisterAt(j)) { |
83 PrintF(" | %s", converter.NameOfCPURegister(j)); | 100 PrintF(" | %s", converter.NameOfCPURegister(j)); |
84 } | 101 } |
85 } | 102 } |
fschneider
2011/01/12 09:57:02
Maybe print the number of arguments for the entry
Vitaly Repeshko
2011/01/12 14:14:35
Good idea. Done.
| |
86 } | 103 } |
87 } | 104 } |
88 | 105 |
89 | 106 |
90 void SafepointTable::PrintBits(uint8_t byte, int digits) { | 107 void SafepointTable::PrintBits(uint8_t byte, int digits) { |
91 ASSERT(digits >= 0 && digits <= kBitsPerByte); | 108 ASSERT(digits >= 0 && digits <= kBitsPerByte); |
92 for (int i = 0; i < digits; i++) { | 109 for (int i = 0; i < digits; i++) { |
93 PrintF("%c", ((byte & (1 << i)) == 0) ? '0' : '1'); | 110 PrintF("%c", ((byte & (1 << i)) == 0) ? '0' : '1'); |
94 } | 111 } |
95 } | 112 } |
96 | 113 |
97 | 114 |
115 void Safepoint::DefinePointerRegister(Register reg) { | |
116 registers_->Add(reg.code()); | |
117 } | |
118 | |
119 | |
98 Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler, | 120 Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler, |
99 int deoptimization_index) { | 121 int deoptimization_index) { |
100 ASSERT(deoptimization_index != -1); | 122 ASSERT(deoptimization_index != -1); |
101 DeoptimizationInfo pc_and_deoptimization_index; | 123 DeoptimizationInfo pc_and_deoptimization_index; |
102 pc_and_deoptimization_index.pc = assembler->pc_offset(); | 124 pc_and_deoptimization_index.pc = assembler->pc_offset(); |
103 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; | 125 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; |
104 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); | 126 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); |
127 pc_and_deoptimization_index.arguments = 0; | |
105 deoptimization_info_.Add(pc_and_deoptimization_index); | 128 deoptimization_info_.Add(pc_and_deoptimization_index); |
106 indexes_.Add(new ZoneList<int>(8)); | 129 indexes_.Add(new ZoneList<int>(8)); |
107 registers_.Add(NULL); | 130 registers_.Add(NULL); |
108 return Safepoint(indexes_.last(), registers_.last()); | 131 return Safepoint(indexes_.last(), registers_.last()); |
109 } | 132 } |
110 | 133 |
111 | 134 |
112 Safepoint SafepointTableBuilder::DefineSafepointWithRegisters( | 135 Safepoint SafepointTableBuilder::DefineSafepointWithRegisters( |
113 Assembler* assembler, int arguments, int deoptimization_index) { | 136 Assembler* assembler, int arguments, int deoptimization_index) { |
114 ASSERT(deoptimization_index != -1); | 137 ASSERT(deoptimization_index != -1); |
115 ASSERT(arguments == 0); // Only case that works for now. | 138 ASSERT(arguments >= 0); |
116 DeoptimizationInfo pc_and_deoptimization_index; | 139 DeoptimizationInfo pc_and_deoptimization_index; |
117 pc_and_deoptimization_index.pc = assembler->pc_offset(); | 140 pc_and_deoptimization_index.pc = assembler->pc_offset(); |
118 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; | 141 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; |
119 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); | 142 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); |
143 pc_and_deoptimization_index.arguments = arguments; | |
120 deoptimization_info_.Add(pc_and_deoptimization_index); | 144 deoptimization_info_.Add(pc_and_deoptimization_index); |
121 indexes_.Add(new ZoneList<int>(8)); | 145 indexes_.Add(new ZoneList<int>(8)); |
122 registers_.Add(new ZoneList<int>(4)); | 146 registers_.Add(new ZoneList<int>(4)); |
123 return Safepoint(indexes_.last(), registers_.last()); | 147 return Safepoint(indexes_.last(), registers_.last()); |
124 } | 148 } |
125 | 149 |
126 | 150 |
127 unsigned SafepointTableBuilder::GetCodeOffset() const { | 151 unsigned SafepointTableBuilder::GetCodeOffset() const { |
128 ASSERT(emitted_); | 152 ASSERT(emitted_); |
129 return offset_; | 153 return offset_; |
(...skipping 15 matching lines...) Expand all Loading... | |
145 | 169 |
146 // Emit the table header. | 170 // Emit the table header. |
147 int length = deoptimization_info_.length(); | 171 int length = deoptimization_info_.length(); |
148 assembler->dd(length); | 172 assembler->dd(length); |
149 assembler->dd(bytes_per_entry); | 173 assembler->dd(bytes_per_entry); |
150 | 174 |
151 // Emit sorted table of pc offsets together with deoptimization indexes and | 175 // Emit sorted table of pc offsets together with deoptimization indexes and |
152 // pc after gap information. | 176 // pc after gap information. |
153 for (int i = 0; i < length; i++) { | 177 for (int i = 0; i < length; i++) { |
154 assembler->dd(deoptimization_info_[i].pc); | 178 assembler->dd(deoptimization_info_[i].pc); |
155 assembler->dd(EncodeDeoptimizationIndexAndGap(deoptimization_info_[i])); | 179 assembler->dd(EncodeExceptPC(deoptimization_info_[i])); |
156 } | 180 } |
157 | 181 |
158 // Emit table of bitmaps. | 182 // Emit table of bitmaps. |
159 ZoneList<uint8_t> bits(bytes_per_entry); | 183 ZoneList<uint8_t> bits(bytes_per_entry); |
160 for (int i = 0; i < length; i++) { | 184 for (int i = 0; i < length; i++) { |
161 ZoneList<int>* indexes = indexes_[i]; | 185 ZoneList<int>* indexes = indexes_[i]; |
162 ZoneList<int>* registers = registers_[i]; | 186 ZoneList<int>* registers = registers_[i]; |
163 bits.Clear(); | 187 bits.Clear(); |
164 bits.AddBlock(0, bytes_per_entry); | 188 bits.AddBlock(0, bytes_per_entry); |
165 | 189 |
(...skipping 24 matching lines...) Expand all Loading... | |
190 | 214 |
191 // Emit the bitmap for the current entry. | 215 // Emit the bitmap for the current entry. |
192 for (int k = 0; k < bytes_per_entry; k++) { | 216 for (int k = 0; k < bytes_per_entry; k++) { |
193 assembler->db(bits[k]); | 217 assembler->db(bits[k]); |
194 } | 218 } |
195 } | 219 } |
196 emitted_ = true; | 220 emitted_ = true; |
197 } | 221 } |
198 | 222 |
199 | 223 |
200 uint32_t SafepointTableBuilder::EncodeDeoptimizationIndexAndGap( | 224 uint32_t SafepointTableBuilder::EncodeExceptPC(const DeoptimizationInfo& info) { |
201 DeoptimizationInfo info) { | |
202 unsigned index = info.deoptimization_index; | 225 unsigned index = info.deoptimization_index; |
203 unsigned gap_size = info.pc_after_gap - info.pc; | 226 unsigned gap_size = info.pc_after_gap - info.pc; |
204 uint32_t encoding = SafepointTable::DeoptimizationIndexField::encode(index); | 227 uint32_t encoding = SafepointEntry::DeoptimizationIndexField::encode(index); |
205 encoding |= SafepointTable::GapCodeSizeField::encode(gap_size); | 228 encoding |= SafepointEntry::GapCodeSizeField::encode(gap_size); |
229 encoding |= SafepointEntry::ArgumentsField::encode(info.arguments); | |
206 return encoding; | 230 return encoding; |
207 } | 231 } |
208 | 232 |
209 | 233 |
210 } } // namespace v8::internal | 234 } } // namespace v8::internal |
OLD | NEW |