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

Issue 2912863006: Inline instance object hash code into object header on 64 bit. (Closed)

Created:
3 years, 6 months ago by erikcorry
Modified:
3 years, 6 months ago
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Inline instance object hash code into object header on 64 bit. 64 bit objects have 32 bits of free space in the header word. This is used for the hash code in string objects. We take it for the default hash code on all objects that don't override the hashCode getter. This is both faster and a memory reduction. Eg it shaves about 70% off the running time of this microbenchmark: List list = []; class Thing { get hashCode => 42; } class Thing2 { get hashCode => 42; } class Thing3 { } class Thing4 { } main() { int sum = 103; for (int i = 0; i < 10000000; i++) { list = []; list.add("foo"); list.add(123); list.add(1.23); list.add(new Object()); list.add(new Thing()); list.add(new Thing2()); list.add(new Thing3()); list.add(new Thing4()); for (int j = 0; j < 2; j++) { sum ^= biz(list); } } print(sum); } int biz(List list) { int sum = 103; for (var x in list) { sum ^= x.hashCode; } return sum; } R=rmacnak@google.com, vegorov@google.com BUG= Committed: https://github.com/dart-lang/sdk/commit/ac6310d5f30af5a338207a9948565096ac47c4a5

Patch Set 1 #

Total comments: 2

Patch Set 2 : Teach intrinsifier about _getHash and _setHash #

Patch Set 3 : Use visitor to give objects in VM isolate hash codes. #

Total comments: 7

Patch Set 4 : Use 32 bit atomic operations for tags on 64 bit platforms #

Patch Set 5 : Feedback from Slava #

Patch Set 6 : Bug fixes #

Total comments: 14

Patch Set 7 : Add assembler tests and other feedback from Ryan #

