[vm] Standardize hashing instance methods in C++.

In the codebase, we have several different interfaces for instance
methods that return a hash:

- uword Hash() const;
- intptr_t Hash() const;
- uint32_t Hash() const;
- intptr_t Hashcode() const;

This CL standardizes on `uword Hash() const` and adjusts any related
functions to match.

TEST=Existing test suites, as this is an internal refactoring.

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Change-Id: If2cbce57f3fae0f0d24031b6e324f0323c965f41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195067
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
diff --git a/runtime/vm/canonical_tables.h b/runtime/vm/canonical_tables.h
index 004b07f..b0e25b5 100644
--- a/runtime/vm/canonical_tables.h
+++ b/runtime/vm/canonical_tables.h
@@ -30,12 +30,12 @@
     }
     return other.Equals(data_, len_);
   }
-  intptr_t Hash() const { return hash_; }
+  uword Hash() const { return hash_; }
 
  private:
   const CharType* data_;
   intptr_t len_;
-  intptr_t hash_;
+  uword hash_;
 };
 typedef CharArray<uint8_t> Latin1Array;
 typedef CharArray<uint16_t> UTF16Array;
@@ -55,14 +55,14 @@
     }
     return other.Equals(str_, begin_index_, len_);
   }
-  intptr_t Hash() const { return hash_; }
+  uword Hash() const { return hash_; }
 
  private:
   bool is_all() const { return begin_index_ == 0 && len_ == str_.Length(); }
   const String& str_;
   intptr_t begin_index_;
   intptr_t len_;
-  intptr_t hash_;
+  uword hash_;
 };
 
 class ConcatString {
@@ -77,12 +77,12 @@
     }
     return other.EqualsConcat(str1_, str2_);
   }
-  intptr_t Hash() const { return hash_; }
+  uword Hash() const { return hash_; }
 
  private:
   const String& str1_;
   const String& str2_;
