changeset 23523:75f522e33395

8037295: Add size_t versions of Atomic::add, dec, and inc Reviewed-by: dholmes, fparain Contributed-by: david.simms@oracle.com
author mgronlun
date Tue, 01 Apr 2014 15:45:36 +0200
parents 217a6a90aad3
children 338d8d86560e 1a6ab02cf5ca
files hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp hotspot/src/share/vm/runtime/atomic.hpp hotspot/src/share/vm/runtime/atomic.inline.hpp
diffstat 3 files changed, 26 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp	Tue Apr 01 03:59:01 2014 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp	Tue Apr 01 15:45:36 2014 +0200
@@ -245,7 +245,7 @@
 
   enum ParIterState { Unclaimed, Claimed, Complete };
   volatile ParIterState _iter_state;
-  volatile jlong _iter_claimed;
+  volatile size_t _iter_claimed;
 
   // Unused unless G1RecordHRRSOops is true.
 
@@ -319,16 +319,12 @@
   bool iter_is_complete();
 
   // Support for claiming blocks of cards during iteration
-  size_t iter_claimed() const { return (size_t)_iter_claimed; }
+  size_t iter_claimed() const { return _iter_claimed; }
   // Claim the next block of cards
   size_t iter_claimed_next(size_t step) {
-    size_t current, next;
-    do {
-      current = iter_claimed();
-      next = current + step;
-    } while (Atomic::cmpxchg((jlong)next, &_iter_claimed, (jlong)current) != (jlong)current);
-    return current;
+    return Atomic::add(step, &_iter_claimed) - step;
   }
+
   void reset_for_par_iteration();
 
   bool verify_ready_for_par_iteration() {
--- a/hotspot/src/share/vm/runtime/atomic.hpp	Tue Apr 01 03:59:01 2014 -0700
+++ b/hotspot/src/share/vm/runtime/atomic.hpp	Tue Apr 01 15:45:36 2014 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -57,6 +57,7 @@
 
   // Atomically add to a location, return updated value
   inline static jint     add    (jint     add_value, volatile jint*     dest);
+  inline static size_t   add    (size_t   add_value, volatile size_t*   dest);
   inline static intptr_t add_ptr(intptr_t add_value, volatile intptr_t* dest);
   inline static void*    add_ptr(intptr_t add_value, volatile void*     dest);
   // See comment above about using jlong atomics on 32-bit platforms
@@ -65,12 +66,14 @@
   // Atomically increment location
   inline static void inc    (volatile jint*     dest);
          static void inc    (volatile jshort*   dest);
+  inline static void inc    (volatile size_t*   dest);
   inline static void inc_ptr(volatile intptr_t* dest);
   inline static void inc_ptr(volatile void*     dest);
 
   // Atomically decrement a location
   inline static void dec    (volatile jint*     dest);
          static void dec    (volatile jshort*    dest);
+  inline static void dec    (volatile size_t*   dest);
   inline static void dec_ptr(volatile intptr_t* dest);
   inline static void dec_ptr(volatile void*     dest);
 
--- a/hotspot/src/share/vm/runtime/atomic.inline.hpp	Tue Apr 01 03:59:01 2014 -0700
+++ b/hotspot/src/share/vm/runtime/atomic.inline.hpp	Tue Apr 01 15:45:36 2014 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -70,4 +70,21 @@
 # include "atomic_bsd_zero.inline.hpp"
 #endif
 
+// size_t casts...
+#if (SIZE_MAX != UINTPTR_MAX)
+#error size_t is not WORD_SIZE, interesting platform, but missing implementation here
+#endif
+
+inline size_t Atomic::add(size_t add_value, volatile size_t* dest) {
+  return (size_t) add_ptr((intptr_t) add_value, (volatile intptr_t*) dest);
+}
+
+inline void Atomic::inc(volatile size_t* dest) {
+  inc_ptr((volatile intptr_t*) dest);
+}
+
+inline void Atomic::dec(volatile size_t* dest) {
+  dec_ptr((volatile intptr_t*) dest);
+}
+
 #endif // SHARE_VM_RUNTIME_ATOMIC_INLINE_HPP