Unified diffs Side-by-side diffs Delta from patch set Stats (+493 lines, -147 lines) Patch
M runtime/lib/object.cc View 1 chunk +9 lines, -1 line 0 comments Download
M runtime/lib/object_patch.dart View 1 2 2 chunks +7 lines, -8 lines 0 comments Download
M runtime/vm/assembler_arm.cc View 1 2 3 2 chunks +2 lines, -2 lines 0 comments Download
M runtime/vm/assembler_arm64.h View 1 2 3 2 chunks +9 lines, -6 lines 0 comments Download
M runtime/vm/assembler_arm64.cc View 1 2 3 2 chunks +6 lines, -2 lines 0 comments Download
M runtime/vm/assembler_arm64_test.cc View 1 2 3 4 5 6 1 chunk +62 lines, -0 lines 0 comments Download
M runtime/vm/assembler_ia32.cc View 1 2 3 2 chunks +2 lines, -2 lines 0 comments Download
M runtime/vm/assembler_mips.cc View 1 2 3 2 chunks +2 lines, -2 lines 0 comments Download
M runtime/vm/assembler_x64.h View 1 2 3 2 chunks +5 lines, -8 lines 0 comments Download
M runtime/vm/assembler_x64.cc View 1 2 3 2 chunks +6 lines, -2 lines 0 comments Download
M runtime/vm/assembler_x64_test.cc View 1 2 3 4 5 6 3 chunks +43 lines, -2 lines 0 comments Download
M runtime/vm/become.h View 1 2 3 4 5 6 1 chunk +4 lines, -1 line 0 comments Download
M runtime/vm/become.cc View 1 2 3 2 chunks +5 lines, -1 line 0 comments Download
M runtime/vm/clustered_snapshot.cc View 1 2 3 1 chunk +4 lines, -1 line 0 comments Download
M runtime/vm/freelist.h View 1 2 3 1 chunk +4 lines, -1 line 0 comments Download
M runtime/vm/freelist.cc View 1 2 3 1 chunk +6 lines, -1 line 0 comments Download
M runtime/vm/heap.h View 1 2 3 4 3 chunks +10 lines, -1 line 0 comments Download
M runtime/vm/heap.cc View 1 chunk +2 lines, -1 line 0 comments Download
M runtime/vm/intermediate_language_dbc.cc View 1 2 3 3 chunks +3 lines, -1 line 0 comments Download
M runtime/vm/intrinsifier_arm64.cc View 1 1 chunk +17 lines, -0 lines 0 comments Download
M runtime/vm/intrinsifier_x64.cc View 1 1 chunk +17 lines, -0 lines 0 comments Download
M runtime/vm/method_recognizer.h View 1 2 chunks +14 lines, -1 line 0 comments Download
M runtime/vm/object.h View 1 2 3 3 chunks +8 lines, -12 lines 0 comments Download
M runtime/vm/object.cc View 1 2 3 4 5 6 13 chunks +86 lines, -24 lines 0 comments Download
M runtime/vm/profiler.cc View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M runtime/vm/raw_object.h View 1 2 3 4 5 17 chunks +56 lines, -31 lines 0 comments Download
M runtime/vm/raw_object.cc View 1 2 3 6 chunks +7 lines, -7 lines 0 comments Download
M runtime/vm/simulator_arm64.h View 1 2 3 1 chunk +3 lines, -0 lines 0 comments Download
M runtime/vm/simulator_arm64.cc View 1 2 3 3 chunks +39 lines, -9 lines 0 comments Download
M runtime/vm/simulator_dbc.cc View 1 2 3 5 chunks +7 lines, -1 line 0 comments Download
M runtime/vm/snapshot.h View 1 2 3 4 5 1 chunk +2 lines, -1 line 0 comments Download
M runtime/vm/snapshot.cc View 1 2 3 4 5 7 chunks +26 lines, -4 lines 0 comments Download
M runtime/vm/stub_code_arm.cc View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M runtime/vm/stub_code_arm64.cc View 1 2 3 3 chunks +7 lines, -4 lines 0 comments Download
M runtime/vm/stub_code_ia32.cc View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M runtime/vm/stub_code_mips.cc View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M runtime/vm/stub_code_x64.cc View 1 2 3 2 chunks +9 lines, -6 lines 0 comments Download

Messages

