dart-sdk/runtime/vm/atomic_fuchsia.h
Alexander Markov 5aead50245 [vm] Implement more efficient CAS in simarm/simarm64 modes, v.2
This CL includes db26c89347 (patch set #1)
with fix (patch set #2):
* Include simulator.h explicitly where it is required as it is no
  longer included implicitly through other header files.

Original review: https://codereview.chromium.org/2995803002/

When running on the simulator for arm/arm64, compare-and-swap operations
used in VM were synchronized with simulator using mutex.
It heavily impacts performance when doing parallel marking due to high
contention (see #30317).
This synchronization was implemented in order to make simulated
LDREX/STREX instructions aware of CAS performed in VM.

This CL drops this synchronization between VM and simulator:
CAS operations in VM become regular, and simulator remembers value loaded
with load-exclusive and performs CAS when doing store-exclusive to catch
any concurrent modifications.

Speeds up gen_snapshot of flutter benchmark complex_layout from 9.2s
to 8.0s on my MacBook.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2999853002 .
2017-08-14 11:10:29 -07:00

60 lines
1.9 KiB
C++

// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// 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.
#ifndef RUNTIME_VM_ATOMIC_FUCHSIA_H_
#define RUNTIME_VM_ATOMIC_FUCHSIA_H_
#if !defined RUNTIME_VM_ATOMIC_H_
#error Do not include atomic_fuchsia.h directly. Use atomic.h instead.
#endif
#if !defined(HOST_OS_FUCHSIA)
#error This file should only be included on Fuchsia builds.
#endif
namespace dart {
inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) {
return __sync_fetch_and_add(p, 1);
}
inline intptr_t AtomicOperations::FetchAndIncrement(intptr_t* p) {
return __sync_fetch_and_add(p, 1);
}
inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) {
__sync_fetch_and_add(p, value);
}
inline void AtomicOperations::IncrementInt64By(int64_t* p, int64_t value) {
__sync_fetch_and_add(p, value);
}
inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) {
return __sync_fetch_and_sub(p, 1);
}
inline intptr_t AtomicOperations::FetchAndDecrement(intptr_t* p) {
return __sync_fetch_and_sub(p, 1);
}
inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) {
__sync_fetch_and_sub(p, value);
}
inline uword AtomicOperations::CompareAndSwapWord(uword* ptr,
uword old_value,
uword new_value) {
return __sync_val_compare_and_swap(ptr, old_value, new_value);
}
inline uint32_t AtomicOperations::CompareAndSwapUint32(uint32_t* ptr,
uint32_t old_value,
uint32_t new_value) {
return __sync_val_compare_and_swap(ptr, old_value, new_value);
}
} // namespace dart
#endif // RUNTIME_VM_ATOMIC_FUCHSIA_H_