Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: runtime/vm/object.h

Issue 2965723002: VM: Reland Inline instance object hash code into object header on 64bit. (Closed)
Patch Set: Fix snapshot incompatibility that sank Flutter Gallery Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 RUNTIME_VM_OBJECT_H_ 5 #ifndef RUNTIME_VM_OBJECT_H_
6 #define RUNTIME_VM_OBJECT_H_ 6 #define RUNTIME_VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 #define MINT_OBJECT_IMPLEMENTATION(object, rettype, super) \ 238 #define MINT_OBJECT_IMPLEMENTATION(object, rettype, super) \
239 FINAL_HEAP_OBJECT_IMPLEMENTATION_HELPER(object, rettype, super) 239 FINAL_HEAP_OBJECT_IMPLEMENTATION_HELPER(object, rettype, super)
240 240
241 class Object { 241 class Object {
242 public: 242 public:
243 virtual ~Object() {} 243 virtual ~Object() {}
244 244
245 RawObject* raw() const { return raw_; } 245 RawObject* raw() const { return raw_; }
246 void operator=(RawObject* value) { initializeHandle(this, value); } 246 void operator=(RawObject* value) { initializeHandle(this, value); }
247 247
248 uword CompareAndSwapTags(uword old_tags, uword new_tags) const { 248 uint32_t CompareAndSwapTags(uint32_t old_tags, uint32_t new_tags) const {
249 return AtomicOperations::CompareAndSwapWord(&raw()->ptr()->tags_, old_tags, 249 return AtomicOperations::CompareAndSwapUint32(&raw()->ptr()->tags_,
250 new_tags); 250 old_tags, new_tags);
251 } 251 }
252 bool IsCanonical() const { return raw()->IsCanonical(); } 252 bool IsCanonical() const { return raw()->IsCanonical(); }
253 void SetCanonical() const { raw()->SetCanonical(); } 253 void SetCanonical() const { raw()->SetCanonical(); }
254 void ClearCanonical() const { raw()->ClearCanonical(); } 254 void ClearCanonical() const { raw()->ClearCanonical(); }
255 intptr_t GetClassId() const { 255 intptr_t GetClassId() const {
256 return !raw()->IsHeapObject() ? static_cast<intptr_t>(kSmiCid) 256 return !raw()->IsHeapObject() ? static_cast<intptr_t>(kSmiCid)
257 : raw()->GetClassId(); 257 : raw()->GetClassId();
258 } 258 }
259 inline RawClass* clazz() const; 259 inline RawClass* clazz() const;
260 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); } 260 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 427 }
428 // Value marking that we are transitioning from sentinel, e.g., computing 428 // Value marking that we are transitioning from sentinel, e.g., computing
429 // a field value. Used to detect circular initialization. 429 // a field value. Used to detect circular initialization.
430 static const Instance& transition_sentinel() { 430 static const Instance& transition_sentinel() {
431 ASSERT(transition_sentinel_ != NULL); 431 ASSERT(transition_sentinel_ != NULL);
432 return *transition_sentinel_; 432 return *transition_sentinel_;
433 } 433 }
434 434
435 #if defined(HASH_IN_OBJECT_HEADER) 435 #if defined(HASH_IN_OBJECT_HEADER)
436 static uint32_t GetCachedHash(const RawObject* obj) { 436 static uint32_t GetCachedHash(const RawObject* obj) {
437 uword tags = obj->ptr()->tags_; 437 return obj->ptr()->hash_;
438 return tags >> 32;
439 } 438 }
440 439
441 static void SetCachedHash(RawObject* obj, uintptr_t hash) { 440 static void SetCachedHash(RawObject* obj, uint32_t hash) {
442 ASSERT(hash >> 32 == 0); 441 obj->ptr()->hash_ = hash;
443 obj->ptr()->tags_ |= hash << 32;
444 } 442 }
445 #endif 443 #endif
446 444
447 // Compiler's constant propagation constants. 445 // Compiler's constant propagation constants.
448 static const Instance& unknown_constant() { 446 static const Instance& unknown_constant() {
449 ASSERT(unknown_constant_ != NULL); 447 ASSERT(unknown_constant_ != NULL);
450 return *unknown_constant_; 448 return *unknown_constant_;
451 } 449 }
452 static const Instance& non_constant() { 450 static const Instance& non_constant() {
453 ASSERT(non_constant_ != NULL); 451 ASSERT(non_constant_ != NULL);
(...skipping 6370 matching lines...) Expand 10 before | Expand all | Expand 10 after
6824 intptr_t Hash() const { 6822 intptr_t Hash() const {
6825 intptr_t result = GetCachedHash(raw()); 6823 intptr_t result = GetCachedHash(raw());
6826 if (result != 0) { 6824 if (result != 0) {
6827 return result; 6825 return result;
6828 } 6826 }
6829 result = String::Hash(*this, 0, this->Length()); 6827 result = String::Hash(*this, 0, this->Length());
6830 SetCachedHash(raw(), result); 6828 SetCachedHash(raw(), result);
6831 return result; 6829 return result;
6832 } 6830 }
6833 6831
6832 static intptr_t Hash(RawString* raw);
6833
6834 bool HasHash() const { 6834 bool HasHash() const {
6835 ASSERT(Smi::New(0) == NULL); 6835 ASSERT(Smi::New(0) == NULL);
6836 return GetCachedHash(raw()) != 0; 6836 return GetCachedHash(raw()) != 0;
6837 } 6837 }
6838 6838
6839 #if defined(HASH_IN_OBJECT_HEADER)
6840 static intptr_t hash_offset() { return kInt32Size; } // Wrong for big-endian?
6841 #else
6842 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } 6839 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
6843 #endif
6844 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); 6840 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
6845 static intptr_t Hash(const char* characters, intptr_t len); 6841 static intptr_t Hash(const char* characters, intptr_t len);
6846 static intptr_t Hash(const uint16_t* characters, intptr_t len); 6842 static intptr_t Hash(const uint16_t* characters, intptr_t len);
6847 static intptr_t Hash(const int32_t* characters, intptr_t len); 6843 static intptr_t Hash(const int32_t* characters, intptr_t len);
6848 static intptr_t HashRawSymbol(const RawString* symbol) { 6844 static intptr_t HashRawSymbol(const RawString* symbol) {
6849 ASSERT(symbol->IsCanonical()); 6845 ASSERT(symbol->IsCanonical());
6850 intptr_t result = GetCachedHash(symbol); 6846 intptr_t result = GetCachedHash(symbol);
6851 ASSERT(result != 0); 6847 ASSERT(result != 0);
6852 return result; 6848 return result;
6853 } 6849 }
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after
9058 9054
9059 inline void TypeArguments::SetHash(intptr_t value) const { 9055 inline void TypeArguments::SetHash(intptr_t value) const {
9060 // This is only safe because we create a new Smi, which does not cause 9056 // This is only safe because we create a new Smi, which does not cause
9061 // heap allocation. 9057 // heap allocation.
9062 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 9058 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
9063 } 9059 }
9064 9060
9065 } // namespace dart 9061 } // namespace dart
9066 9062
9067 #endif // RUNTIME_VM_OBJECT_H_ 9063 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698