src/hotspot/share/gc/shared/gcConfig.cpp
author pliden
Tue, 12 Jun 2018 17:40:28 +0200
changeset 50525 767cdb97f103
parent 50523 7b7c75d87f9b
child 50629 645a5962201d
permissions -rw-r--r--
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental) Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke Contributed-by: per.liden@oracle.com, stefan.karlsson@oracle.com, erik.osterlund@oracle.com, mikael.gerdin@oracle.com, kim.barrett@oracle.com, nils.eliasson@oracle.com, rickard.backman@oracle.com, rwestrel@redhat.com, coleen.phillimore@oracle.com, robbin.ehn@oracle.com, gerard.ziemski@oracle.com, hugh.wilkinson@intel.com, sandhya.viswanathan@intel.com, bill.npo.wheeler@intel.com, vinay.k.awasthi@intel.com, yasuenag@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     1
/*
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     4
 *
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     8
 *
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    13
 * accompanied this code).
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    14
 *
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    18
 *
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    21
 * questions.
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    22
 *
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    23
 */
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    24
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    25
#include "precompiled.hpp"
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    26
#include "gc/shared/gcConfig.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    27
#include "runtime/globals_extension.hpp"
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    28
#include "runtime/java.hpp"
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    29
#include "runtime/os.hpp"
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    30
#include "utilities/macros.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    31
#if INCLUDE_CMSGC
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    32
#include "gc/cms/cmsArguments.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    33
#endif
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 49982
diff changeset
    34
#if INCLUDE_EPSILONGC
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 49982
diff changeset
    35
#include "gc/epsilon/epsilonArguments.hpp"
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 49982
diff changeset
    36
#endif
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    37
#if INCLUDE_G1GC
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    38
#include "gc/g1/g1Arguments.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    39
#endif
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    40
#if INCLUDE_PARALLELGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    41
#include "gc/parallel/parallelArguments.hpp"
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    42
#endif
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    43
#if INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    44
#include "gc/serial/serialArguments.hpp"
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    45
#endif
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
    46
#if INCLUDE_ZGC
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
    47
#include "gc/z/zArguments.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
    48
#endif
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    49
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    50
struct SupportedGC {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    51
  bool&               _flag;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    52
  CollectedHeap::Name _name;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    53
  GCArguments&        _arguments;
49922
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
    54
  const char*         _hs_err_name;
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    55
49922
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
    56
  SupportedGC(bool& flag, CollectedHeap::Name name, GCArguments& arguments, const char* hs_err_name) :
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
    57
      _flag(flag), _name(name), _arguments(arguments), _hs_err_name(hs_err_name) {}
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    58
};
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    59
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    60
     CMSGC_ONLY(static CMSArguments      cmsArguments;)
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 49982
diff changeset
    61
 EPSILONGC_ONLY(static EpsilonArguments  epsilonArguments;)
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    62
      G1GC_ONLY(static G1Arguments       g1Arguments;)
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    63
PARALLELGC_ONLY(static ParallelArguments parallelArguments;)
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    64
  SERIALGC_ONLY(static SerialArguments   serialArguments;)
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
    65
       ZGC_ONLY(static ZArguments        zArguments;)
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    66
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    67
// Table of supported GCs, for translating between command
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    68
// line flag, CollectedHeap::Name and GCArguments instance.
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    69
static const SupportedGC SupportedGCs[] = {
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    70
       CMSGC_ONLY_ARG(SupportedGC(UseConcMarkSweepGC, CollectedHeap::CMS,      cmsArguments,      "concurrent mark sweep gc"))
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 49982
diff changeset
    71
   EPSILONGC_ONLY_ARG(SupportedGC(UseEpsilonGC,       CollectedHeap::Epsilon,  epsilonArguments,  "epsilon gc"))
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    72
        G1GC_ONLY_ARG(SupportedGC(UseG1GC,            CollectedHeap::G1,       g1Arguments,       "g1 gc"))
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    73
  PARALLELGC_ONLY_ARG(SupportedGC(UseParallelGC,      CollectedHeap::Parallel, parallelArguments, "parallel gc"))
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    74
  PARALLELGC_ONLY_ARG(SupportedGC(UseParallelOldGC,   CollectedHeap::Parallel, parallelArguments, "parallel gc"))
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    75
    SERIALGC_ONLY_ARG(SupportedGC(UseSerialGC,        CollectedHeap::Serial,   serialArguments,   "serial gc"))
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
    76
         ZGC_ONLY_ARG(SupportedGC(UseZGC,             CollectedHeap::Z,        zArguments,        "z gc"))
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    77
};
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    78
49923
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
    79
