< prev index next >

src/hotspot/share/gc/g1/g1MonitoringSupport.hpp

Print this page

        

@@ -172,10 +172,25 @@
   size_t _survivor_space_committed;
   size_t _survivor_space_used;
 
   size_t _old_gen_used;
 
+  // It returns x - y if x > y, 0 otherwise.
+  // As described in the comment above, some of the inputs to the
+  // calculations we have to do are obtained concurrently and hence
+  // may be inconsistent with each other. So, this provides a
+  // defensive way of performing the subtraction and avoids the value
+  // going negative (which would mean a very large result, given that
+  // the parameter are size_t).
+  static size_t subtract_up_to_zero(size_t x, size_t y) {
+    if (x > y) {
+      return x - y;
+    } else {
+      return 0;
+    }
+  }
+
   // Recalculate all the sizes.
   void recalculate_sizes();
 
   void recalculate_eden_size();
 
< prev index next >