src/hotspot/share/gc/shared/gcConfig.cpp
changeset 49923 764aea6237ad
parent 49922 3a64eea72624
child 49982 9042ffe5b7fe
child 56508 f67f588ebf15
--- a/src/hotspot/share/gc/shared/gcConfig.cpp	Mon Apr 30 12:19:53 2018 +0200
+++ b/src/hotspot/share/gc/shared/gcConfig.cpp	Mon Apr 30 12:19:55 2018 +0200
@@ -63,6 +63,9 @@
 #endif // INCLUDE_ALL_GCS
 };
 
+#define FOR_EACH_SUPPORTED_GC(var) \
+  for (const SupportedGC* var = &SupportedGCs[0]; var < &SupportedGCs[ARRAY_SIZE(SupportedGCs)]; var++)
+
 GCArguments* GCConfig::_arguments = NULL;
 bool GCConfig::_gc_selected_ergonomically = false;
 
@@ -83,8 +86,8 @@
 }
 
 bool GCConfig::is_no_gc_selected() {
-  for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
-    if (SupportedGCs[i]._flag) {
+  FOR_EACH_SUPPORTED_GC(gc) {
+    if (gc->_flag) {
       return false;
     }
   }
@@ -95,11 +98,11 @@
 bool GCConfig::is_exactly_one_gc_selected() {
   CollectedHeap::Name selected = CollectedHeap::None;
 
-  for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
-    if (SupportedGCs[i]._flag) {
-      if (SupportedGCs[i]._name == selected || selected == CollectedHeap::None) {
+  FOR_EACH_SUPPORTED_GC(gc) {
+    if (gc->_flag) {
+      if (gc->_name == selected || selected == CollectedHeap::None) {
         // Selected
-        selected = SupportedGCs[i]._name;
+        selected = gc->_name;
       } else {
         // More than one selected
         return false;
@@ -127,9 +130,9 @@
 
   if (is_exactly_one_gc_selected()) {
     // Exacly one GC selected
-    for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
-      if (SupportedGCs[i]._flag) {
-        return &SupportedGCs[i]._arguments;
+    FOR_EACH_SUPPORTED_GC(gc) {
+      if (gc->_flag) {
+        return &gc->_arguments;
       }
     }
   }
@@ -146,8 +149,8 @@
 }
 
 bool GCConfig::is_gc_supported(CollectedHeap::Name name) {
-  for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
-    if (SupportedGCs[i]._name == name) {
+  FOR_EACH_SUPPORTED_GC(gc) {
+    if (gc->_name == name) {
       // Supported
       return true;
     }
@@ -158,8 +161,8 @@
 }
 
 bool GCConfig::is_gc_selected(CollectedHeap::Name name) {
-  for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
-    if (SupportedGCs[i]._name == name && SupportedGCs[i]._flag) {
+  FOR_EACH_SUPPORTED_GC(gc) {
+    if (gc->_name == name && gc->_flag) {
       // Selected
       return true;
     }
@@ -176,9 +179,9 @@
 const char* GCConfig::hs_err_name() {
   if (is_exactly_one_gc_selected()) {
     // Exacly one GC selected
-    for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
-      if (SupportedGCs[i]._flag) {
-        return SupportedGCs[i]._hs_err_name;
+    FOR_EACH_SUPPORTED_GC(gc) {
+      if (gc->_flag) {
+        return gc->_hs_err_name;
       }
     }
   }