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

Unified Diff: runtime/vm/object.cc

Issue 2912863006: Inline instance object hash code into object header on 64 bit. (Closed)
Patch Set: Use visitor to give objects in VM isolate hash codes. 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/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_;
};

Powered by Google App Engine
This is Rietveld 408576698