OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 |
(...skipping 10 matching lines...) Expand all Loading... |
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 #ifndef V8_VIRTUAL_FRAME_H_ | 28 #ifndef V8_VIRTUAL_FRAME_H_ |
29 #define V8_VIRTUAL_FRAME_H_ | 29 #define V8_VIRTUAL_FRAME_H_ |
30 | 30 |
31 #include "frame-element.h" | |
32 #include "macro-assembler.h" | 31 #include "macro-assembler.h" |
33 | 32 |
| 33 namespace v8 { namespace internal { |
| 34 |
| 35 // ------------------------------------------------------------------------- |
| 36 // Virtual frame elements |
| 37 // |
| 38 // The internal elements of the virtual frames. There are several kinds of |
| 39 // elements: |
| 40 // * Invalid: elements that are uninitialized or not actually part |
| 41 // of the virtual frame. They should not be read. |
| 42 // * Memory: an element that resides in the actual frame. Its address is |
| 43 // given by its position in the virtual frame. |
| 44 // * Register: an element that resides in a register. |
| 45 // * Constant: an element whose value is known at compile time. |
| 46 |
| 47 class FrameElement BASE_EMBEDDED { |
| 48 public: |
| 49 enum SyncFlag { |
| 50 NOT_SYNCED, |
| 51 SYNCED |
| 52 }; |
| 53 |
| 54 // The default constructor creates an invalid frame element. |
| 55 FrameElement() |
| 56 : static_type_(), type_(INVALID), copied_(false), synced_(false) { |
| 57 data_.reg_ = no_reg; |
| 58 } |
| 59 |
| 60 // Factory function to construct an invalid frame element. |
| 61 static FrameElement InvalidElement() { |
| 62 FrameElement result; |
| 63 return result; |
| 64 } |
| 65 |
| 66 // Factory function to construct an in-memory frame element. |
| 67 static FrameElement MemoryElement() { |
| 68 FrameElement result(MEMORY, no_reg, SYNCED); |
| 69 return result; |
| 70 } |
| 71 |
| 72 // Factory function to construct an in-register frame element. |
| 73 static FrameElement RegisterElement(Register reg, |
| 74 SyncFlag is_synced, |
| 75 StaticType static_type = StaticType()) { |
| 76 return FrameElement(REGISTER, reg, is_synced, static_type); |
| 77 } |
| 78 |
| 79 // Factory function to construct a frame element whose value is known at |
| 80 // compile time. |
| 81 static FrameElement ConstantElement(Handle<Object> value, |
| 82 SyncFlag is_synced) { |
| 83 FrameElement result(value, is_synced); |
| 84 return result; |
| 85 } |
| 86 |
| 87 bool is_synced() const { return synced_; } |
| 88 |
| 89 void set_sync() { |
| 90 ASSERT(type() != MEMORY); |
| 91 synced_ = true; |
| 92 } |
| 93 |
| 94 void clear_sync() { |
| 95 ASSERT(type() != MEMORY); |
| 96 synced_ = false; |
| 97 } |
| 98 |
| 99 bool is_valid() const { return type() != INVALID; } |
| 100 bool is_memory() const { return type() == MEMORY; } |
| 101 bool is_register() const { return type() == REGISTER; } |
| 102 bool is_constant() const { return type() == CONSTANT; } |
| 103 bool is_copy() const { return type() == COPY; } |
| 104 |
| 105 bool is_copied() const { return copied_; } |
| 106 void set_copied() { copied_ = true; } |
| 107 void clear_copied() { copied_ = false; } |
| 108 |
| 109 Register reg() const { |
| 110 ASSERT(is_register()); |
| 111 return data_.reg_; |
| 112 } |
| 113 |
| 114 Handle<Object> handle() const { |
| 115 ASSERT(is_constant()); |
| 116 return Handle<Object>(data_.handle_); |
| 117 } |
| 118 |
| 119 int index() const { |
| 120 ASSERT(is_copy()); |
| 121 return data_.index_; |
| 122 } |
| 123 |
| 124 StaticType static_type() { return static_type_; } |
| 125 |
| 126 void set_static_type(StaticType static_type) { |
| 127 // TODO(lrn): If it's s copy, it would be better to update the real one, |
| 128 // but we can't from here. The caller must handle this. |
| 129 static_type_ = static_type; |
| 130 } |
| 131 |
| 132 // True if the frame elements are identical (all data members). |
| 133 bool Equals(FrameElement other); |
| 134 |
| 135 // Given a pair of non-null frame element pointers, return one of them |
| 136 // as an entry frame candidate or null if they are incompatible. |
| 137 FrameElement* Combine(FrameElement* other) { |
| 138 // If either is invalid, the result is. |
| 139 if (!is_valid()) return this; |
| 140 if (!other->is_valid()) return other; |
| 141 |
| 142 // If they do not have the exact same location we reallocate. |
| 143 bool not_same_location = |
| 144 (type_ != other->type_) || |
| 145 (is_register() && !reg().is(other->reg())) || |
| 146 (is_constant() && !handle().is_identical_to(other->handle())) || |
| 147 (is_copy() && index() != other->index()); |
| 148 if (not_same_location) return NULL; |
| 149 |
| 150 // If either is unsynced, the result is. The result static type is |
| 151 // the merge of the static types. It's safe to set it on one of the |
| 152 // frame elements, and harmless too (because we are only going to |
| 153 // merge the reaching frames and will ensure that the types are |
| 154 // coherent, and changing the static type does not emit code). |
| 155 FrameElement* result = is_synced() ? other : this; |
| 156 result->set_static_type(static_type().merge(other->static_type())); |
| 157 return result; |
| 158 } |
| 159 |
| 160 private: |
| 161 enum Type { |
| 162 INVALID, |
| 163 MEMORY, |
| 164 REGISTER, |
| 165 CONSTANT, |
| 166 COPY |
| 167 }; |
| 168 |
| 169 Type type() const { return static_cast<Type>(type_); } |
| 170 |
| 171 StaticType static_type_; |
| 172 |
| 173 // The element's type. |
| 174 byte type_; |
| 175 |
| 176 bool copied_; |
| 177 |
| 178 // The element's dirty-bit. The dirty bit can be cleared |
| 179 // for non-memory elements to indicate that the element agrees with |
| 180 // the value in memory in the actual frame. |
| 181 bool synced_; |
| 182 |
| 183 union { |
| 184 Register reg_; |
| 185 Object** handle_; |
| 186 int index_; |
| 187 } data_; |
| 188 |
| 189 // Used to construct memory and register elements. |
| 190 FrameElement(Type type, Register reg, SyncFlag is_synced) |
| 191 : static_type_(), |
| 192 type_(type), |
| 193 copied_(false), |
| 194 synced_(is_synced != NOT_SYNCED) { |
| 195 data_.reg_ = reg; |
| 196 } |
| 197 |
| 198 FrameElement(Type type, Register reg, SyncFlag is_synced, StaticType stype) |
| 199 : static_type_(stype), |
| 200 type_(type), |
| 201 copied_(false), |
| 202 synced_(is_synced != NOT_SYNCED) { |
| 203 data_.reg_ = reg; |
| 204 } |
| 205 |
| 206 // Used to construct constant elements. |
| 207 FrameElement(Handle<Object> value, SyncFlag is_synced) |
| 208 : static_type_(StaticType::TypeOf(*value)), |
| 209 type_(CONSTANT), |
| 210 copied_(false), |
| 211 synced_(is_synced != NOT_SYNCED) { |
| 212 data_.handle_ = value.location(); |
| 213 } |
| 214 |
| 215 void set_index(int new_index) { |
| 216 ASSERT(is_copy()); |
| 217 data_.index_ = new_index; |
| 218 } |
| 219 |
| 220 void set_reg(Register new_reg) { |
| 221 ASSERT(is_register()); |
| 222 data_.reg_ = new_reg; |
| 223 } |
| 224 |
| 225 friend class VirtualFrame; |
| 226 }; |
| 227 |
| 228 |
| 229 } } // namespace v8::internal |
| 230 |
34 #if V8_TARGET_ARCH_IA32 | 231 #if V8_TARGET_ARCH_IA32 |
35 #include "ia32/virtual-frame-ia32.h" | 232 #include "ia32/virtual-frame-ia32.h" |
36 #elif V8_TARGET_ARCH_X64 | 233 #elif V8_TARGET_ARCH_X64 |
37 #include "x64/virtual-frame-x64.h" | 234 #include "x64/virtual-frame-x64.h" |
38 #elif V8_TARGET_ARCH_ARM | 235 #elif V8_TARGET_ARCH_ARM |
39 #include "arm/virtual-frame-arm.h" | 236 #include "arm/virtual-frame-arm.h" |
40 #endif | 237 #endif |
41 | 238 |
42 #endif // V8_VIRTUAL_FRAME_H_ | 239 #endif // V8_VIRTUAL_FRAME_H_ |
OLD | NEW |