Refactor atomic integer.
Refactored atomic integer to be similar to c++11 std::atomic<int>.
Removed jdwp serial lock and reverted lock level name change from
https://googleplex-android-review.googlesource.com/#/c/327297/
Change-Id: I2229f30c4d5762a0e8c72697d6aca4683750af35
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index eae1520..fe0b740 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -580,7 +580,7 @@
VerifyObject(obj);
if (measure_allocation_time_) {
- total_allocation_time_ += NanoTime() / kTimeAdjust - allocation_start;
+ total_allocation_time_.fetch_add(NanoTime() / kTimeAdjust - allocation_start);
}
return obj;
@@ -729,7 +729,7 @@
void Heap::RecordAllocation(size_t size, mirror::Object* obj) {
DCHECK(obj != NULL);
DCHECK_GT(size, 0u);
- num_bytes_allocated_ += size;
+ num_bytes_allocated_.fetch_add(size);
if (Runtime::Current()->HasStatsEnabled()) {
RuntimeStats* thread_stats = Thread::Current()->GetStats();
@@ -751,7 +751,7 @@
void Heap::RecordFree(size_t freed_objects, size_t freed_bytes) {
DCHECK_LE(freed_bytes, static_cast<size_t>(num_bytes_allocated_));
- num_bytes_allocated_ -= freed_bytes;
+ num_bytes_allocated_.fetch_sub(freed_bytes);
if (Runtime::Current()->HasStatsEnabled()) {
RuntimeStats* thread_stats = Thread::Current()->GetStats();
@@ -1984,7 +1984,7 @@
void Heap::RegisterNativeAllocation(int bytes) {
// Total number of native bytes allocated.
- native_bytes_allocated_ += bytes;
+ native_bytes_allocated_.fetch_add(bytes);
Thread* self = Thread::Current();
if (static_cast<size_t>(native_bytes_allocated_) > native_footprint_gc_watermark_) {
// The second watermark is higher than the gc watermark. If you hit this it means you are
@@ -2027,14 +2027,14 @@
void Heap::RegisterNativeFree(int bytes) {
int expected_size, new_size;
do {
- expected_size = native_bytes_allocated_.get();
+ expected_size = native_bytes_allocated_.load();
new_size = expected_size - bytes;
if (new_size < 0) {
ThrowRuntimeException("attempted to free %d native bytes with only %d native bytes registered as allocated",
bytes, expected_size);
break;
}
- } while (!native_bytes_allocated_.CompareAndSwap(expected_size, new_size));
+ } while (!native_bytes_allocated_.compare_and_swap(expected_size, new_size));
}
} // namespace gc