1 /*
   2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "jvmci/jvmci_globals.hpp"
  28 #include "gc/shared/gcConfig.hpp"
  29 #include "utilities/defaultStream.hpp"
  30 #include "utilities/ostream.hpp"
  31 #include "runtime/globals_extension.hpp"
  32 
  33 fileStream* JVMCIGlobals::_jni_config_file = NULL;
  34 
  35 JVMCI_FLAGS(MATERIALIZE_DEVELOPER_FLAG, \
  36             MATERIALIZE_PD_DEVELOPER_FLAG, \
  37             MATERIALIZE_PRODUCT_FLAG, \
  38             MATERIALIZE_PD_PRODUCT_FLAG, \
  39             MATERIALIZE_DIAGNOSTIC_FLAG, \
  40             MATERIALIZE_PD_DIAGNOSTIC_FLAG, \
  41             MATERIALIZE_EXPERIMENTAL_FLAG, \
  42             MATERIALIZE_NOTPRODUCT_FLAG,
  43             IGNORE_RANGE, \
  44             IGNORE_CONSTRAINT, \
  45             IGNORE_WRITEABLE)
  46 
  47 // Return true if jvmci flags are consistent.
  48 bool JVMCIGlobals::check_jvmci_flags_are_consistent() {
  49 
  50 #ifndef PRODUCT
  51 #define APPLY_JVMCI_FLAGS(params3, params4) \
  52   JVMCI_FLAGS(params4, params3, params4, params3, params4, params3, params4, params4, IGNORE_RANGE, IGNORE_CONSTRAINT, IGNORE_WRITEABLE)
  53 #define JVMCI_DECLARE_CHECK4(type, name, value, doc) bool name##checked = false;
  54 #define JVMCI_DECLARE_CHECK3(type, name, doc)        bool name##checked = false;
  55 #define JVMCI_FLAG_CHECKED(name)                          name##checked = true;
  56   APPLY_JVMCI_FLAGS(JVMCI_DECLARE_CHECK3, JVMCI_DECLARE_CHECK4)
  57 #else
  58 #define JVMCI_FLAG_CHECKED(name)
  59 #endif
  60 
  61   // Checks that a given flag is not set if a given guard flag is false.
  62 #define CHECK_NOT_SET(FLAG, GUARD)                     \
  63   JVMCI_FLAG_CHECKED(FLAG)                             \
  64   if (!GUARD && !FLAG_IS_DEFAULT(FLAG)) {              \
  65     jio_fprintf(defaultStream::error_stream(),         \
  66         "Improperly specified VM option '%s': '%s' must be enabled\n", #FLAG, #GUARD); \
  67     return false;                                      \
  68   }
  69 
  70   JVMCI_FLAG_CHECKED(UseJVMCICompiler)
  71   JVMCI_FLAG_CHECKED(EnableJVMCI)
  72 
  73   CHECK_NOT_SET(BootstrapJVMCI,   UseJVMCICompiler)
  74   CHECK_NOT_SET(PrintBootstrap,   UseJVMCICompiler)
  75   CHECK_NOT_SET(JVMCIThreads,     UseJVMCICompiler)
  76   CHECK_NOT_SET(JVMCIHostThreads, UseJVMCICompiler)
  77 
  78   if (UseJVMCICompiler) {
  79     if (!FLAG_IS_DEFAULT(EnableJVMCI) && !EnableJVMCI) {
  80       jio_fprintf(defaultStream::error_stream(),
  81           "Improperly specified VM option UseJVMCICompiler: EnableJVMCI cannot be disabled\n");
  82       return false;
  83     }
  84     FLAG_SET_DEFAULT(EnableJVMCI, true);
  85     if (BootstrapJVMCI && UseJVMCINativeLibrary) {
  86       jio_fprintf(defaultStream::error_stream(), "-XX:+BootstrapJVMCI is not compatible with -XX:+UseJVMCINativeLibrary\n");
  87       return false;
  88     }
  89   }
  90 
  91   if (!EnableJVMCI) {
  92     // Switch off eager JVMCI initialization if JVMCI is disabled.
  93     // Don't throw error if EagerJVMCI is set to allow testing.
  94     if (EagerJVMCI) {
  95       FLAG_SET_DEFAULT(EagerJVMCI, false);
  96     }
  97   }
  98   JVMCI_FLAG_CHECKED(EagerJVMCI)
  99 
 100   CHECK_NOT_SET(JVMCITraceLevel,              EnableJVMCI)
 101   CHECK_NOT_SET(JVMCICounterSize,             EnableJVMCI)
 102   CHECK_NOT_SET(JVMCICountersExcludeCompiler, EnableJVMCI)
 103   CHECK_NOT_SET(JVMCIUseFastLocking,          EnableJVMCI)
 104   CHECK_NOT_SET(JVMCINMethodSizeLimit,        EnableJVMCI)
 105   CHECK_NOT_SET(MethodProfileWidth,           EnableJVMCI)
 106   CHECK_NOT_SET(JVMCIPrintProperties,         EnableJVMCI)
 107   CHECK_NOT_SET(UseJVMCINativeLibrary,        EnableJVMCI)
 108   CHECK_NOT_SET(JVMCILibPath,                 EnableJVMCI)
 109   CHECK_NOT_SET(JVMCILibDumpJNIConfig,        EnableJVMCI)
 110 
 111 #ifndef PRODUCT
 112 #define JVMCI_CHECK4(type, name, value, doc) assert(name##checked, #name " flag not checked");
 113 #define JVMCI_CHECK3(type, name, doc)        assert(name##checked, #name " flag not checked");
 114   // Ensures that all JVMCI flags are checked by this method.
 115   APPLY_JVMCI_FLAGS(JVMCI_CHECK3, JVMCI_CHECK4)
 116 #undef APPLY_JVMCI_FLAGS
 117 #undef JVMCI_DECLARE_CHECK3
 118 #undef JVMCI_DECLARE_CHECK4
 119 #undef JVMCI_CHECK3
 120 #undef JVMCI_CHECK4
 121 #undef JVMCI_FLAG_CHECKED
 122 #endif // PRODUCT
 123 #undef CHECK_NOT_SET
 124 
 125   if (JVMCILibDumpJNIConfig != NULL) {
 126     _jni_config_file = new(ResourceObj::C_HEAP, mtJVMCI) fileStream(JVMCILibDumpJNIConfig);
 127     if (_jni_config_file == NULL || !_jni_config_file->is_open()) {
 128       jio_fprintf(defaultStream::error_stream(),
 129           "Could not open file for dumping JVMCI shared library JNI config: %s\n", JVMCILibDumpJNIConfig);
 130       return false;
 131     }
 132   }
 133 
 134   return true;
 135 }
 136 
 137 void JVMCIGlobals::check_jvmci_supported_gc() {
 138   if (EnableJVMCI) {
 139     // Check if selected GC is supported by JVMCI and Java compiler
 140     if (!(UseSerialGC || UseParallelGC || UseParallelOldGC || UseG1GC)) {
 141       vm_exit_during_initialization("JVMCI Compiler does not support selected GC", GCConfig::hs_err_name());
 142       FLAG_SET_DEFAULT(EnableJVMCI, false);
 143       FLAG_SET_DEFAULT(UseJVMCICompiler, false);
 144     }
 145   }
 146 }