8203262: Incorrect cmpxchg usage in MetaspaceGC::inc_capacity_until_GC
authortschatzl
Mon, 28 May 2018 12:10:18 +0200
changeset 50283 2f9811d99ba8
parent 50281 bc1336220671
child 50284 274b2806c34c
8203262: Incorrect cmpxchg usage in MetaspaceGC::inc_capacity_until_GC Reviewed-by: pliden, shade
src/hotspot/share/memory/metaspace.cpp
--- a/src/hotspot/share/memory/metaspace.cpp	Mon May 28 11:13:21 2018 +0200
+++ b/src/hotspot/share/memory/metaspace.cpp	Mon May 28 12:10:18 2018 +0200
@@ -132,18 +132,17 @@
 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
   assert_is_aligned(v, Metaspace::commit_alignment());
 
-  size_t capacity_until_GC = _capacity_until_GC;
-  size_t new_value = capacity_until_GC + v;
+  size_t old_capacity_until_GC = _capacity_until_GC;
+  size_t new_value = old_capacity_until_GC + v;
 
-  if (new_value < capacity_until_GC) {
+  if (new_value < old_capacity_until_GC) {
     // The addition wrapped around, set new_value to aligned max value.
     new_value = align_down(max_uintx, Metaspace::commit_alignment());
   }
 
-  size_t expected = _capacity_until_GC;
-  size_t actual = Atomic::cmpxchg(new_value, &_capacity_until_GC, expected);
+  size_t prev_value = Atomic::cmpxchg(new_value, &_capacity_until_GC, old_capacity_until_GC);
 
-  if (expected != actual) {
+  if (old_capacity_until_GC != prev_value) {
     return false;
   }
 
@@ -151,7 +150,7 @@
     *new_cap_until_GC = new_value;
   }
   if (old_cap_until_GC != NULL) {
-    *old_cap_until_GC = capacity_until_GC;
+    *old_cap_until_GC = old_capacity_until_GC;
   }
   return true;
 }