< prev index next >

src/hotspot/share/gc/shared/gcConfig.cpp

Print this page




  46 
  47 static SerialArguments   serialArguments;
  48 #if INCLUDE_ALL_GCS
  49 static ParallelArguments parallelArguments;
  50 static CMSArguments      cmsArguments;
  51 static G1Arguments       g1Arguments;
  52 #endif // INCLUDE_ALL_GCS
  53 
  54 // Table of supported GCs, for translating between command
  55 // line flag, CollectedHeap::Name and GCArguments instance.
  56 static const SupportedGC SupportedGCs[] = {
  57   SupportedGC(UseSerialGC,        CollectedHeap::Serial,   serialArguments,   "serialgc"  ),
  58 #if INCLUDE_ALL_GCS
  59   SupportedGC(UseParallelGC,      CollectedHeap::Parallel, parallelArguments, "parallelgc"),
  60   SupportedGC(UseParallelOldGC,   CollectedHeap::Parallel, parallelArguments, "parallelgc"),
  61   SupportedGC(UseConcMarkSweepGC, CollectedHeap::CMS,      cmsArguments,      "cmsgc"     ),
  62   SupportedGC(UseG1GC,            CollectedHeap::G1,       g1Arguments,       "g1gc"      ),
  63 #endif // INCLUDE_ALL_GCS
  64 };
  65 



  66 GCArguments* GCConfig::_arguments = NULL;
  67 bool GCConfig::_gc_selected_ergonomically = false;
  68 
  69 void GCConfig::select_gc_ergonomically() {
  70 #if INCLUDE_ALL_GCS
  71   if (os::is_server_class_machine()) {
  72     FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
  73   } else {
  74     FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
  75   }
  76 #else
  77   UNSUPPORTED_OPTION(UseG1GC);
  78   UNSUPPORTED_OPTION(UseParallelGC);
  79   UNSUPPORTED_OPTION(UseParallelOldGC);
  80   UNSUPPORTED_OPTION(UseConcMarkSweepGC);
  81   FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
  82 #endif // INCLUDE_ALL_GCS
  83 }
  84 
  85 bool GCConfig::is_no_gc_selected() {
  86   for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
  87     if (SupportedGCs[i]._flag) {
  88       return false;
  89     }
  90   }
  91 
  92   return true;
  93 }
  94 
  95 bool GCConfig::is_exactly_one_gc_selected() {
  96   CollectedHeap::Name selected = CollectedHeap::None;
  97 
  98   for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
  99     if (SupportedGCs[i]._flag) {
 100       if (SupportedGCs[i]._name == selected || selected == CollectedHeap::None) {
 101         // Selected
 102         selected = SupportedGCs[i]._name;
 103       } else {
 104         // More than one selected
 105         return false;
 106       }
 107     }
 108   }
 109 
 110   return selected != CollectedHeap::None;
 111 }
 112 
 113 GCArguments* GCConfig::select_gc() {
 114   if (is_no_gc_selected()) {
 115     // Try select GC ergonomically
 116     select_gc_ergonomically();
 117 
 118     if (is_no_gc_selected()) {
 119       // Failed to select GC ergonomically
 120       vm_exit_during_initialization("Garbage collector not selected "
 121                                     "(default collector explicitly disabled)", NULL);
 122     }
 123 
 124     // Succeeded to select GC ergonomically
 125     _gc_selected_ergonomically = true;
 126   }
 127 
 128   if (is_exactly_one_gc_selected()) {
 129     // Exacly one GC selected
 130     for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
 131       if (SupportedGCs[i]._flag) {
 132         return &SupportedGCs[i]._arguments;
 133       }
 134     }
 135   }
 136 
 137   // More than one GC selected
 138   vm_exit_during_initialization("Multiple garbage collectors selected", NULL);
 139 
 140   return NULL;
 141 }
 142 
 143 void GCConfig::initialize() {
 144   assert(_arguments == NULL, "Already initialized");
 145   _arguments = select_gc();
 146 }
 147 
 148 bool GCConfig::is_gc_supported(CollectedHeap::Name name) {
 149   for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
 150     if (SupportedGCs[i]._name == name) {
 151       // Supported
 152       return true;
 153     }
 154   }
 155 
 156   // Not supported
 157   return false;
 158 }
 159 
 160 bool GCConfig::is_gc_selected(CollectedHeap::Name name) {
 161   for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
 162     if (SupportedGCs[i]._name == name && SupportedGCs[i]._flag) {
 163       // Selected
 164       return true;
 165     }
 166   }
 167 
 168   // Not selected
 169   return false;
 170 }
 171 
 172 bool GCConfig::is_gc_selected_ergonomically() {
 173   return _gc_selected_ergonomically;
 174 }
 175 
 176 const char* GCConfig::hs_err_name() {
 177   if (is_exactly_one_gc_selected()) {
 178     // Exacly one GC selected
 179     for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
 180       if (SupportedGCs[i]._flag) {
 181         return SupportedGCs[i]._hs_err_name;
 182       }
 183     }
 184   }
 185 
 186   // Zero or more than one GC selected
 187   return "<unknown gc>";
 188 }
 189 
 190 GCArguments* GCConfig::arguments() {
 191   assert(_arguments != NULL, "Not initialized");
 192   return _arguments;
 193 }


  46 
  47 static SerialArguments   serialArguments;
  48 #if INCLUDE_ALL_GCS
  49 static ParallelArguments parallelArguments;
  50 static CMSArguments      cmsArguments;
  51 static G1Arguments       g1Arguments;
  52 #endif // INCLUDE_ALL_GCS
  53 
  54 // Table of supported GCs, for translating between command
  55 // line flag, CollectedHeap::Name and GCArguments instance.
  56 static const SupportedGC SupportedGCs[] = {
  57   SupportedGC(UseSerialGC,        CollectedHeap::Serial,   serialArguments,   "serialgc"  ),
  58 #if INCLUDE_ALL_GCS
  59   SupportedGC(UseParallelGC,      CollectedHeap::Parallel, parallelArguments, "parallelgc"),
  60   SupportedGC(UseParallelOldGC,   CollectedHeap::Parallel, parallelArguments, "parallelgc"),
  61   SupportedGC(UseConcMarkSweepGC, CollectedHeap::CMS,      cmsArguments,      "cmsgc"     ),
  62   SupportedGC(UseG1GC,            CollectedHeap::G1,       g1Arguments,       "g1gc"      ),
  63 #endif // INCLUDE_ALL_GCS
  64 };
  65 
  66 #define FOR_EACH_SUPPORTED_GC(var) \
  67   for (const SupportedGC* var = &SupportedGCs[0]; var < &SupportedGCs[ARRAY_SIZE(SupportedGCs)]; var++)
  68 
  69 GCArguments* GCConfig::_arguments = NULL;
  70 bool GCConfig::_gc_selected_ergonomically = false;
  71 
  72 void GCConfig::select_gc_ergonomically() {
  73 #if INCLUDE_ALL_GCS
  74   if (os::is_server_class_machine()) {
  75     FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
  76   } else {
  77     FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
  78   }
  79 #else
  80   UNSUPPORTED_OPTION(UseG1GC);
  81   UNSUPPORTED_OPTION(UseParallelGC);
  82   UNSUPPORTED_OPTION(UseParallelOldGC);
  83   UNSUPPORTED_OPTION(UseConcMarkSweepGC);
  84   FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
  85 #endif // INCLUDE_ALL_GCS
  86 }
  87 
  88 bool GCConfig::is_no_gc_selected() {
  89   FOR_EACH_SUPPORTED_GC(gc) {
  90     if (gc->_flag) {
  91       return false;
  92     }
  93   }
  94 
  95   return true;
  96 }
  97 
  98 bool GCConfig::is_exactly_one_gc_selected() {
  99   CollectedHeap::Name selected = CollectedHeap::None;
 100 
 101   FOR_EACH_SUPPORTED_GC(gc) {
 102     if (gc->_flag) {
 103       if (gc->_name == selected || selected == CollectedHeap::None) {
 104         // Selected
 105         selected = gc->_name;
 106       } else {
 107         // More than one selected
 108         return false;
 109       }
 110     }
 111   }
 112 
 113   return selected != CollectedHeap::None;
 114 }
 115 
 116 GCArguments* GCConfig::select_gc() {
 117   if (is_no_gc_selected()) {
 118     // Try select GC ergonomically
 119     select_gc_ergonomically();
 120 
 121     if (is_no_gc_selected()) {
 122       // Failed to select GC ergonomically
 123       vm_exit_during_initialization("Garbage collector not selected "
 124                                     "(default collector explicitly disabled)", NULL);
 125     }
 126 
 127     // Succeeded to select GC ergonomically
 128     _gc_selected_ergonomically = true;
 129   }
 130 
 131   if (is_exactly_one_gc_selected()) {
 132     // Exacly one GC selected
 133     FOR_EACH_SUPPORTED_GC(gc) {
 134       if (gc->_flag) {
 135         return &gc->_arguments;
 136       }
 137     }
 138   }
 139 
 140   // More than one GC selected
 141   vm_exit_during_initialization("Multiple garbage collectors selected", NULL);
 142 
 143   return NULL;
 144 }
 145 
 146 void GCConfig::initialize() {
 147   assert(_arguments == NULL, "Already initialized");
 148   _arguments = select_gc();
 149 }
 150 
 151 bool GCConfig::is_gc_supported(CollectedHeap::Name name) {
 152   FOR_EACH_SUPPORTED_GC(gc) {
 153     if (gc->_name == name) {
 154       // Supported
 155       return true;
 156     }
 157   }
 158 
 159   // Not supported
 160   return false;
 161 }
 162 
 163 bool GCConfig::is_gc_selected(CollectedHeap::Name name) {
 164   FOR_EACH_SUPPORTED_GC(gc) {
 165     if (gc->_name == name && gc->_flag) {
 166       // Selected
 167       return true;
 168     }
 169   }
 170 
 171   // Not selected
 172   return false;
 173 }
 174 
 175 bool GCConfig::is_gc_selected_ergonomically() {
 176   return _gc_selected_ergonomically;
 177 }
 178 
 179 const char* GCConfig::hs_err_name() {
 180   if (is_exactly_one_gc_selected()) {
 181     // Exacly one GC selected
 182     FOR_EACH_SUPPORTED_GC(gc) {
 183       if (gc->_flag) {
 184         return gc->_hs_err_name;
 185       }
 186     }
 187   }
 188 
 189   // Zero or more than one GC selected
 190   return "<unknown gc>";
 191 }
 192 
 193 GCArguments* GCConfig::arguments() {
 194   assert(_arguments != NULL, "Not initialized");
 195   return _arguments;
 196 }
< prev index next >