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

Issue 529823002: - Add AtomicOperations::CompareAndSwapWord (Closed)

Created:
6 years, 3 months ago by Ivan Posva
Modified:
6 years, 3 months ago
Reviewers:
koda
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Visibility:
Public.

Description

- Add AtomicOperations::CompareAndSwapWord - Make AtomicOperations inlineable. - Use atomic tag word updates from C++ where necessary. Committed: https://code.google.com/p/dart/source/detail?r=39731

Patch Set 1 #

Patch Set 2 : #

Total comments: 9
Unified diffs Side-by-side diffs Delta from patch set Stats (+265 lines, -176 lines) Patch
M runtime/vm/atomic.h View 2 chunks +16 lines, -0 lines 0 comments Download
A + runtime/vm/atomic_android.h View 2 chunks +16 lines, -4 lines 0 comments Download
D runtime/vm/atomic_android.cc View 1 chunk +0 lines, -20 lines 0 comments Download
A + runtime/vm/atomic_linux.h View 1 chunk +17 lines, -6 lines 0 comments Download
D runtime/vm/atomic_linux.cc View 1 chunk +0 lines, -21 lines 0 comments Download
A + runtime/vm/atomic_macos.h View 1 chunk +17 lines, -5 lines 0 comments Download
D runtime/vm/atomic_macos.cc View 1 chunk +0 lines, -20 lines 0 comments Download
A + runtime/vm/atomic_win.h View 2 chunks +29 lines, -6 lines 0 comments Download
D runtime/vm/atomic_win.cc View 1 chunk +0 lines, -28 lines 0 comments Download
M runtime/vm/object.h View 1 chunk +10 lines, -3 lines 1 comment Download
M runtime/vm/object.cc View 9 chunks +74 lines, -36 lines 5 comments Download
M runtime/vm/raw_object.h View 4 chunks +36 lines, -5 lines 1 comment Download
M runtime/vm/snapshot.h View 4 chunks +8 lines, -6 lines 0 comments Download
M runtime/vm/snapshot.cc View 8 chunks +35 lines, -12 lines 2 comments Download
M runtime/vm/stub_code_ia32.cc View 1 chunk +3 lines, -0 lines 0 comments Download
M runtime/vm/vm_sources.gypi View 1 chunk +4 lines, -4 lines 0 comments Download

Messages

Total messages: 4 (1 generated)
Ivan Posva
6 years, 3 months ago (2014-09-01 18:18:17 UTC) #2
Ivan Posva
Committed patchset #2 (id:20001) manually as r39731 (presubmit successful).
6 years, 3 months ago (2014-09-01 18:18:55 UTC) #3
koda
6 years, 3 months ago (2014-09-02 04:18:32 UTC) #4
Message was sent while issue was closed.
https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.cc
File runtime/vm/object.cc (right):

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.cc#new...
runtime/vm/object.cc:801: // Make unused space in an object whose type has been
transformed safe
Update comment to reflect that this method must now be called *before* updating
the tags of the original object. Also consider ASSERTing that the size of obj,
as obtained from decoding its tags, is still original_size.

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.cc#new...
runtime/vm/object.cc:823: // TODO(iposva): Investigate whether
CompareAndSwapWord is necessary.
As long as this update happens strictly before the tags/size update of the
original object (see comment above), I don't think CAS is needed here.

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.cc#new...
runtime/vm/object.cc:17222: // If there is any left over space fill it with
either an Array object or
is -> will be

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.cc#new...
runtime/vm/object.cc:17261: // If there is any left over space fill it with
either an Array object or
Ditto.

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.cc#new...
runtime/vm/object.cc:18191: // If there is any left over space fill it with
either an Array object or
Ditto.

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.h
File runtime/vm/object.h (right):

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/object.h#newc...
runtime/vm/object.h:235: // here only allows for canonical and from_snapshot
flags to be set.
Before masking (i.e., ignoring part of the input...), please assert that the old
and new tag value only differ on those flags:
ASSERT(((value ^ tags) & ~static_cast<uword>(0xc)) == 0);

Also, please put 0x0...c into a uword-typed local constant and file an issue for
the TODO.

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/raw_object.h
File runtime/vm/raw_object.h (right):

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/raw_object.h#...
runtime/vm/raw_object.h:336: uword new_tags = MarkBit::update(false, old_tags);
All five changes in this file (and probably some in the other files too) can be
handled by a single template method:

template<typename BitFieldType, typename ValueType>
void RawObject::AtomicUpdateTagField(ValueType new_value) {
  uword tags = ptr()->tags_;
  uword old_tags;
  do {
    old_tags = tags;
    uword new_tags = BitFieldType::update(new_value, old_tags);
    tags = AtomicOperations::CompareAndSwapWord(
        &ptr()->tags_, old_tags, new_tags);
  } while (tags != old_tags);
}

void ClearMarkBit() {
  ASSERT(IsMarked()); 
  AtomicUpdateTagField<MarkBit, bool>(false);
}

etc.

I think this is safer than copy-pasting, especially for synchronization code,
which I find notoriously bug-prone.

Also consider forcing inlining of these methods.

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/snapshot.cc
File runtime/vm/snapshot.cc (right):

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/snapshot.cc#n...
runtime/vm/snapshot.cc:1306: // The ForwardList encodes information in the
header tag word. There cannot
cannot -> must not?

I.e., are you saying that this is already guaranteed by other code, or that you
will enforce this using the code below? Seems like the latter to me.

https://codereview.chromium.org/529823002/diff/20001/runtime/vm/snapshot.cc#n...
runtime/vm/snapshot.cc:1313: page_space->set_tasks(1);
Do you consider this an actual "task", or are you just (ab)using the task count
to block sweeper tasks from spawning?  Why not add a NoGCScope?

Powered by Google App Engine
This is Rietveld 408576698