Total messages: 16 (3 generated)
erikcorry
3 years, 6 months ago (2017-05-30 14:19:04 UTC) #1
Vyacheslav Egorov (Google)
https://codereview.chromium.org/2912863006/diff/1/runtime/vm/object.cc File runtime/vm/object.cc (right): https://codereview.chromium.org/2912863006/diff/1/runtime/vm/object.cc#newcode914 runtime/vm/object.cc:914: #if defined(HASH_IN_OBJECT_HEADER) How do we make sure that this ...
3 years, 6 months ago (2017-05-30 15:25:00 UTC) #2
erikcorry
https://codereview.chromium.org/2912863006/diff/1/runtime/vm/object.cc File runtime/vm/object.cc (right): https://codereview.chromium.org/2912863006/diff/1/runtime/vm/object.cc#newcode914 runtime/vm/object.cc:914: #if defined(HASH_IN_OBJECT_HEADER) On 2017/05/30 15:25:00, Vyacheslav Egorov (Google) wrote: ...
3 years, 6 months ago (2017-06-02 15:34:04 UTC) #4
Vyacheslav Egorov (Google)
lgtm https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/heap.h File runtime/vm/heap.h (right): https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/heap.h#newcode36 runtime/vm/heap.h:36: #if defined(HASH_IN_OBJECT_HEADER) maybe instead enum WeakSelector { #if ...
3 years, 6 months ago (2017-06-07 06:21:15 UTC) #5
rmacnak
https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/intrinsifier_arm64.cc File runtime/vm/intrinsifier_arm64.cc (right): https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/intrinsifier_arm64.cc#newcode1847 runtime/vm/intrinsifier_arm64.cc:1847: __ str(R1, FieldAddress(R0, String::hash_offset()), kUnsignedWord); These intrinsics and their ...
3 years, 6 months ago (2017-06-13 00:17:53 UTC) #7
Vyacheslav Egorov (Google)
https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/intrinsifier_arm64.cc File runtime/vm/intrinsifier_arm64.cc (right): https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/intrinsifier_arm64.cc#newcode1847 runtime/vm/intrinsifier_arm64.cc:1847: __ str(R1, FieldAddress(R0, String::hash_offset()), kUnsignedWord); On 2017/06/13 00:17:52, rmacnak ...
3 years, 6 months ago (2017-06-13 06:12:25 UTC) #8
erikcorry
This CL is ready for another look https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/heap.h File runtime/vm/heap.h (right): https://codereview.chromium.org/2912863006/diff/40001/runtime/vm/heap.h#newcode36 runtime/vm/heap.h:36: #if defined(HASH_IN_OBJECT_HEADER) ...
3 years, 6 months ago (2017-06-16 09:26:39 UTC) #9
rmacnak
lgtm w/ assembler tests https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/assembler_arm64.h File runtime/vm/assembler_arm64.h (right): https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/assembler_arm64.h#newcode745 runtime/vm/assembler_arm64.h:745: void ldxr(Register rt, Register rn, ...
3 years, 6 months ago (2017-06-19 18:12:22 UTC) #10
erikcorry
https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/raw_object.h File runtime/vm/raw_object.h (right): https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/raw_object.h#newcode1289 runtime/vm/raw_object.h:1289: // uword so that the variable length data is ...
3 years, 6 months ago (2017-06-19 18:42:33 UTC) #11
erikcorry
https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/assembler_arm64.h File runtime/vm/assembler_arm64.h (right): https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/assembler_arm64.h#newcode745 runtime/vm/assembler_arm64.h:745: void ldxr(Register rt, Register rn, OperandSize size = kDoubleWord) ...
3 years, 6 months ago (2017-06-21 12:12:12 UTC) #12
erikcorry
Committed patchset #7 (id:120001) manually as ac6310d5f30af5a338207a9948565096ac47c4a5 (presubmit successful).
3 years, 6 months ago (2017-06-22 07:25:59 UTC) #14
Vyacheslav Egorov (Google)
DBC https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/object.cc File runtime/vm/object.cc (right): https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/object.cc#newcode1036 runtime/vm/object.cc:1036: int counter_; On 2017/06/21 12:12:12, erikcorry wrote: > ...
3 years, 6 months ago (2017-06-22 07:30:46 UTC) #15
erikcorry
3 years, 6 months ago (2017-06-22 08:00:53 UTC) #16
Message was sent while issue was closed.
https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/object.cc
File runtime/vm/object.cc (right):

https://codereview.chromium.org/2912863006/diff/100001/runtime/vm/object.cc#n...
runtime/vm/object.cc:1036: int counter_;
On 2017/06/22 07:30:46, Vyacheslav Egorov (Google) wrote:
> On 2017/06/21 12:12:12, erikcorry wrote:
> > On 2017/06/19 18:12:21, rmacnak wrote:
> > > intptr_t
> > 
> > We are storing it into a 32 bit field, and it may not be 0.  If I make this
an
> > intptr_t then it could be 0x100000000 which is not zero, but then it would
be
> > zero when stored.  So leaving as is.
> 
> We mask it before storing so it can't be 0x100000000.
> 
> Also if you make assumptions about the size of the variable you need to use a
> type with explicit size uint32_t because int can be anything (4, 8 byte etc)

Oh yeah, good point about the masking.

In this case we really don't care what size the counter is, but I get that the
VM has a historical bias against the 'int' type (which is 4 bytes on all but the
most obscure platforms that we don't support anyway).

Fixed in https://codereview.chromium.org/2948153003

Powered by Google App Engine
This is Rietveld 408576698