-  intptr_t hash_;
+  uword hash_;
 };
 
 class SymbolTraits {
diff --git a/runtime/vm/compiler/aot/precompiler.cc b/runtime/vm/compiler/aot/precompiler.cc
index 8dacf84..e638bf2 100644
--- a/runtime/vm/compiler/aot/precompiler.cc
+++ b/runtime/vm/compiler/aot/precompiler.cc
@@ -255,7 +255,7 @@
 
     static Value ValueOf(Pair kv) { return kv.value; }
 
-    static inline intptr_t Hashcode(Key key) {
+    static inline uword Hash(Key key) {
       if (key->IsFunction()) {
         return Function::Cast(*key).Hash();
       }
diff --git a/runtime/vm/compiler/aot/precompiler.h b/runtime/vm/compiler/aot/precompiler.h
index 2af72af..315c712 100644
--- a/runtime/vm/compiler/aot/precompiler.h
+++ b/runtime/vm/compiler/aot/precompiler.h
@@ -42,7 +42,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key; }
+  static inline uword Hash(Key key) { return key; }
 
   static inline bool IsKeyEqual(Pair pair, Key key) { return pair == key; }
 };
@@ -60,7 +60,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->ptr() == key->ptr();
@@ -92,7 +92,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) {
+  static inline uword Hash(Key key) {
     const TokenPosition token_pos = key->token_pos();
     if (token_pos.IsReal()) {
       return token_pos.Hash();
@@ -118,7 +118,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->token_pos().Hash(); }
+  static inline uword Hash(Key key) { return key->token_pos().Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->ptr() == key->ptr();
@@ -138,7 +138,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->ptr() == key->ptr();
@@ -158,7 +158,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->ptr() == key->ptr();
@@ -178,7 +178,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->ptr() == key->ptr();
@@ -198,7 +198,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->ptr() == key->ptr();
@@ -218,7 +218,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->GetClassId(); }
+  static inline uword Hash(Key key) { return key->GetClassId(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->ptr() == key->ptr();
diff --git a/runtime/vm/compiler/aot/precompiler_tracer.h b/runtime/vm/compiler/aot/precompiler_tracer.h
index 70a9359..324e82c 100644
--- a/runtime/vm/compiler/aot/precompiler_tracer.h
+++ b/runtime/vm/compiler/aot/precompiler_tracer.h
@@ -54,7 +54,7 @@
   struct CString {
     const char* str;
     const intptr_t length;
-    intptr_t hash;
+    uword hash;
   };
 
   struct StringTableTraits {
diff --git a/runtime/vm/compiler/assembler/assembler_base.cc b/runtime/vm/compiler/assembler/assembler_base.cc
index 7034652..9d50186 100644
--- a/runtime/vm/compiler/assembler/assembler_base.cc
+++ b/runtime/vm/compiler/assembler/assembler_base.cc
@@ -259,7 +259,7 @@
   Breakpoint();
 }
 
-intptr_t ObjIndexPair::Hashcode(Key key) {
+uword ObjIndexPair::Hash(Key key) {
   if (key.type() != ObjectPoolBuilderEntry::kTaggedObject) {
     return key.raw_value_;
   }
diff --git a/runtime/vm/compiler/assembler/object_pool_builder.h b/runtime/vm/compiler/assembler/object_pool_builder.h
index 2bc2add..db77eb8 100644
--- a/runtime/vm/compiler/assembler/object_pool_builder.h
+++ b/runtime/vm/compiler/assembler/object_pool_builder.h
@@ -95,7 +95,7 @@
 
   static Value ValueOf(Pair kv) { return kv.value_; }
 
-  static intptr_t Hashcode(Key key);
+  static uword Hash(Key key);
 
   static inline bool IsKeyEqual(Pair kv, Key key) {
     if (kv.key_.entry_bits_ != key.entry_bits_) return false;
diff --git a/runtime/vm/compiler/backend/flow_graph.h b/runtime/vm/compiler/backend/flow_graph.h
index 09e3caf..b028847 100644
--- a/runtime/vm/compiler/backend/flow_graph.h
+++ b/runtime/vm/compiler/backend/flow_graph.h
@@ -58,7 +58,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) {
+  static inline uword Hash(Key key) {
     if (key.IsSmi()) {
       return Smi::Cast(key).Value();
     }
diff --git a/runtime/vm/compiler/backend/il.cc b/runtime/vm/compiler/backend/il.cc
index 449eeaf..74532bb 100644
--- a/runtime/vm/compiler/backend/il.cc
+++ b/runtime/vm/compiler/backend/il.cc
@@ -649,14 +649,13 @@
   return result;
 }
 
-intptr_t Instruction::Hashcode() const {
-  intptr_t result = tag();
+uword Instruction::Hash() const {
+  uword result = tag();
   for (intptr_t i = 0; i < InputCount(); ++i) {
     Value* value = InputAt(i);
-    intptr_t j = value->definition()->ssa_temp_index();
-    result = result * 31 + j;
+    result = CombineHashes(result, value->definition()->ssa_temp_index());
   }
-  return result;
+  return FinalizeHash(result, kBitsPerInt32 - 1);
 }
 
 bool Instruction::Equals(Instruction* other) const {
diff --git a/runtime/vm/compiler/backend/il.h b/runtime/vm/compiler/backend/il.h
index 3516f74..c4ff302 100644
--- a/runtime/vm/compiler/backend/il.h
+++ b/runtime/vm/compiler/backend/il.h
@@ -1077,7 +1077,7 @@
   virtual bool has_inlining_id() const { return inlining_id_ >= 0; }
 
   // Returns a hash code for use with hash maps.
-  virtual intptr_t Hashcode() const;
+  virtual uword Hash() const;
 
   // Compares two instructions.  Returns true, iff:
   // 1. They have the same tag.
@@ -2486,7 +2486,7 @@
     return CompilerState::Current().is_aot() ? kNotSpeculative : kGuardInputs;
   }
 
-  virtual intptr_t Hashcode() const {
+  virtual uword Hash() const {
     UNREACHABLE();
     return 0;
   }
@@ -2587,7 +2587,7 @@
 
   virtual bool HasUnknownSideEffects() const { return false; }
 
-  virtual intptr_t Hashcode() const {
+  virtual uword Hash() const {
     UNREACHABLE();
     return 0;
   }
diff --git a/runtime/vm/compiler/backend/redundancy_elimination.cc b/runtime/vm/compiler/backend/redundancy_elimination.cc
index fb3d09c..6edc0f3 100644
--- a/runtime/vm/compiler/backend/redundancy_elimination.cc
+++ b/runtime/vm/compiler/backend/redundancy_elimination.cc
@@ -428,9 +428,10 @@
     }
   }
 
-  intptr_t Hashcode() const {
-    return (flags_ * 63 + reinterpret_cast<intptr_t>(instance_)) * 31 +
-           FieldHashcode();
+  uword Hash() const {
+    return FinalizeHash(
+        CombineHashes(flags_, reinterpret_cast<uword>(instance_)),
+        kBitsPerInt32 - 1);
   }
 
   bool Equals(const Place* other) const {
@@ -460,7 +461,7 @@
                : (raw_selector_ == other->raw_selector_);
   }
 
-  intptr_t FieldHashcode() const {
+  uword FieldHash() const {
     return (kind() == kStaticField)
                ? String::Handle(Field::Handle(static_field().Original()).name())
                      .Hash()
diff --git a/runtime/vm/compiler/backend/slot.cc b/runtime/vm/compiler/backend/slot.cc
index 75fccf8..d0c4d9e 100644
--- a/runtime/vm/compiler/backend/slot.cc
+++ b/runtime/vm/compiler/backend/slot.cc
@@ -408,8 +408,8 @@
   }
 }
 
-intptr_t Slot::Hashcode() const {
-  intptr_t result = (static_cast<int8_t>(kind_) * 63 + offset_in_bytes_) * 31;
+uword Slot::Hash() const {
+  uword result = (static_cast<int8_t>(kind_) * 63 + offset_in_bytes_) * 31;
   if (IsDartField()) {
     result += String::Handle(DataAs<const Field>()->name()).Hash();
   } else if (IsLocalVariable()) {
diff --git a/runtime/vm/compiler/backend/slot.h b/runtime/vm/compiler/backend/slot.h
index 8a776de..c2078b7 100644
--- a/runtime/vm/compiler/backend/slot.h
+++ b/runtime/vm/compiler/backend/slot.h
@@ -265,7 +265,7 @@
   }
 
   bool Equals(const Slot* other) const;
-  intptr_t Hashcode() const;
+  uword Hash() const;
 
   bool IsIdentical(const Slot& other) const { return this == &other; }
 
diff --git a/runtime/vm/compiler/relocation.h b/runtime/vm/compiler/relocation.h
index e9b6d44..948dffc 100644
--- a/runtime/vm/compiler/relocation.h
+++ b/runtime/vm/compiler/relocation.h
@@ -117,8 +117,8 @@
 
   static Key KeyOf(Pair kv) { return kv.instructions; }
   static ValueType ValueOf(Pair kv) { return kv.value; }
-  static inline intptr_t Hashcode(Key key) {
-    return static_cast<intptr_t>(key);
+  static inline uword Hash(Key key) {
+    return Utils::WordHash(static_cast<intptr_t>(key));
   }
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair.instructions == key;
diff --git a/runtime/vm/compiler/write_barrier_elimination.cc b/runtime/vm/compiler/write_barrier_elimination.cc
index 84b000f..855cffb 100644
--- a/runtime/vm/compiler/write_barrier_elimination.cc
+++ b/runtime/vm/compiler/write_barrier_elimination.cc
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-#include <functional>
-
 #include "vm/compiler/backend/flow_graph.h"
 #include "vm/compiler/compiler_pass.h"
 #include "vm/compiler/write_barrier_elimination.h"
@@ -31,7 +29,9 @@
 
   static Key KeyOf(Pair kv) { return kv.definition; }
   static Value ValueOf(Pair kv) { return kv.index; }
-  static inline intptr_t Hashcode(Key key) { return std::hash<Key>()(key); }
+  static inline uword Hash(Key key) {
+    return Utils::WordHash(reinterpret_cast<intptr_t>(key));
+  }
   static inline bool IsKeyEqual(Pair kv, Key key) {
     return kv.definition == key;
   }
diff --git a/runtime/vm/debugger.h b/runtime/vm/debugger.h
index b9d99de..6dd2515 100644
--- a/runtime/vm/debugger.h
+++ b/runtime/vm/debugger.h
@@ -548,7 +548,9 @@
 
   static Key KeyOf(Pair kv) { return kv.key; }
   static Value ValueOf(Pair kv) { return kv.value; }
-  static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); }
+  static uword Hash(Key key) {
+    return Utils::WordHash(reinterpret_cast<intptr_t>(key));
+  }
   static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; }
 };
 
diff --git a/runtime/vm/dwarf.h b/runtime/vm/dwarf.h
index ccf9c83..66851c4 100644
--- a/runtime/vm/dwarf.h
+++ b/runtime/vm/dwarf.h
@@ -28,7 +28,7 @@
 
   static Value ValueOf(Pair kv) { return kv.index_; }
 
-  static inline intptr_t Hashcode(Key key) {
+  static inline uword Hash(Key key) {
     return String::Handle(key->url()).Hash();
   }
 
@@ -61,7 +61,7 @@
 
   static Value ValueOf(Pair kv) { return kv.index_; }
 
-  static inline intptr_t Hashcode(Key key) { return key->token_pos().Hash(); }
+  static inline uword Hash(Key key) { return key->token_pos().Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair.function_->ptr() == key->ptr();
@@ -110,9 +110,9 @@
 
   static Value ValueOf(Pair kv) { return kv.value; }
 
-  static inline intptr_t Hashcode(Key key) {
+  static inline uword Hash(Key key) {
     // Instructions are always allocated in old space, so they don't move.
-    return FinalizeHash(key->PayloadStart(), 32);
+    return Utils::WordHash(key->PayloadStart());
   }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
diff --git a/runtime/vm/hash_map.h b/runtime/vm/hash_map.h
index 5af4c15..77a3389 100644
--- a/runtime/vm/hash_map.h
+++ b/runtime/vm/hash_map.h
@@ -155,7 +155,7 @@
   const typename KeyValueTrait::Value kNoValue =
       KeyValueTrait::ValueOf(typename KeyValueTrait::Pair());
 
-  uword hash = static_cast<uword>(KeyValueTrait::Hashcode(key));
+  uword hash = KeyValueTrait::Hash(key);
   uword pos = Bound(hash);
   if (KeyValueTrait::ValueOf(array_[pos].kv) != kNoValue) {
     if (KeyValueTrait::IsKeyEqual(array_[pos].kv, key)) {
@@ -301,8 +301,7 @@
   if (count_ >= array_size_ >> 1) Resize(array_size_ << 1);
   ASSERT(count_ < array_size_);
   count_++;
-  uword pos = Bound(
-      static_cast<uword>(KeyValueTrait::Hashcode(KeyValueTrait::KeyOf(kv))));
+  uword pos = Bound(KeyValueTrait::Hash(KeyValueTrait::KeyOf(kv)));
   if (KeyValueTrait::ValueOf(array_[pos].kv) == kNoValue) {
     array_[pos].kv = kv;
     array_[pos].next = kNil;
@@ -341,7 +340,7 @@
   const typename KeyValueTrait::Value kNoValue =
       KeyValueTrait::ValueOf(typename KeyValueTrait::Pair());
 
-  uword pos = Bound(static_cast<uword>(KeyValueTrait::Hashcode(key)));
+  uword pos = Bound(KeyValueTrait::Hash(key));
 
   // Check to see if the first element in the bucket is the one we want to
   // remove.
@@ -465,7 +464,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hashcode(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair kv, Key key) { return kv->Equals(key); }
 };
@@ -479,7 +478,7 @@
 
   static intptr_t KeyOf(Pair kv) { return kv.first(); }
   static T ValueOf(Pair kv) { return kv; }
-  static inline intptr_t Hashcode(Key key) { return key; }
+  static inline uword Hash(Key key) { return key; }
   static inline bool IsKeyEqual(Pair kv, Key key) { return kv.first() == key; }
 };
 
@@ -500,7 +499,7 @@
 
   static Key KeyOf(Pair kv) { return kv.key; }
   static Value ValueOf(Pair kv) { return kv.value; }
-  static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); }
+  static uword Hash(Key key) { return reinterpret_cast<intptr_t>(key); }
   static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; }
 };
 
@@ -510,7 +509,7 @@
   using Value = PointerKeyValueTrait<const char>::Value;
   using Pair = PointerKeyValueTrait<const char>::Pair;
 
-  static intptr_t Hashcode(Key key) {
+  static uword Hash(Key key) {
     ASSERT(key != nullptr);
     return Utils::StringHash(key, strlen(key));
   }
@@ -550,7 +549,7 @@
   typedef typename RawPointerKeyValueTrait<const char, V>::Value Value;
   typedef typename RawPointerKeyValueTrait<const char, V>::Pair Pair;
 
-  static intptr_t Hashcode(Key key) {
+  static uword Hash(Key key) {
     ASSERT(key != nullptr);
     return Utils::StringHash(key, strlen(key));
   }
@@ -603,7 +602,7 @@
 
   static Key KeyOf(Pair kv) { return kv.key; }
   static Value ValueOf(Pair kv) { return kv.value; }
-  static intptr_t Hashcode(Key key) { return key; }
+  static uword Hash(Key key) { return key; }
   static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; }
 };
 
@@ -653,8 +652,8 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) {
-    return reinterpret_cast<intptr_t>(key);
+  static inline uword Hash(Key key) {
+    return Utils::WordHash(reinterpret_cast<intptr_t>(key));
   }
 
   static inline bool IsKeyEqual(Pair pair, Key key) { return pair == key; }
diff --git a/runtime/vm/hash_map_test.cc b/runtime/vm/hash_map_test.cc
index 27385d9..6d02c08 100644
--- a/runtime/vm/hash_map_test.cc
+++ b/runtime/vm/hash_map_test.cc
@@ -11,7 +11,7 @@
 class TestValue {
  public:
   explicit TestValue(intptr_t x) : x_(x) {}
-  intptr_t Hashcode() const { return x_ & 1; }
+  uword Hash() const { return x_ & 1; }
   bool Equals(TestValue* other) { return x_ == other->x_; }
 
  private:
diff --git a/runtime/vm/heap/weak_table.h b/runtime/vm/heap/weak_table.h
index c72d773..d5ddc2e 100644
--- a/runtime/vm/heap/weak_table.h
+++ b/runtime/vm/heap/weak_table.h
@@ -193,9 +193,7 @@
 
   void Rehash();
 
-  static intptr_t Hash(ObjectPtr key) {
-    return static_cast<uintptr_t>(key) * 92821;
-  }
+  static uword Hash(ObjectPtr key) { return static_cast<uword>(key) * 92821; }
 
   Mutex mutex_;
 
diff --git a/runtime/vm/image_snapshot.cc b/runtime/vm/image_snapshot.cc
index 982cb7a..73cc3d6 100644
--- a/runtime/vm/image_snapshot.cc
+++ b/runtime/vm/image_snapshot.cc
@@ -142,7 +142,7 @@
 #endif
 }
 
-intptr_t ObjectOffsetTrait::Hashcode(Key key) {
+uword ObjectOffsetTrait::Hash(Key key) {
   ObjectPtr obj = key;
   ASSERT(!obj->IsSmi());
 
diff --git a/runtime/vm/image_snapshot.h b/runtime/vm/image_snapshot.h
index 84040d4..c234dd8 100644
--- a/runtime/vm/image_snapshot.h
+++ b/runtime/vm/image_snapshot.h
@@ -178,7 +178,7 @@
 
   static Key KeyOf(Pair kv) { return kv.object; }
   static Value ValueOf(Pair kv) { return kv.offset; }
-  static intptr_t Hashcode(Key key);
+  static uword Hash(Key key);
   static inline bool IsKeyEqual(Pair pair, Key key);
 };
 
diff --git a/runtime/vm/isolate_reload.h b/runtime/vm/isolate_reload.h
index a09f604..69a399c 100644
--- a/runtime/vm/isolate_reload.h
+++ b/runtime/vm/isolate_reload.h
@@ -256,7 +256,7 @@
 
     static Key KeyOf(Pair kv) { return kv->cid(); }
     static Value ValueOf(Pair kv) { return kv; }
-    static intptr_t Hashcode(Key key) { return key; }
+    static uword Hash(Key key) { return Utils::WordHash(key); }
     static bool IsKeyEqual(Pair kv, Key key) { return kv->cid() == key; }
   };
 
diff --git a/runtime/vm/kernel_loader.h b/runtime/vm/kernel_loader.h
index dec4c98..1943dc8 100644
--- a/runtime/vm/kernel_loader.h
+++ b/runtime/vm/kernel_loader.h
@@ -168,7 +168,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->uri->Hash(); }
+  static inline uword Hash(Key key) { return key->uri->Hash(); }
 
   static inline bool IsKeyEqual(Pair kv, Key key) {
     // Only compare uri.
diff --git a/runtime/vm/malloc_hooks_tcmalloc.cc b/runtime/vm/malloc_hooks_tcmalloc.cc
index ff9bed6..787a429 100644
--- a/runtime/vm/malloc_hooks_tcmalloc.cc
+++ b/runtime/vm/malloc_hooks_tcmalloc.cc
@@ -180,7 +180,9 @@
 
   static Key KeyOf(Pair kv) { return kv.key; }
   static Value ValueOf(Pair kv) { return kv.value; }
-  static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); }
+  static uword Hash(Key key) {
+    return Utils::WordHash(reinterpret_cast<intptr_t>(key));
+  }
   static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; }
 };
 
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index ec54a16..2272cf7 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -6012,7 +6012,7 @@
   untag()->set_nullability(Smi::New(value));
 }
 
-intptr_t TypeArguments::HashForRange(intptr_t from_index, intptr_t len) const {
+uword TypeArguments::HashForRange(intptr_t from_index, intptr_t len) const {
   if (IsNull()) return kAllDynamicHash;
   if (IsRaw(from_index, len)) return kAllDynamicHash;
   uint32_t result = 0;
@@ -6045,10 +6045,9 @@
   return result;
 }
 
-intptr_t TypeArguments::ComputeHash() const {
+uword TypeArguments::ComputeHash() const {
   if (IsNull()) return kAllDynamicHash;
-  const intptr_t num_types = Length();
-  const uint32_t result = HashForRange(0, num_types);
+  const uword result = HashForRange(0, Length());
   if (result != 0) {
     SetHash(result);
   }
@@ -6819,7 +6818,7 @@
   untag()->set_library_kernel_data(data.ptr());
 }
 
-intptr_t Function::Hash() const {
+uword Function::Hash() const {
   return String::HashRawSymbol(name());
 }
 
@@ -14567,7 +14566,7 @@
   return "CodeSourceMap";
 }
 
-intptr_t CompressedStackMaps::Hashcode() const {
+uword CompressedStackMaps::Hash() const {
   NoSafepointScope scope;
   uint8_t* data = UnsafeMutableNonPointer(&untag()->data()[0]);
   uint8_t* end = data + payload_size();
@@ -15111,7 +15110,7 @@
   StoreNonPointer(&untag()->can_patch_to_monomorphic_, value);
 }
 
-intptr_t UnlinkedCall::Hashcode() const {
+uword UnlinkedCall::Hash() const {
   return String::Handle(target_name()).Hash();
 }
 
@@ -19955,7 +19954,7 @@
   return false;
 }
 
-intptr_t AbstractType::Hash() const {
+uword AbstractType::Hash() const {
   // AbstractType is an abstract class.
   UNREACHABLE();
   return 0;
@@ -20662,7 +20661,7 @@
   type_args.EnumerateURIs(uris);
 }
 
-intptr_t Type::ComputeHash() const {
+uword Type::ComputeHash() const {
   ASSERT(IsFinalized());
   uint32_t result = type_class_id();
   // A legacy type should have the same hash as its non-nullable version to be
@@ -20695,7 +20694,7 @@
   return result;
 }
 
-intptr_t FunctionType::ComputeHash() const {
+uword FunctionType::ComputeHash() const {
   ASSERT(IsFinalized());
   uint32_t result = packed_fields();
   // A legacy type should have the same hash as its non-nullable version to be
@@ -21121,7 +21120,7 @@
   // Break cycle by not printing type arguments.
 }
 
-intptr_t TypeRef::Hash() const {
+uword TypeRef::Hash() const {
   // Do not use hash of the referenced type because
   //  - we could be in process of calculating it (as TypeRef is used to
   //    represent recursive references to types).
@@ -21614,7 +21613,7 @@
 }
 #endif  // DEBUG
 
-intptr_t TypeParameter::ComputeHash() const {
+uword TypeParameter::ComputeHash() const {
   ASSERT(IsFinalized() || IsBeingFinalized());  // Bound may not be finalized.
   uint32_t result = parameterized_class_id();
   // Hashing the bound reduces collisions, but may also create cycles.
@@ -22308,20 +22307,20 @@
   }
 }
 
-intptr_t String::Hash(const String& str, intptr_t begin_index, intptr_t len) {
+uword String::Hash(const String& str, intptr_t begin_index, intptr_t len) {
   StringHasher hasher;
   hasher.Add(str, begin_index, len);
   return hasher.Finalize();
 }
 
-intptr_t String::HashConcat(const String& str1, const String& str2) {
+uword String::HashConcat(const String& str1, const String& str2) {
   StringHasher hasher;
   hasher.Add(str1, 0, str1.Length());
   hasher.Add(str2, 0, str2.Length());
   return hasher.Finalize();
 }
 
-intptr_t String::Hash(StringPtr raw) {
+uword String::Hash(StringPtr raw) {
   StringHasher hasher;
   uword length = Smi::Value(raw->untag()->length());
   if (raw->IsOneByteString() || raw->IsExternalOneByteString()) {
@@ -22347,19 +22346,19 @@
   }
 }
 
-intptr_t String::Hash(const char* characters, intptr_t len) {
+uword String::Hash(const char* characters, intptr_t len) {
   StringHasher hasher;
   hasher.Add(reinterpret_cast<const uint8_t*>(characters), len);
   return hasher.Finalize();
 }
 
-intptr_t String::Hash(const uint8_t* characters, intptr_t len) {
+uword String::Hash(const uint8_t* characters, intptr_t len) {
   StringHasher hasher;
   hasher.Add(characters, len);
   return hasher.Finalize();
 }
 
-intptr_t String::Hash(const uint16_t* characters, intptr_t len) {
+uword String::Hash(const uint16_t* characters, intptr_t len) {
   StringHasher hasher;
   hasher.Add(characters, len);
   return hasher.Finalize();
@@ -24767,7 +24766,7 @@
   return buffer.buffer();
 }
 
-int64_t Closure::ComputeHash() const {
+uword Closure::ComputeHash() const {
   Thread* thread = Thread::Current();
   DEBUG_ASSERT(thread->TopErrorHandlerIsExitFrame());
   Zone* zone = thread->zone();
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 8c000c9..e5c69e7 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -1918,7 +1918,7 @@
     return RoundedAllocationSize(sizeof(UntaggedUnlinkedCall));
   }
 
-  intptr_t Hashcode() const;
+  uword Hash() const;
   bool Equals(const UnlinkedCall& other) const;
 
   static UnlinkedCallPtr New();
@@ -2684,7 +2684,7 @@
     return OFFSET_OF(UntaggedFunction, unchecked_entry_point_);
   }
 
-  virtual intptr_t Hash() const;
+  virtual uword Hash() const;
 
   // Returns true if there is at least one debugger breakpoint
   // set in this function.
@@ -5752,7 +5752,7 @@
 
   // Methods to allow use with PointerKeyValueTrait to create sets of CSMs.
   bool Equals(const CompressedStackMaps* other) const { return Equals(*other); }
-  intptr_t Hashcode() const;
+  uword Hash() const;
 
   static intptr_t HeaderSize() { return sizeof(UntaggedCompressedStackMaps); }
   static intptr_t UnroundedSize(CompressedStackMapsPtr maps) {
@@ -7668,8 +7668,8 @@
     // Hash() is not stable until finalization is done.
     return 0;
   }
-  intptr_t Hash() const;
-  intptr_t HashForRange(intptr_t from_index, intptr_t len) const;
+  uword Hash() const;
+  uword HashForRange(intptr_t from_index, intptr_t len) const;
 
   static TypeArgumentsPtr New(intptr_t len, Heap::Space space = Heap::kOld);
 
@@ -7677,7 +7677,7 @@
   intptr_t ComputeNullability() const;
   void set_nullability(intptr_t value) const;
 
-  intptr_t ComputeHash() const;
+  uword ComputeHash() const;
   void SetHash(intptr_t value) const;
 
   // Check if the subvector of length 'len' starting at 'from_index' of this
@@ -7843,7 +7843,7 @@
   // list and mark ambiguous triplets to be printed.
   virtual void EnumerateURIs(URIs* uris) const;
 
-  virtual intptr_t Hash() const;
+  virtual uword Hash() const;
 
   // The name of this type's class, i.e. without the type argument names of this
   // type.
@@ -8047,8 +8047,8 @@
 #endif  // DEBUG
   virtual void EnumerateURIs(URIs* uris) const;
 
-  virtual intptr_t Hash() const;
-  intptr_t ComputeHash() const;
+  virtual uword Hash() const;
+  uword ComputeHash() const;
 
   static intptr_t InstanceSize() {
     return RoundedAllocationSize(sizeof(UntaggedType));
@@ -8191,8 +8191,8 @@
 #endif  // DEBUG
   virtual void EnumerateURIs(URIs* uris) const;
 
-  virtual intptr_t Hash() const;
-  intptr_t ComputeHash() const;
+  virtual uword Hash() const;
+  uword ComputeHash() const;
 
   bool IsSubtypeOf(const FunctionType& other, Heap::Space space) const;
 
@@ -8447,7 +8447,7 @@
 #endif  // DEBUG
   virtual void EnumerateURIs(URIs* uris) const;
 
-  virtual intptr_t Hash() const;
+  virtual uword Hash() const;
 
   static intptr_t InstanceSize() {
     return RoundedAllocationSize(sizeof(UntaggedTypeRef));
@@ -8561,7 +8561,7 @@
 #endif  // DEBUG
   virtual void EnumerateURIs(URIs* uris) const { return; }
 
-  virtual intptr_t Hash() const;
+  virtual uword Hash() const;
 
   // Returns type corresponding to [this] type parameter from the
   // given [instantiator_type_arguments] and [function_type_arguments].
@@ -8585,7 +8585,7 @@
                               Nullability nullability);
 
  private:
-  intptr_t ComputeHash() const;
+  uword ComputeHash() const;
   void SetHash(intptr_t value) const;
 
   void set_parameterized_class(const Class& value) const;
@@ -8918,8 +8918,8 @@
   }
   static intptr_t length_offset() { return OFFSET_OF(UntaggedString, length_); }
 
-  intptr_t Hash() const {
-    intptr_t result = GetCachedHash(ptr());
+  uword Hash() const {
+    uword result = GetCachedHash(ptr());
     if (result != 0) {
       return result;
     }
@@ -8928,7 +8928,7 @@
     return result;
   }
 
-  static intptr_t Hash(StringPtr raw);
+  static uword Hash(StringPtr raw);
 
   bool HasHash() const {
     ASSERT(Smi::New(0) == nullptr);
@@ -8944,19 +8944,19 @@
     return OFFSET_OF(UntaggedString, hash_);
 #endif
   }
-  static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
-  static intptr_t Hash(const char* characters, intptr_t len);
-  static intptr_t Hash(const uint16_t* characters, intptr_t len);
-  static intptr_t Hash(const int32_t* characters, intptr_t len);
-  static intptr_t HashRawSymbol(const StringPtr symbol) {
+  static uword Hash(const String& str, intptr_t begin_index, intptr_t len);
+  static uword Hash(const char* characters, intptr_t len);
+  static uword Hash(const uint16_t* characters, intptr_t len);
+  static uword Hash(const int32_t* characters, intptr_t len);
+  static uword HashRawSymbol(const StringPtr symbol) {
     ASSERT(symbol->untag()->IsCanonical());
-    intptr_t result = GetCachedHash(symbol);
+    const uword result = GetCachedHash(symbol);
     ASSERT(result != 0);
     return result;
   }
 
   // Returns the hash of str1 + str2.
-  static intptr_t HashConcat(const String& str1, const String& str2);
+  static uword HashConcat(const String& str1, const String& str2);
 
   virtual ObjectPtr HashCode() const { return Integer::New(Hash()); }
 
@@ -9178,7 +9178,7 @@
   // They are protected to avoid mistaking Latin-1 for UTF-8, but used
   // by friendly templated code (e.g., Symbols).
   bool Equals(const uint8_t* characters, intptr_t len) const;
-  static intptr_t Hash(const uint8_t* characters, intptr_t len);
+  static uword Hash(const uint8_t* characters, intptr_t len);
 
   void SetLength(intptr_t value) const {
     // This is only safe because we create a new Smi, which does not cause
@@ -10812,7 +10812,7 @@
   virtual uint32_t CanonicalizeHash() const {
     return Function::Handle(function()).Hash();
   }
-  int64_t ComputeHash() const;
+  uword ComputeHash() const;
 
   static ClosurePtr New(const TypeArguments& instantiator_type_arguments,
                         const TypeArguments& function_type_arguments,
@@ -11536,7 +11536,7 @@
   return array.At((index * kEntryLength) + kTargetFunctionIndex);
 }
 
-inline intptr_t Type::Hash() const {
+inline uword Type::Hash() const {
   ASSERT(IsFinalized());
   intptr_t result = Smi::Value(untag()->hash());
   if (result != 0) {
@@ -11551,7 +11551,7 @@
   untag()->set_hash(Smi::New(value));
 }
 
-inline intptr_t FunctionType::Hash() const {
+inline uword FunctionType::Hash() const {
   ASSERT(IsFinalized());
   intptr_t result = Smi::Value(untag()->hash());
   if (result != 0) {
@@ -11566,7 +11566,7 @@
   untag()->set_hash(Smi::New(value));
 }
 
-inline intptr_t TypeParameter::Hash() const {
+inline uword TypeParameter::Hash() const {
   ASSERT(IsFinalized() || IsBeingFinalized());  // Bound may not be finalized.
   intptr_t result = Smi::Value(untag()->hash());
   if (result != 0) {
@@ -11581,7 +11581,7 @@
   untag()->set_hash(Smi::New(value));
 }
 
-inline intptr_t TypeArguments::Hash() const {
+inline uword TypeArguments::Hash() const {
   if (IsNull()) return kAllDynamicHash;
   intptr_t result = Smi::Value(untag()->hash());
   if (result != 0) {
diff --git a/runtime/vm/object_test.cc b/runtime/vm/object_test.cc
index 8d94071..5417f6d 100644
--- a/runtime/vm/object_test.cc
+++ b/runtime/vm/object_test.cc
@@ -1365,7 +1365,7 @@
   const String& clef = String::Handle(String::FromUTF16(clef_utf16, 2));
   int32_t clef_utf32[] = {0x1D11E};
   EXPECT(clef.Equals(clef_utf32, 1));
-  intptr_t hash32 = String::Hash(String::FromUTF32(clef_utf32, 1));
+  uword hash32 = String::Hash(String::FromUTF32(clef_utf32, 1));
   EXPECT_EQ(hash32, clef.Hash());
   EXPECT_EQ(hash32, String::HashConcat(
                         String::Handle(String::FromUTF16(clef_utf16, 1)),
diff --git a/runtime/vm/profiler_service.cc b/runtime/vm/profiler_service.cc
index 9cf5d12..a61fb94 100644
--- a/runtime/vm/profiler_service.cc
+++ b/runtime/vm/profiler_service.cc
@@ -540,7 +540,7 @@
 
     static Value ValueOf(Pair kv) { return kv; }
 
-    static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+    static inline uword Hash(Key key) { return key->Hash(); }
 
     static inline bool IsKeyEqual(Pair kv, Key key) {
       return kv->function()->ptr() == key->ptr();
diff --git a/runtime/vm/program_visitor.cc b/runtime/vm/program_visitor.cc
index b8e3de1..2e4bb01 100644
--- a/runtime/vm/program_visitor.cc
+++ b/runtime/vm/program_visitor.cc
@@ -468,7 +468,7 @@
 
   static const intptr_t kHashBits = 30;
 
-  intptr_t Hashcode() {
+  uword Hash() {
     if (hash_ != 0) return hash_;
     uint32_t hash = 0;
     hash = CombineHashes(hash, spill_slot_bit_count_);
@@ -555,7 +555,7 @@
 
   static Key KeyOf(Pair kv) { return kv.key; }
   static Value ValueOf(Pair kv) { return kv.value; }
-  static intptr_t Hashcode(Key key) { return key->Hashcode(); }
+  static uword Hash(Key key) { return key->Hash(); }
   static bool IsKeyEqual(Pair kv, Key key) { return key->Equals(kv.key); }
 };
 
@@ -739,7 +739,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Length(); }
+  static inline uword Hash(Key key) { return Utils::WordHash(key->Length()); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->Equals(*key);
@@ -786,7 +786,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->CanonicalizeHash(); }
+  static inline uword Hash(Key key) { return key->CanonicalizeHash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->CanonicalizeEquals(*key);
@@ -876,7 +876,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hashcode(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->Equals(*key);
@@ -951,9 +951,9 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) {
+  static inline uword Hash(Key key) {
     ASSERT(!key->IsNull());
-    return key->Length();
+    return Utils::WordHash(key->Length());
   }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
@@ -1001,9 +1001,9 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) {
+  static inline uword Hash(Key key) {
     ASSERT(!key->IsNull());
-    return key->Length();
+    return Utils::WordHash(key->Length());
   }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
@@ -1125,7 +1125,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+  static inline uword Hash(Key key) { return key->Hash(); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     return pair->Equals(*key);
@@ -1157,7 +1157,7 @@
 
   static Value ValueOf(Pair kv) { return kv; }
 
-  static inline intptr_t Hashcode(Key key) { return key->Size(); }
+  static inline uword Hash(Key key) { return Utils::WordHash(key->Size()); }
 
   static inline bool IsKeyEqual(Pair pair, Key key) {
     // In AOT, disabled code objects should not be considered for deduplication.
diff --git a/runtime/vm/raw_object_fields.h b/runtime/vm/raw_object_fields.h
index 54a7a27..2b456be8 100644
--- a/runtime/vm/raw_object_fields.h
+++ b/runtime/vm/raw_object_fields.h
@@ -51,7 +51,9 @@
 
     static Value ValueOf(Pair pair) { return pair.value; }
     static Key KeyOf(Pair pair) { return pair.key; }
-    static size_t Hashcode(Key key) { return key.first ^ key.second; }
+    static uword Hash(Key key) {
+      return Utils::WordHash(key.first ^ key.second);
+    }
     static bool IsKeyEqual(Pair x, Key y) {
       return x.key.first == y.first && x.key.second == y.second;
     }
diff --git a/runtime/vm/source_report.h b/runtime/vm/source_report.h
index 08f0441..a7acf00 100644
--- a/runtime/vm/source_report.h
+++ b/runtime/vm/source_report.h
@@ -105,7 +105,7 @@
 
     static Value ValueOf(Pair kv) { return kv; }
 
-    static inline intptr_t Hashcode(Key key) { return key->key->Hash(); }
+    static inline uword Hash(Key key) { return key->key->Hash(); }
 
     static inline bool IsKeyEqual(Pair kv, Key key) {
       return kv->script->ptr() == key->script->ptr();
diff --git a/runtime/vm/token_position.cc b/runtime/vm/token_position.cc
index 507a528..14f7058 100644
--- a/runtime/vm/token_position.cc
+++ b/runtime/vm/token_position.cc
@@ -4,14 +4,13 @@
 
 #include "vm/token_position.h"
 
-#include "vm/hash.h"
 #include "vm/object.h"
 #include "vm/zone_text_buffer.h"
 
 namespace dart {
 
-intptr_t TokenPosition::Hash() const {
-  return FinalizeHash(value_, 31);
+uword TokenPosition::Hash() const {
+  return Utils::WordHash(value_);
 }
 
 TokenPosition TokenPosition::Deserialize(int32_t value) {
diff --git a/runtime/vm/token_position.h b/runtime/vm/token_position.h
index d15553e..8dcf100 100644
--- a/runtime/vm/token_position.h
+++ b/runtime/vm/token_position.h
@@ -61,7 +61,7 @@
 // by the profiler.
 class TokenPosition {
  public:
-  intptr_t Hash() const;
+  uword Hash() const;
 
   // Returns whether the token positions are equal.  Defined for all token
   // positions.
diff --git a/runtime/vm/type_testing_stubs.h b/runtime/vm/type_testing_stubs.h
index 848ae1a..d8307b8 100644
--- a/runtime/vm/type_testing_stubs.h
+++ b/runtime/vm/type_testing_stubs.h
@@ -287,7 +287,7 @@
 
     static Key KeyOf(Pair kv) { return kv; }
     static Value ValueOf(Pair kv) { return kv; }
-    static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+    static inline uword Hash(Key key) { return key->Hash(); }
   };
 
   class TypeSetTrait : public ObjectSetTrait<const AbstractType> {
diff --git a/runtime/vm/v8_snapshot_writer.h b/runtime/vm/v8_snapshot_writer.h
index 3fc3e61..5778d59 100644
--- a/runtime/vm/v8_snapshot_writer.h
+++ b/runtime/vm/v8_snapshot_writer.h
@@ -31,7 +31,7 @@
 
   static Key KeyOf(Pair pair) { return pair.key; }
 
-  static size_t Hashcode(Key key) { return String::Hash(key, strlen(key)); }
+  static uword Hash(Key key) { return String::Hash(key, strlen(key)); }
 
   static bool IsKeyEqual(Pair x, Key y) { return strcmp(x.key, y) == 0; }
 };
@@ -234,7 +234,7 @@
 
     static Value ValueOf(const Pair& pair) { return pair; }
 
-    static size_t Hashcode(Key key) { return NodeIdFor(key); }
+    static uword Hash(Key key) { return Utils::WordHash(NodeIdFor(key)); }
 
     static bool IsKeyEqual(const Pair& x, Key y) { return x.id == y; }
   };