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

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

Issue 2893553002: More compact string representation on 64 bit. (Closed)
Patch Set: Created 3 years, 7 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_RAW_OBJECT_H_ 5 #ifndef RUNTIME_VM_RAW_OBJECT_H_
6 #define RUNTIME_VM_RAW_OBJECT_H_ 6 #define RUNTIME_VM_RAW_OBJECT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/atomic.h" 9 #include "vm/atomic.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
11 #include "vm/globals.h" 11 #include "vm/globals.h"
12 #include "vm/snapshot.h" 12 #include "vm/snapshot.h"
13 #include "vm/token.h" 13 #include "vm/token.h"
14 #include "vm/token_position.h" 14 #include "vm/token_position.h"
15 15
16 #if defined(ARCH_IS_64_BIT)
17 #define HASH_IN_OBJECT_HEADER 1
Vyacheslav Egorov (Google) 2017/05/18 06:14:43 maybe this needs to go to globals.h?
erikcorry 2017/05/18 14:28:38 Done.
18 #endif
19
16 namespace dart { 20 namespace dart {
17 21
18 // Macrobatics to define the Object hierarchy of VM implementation classes. 22 // Macrobatics to define the Object hierarchy of VM implementation classes.
19 #define CLASS_LIST_NO_OBJECT_NOR_STRING_NOR_ARRAY(V) \ 23 #define CLASS_LIST_NO_OBJECT_NOR_STRING_NOR_ARRAY(V) \
20 V(Class) \ 24 V(Class) \
21 V(UnresolvedClass) \ 25 V(UnresolvedClass) \
22 V(TypeArguments) \ 26 V(TypeArguments) \
23 V(PatchClass) \ 27 V(PatchClass) \
24 V(Function) \ 28 V(Function) \
25 V(ClosureData) \ 29 V(ClosureData) \
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 class RawObject { 263 class RawObject {
260 public: 264 public:
261 // The tags field which is a part of the object header uses the following 265 // The tags field which is a part of the object header uses the following
262 // bit fields for storing tags. 266 // bit fields for storing tags.
263 enum TagBits { 267 enum TagBits {
264 kMarkBit = 0, 268 kMarkBit = 0,
265 kCanonicalBit = 1, 269 kCanonicalBit = 1,
266 kVMHeapObjectBit = 2, 270 kVMHeapObjectBit = 2,
267 kRememberedBit = 3, 271 kRememberedBit = 3,
268 kReservedTagPos = 4, // kReservedBit{100K,1M,10M} 272 kReservedTagPos = 4, // kReservedBit{100K,1M,10M}
269 #if defined(ARCH_IS_32_BIT)
270 kReservedTagSize = 4, 273 kReservedTagSize = 4,
271 kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 8 274 kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 8
272 kSizeTagSize = 8, 275 kSizeTagSize = 8,
273 kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 16 276 kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 16
274 kClassIdTagSize = 16, 277 kClassIdTagSize = 16,
275 #elif defined(ARCH_IS_64_BIT)
276 kReservedTagSize = 12,
277 kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 16
278 kSizeTagSize = 16,
279 kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 32
280 kClassIdTagSize = 32,
281 #else
282 #error Unexpected architecture word size
283 #endif
284 }; 278 };
285 279
286 COMPILE_ASSERT(kClassIdTagSize == (sizeof(classid_t) * kBitsPerByte)); 280 COMPILE_ASSERT(kClassIdTagSize == (sizeof(classid_t) * kBitsPerByte));
287 281
288 // Encodes the object size in the tag in units of object alignment. 282 // Encodes the object size in the tag in units of object alignment.
289 class SizeTag { 283 class SizeTag {
290 public: 284 public:
291 static const intptr_t kMaxSizeTag = ((1 << RawObject::kSizeTagSize) - 1) 285 static const intptr_t kMaxSizeTag = ((1 << RawObject::kSizeTagSize) - 1)
292 << kObjectAlignmentLog2; 286 << kObjectAlignmentLog2;
293 287
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 intptr_t GetClassId() const { 522 intptr_t GetClassId() const {
529 uword tags = ptr()->tags_; 523 uword tags = ptr()->tags_;
530 return ClassIdTag::decode(tags); 524 return ClassIdTag::decode(tags);
531 } 525 }
532 526
533 void SetClassId(intptr_t new_cid) { 527 void SetClassId(intptr_t new_cid) {
534 uword tags = ptr()->tags_; 528 uword tags = ptr()->tags_;
535 ptr()->tags_ = ClassIdTag::update(new_cid, tags); 529 ptr()->tags_ = ClassIdTag::update(new_cid, tags);
536 } 530 }
537 531
532 #if defined(HASH_IN_OBJECT_HEADER)
533 int32_t GetHeaderHash() const {
534 ASSERT(IsHeapObject());
535 uword tags = ptr()->tags_;
536 return tags >> 32;
537 }
538
539 void SetHeaderHash(uintptr_t hash) {
540 ASSERT(GetHeaderHash() == 0);
541 ASSERT(hash >> 32 == 0);
542 ptr()->tags_ |= hash << 32ul;
543 }
544 #endif
545
538 template <class TagBitField> 546 template <class TagBitField>
539 void UpdateTagBit(bool value) { 547 void UpdateTagBit(bool value) {
540 uword tags = ptr()->tags_; 548 uword tags = ptr()->tags_;
541 uword old_tags; 549 uword old_tags;
542 do { 550 do {
543 old_tags = tags; 551 old_tags = tags;
544 uword new_tags = TagBitField::update(value, old_tags); 552 uword new_tags = TagBitField::update(value, old_tags);
545 tags = AtomicOperations::CompareAndSwapWord(&ptr()->tags_, old_tags, 553 tags = AtomicOperations::CompareAndSwapWord(&ptr()->tags_, old_tags,
546 new_tags); 554 new_tags);
547 } while (tags != old_tags); 555 } while (tags != old_tags);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 friend class ClassStatsVisitor; 615 friend class ClassStatsVisitor;
608 template <bool> 616 template <bool>
609 friend class MarkingVisitorBase; 617 friend class MarkingVisitorBase;
610 friend class Mint; 618 friend class Mint;
611 friend class Object; 619 friend class Object;
612 friend class OneByteString; // StoreSmi 620 friend class OneByteString; // StoreSmi
613 friend class RawCode; 621 friend class RawCode;
614 friend class RawExternalTypedData; 622 friend class RawExternalTypedData;
615 friend class RawInstructions; 623 friend class RawInstructions;
616 friend class RawInstance; 624 friend class RawInstance;
625 friend class RawString;
617 friend class RawTypedData; 626 friend class RawTypedData;
618 friend class Scavenger; 627 friend class Scavenger;
619 friend class ScavengerVisitor; 628 friend class ScavengerVisitor;
620 friend class SizeExcludingClassVisitor; // GetClassId 629 friend class SizeExcludingClassVisitor; // GetClassId
621 friend class InstanceAccumulator; // GetClassId 630 friend class InstanceAccumulator; // GetClassId
622 friend class RetainingPathVisitor; // GetClassId 631 friend class RetainingPathVisitor; // GetClassId
623 friend class SkippedCodeFunctions; // StorePointer 632 friend class SkippedCodeFunctions; // StorePointer
624 friend class ImageReader; // tags_ check 633 friend class ImageReader; // tags_ check
625 friend class ImageWriter; 634 friend class ImageWriter;
626 friend class AssemblyImageWriter; 635 friend class AssemblyImageWriter;
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 RAW_OBJECT_IMPLEMENTATION(Number); 1822 RAW_OBJECT_IMPLEMENTATION(Number);
1814 }; 1823 };
1815 1824
1816 1825
1817 class RawInteger : public RawNumber { 1826 class RawInteger : public RawNumber {
1818 RAW_OBJECT_IMPLEMENTATION(Integer); 1827 RAW_OBJECT_IMPLEMENTATION(Integer);
1819 }; 1828 };
1820 1829
1821 1830
1822 class RawSmi : public RawInteger { 1831 class RawSmi : public RawInteger {
1832 public:
1833 static RawSmi* New(intptr_t value) {
Vyacheslav Egorov (Google) 2017/05/18 06:14:42 It's very uncommon to have these here. Especially
erikcorry 2017/05/18 14:28:38 I managed to move them
1834 intptr_t raw_smi = (value << kSmiTagShift) | kSmiTag;
1835 return reinterpret_cast<RawSmi*>(raw_smi);
1836 }
1837
1838 intptr_t Value() {
1839 ASSERT(kSmiTag == 0);
1840 return reinterpret_cast<intptr_t>(this) >> kSmiTagShift;
1841 }
1842
1823 RAW_OBJECT_IMPLEMENTATION(Smi); 1843 RAW_OBJECT_IMPLEMENTATION(Smi);
1824 }; 1844 };
1825 1845
1826 1846
1827 class RawMint : public RawInteger { 1847 class RawMint : public RawInteger {
1828 RAW_HEAP_OBJECT_IMPLEMENTATION(Mint); 1848 RAW_HEAP_OBJECT_IMPLEMENTATION(Mint);
1829 1849
1830 ALIGN8 int64_t value_; 1850 ALIGN8 int64_t value_;
1831 1851
1832 friend class Api; 1852 friend class Api;
(...skipping 23 matching lines...) Expand all
1856 }; 1876 };
1857 COMPILE_ASSERT(sizeof(RawDouble) == 16); 1877 COMPILE_ASSERT(sizeof(RawDouble) == 16);
1858 1878
1859 1879
1860 class RawString : public RawInstance { 1880 class RawString : public RawInstance {
1861 RAW_HEAP_OBJECT_IMPLEMENTATION(String); 1881 RAW_HEAP_OBJECT_IMPLEMENTATION(String);
1862 1882
1863 protected: 1883 protected:
1864 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } 1884 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); }
1865 RawSmi* length_; 1885 RawSmi* length_;
1886 #if !defined(HASH_IN_OBJECT_HEADER)
1866 RawSmi* hash_; 1887 RawSmi* hash_;
1867 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->hash_); } 1888 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->hash_); }
1889 #else
1890 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); }
1891 #endif
1892
1893 private:
1894 #if defined(HASH_IN_OBJECT_HEADER)
Vyacheslav Egorov (Google) 2017/05/18 06:14:43 I think this needs to go to object.h you can have
erikcorry 2017/05/18 14:28:38 Done.
1895 uint32_t GetRawHash() const { return GetHeaderHash(); }
1896 void SetRawHash(uintptr_t hash) {
Vyacheslav Egorov (Google) 2017/05/18 06:14:43 can this be uint32_t hash for consistency with Set
erikcorry 2017/05/18 14:28:38 No, then the assert doesn't work. I want to ensur
1897 ASSERT(hash >> 32 == 0);
1898 SetHeaderHash(hash);
Vyacheslav Egorov (Google) 2017/05/18 06:14:43 I would better call is SetHashInHeader() or SetHas
erikcorry 2017/05/18 14:28:38 This no longer exists.
1899 }
1900 #else
1901 uint32_t GetRawHash() const { return ptr()->hash_->Value(); }
1902 void SetRawHash(uint32_t hash) { ptr()->hash_ = RawSmi::New(hash); }
1903 #endif
1868 1904
1869 friend class Library; 1905 friend class Library;
1906 friend class OneByteStringSerializationCluster;
1907 friend class TwoByteStringSerializationCluster;
1908 friend class OneByteStringDeserializationCluster;
1909 friend class TwoByteStringDeserializationCluster;
1910 friend class RODataSerializationCluster;
1870 }; 1911 };
1871 1912
1872 1913
1873 class RawOneByteString : public RawString { 1914 class RawOneByteString : public RawString {
1874 RAW_HEAP_OBJECT_IMPLEMENTATION(OneByteString); 1915 RAW_HEAP_OBJECT_IMPLEMENTATION(OneByteString);
1875 1916
1876 // Variable length data follows here. 1917 // Variable length data follows here.
1877 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); } 1918 uint8_t* data() { OPEN_ARRAY_START(uint8_t, uint8_t); }
1878 const uint8_t* data() const { OPEN_ARRAY_START(uint8_t, uint8_t); } 1919 const uint8_t* data() const { OPEN_ARRAY_START(uint8_t, uint8_t); }
1879 1920
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
2446 inline intptr_t RawObject::NumberOfTypedDataClasses() { 2487 inline intptr_t RawObject::NumberOfTypedDataClasses() {
2447 // Make sure this is updated when new TypedData types are added. 2488 // Make sure this is updated when new TypedData types are added.
2448 COMPILE_ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14); 2489 COMPILE_ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14);
2449 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == 2490 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid ==
2450 kTypedDataInt8ArrayViewCid + 15); 2491 kTypedDataInt8ArrayViewCid + 15);
2451 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); 2492 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14);
2452 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); 2493 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1);
2453 return (kNullCid - kTypedDataInt8ArrayCid); 2494 return (kNullCid - kTypedDataInt8ArrayCid);
2454 } 2495 }
2455 2496
2497
2456 } // namespace dart 2498 } // namespace dart
2457 2499
2458 #endif // RUNTIME_VM_RAW_OBJECT_H_ 2500 #endif // RUNTIME_VM_RAW_OBJECT_H_
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698