| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_ASSEMBLER_H_ | 5 #ifndef VM_ASSEMBLER_H_ |
| 6 #define VM_ASSEMBLER_H_ | 6 #define VM_ASSEMBLER_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 static uword ComputeLimit(uword data, intptr_t capacity) { | 205 static uword ComputeLimit(uword data, intptr_t capacity) { |
| 206 return data + capacity - kMinimumGap; | 206 return data + capacity - kMinimumGap; |
| 207 } | 207 } |
| 208 | 208 |
| 209 void ExtendCapacity(); | 209 void ExtendCapacity(); |
| 210 | 210 |
| 211 friend class AssemblerFixup; | 211 friend class AssemblerFixup; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 | 214 |
| 215 struct ObjectPoolWrapperEntry { |
| 216 ObjectPoolWrapperEntry() |
| 217 : raw_value_(), type_(), equivalence_() { } |
| 218 explicit ObjectPoolWrapperEntry(const Object* obj) |
| 219 : obj_(obj), type_(ObjectPool::kTaggedObject), equivalence_(obj) { } |
| 220 explicit ObjectPoolWrapperEntry(const Object* obj, const Object* eqv) |
| 221 : obj_(obj), type_(ObjectPool::kTaggedObject), equivalence_(eqv) { } |
| 222 ObjectPoolWrapperEntry(uword value, ObjectPool::EntryType info) |
| 223 : raw_value_(value), type_(info), equivalence_() { } |
| 224 |
| 225 union { |
| 226 const Object* obj_; |
| 227 uword raw_value_; |
| 228 }; |
| 229 ObjectPool::EntryType type_; |
| 230 const Object* equivalence_; |
| 231 }; |
| 232 |
| 233 |
| 215 // Pair type parameter for DirectChainedHashMap used for the constant pool. | 234 // Pair type parameter for DirectChainedHashMap used for the constant pool. |
| 216 class ObjIndexPair { | 235 class ObjIndexPair { |
| 217 public: | 236 public: |
| 218 // Typedefs needed for the DirectChainedHashMap template. | 237 // Typedefs needed for the DirectChainedHashMap template. |
| 219 typedef ObjectPool::Entry Key; | 238 typedef ObjectPoolWrapperEntry Key; |
| 220 typedef intptr_t Value; | 239 typedef intptr_t Value; |
| 221 typedef ObjIndexPair Pair; | 240 typedef ObjIndexPair Pair; |
| 222 | 241 |
| 223 static const intptr_t kNoIndex = -1; | 242 static const intptr_t kNoIndex = -1; |
| 224 | 243 |
| 225 ObjIndexPair() : key_(static_cast<uword>(NULL), ObjectPool::kTaggedObject), | 244 ObjIndexPair() : key_(static_cast<uword>(NULL), ObjectPool::kTaggedObject), |
| 226 value_(kNoIndex) { } | 245 value_(kNoIndex) { } |
| 227 | 246 |
| 228 ObjIndexPair(Key key, Value value) : value_(value) { | 247 ObjIndexPair(Key key, Value value) : value_(value) { |
| 229 key_.type_ = key.type_; | 248 key_.type_ = key.type_; |
| 230 if (key.type_ == ObjectPool::kTaggedObject) { | 249 if (key.type_ == ObjectPool::kTaggedObject) { |
| 231 if (key.obj_->IsNotTemporaryScopedHandle()) { | 250 if (key.obj_->IsNotTemporaryScopedHandle()) { |
| 232 key_.obj_ = key.obj_; | 251 key_.obj_ = key.obj_; |
| 233 } else { | 252 } else { |
| 234 key_.obj_ = &Object::ZoneHandle(key.obj_->raw()); | 253 key_.obj_ = &Object::ZoneHandle(key.obj_->raw()); |
| 235 } | 254 } |
| 255 if (key.equivalence_->IsNotTemporaryScopedHandle()) { |
| 256 key_.equivalence_ = key.equivalence_; |
| 257 } else { |
| 258 key_.equivalence_ = &Object::ZoneHandle(key.equivalence_->raw()); |
| 259 } |
| 236 } else { | 260 } else { |
| 237 key_.raw_value_ = key.raw_value_; | 261 key_.raw_value_ = key.raw_value_; |
| 238 } | 262 } |
| 239 } | 263 } |
| 240 | 264 |
| 241 static Key KeyOf(Pair kv) { return kv.key_; } | 265 static Key KeyOf(Pair kv) { return kv.key_; } |
| 242 | 266 |
| 243 static Value ValueOf(Pair kv) { return kv.value_; } | 267 static Value ValueOf(Pair kv) { return kv.value_; } |
| 244 | 268 |
| 245 static intptr_t Hashcode(Key key) { | 269 static intptr_t Hashcode(Key key) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 261 return String::Cast(*key.obj_).Hash(); | 285 return String::Cast(*key.obj_).Hash(); |
| 262 } | 286 } |
| 263 // TODO(fschneider): Add hash function for other classes commonly used as | 287 // TODO(fschneider): Add hash function for other classes commonly used as |
| 264 // compile-time constants. | 288 // compile-time constants. |
| 265 return key.obj_->GetClassId(); | 289 return key.obj_->GetClassId(); |
| 266 } | 290 } |
| 267 | 291 |
| 268 static inline bool IsKeyEqual(Pair kv, Key key) { | 292 static inline bool IsKeyEqual(Pair kv, Key key) { |
| 269 if (kv.key_.type_ != key.type_) return false; | 293 if (kv.key_.type_ != key.type_) return false; |
| 270 if (kv.key_.type_ == ObjectPool::kTaggedObject) { | 294 if (kv.key_.type_ == ObjectPool::kTaggedObject) { |
| 271 return kv.key_.obj_->raw() == key.obj_->raw(); | 295 return (kv.key_.obj_->raw() == key.obj_->raw()) && |
| 296 (kv.key_.equivalence_->raw() == key.equivalence_->raw()); |
| 272 } | 297 } |
| 273 return kv.key_.raw_value_ == key.raw_value_; | 298 return kv.key_.raw_value_ == key.raw_value_; |
| 274 } | 299 } |
| 275 | 300 |
| 276 private: | 301 private: |
| 277 Key key_; | 302 Key key_; |
| 278 Value value_; | 303 Value value_; |
| 279 }; | 304 }; |
| 280 | 305 |
| 281 | 306 |
| 282 enum Patchability { | 307 enum Patchability { |
| 283 kPatchable, | 308 kPatchable, |
| 284 kNotPatchable, | 309 kNotPatchable, |
| 285 }; | 310 }; |
| 286 | 311 |
| 287 | 312 |
| 288 class ObjectPoolWrapper : public ValueObject { | 313 class ObjectPoolWrapper : public ValueObject { |
| 289 public: | 314 public: |
| 290 intptr_t AddObject(const Object& obj, | 315 intptr_t AddObject(const Object& obj, |
| 291 Patchability patchable = kNotPatchable); | 316 Patchability patchable = kNotPatchable); |
| 292 intptr_t AddImmediate(uword imm); | 317 intptr_t AddImmediate(uword imm); |
| 293 | 318 |
| 294 intptr_t FindObject(const Object& obj, | 319 intptr_t FindObject(const Object& obj, |
| 295 Patchability patchable = kNotPatchable); | 320 Patchability patchable = kNotPatchable); |
| 321 intptr_t FindObject(const Object& obj, |
| 322 const Object& equivalence); |
| 296 intptr_t FindImmediate(uword imm); | 323 intptr_t FindImmediate(uword imm); |
| 297 intptr_t FindNativeEntry(const ExternalLabel* label, | 324 intptr_t FindNativeEntry(const ExternalLabel* label, |
| 298 Patchability patchable); | 325 Patchability patchable); |
| 299 | 326 |
| 300 RawObjectPool* MakeObjectPool(); | 327 RawObjectPool* MakeObjectPool(); |
| 301 | 328 |
| 302 private: | 329 private: |
| 303 intptr_t AddObject(ObjectPool::Entry entry, Patchability patchable); | 330 intptr_t AddObject(ObjectPoolWrapperEntry entry, Patchability patchable); |
| 304 intptr_t FindObject(ObjectPool::Entry entry, Patchability patchable); | 331 intptr_t FindObject(ObjectPoolWrapperEntry entry, Patchability patchable); |
| 305 | 332 |
| 306 // Objects and jump targets. | 333 // Objects and jump targets. |
| 307 GrowableArray<ObjectPool::Entry> object_pool_; | 334 GrowableArray<ObjectPoolWrapperEntry> object_pool_; |
| 308 | 335 |
| 309 // Hashmap for fast lookup in object pool. | 336 // Hashmap for fast lookup in object pool. |
| 310 DirectChainedHashMap<ObjIndexPair> object_pool_index_table_; | 337 DirectChainedHashMap<ObjIndexPair> object_pool_index_table_; |
| 311 }; | 338 }; |
| 312 | 339 |
| 313 | 340 |
| 314 enum RestorePP { | 341 enum RestorePP { |
| 315 kRestoreCallerPP, | 342 kRestoreCallerPP, |
| 316 kKeepCalleePP | 343 kKeepCalleePP |
| 317 }; | 344 }; |
| 318 | 345 |
| 319 } // namespace dart | 346 } // namespace dart |
| 320 | 347 |
| 321 | 348 |
| 322 #if defined(TARGET_ARCH_IA32) | 349 #if defined(TARGET_ARCH_IA32) |
| 323 #include "vm/assembler_ia32.h" | 350 #include "vm/assembler_ia32.h" |
| 324 #elif defined(TARGET_ARCH_X64) | 351 #elif defined(TARGET_ARCH_X64) |
| 325 #include "vm/assembler_x64.h" | 352 #include "vm/assembler_x64.h" |
| 326 #elif defined(TARGET_ARCH_ARM) | 353 #elif defined(TARGET_ARCH_ARM) |
| 327 #include "vm/assembler_arm.h" | 354 #include "vm/assembler_arm.h" |
| 328 #elif defined(TARGET_ARCH_ARM64) | 355 #elif defined(TARGET_ARCH_ARM64) |
| 329 #include "vm/assembler_arm64.h" | 356 #include "vm/assembler_arm64.h" |
| 330 #elif defined(TARGET_ARCH_MIPS) | 357 #elif defined(TARGET_ARCH_MIPS) |
| 331 #include "vm/assembler_mips.h" | 358 #include "vm/assembler_mips.h" |
| 332 #else | 359 #else |
| 333 #error Unknown architecture. | 360 #error Unknown architecture. |
| 334 #endif | 361 #endif |
| 335 | 362 |
| 336 #endif // VM_ASSEMBLER_H_ | 363 #endif // VM_ASSEMBLER_H_ |
| OLD | NEW |