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

Unified Diff: runtime/lib/object_patch.dart

Issue 2912863006: Inline instance object hash code into object header on 64 bit. (Closed)
Patch Set: Add assembler tests and other feedback from Ryan Created 3 years, 6 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
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/vm/assembler_arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/object_patch.dart
diff --git a/runtime/lib/object_patch.dart b/runtime/lib/object_patch.dart
index 603911f3ee7034b0895c0baae47e38db80673eda..cd1166c775ca8de641ac0320ad74e264b3b20836 100644
--- a/runtime/lib/object_patch.dart
+++ b/runtime/lib/object_patch.dart
@@ -2,6 +2,9 @@
// 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.
+int _getHash(obj) native "Object_getHash";
+int _setHash(obj, hash) native "Object_setHash";
+
@patch
class Object {
// The VM has its own implementation of equals.
@@ -9,22 +12,18 @@ class Object {
bool operator ==(other) native "Object_equals";
// Helpers used to implement hashCode. If a hashCode is used, we remember it
- // in a weak table in the VM. A new hashCode value is calculated using a
- // number generator.
+ // in a weak table in the VM (32 bit) or in the header of the object (64
+ // bit). A new hashCode value is calculated using a random number generator.
static final _hashCodeRnd = new Random();
- static _getHash(obj) native "Object_getHash";
- static _setHash(obj, hash) native "Object_setHash";
-
// Shared static implentation for hashCode and _identityHashCode.
static int _objectHashCode(obj) {
var result = _getHash(obj);
if (result == 0) {
// We want the hash to be a Smi value greater than 0.
- result = _hashCodeRnd.nextInt(0x40000000);
- while (result == 0) {
+ do {
result = _hashCodeRnd.nextInt(0x40000000);
- }
+ } while (result == 0);
_setHash(obj, result);
}
return result;
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/vm/assembler_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698