mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:10:22 +00:00
83a4d98554
Tighten some sequences in the write barrier stub. Change-Id: Ib3657b9b582082137d17e86135200444172f428a Reviewed-on: https://dart-review.googlesource.com/60820 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
88 lines
2.5 KiB
C++
88 lines
2.5 KiB
C++
// Copyright (c) 2015, 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.
|
|
|
|
#include "platform/atomic.h"
|
|
#include "platform/assert.h"
|
|
#include "platform/utils.h"
|
|
#include "vm/globals.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
VM_UNIT_TEST_CASE(FetchAndIncrement) {
|
|
uintptr_t v = 42;
|
|
EXPECT_EQ(static_cast<uintptr_t>(42),
|
|
AtomicOperations::FetchAndIncrement(&v));
|
|
EXPECT_EQ(static_cast<uintptr_t>(43), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(FetchAndDecrement) {
|
|
uintptr_t v = 42;
|
|
EXPECT_EQ(static_cast<uintptr_t>(42),
|
|
AtomicOperations::FetchAndDecrement(&v));
|
|
EXPECT_EQ(static_cast<uintptr_t>(41), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(FetchAndIncrementSigned) {
|
|
intptr_t v = -42;
|
|
EXPECT_EQ(static_cast<intptr_t>(-42),
|
|
AtomicOperations::FetchAndIncrement(&v));
|
|
EXPECT_EQ(static_cast<intptr_t>(-41), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(FetchAndDecrementSigned) {
|
|
intptr_t v = -42;
|
|
EXPECT_EQ(static_cast<intptr_t>(-42),
|
|
AtomicOperations::FetchAndDecrement(&v));
|
|
EXPECT_EQ(static_cast<intptr_t>(-43), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(IncrementBy) {
|
|
intptr_t v = 42;
|
|
AtomicOperations::IncrementBy(&v, 100);
|
|
EXPECT_EQ(static_cast<intptr_t>(142), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(DecrementBy) {
|
|
intptr_t v = 42;
|
|
AtomicOperations::DecrementBy(&v, 41);
|
|
EXPECT_EQ(static_cast<intptr_t>(1), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(FetchOrRelaxed) {
|
|
uint32_t v = 42;
|
|
uint32_t previous = AtomicOperations::FetchOrRelaxedUint32(&v, 3);
|
|
EXPECT_EQ(static_cast<uint32_t>(42), previous);
|
|
EXPECT_EQ(static_cast<uint32_t>(43), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(FetchAndRelaxed) {
|
|
uint32_t v = 42;
|
|
uint32_t previous = AtomicOperations::FetchAndRelaxedUint32(&v, 3);
|
|
EXPECT_EQ(static_cast<uint32_t>(42), previous);
|
|
EXPECT_EQ(static_cast<uint32_t>(2), v);
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(LoadRelaxed) {
|
|
uword v = 42;
|
|
EXPECT_EQ(static_cast<uword>(42), AtomicOperations::LoadRelaxed(&v));
|
|
}
|
|
|
|
TEST_CASE(CompareAndSwapWord) {
|
|
uword old_value = 42;
|
|
uword new_value = 100;
|
|
uword result =
|
|
AtomicOperations::CompareAndSwapWord(&old_value, old_value, new_value);
|
|
EXPECT_EQ(static_cast<uword>(42), result);
|
|
}
|
|
|
|
TEST_CASE(CompareAndSwapUint32) {
|
|
uint32_t old_value = 42;
|
|
uint32_t new_value = 100;
|
|
uint32_t result =
|
|
AtomicOperations::CompareAndSwapUint32(&old_value, old_value, new_value);
|
|
EXPECT_EQ(static_cast<uint32_t>(42), result);
|
|
}
|
|
|
|
} // namespace dart
|