| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 |
| 28 #ifndef V8_SAFEPOINT_TABLE_H_ |
| 29 #define V8_SAFEPOINT_TABLE_H_ |
| 30 |
| 31 #include "v8.h" |
| 32 |
| 33 #include "macro-assembler.h" |
| 34 #include "zone.h" |
| 35 #include "zone-inl.h" |
| 36 |
| 37 namespace v8 { |
| 38 namespace internal { |
| 39 |
| 40 class SafepointTable BASE_EMBEDDED { |
| 41 public: |
| 42 explicit SafepointTable(Code* code); |
| 43 |
| 44 int size() const { |
| 45 return kHeaderSize + |
| 46 (length_ * (kPcAndDeoptimizationIndexSize + entry_size_)); } |
| 47 unsigned length() const { return length_; } |
| 48 unsigned entry_size() const { return entry_size_; } |
| 49 |
| 50 unsigned GetPcOffset(unsigned index) const { |
| 51 ASSERT(index < length_); |
| 52 return Memory::uint32_at(GetPcOffsetLocation(index)); |
| 53 } |
| 54 |
| 55 int GetDeoptimizationIndex(unsigned index) const { |
| 56 ASSERT(index < length_); |
| 57 unsigned value = Memory::uint32_at(GetDeoptimizationLocation(index)); |
| 58 return DeoptimizationIndexField::decode(value); |
| 59 } |
| 60 |
| 61 unsigned GetGapCodeSize(unsigned index) const { |
| 62 ASSERT(index < length_); |
| 63 unsigned value = Memory::uint32_at(GetDeoptimizationLocation(index)); |
| 64 return GapCodeSizeField::decode(value); |
| 65 } |
| 66 |
| 67 uint8_t* GetEntry(unsigned index) const { |
| 68 ASSERT(index < length_); |
| 69 return &Memory::uint8_at(entries_ + (index * entry_size_)); |
| 70 } |
| 71 |
| 72 class GapCodeSizeField: public BitField<unsigned, 0, 8> {}; |
| 73 class DeoptimizationIndexField: public BitField<int, 8, 24> {}; |
| 74 |
| 75 static bool HasRegisters(uint8_t* entry); |
| 76 static bool HasRegisterAt(uint8_t* entry, int reg_index); |
| 77 |
| 78 void PrintEntry(unsigned index) const; |
| 79 |
| 80 private: |
| 81 static const uint8_t kNoRegisters = 0xFF; |
| 82 |
| 83 static const int kLengthOffset = 0; |
| 84 static const int kEntrySizeOffset = kLengthOffset + kIntSize; |
| 85 static const int kHeaderSize = kEntrySizeOffset + kIntSize; |
| 86 |
| 87 static const int kPcSize = kIntSize; |
| 88 static const int kDeoptimizationIndexSize = kIntSize; |
| 89 static const int kPcAndDeoptimizationIndexSize = |
| 90 kPcSize + kDeoptimizationIndexSize; |
| 91 |
| 92 Address GetPcOffsetLocation(unsigned index) const { |
| 93 return pc_and_deoptimization_indexes_ + |
| 94 (index * kPcAndDeoptimizationIndexSize); |
| 95 } |
| 96 |
| 97 Address GetDeoptimizationLocation(unsigned index) const { |
| 98 return GetPcOffsetLocation(index) + kPcSize; |
| 99 } |
| 100 |
| 101 static void PrintBits(uint8_t byte, int digits); |
| 102 |
| 103 AssertNoAllocation no_allocation_; |
| 104 Code* code_; |
| 105 unsigned length_; |
| 106 unsigned entry_size_; |
| 107 |
| 108 Address pc_and_deoptimization_indexes_; |
| 109 Address entries_; |
| 110 |
| 111 friend class SafepointTableBuilder; |
| 112 }; |
| 113 |
| 114 |
| 115 class Safepoint BASE_EMBEDDED { |
| 116 public: |
| 117 static const int kNoDeoptimizationIndex = 0x00ffffff; |
| 118 |
| 119 void DefinePointerSlot(int index) { indexes_->Add(index); } |
| 120 void DefinePointerRegister(Register reg) { registers_->Add(reg.code()); } |
| 121 |
| 122 private: |
| 123 Safepoint(ZoneList<int>* indexes, ZoneList<int>* registers) : |
| 124 indexes_(indexes), registers_(registers) { } |
| 125 ZoneList<int>* indexes_; |
| 126 ZoneList<int>* registers_; |
| 127 |
| 128 friend class SafepointTableBuilder; |
| 129 }; |
| 130 |
| 131 |
| 132 class SafepointTableBuilder BASE_EMBEDDED { |
| 133 public: |
| 134 SafepointTableBuilder() |
| 135 : deoptimization_info_(32), |
| 136 indexes_(32), |
| 137 registers_(32), |
| 138 emitted_(false) { } |
| 139 |
| 140 // Get the offset of the emitted safepoint table in the code. |
| 141 unsigned GetCodeOffset() const; |
| 142 |
| 143 // Define a new safepoint for the current position in the body. |
| 144 Safepoint DefineSafepoint( |
| 145 Assembler* assembler, |
| 146 int deoptimization_index = Safepoint::kNoDeoptimizationIndex); |
| 147 |
| 148 // Define a new safepoint with registers on the stack for the |
| 149 // current position in the body and take the number of arguments on |
| 150 // top of the registers into account. |
| 151 Safepoint DefineSafepointWithRegisters( |
| 152 Assembler* assembler, |
| 153 int arguments, |
| 154 int deoptimization_index = Safepoint::kNoDeoptimizationIndex); |
| 155 |
| 156 // Update the last safepoint with the size of the code generated for the gap |
| 157 // following it. |
| 158 void SetPcAfterGap(int pc) { |
| 159 ASSERT(!deoptimization_info_.is_empty()); |
| 160 int index = deoptimization_info_.length() - 1; |
| 161 deoptimization_info_[index].pc_after_gap = pc; |
| 162 } |
| 163 |
| 164 // Emit the safepoint table after the body. The number of bits per |
| 165 // entry must be enough to hold all the pointer indexes. |
| 166 void Emit(Assembler* assembler, int bits_per_entry); |
| 167 |
| 168 private: |
| 169 struct DeoptimizationInfo { |
| 170 unsigned pc; |
| 171 unsigned deoptimization_index; |
| 172 unsigned pc_after_gap; |
| 173 }; |
| 174 |
| 175 uint32_t EncodeDeoptimizationIndexAndGap(DeoptimizationInfo info); |
| 176 |
| 177 ZoneList<DeoptimizationInfo> deoptimization_info_; |
| 178 ZoneList<ZoneList<int>*> indexes_; |
| 179 ZoneList<ZoneList<int>*> registers_; |
| 180 |
| 181 bool emitted_; |
| 182 unsigned offset_; |
| 183 |
| 184 DISALLOW_COPY_AND_ASSIGN(SafepointTableBuilder); |
| 185 }; |
| 186 |
| 187 } } // namespace v8::internal |
| 188 |
| 189 #endif // V8_SAFEPOINT_TABLE_H_ |
| OLD | NEW |