#define FOR_EACH_SUPPORTED_GC(var) \
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
    80
  for (const SupportedGC* var = &SupportedGCs[0]; var < &SupportedGCs[ARRAY_SIZE(SupportedGCs)]; var++)
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
    81
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    82
GCArguments* GCConfig::_arguments = NULL;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    83
bool GCConfig::_gc_selected_ergonomically = false;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    84
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    85
void GCConfig::select_gc_ergonomically() {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    86
  if (os::is_server_class_machine()) {
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    87
#if INCLUDE_G1GC
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    88
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    89
#elif INCLUDE_PARALLELGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    90
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseParallelGC, true);
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    91
#elif INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    92
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    93
#endif
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    94
  } else {
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    95
#if INCLUDE_SERIALGC
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    96
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    97
#endif
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
    98
  }
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
    99
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   100
  NOT_CMSGC(     UNSUPPORTED_OPTION(UseConcMarkSweepGC));
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 49982
diff changeset
   101
  NOT_EPSILONGC( UNSUPPORTED_OPTION(UseEpsilonGC);)
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   102
  NOT_G1GC(      UNSUPPORTED_OPTION(UseG1GC);)
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   103
  NOT_PARALLELGC(UNSUPPORTED_OPTION(UseParallelGC);)
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   104
  NOT_PARALLELGC(UNSUPPORTED_OPTION(UseParallelOldGC));
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   105
  NOT_SERIALGC(  UNSUPPORTED_OPTION(UseSerialGC);)
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
   106
  NOT_ZGC(       UNSUPPORTED_OPTION(UseZGC);)
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   107
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   108
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   109
bool GCConfig::is_no_gc_selected() {
49923
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   110
  FOR_EACH_SUPPORTED_GC(gc) {
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   111
    if (gc->_flag) {
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   112
      return false;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   113
    }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   114
  }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   115
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   116
  return true;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   117
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   118
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   119
bool GCConfig::is_exactly_one_gc_selected() {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   120
  CollectedHeap::Name selected = CollectedHeap::None;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   121
49923
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   122
  FOR_EACH_SUPPORTED_GC(gc) {
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   123
    if (gc->_flag) {
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   124
      if (gc->_name == selected || selected == CollectedHeap::None) {
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   125
        // Selected
49923
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   126
        selected = gc->_name;
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   127
      } else {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   128
        // More than one selected
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   129
        return false;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   130
      }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   131
    }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   132
  }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   133
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   134
  return selected != CollectedHeap::None;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   135
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   136
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   137
GCArguments* GCConfig::select_gc() {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   138
  if (is_no_gc_selected()) {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   139
    // Try select GC ergonomically
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   140
    select_gc_ergonomically();
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   141
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   142
    if (is_no_gc_selected()) {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   143
      // Failed to select GC ergonomically
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   144
      vm_exit_during_initialization("Garbage collector not selected "
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   145
                                    "(default collector explicitly disabled)", NULL);
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   146
    }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   147
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   148
    // Succeeded to select GC ergonomically
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   149
    _gc_selected_ergonomically = true;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   150
  }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   151
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   152
  if (!is_exactly_one_gc_selected()) {
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   153
    // More than one GC selected
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   154
    vm_exit_during_initialization("Multiple garbage collectors selected", NULL);
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   155
  }
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   156
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   157
#if INCLUDE_PARALLELGC && !INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   158
  if (FLAG_IS_CMDLINE(UseParallelOldGC) && !UseParallelOldGC) {
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   159
    vm_exit_during_initialization("This JVM build only supports UseParallelOldGC as the full GC");
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   160
  }
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   161
#endif
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   162
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   163
  // Exactly one GC selected
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   164
  FOR_EACH_SUPPORTED_GC(gc) {
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   165
    if (gc->_flag) {
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   166
      return &gc->_arguments;
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   167
    }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   168
  }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   169
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49923
diff changeset
   170
  fatal("Should have found the selected GC");
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   171
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   172
  return NULL;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   173
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   174
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   175
void GCConfig::initialize() {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   176
  assert(_arguments == NULL, "Already initialized");
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   177
  _arguments = select_gc();
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   178
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   179
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   180
bool GCConfig::is_gc_supported(CollectedHeap::Name name) {
49923
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   181
  FOR_EACH_SUPPORTED_GC(gc) {
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   182
    if (gc->_name == name) {
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   183
      // Supported
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   184
      return true;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   185
    }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   186
  }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   187
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   188
  // Not supported
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   189
  return false;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   190
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   191
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   192
bool GCConfig::is_gc_selected(CollectedHeap::Name name) {
49923
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   193
  FOR_EACH_SUPPORTED_GC(gc) {
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   194
    if (gc->_name == name && gc->_flag) {
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   195
      // Selected
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   196
      return true;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   197
    }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   198
  }
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   199
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   200
  // Not selected
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   201
  return false;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   202
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   203
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   204
bool GCConfig::is_gc_selected_ergonomically() {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   205
  return _gc_selected_ergonomically;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   206
}
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   207
49922
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   208
const char* GCConfig::hs_err_name() {
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   209
  if (is_exactly_one_gc_selected()) {
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   210
    // Exacly one GC selected
49923
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   211
    FOR_EACH_SUPPORTED_GC(gc) {
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   212
      if (gc->_flag) {
764aea6237ad 8202366: Add macro for common loop in GCConfig
pliden
parents: 49922
diff changeset
   213
        return gc->_hs_err_name;
49922
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   214
      }
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   215
    }
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   216
  }
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   217
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   218
  // Zero or more than one GC selected
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   219
  return "unknown gc";
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   220
}
3a64eea72624 8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
pliden
parents: 49629
diff changeset
   221
49629
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   222
GCArguments* GCConfig::arguments() {
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   223
  assert(_arguments != NULL, "Not initialized");
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   224
  return _arguments;
b786280276dc 8199925: Break out GC selection logic from GCArguments to GCConfig
pliden
parents:
diff changeset
   225
}