8026852: Use restricted_align_down in collector policy code
authorjwilhelm
Mon, 21 Oct 2013 18:52:13 +0200
changeset 21559 c5421f5c6ffd
parent 21558 8dcd5451cdca
child 21560 b3ae3ba25ebb
8026852: Use restricted_align_down in collector policy code Summary: Moved restricted_align_down to globalDefinitions and renamed it align_size_down_bounded Reviewed-by: stefank, mgerdin, tschatzl
hotspot/src/share/vm/memory/collectorPolicy.cpp
hotspot/src/share/vm/memory/metaspace.cpp
hotspot/src/share/vm/utilities/globalDefinitions.hpp
--- a/hotspot/src/share/vm/memory/collectorPolicy.cpp	Mon Oct 21 18:51:37 2013 +0200
+++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp	Mon Oct 21 18:52:13 2013 +0200
@@ -146,11 +146,7 @@
 // GenCollectorPolicy methods.
 
 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
-  size_t x = base_size / (NewRatio+1);
-  size_t new_gen_size = x > _min_alignment ?
-                     align_size_down(x, _min_alignment) :
-                     _min_alignment;
-  return new_gen_size;
+  return align_size_down_bounded(base_size / (NewRatio + 1), _min_alignment);
 }
 
 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
@@ -410,15 +406,11 @@
     if ((heap_size < (*gen0_size_ptr + min_gen1_size)) &&
         (heap_size >= min_gen1_size + _min_alignment)) {
       // Adjust gen0 down to accommodate min_gen1_size
-      *gen0_size_ptr = heap_size - min_gen1_size;
-      *gen0_size_ptr =
-        MAX2((uintx)align_size_down(*gen0_size_ptr, _min_alignment), _min_alignment);
+      *gen0_size_ptr = align_size_down_bounded(heap_size - min_gen1_size, _min_alignment);
       assert(*gen0_size_ptr > 0, "Min gen0 is too large");
       result = true;
     } else {
-      *gen1_size_ptr = heap_size - *gen0_size_ptr;
-      *gen1_size_ptr =
-        MAX2((uintx)align_size_down(*gen1_size_ptr, _min_alignment), _min_alignment);
+      *gen1_size_ptr = align_size_down_bounded(heap_size - *gen0_size_ptr, _min_alignment);
     }
   }
   return result;
--- a/hotspot/src/share/vm/memory/metaspace.cpp	Mon Oct 21 18:51:37 2013 +0200
+++ b/hotspot/src/share/vm/memory/metaspace.cpp	Mon Oct 21 18:52:13 2013 +0200
@@ -2965,11 +2965,6 @@
 
 #endif
 
-// Align down. If the aligning result in 0, return 'alignment'.
-static size_t restricted_align_down(size_t size, size_t alignment) {
-  return MAX2(alignment, align_size_down_(size, alignment));
-}
-
 void Metaspace::ergo_initialize() {
   if (DumpSharedSpaces) {
     // Using large pages when dumping the shared archive is currently not implemented.
@@ -2992,13 +2987,13 @@
   // Ideally, we would be able to set the default value of MaxMetaspaceSize in
   // globals.hpp to the aligned value, but this is not possible, since the
   // alignment depends on other flags being parsed.
-  MaxMetaspaceSize = restricted_align_down(MaxMetaspaceSize, _reserve_alignment);
+  MaxMetaspaceSize = align_size_down_bounded(MaxMetaspaceSize, _reserve_alignment);
 
   if (MetaspaceSize > MaxMetaspaceSize) {
     MetaspaceSize = MaxMetaspaceSize;
   }
 
-  MetaspaceSize = restricted_align_down(MetaspaceSize, _commit_alignment);
+  MetaspaceSize = align_size_down_bounded(MetaspaceSize, _commit_alignment);
 
   assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
 
@@ -3006,10 +3001,10 @@
     vm_exit_during_initialization("Too small initial Metaspace size");
   }
 
-  MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, _commit_alignment);
-  MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, _commit_alignment);
-
-  CompressedClassSpaceSize = restricted_align_down(CompressedClassSpaceSize, _reserve_alignment);
+  MinMetaspaceExpansion = align_size_down_bounded(MinMetaspaceExpansion, _commit_alignment);
+  MaxMetaspaceExpansion = align_size_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
+
+  CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
   set_class_metaspace_size(CompressedClassSpaceSize);
 }
 
--- a/hotspot/src/share/vm/utilities/globalDefinitions.hpp	Mon Oct 21 18:51:37 2013 +0200
+++ b/hotspot/src/share/vm/utilities/globalDefinitions.hpp	Mon Oct 21 18:52:13 2013 +0200
@@ -458,6 +458,13 @@
   return (void*) align_size_up_((uintptr_t)addr, size);
 }
 
+// Align down with a lower bound. If the aligning results in 0, return 'alignment'.
+
+inline size_t align_size_down_bounded(size_t size, size_t alignment) {
+  size_t aligned_size = align_size_down_(size, alignment);
+  return aligned_size > 0 ? aligned_size : alignment;
+}
+
 // Clamp an address to be within a specific page
 // 1. If addr is on the page it is returned as is
 // 2. If addr is above the page_address the start of the *next* page will be returned