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

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

Issue 2912863006: Inline instance object hash code into object header on 64 bit. (Closed)
Patch Set: Add assembler tests and other feedback from Ryan Created 3 years, 6 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
« no previous file with comments | « runtime/vm/method_recognizer.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6354 matching lines...) Expand 10 before | Expand all | Expand 10 after
6808 intptr_t Hash() const { 6806 intptr_t Hash() const {
6809 intptr_t result = GetCachedHash(raw()); 6807 intptr_t result = GetCachedHash(raw());
6810 if (result != 0) { 6808 if (result != 0) {
6811 return result; 6809 return result;
6812 } 6810 }
6813 result = String::Hash(*this, 0, this->Length()); 6811 result = String::Hash(*this, 0, this->Length());
6814 SetCachedHash(raw(), result); 6812 SetCachedHash(raw(), result);
6815 return result; 6813 return result;
6816 } 6814 }
6817 6815
6816 static intptr_t Hash(RawString* raw);
6817
6818 bool HasHash() const { 6818 bool HasHash() const {
6819 ASSERT(Smi::New(0) == NULL); 6819 ASSERT(Smi::New(0) == NULL);
6820 return GetCachedHash(raw()) != 0; 6820 return GetCachedHash(raw()) != 0;
6821 } 6821 }
6822 6822
6823 #if defined(HASH_IN_OBJECT_HEADER)
6824 static intptr_t hash_offset() { return kInt32Size; } // Wrong for big-endian?
6825 #else
6826 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } 6823 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
6827 #endif
6828 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); 6824 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
6829 static intptr_t Hash(const char* characters, intptr_t len); 6825 static intptr_t Hash(const char* characters, intptr_t len);
6830 static intptr_t Hash(const uint16_t* characters, intptr_t len); 6826 static intptr_t Hash(const uint16_t* characters, intptr_t len);
6831 static intptr_t Hash(const int32_t* characters, intptr_t len); 6827 static intptr_t Hash(const int32_t* characters, intptr_t len);
6832 static intptr_t HashRawSymbol(const RawString* symbol) { 6828 static intptr_t HashRawSymbol(const RawString* symbol) {
6833 ASSERT(symbol->IsCanonical()); 6829 ASSERT(symbol->IsCanonical());
6834 intptr_t result = GetCachedHash(symbol); 6830 intptr_t result = GetCachedHash(symbol);
6835 ASSERT(result != 0); 6831 ASSERT(result != 0);
6836 return result; 6832 return result;
6837 } 6833 }
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after
9055 9051
9056 inline void TypeArguments::SetHash(intptr_t value) const { 9052 inline void TypeArguments::SetHash(intptr_t value) const {
9057 // This is only safe because we create a new Smi, which does not cause 9053 // This is only safe because we create a new Smi, which does not cause
9058 // heap allocation. 9054 // heap allocation.
9059 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 9055 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
9060 } 9056 }
9061 9057
9062 } // namespace dart 9058 } // namespace dart
9063 9059
9064 #endif // RUNTIME_VM_OBJECT_H_ 9060 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/method_recognizer.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698