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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/vm/assembler_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 int _getHash(obj) native "Object_getHash";
6 int _setHash(obj, hash) native "Object_setHash";
7
5 @patch 8 @patch
6 class Object { 9 class Object {
7 // The VM has its own implementation of equals. 10 // The VM has its own implementation of equals.
8 @patch 11 @patch
9 bool operator ==(other) native "Object_equals"; 12 bool operator ==(other) native "Object_equals";
10 13
11 // Helpers used to implement hashCode. If a hashCode is used, we remember it 14 // Helpers used to implement hashCode. If a hashCode is used, we remember it
12 // in a weak table in the VM. A new hashCode value is calculated using a 15 // in a weak table in the VM (32 bit) or in the header of the object (64
13 // number generator. 16 // bit). A new hashCode value is calculated using a random number generator.
14 static final _hashCodeRnd = new Random(); 17 static final _hashCodeRnd = new Random();
15 18
16 static _getHash(obj) native "Object_getHash";
17 static _setHash(obj, hash) native "Object_setHash";
18
19 // Shared static implentation for hashCode and _identityHashCode. 19 // Shared static implentation for hashCode and _identityHashCode.
20 static int _objectHashCode(obj) { 20 static int _objectHashCode(obj) {
21 var result = _getHash(obj); 21 var result = _getHash(obj);
22 if (result == 0) { 22 if (result == 0) {
23 // We want the hash to be a Smi value greater than 0. 23 // We want the hash to be a Smi value greater than 0.
24 result = _hashCodeRnd.nextInt(0x40000000); 24 do {
25 while (result == 0) {
26 result = _hashCodeRnd.nextInt(0x40000000); 25 result = _hashCodeRnd.nextInt(0x40000000);
27 } 26 } while (result == 0);
28 _setHash(obj, result); 27 _setHash(obj, result);
29 } 28 }
30 return result; 29 return result;
31 } 30 }
32 31
33 @patch 32 @patch
34 int get hashCode => _objectHashCode(this); 33 int get hashCode => _objectHashCode(this);
35 int get _identityHashCode => _objectHashCode(this); 34 int get _identityHashCode => _objectHashCode(this);
36 35
37 @patch 36 @patch
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 native "Object_as"; 72 native "Object_as";
74 73
75 static _symbolMapToStringMap(Map<Symbol, dynamic> map) { 74 static _symbolMapToStringMap(Map<Symbol, dynamic> map) {
76 var result = new Map<String, dynamic>(); 75 var result = new Map<String, dynamic>();
77 map.forEach((Symbol key, value) { 76 map.forEach((Symbol key, value) {
78 result[internal.Symbol.getName(key)] = value; 77 result[internal.Symbol.getName(key)] = value;
79 }); 78 });
80 return result; 79 return result;
81 } 80 }
82 } 81 }
OLDNEW
« 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