Index: runtime/vm/object.cc |
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
index 2c6422e7d0e5d68d8799ed3ba5034b6b3bc99174..67d1fa2d3a4e47deda358a78e68267b4ab590490 100644 |
--- a/runtime/vm/object.cc |
+++ b/runtime/vm/object.cc |
@@ -995,7 +995,7 @@ void Object::InitOnce(Isolate* isolate) { |
// premark all objects in the vm_isolate_ heap. |
class PremarkingVisitor : public ObjectVisitor { |
Vyacheslav Egorov (Google)
2017/06/07 06:21:15
Maybe this name needs to be changed?
erikcorry
2017/06/16 09:26:39
VMIsolateFixingVisitor
|
public: |
- PremarkingVisitor() {} |
+ PremarkingVisitor() : counter_(1337) {} |
void VisitObject(RawObject* obj) { |
// Free list elements should never be marked. |
@@ -1005,8 +1005,28 @@ class PremarkingVisitor : public ObjectVisitor { |
if (!obj->IsFreeListElement()) { |
ASSERT(obj->IsVMHeapObject()); |
obj->SetMarkBitUnsynchronized(); |
+#if defined(HASH_IN_OBJECT_HEADER) |
+ // These objects end up in the read-only VM isolate which is shared |
+ // between isolates, so we have to prepopulate them with identity hash |
+ // codes, since we can't add hash codes later. |
+ if (Object::GetCachedHash(obj) == 0) { |
+ // Some classes have identity hash codes that depend on their contents, |
+ // not per object. |
+ ASSERT(!obj->IsStringInstance()); |
+ if (!obj->IsMint() && !obj->IsDouble() && !obj->IsBigint() && |
+ !obj->IsRawNull() && !obj->IsBool()) { |
+ counter_ += 2011; // The year Dart was announced and a prime. |
+ counter_ &= 0x3fffffff; |
+ if (counter_ == 0) counter_++; |
+ Object::SetCachedHash(obj, counter_); |
+ } |
+ } |
+#endif |
} |
} |
+ |
+ private: |
+ int counter_; |
}; |