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
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.
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.
28 #ifndef V8_SAFEPOINT_TABLE_H_
29 #define V8_SAFEPOINT_TABLE_H_
33 #include "macro-assembler.h"
40 class SafepointTable BASE_EMBEDDED {
42 explicit SafepointTable(Code* code);
46 (length_ * (kPcAndDeoptimizationIndexSize + entry_size_)); }
47 unsigned length() const { return length_; }
48 unsigned entry_size() const { return entry_size_; }
50 unsigned GetPcOffset(unsigned index) const {
51 ASSERT(index < length_);
52 return Memory::uint32_at(GetPcOffsetLocation(index));
55 int GetDeoptimizationIndex(unsigned index) const {
56 ASSERT(index < length_);
57 unsigned value = Memory::uint32_at(GetDeoptimizationLocation(index));
58 return DeoptimizationIndexField::decode(value);
61 unsigned GetGapCodeSize(unsigned index) const {
62 ASSERT(index < length_);
63 unsigned value = Memory::uint32_at(GetDeoptimizationLocation(index));
64 return GapCodeSizeField::decode(value);
67 uint8_t* GetEntry(unsigned index) const {
68 ASSERT(index < length_);
69 return &Memory::uint8_at(entries_ + (index * entry_size_));
72 class GapCodeSizeField: public BitField<unsigned, 0, 8> {};
73 class DeoptimizationIndexField: public BitField<int, 8, 24> {};
75 static bool HasRegisters(uint8_t* entry);
76 static bool HasRegisterAt(uint8_t* entry, int reg_index);
78 void PrintEntry(unsigned index) const;
81 static const uint8_t kNoRegisters = 0xFF;
83 static const int kLengthOffset = 0;
84 static const int kEntrySizeOffset = kLengthOffset + kIntSize;
85 static const int kHeaderSize = kEntrySizeOffset + kIntSize;
87 static const int kPcSize = kIntSize;
88 static const int kDeoptimizationIndexSize = kIntSize;
89 static const int kPcAndDeoptimizationIndexSize =
90 kPcSize + kDeoptimizationIndexSize;
92 Address GetPcOffsetLocation(unsigned index) const {
93 return pc_and_deoptimization_indexes_ +
94 (index * kPcAndDeoptimizationIndexSize);
97 Address GetDeoptimizationLocation(unsigned index) const {
98 return GetPcOffsetLocation(index) + kPcSize;
101 static void PrintBits(uint8_t byte, int digits);
103 AssertNoAllocation no_allocation_;
106 unsigned entry_size_;
108 Address pc_and_deoptimization_indexes_;
111 friend class SafepointTableBuilder;
115 class Safepoint BASE_EMBEDDED {
117 static const int kNoDeoptimizationIndex = 0x00ffffff;
119 void DefinePointerSlot(int index) { indexes_->Add(index); }
120 void DefinePointerRegister(Register reg) { registers_->Add(reg.code()); }
123 Safepoint(ZoneList<int>* indexes, ZoneList<int>* registers) :
124 indexes_(indexes), registers_(registers) { }
125 ZoneList<int>* indexes_;
126 ZoneList<int>* registers_;
128 friend class SafepointTableBuilder;
132 class SafepointTableBuilder BASE_EMBEDDED {
134 SafepointTableBuilder()
135 : deoptimization_info_(32),
140 // Get the offset of the emitted safepoint table in the code.
141 unsigned GetCodeOffset() const;
143 // Define a new safepoint for the current position in the body.
144 Safepoint DefineSafepoint(
145 Assembler* assembler,
146 int deoptimization_index = Safepoint::kNoDeoptimizationIndex);
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,
154 int deoptimization_index = Safepoint::kNoDeoptimizationIndex);
156 // Update the last safepoint with the size of the code generated for the gap
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;
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);
169 struct DeoptimizationInfo {
171 unsigned deoptimization_index;
172 unsigned pc_after_gap;
175 uint32_t EncodeDeoptimizationIndexAndGap(DeoptimizationInfo info);
177 ZoneList<DeoptimizationInfo> deoptimization_info_;
178 ZoneList<ZoneList<int>*> indexes_;
179 ZoneList<ZoneList<int>*> registers_;
184 DISALLOW_COPY_AND_ASSIGN(SafepointTableBuilder);
187 } } // namespace v8::internal
189 #endif // V8_SAFEPOINT_TABLE_H_