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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/raw_object.h
diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h
index 95288b1e1407513aceb2514fe2abea4016cd6c76..dc0aa7e7bc3a50767c89e435015ddb7879163623 100644
--- a/runtime/vm/raw_object.h
+++ b/runtime/vm/raw_object.h
@@ -13,6 +13,10 @@
#include "vm/token.h"
#include "vm/token_position.h"
+#if defined(ARCH_IS_64_BIT)
+#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.
+#endif
+
namespace dart {
// Macrobatics to define the Object hierarchy of VM implementation classes.
@@ -266,21 +270,11 @@ class RawObject {
kVMHeapObjectBit = 2,
kRememberedBit = 3,
kReservedTagPos = 4, // kReservedBit{100K,1M,10M}
-#if defined(ARCH_IS_32_BIT)
kReservedTagSize = 4,
kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 8
kSizeTagSize = 8,
kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 16
kClassIdTagSize = 16,
-#elif defined(ARCH_IS_64_BIT)
- kReservedTagSize = 12,
- kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 16
- kSizeTagSize = 16,
- kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 32
- kClassIdTagSize = 32,
-#else
-#error Unexpected architecture word size
-#endif
};
COMPILE_ASSERT(kClassIdTagSize == (sizeof(classid_t) * kBitsPerByte));
@@ -535,6 +529,20 @@ class RawObject {
ptr()->tags_ = ClassIdTag::update(new_cid, tags);
}
+#if defined(HASH_IN_OBJECT_HEADER)
+ int32_t GetHeaderHash() const {
+ ASSERT(IsHeapObject());
+ uword tags = ptr()->tags_;
+ return tags >> 32;
+ }
+
+ void SetHeaderHash(uintptr_t hash) {
+ ASSERT(GetHeaderHash() == 0);
+ ASSERT(hash >> 32 == 0);
+ ptr()->tags_ |= hash << 32ul;
+ }
+#endif
+
template <class TagBitField>
void UpdateTagBit(bool value) {
uword tags = ptr()->tags_;
@@ -614,6 +622,7 @@ class RawObject {
friend class RawExternalTypedData;
friend class RawInstructions;
friend class RawInstance;
+ friend class RawString;
friend class RawTypedData;
friend class Scavenger;
friend class ScavengerVisitor;
@@ -1820,6 +1829,17 @@ class RawInteger : public RawNumber {
class RawSmi : public RawInteger {
+ public:
+ 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
+ intptr_t raw_smi = (value << kSmiTagShift) | kSmiTag;
+ return reinterpret_cast<RawSmi*>(raw_smi);
+ }
+
+ intptr_t Value() {
+ ASSERT(kSmiTag == 0);
+ return reinterpret_cast<intptr_t>(this) >> kSmiTagShift;
+ }
+
RAW_OBJECT_IMPLEMENTATION(Smi);
};
@@ -1863,10 +1883,31 @@ class RawString : public RawInstance {
protected:
RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); }
RawSmi* length_;
+#if !defined(HASH_IN_OBJECT_HEADER)
RawSmi* hash_;
RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->hash_); }
+#else
+ RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); }
+#endif
+
+ private:
+#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.
+ uint32_t GetRawHash() const { return GetHeaderHash(); }
+ 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
+ ASSERT(hash >> 32 == 0);
+ 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.
+ }
+#else
+ uint32_t GetRawHash() const { return ptr()->hash_->Value(); }
+ void SetRawHash(uint32_t hash) { ptr()->hash_ = RawSmi::New(hash); }
+#endif
friend class Library;
+ friend class OneByteStringSerializationCluster;
+ friend class TwoByteStringSerializationCluster;
+ friend class OneByteStringDeserializationCluster;
+ friend class TwoByteStringDeserializationCluster;
+ friend class RODataSerializationCluster;
};
@@ -2453,6 +2494,7 @@ inline intptr_t RawObject::NumberOfTypedDataClasses() {
return (kNullCid - kTypedDataInt8ArrayCid);
}
+
} // namespace dart
#endif // RUNTIME_VM_RAW_OBJECT_H_
« 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