Path: blob/master/src/hotspot/share/jvmci/jvmci_globals.cpp
40950 views
/*1* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "compiler/compilerDefinitions.hpp"26#include "gc/shared/gcConfig.hpp"27#include "jvm.h"28#include "jvmci/jvmci_globals.hpp"29#include "logging/log.hpp"30#include "runtime/arguments.hpp"31#include "runtime/flags/jvmFlagAccess.hpp"32#include "runtime/globals_extension.hpp"33#include "utilities/defaultStream.hpp"34#include "utilities/ostream.hpp"3536fileStream* JVMCIGlobals::_jni_config_file = NULL;3738// Return true if jvmci flags are consistent.39bool JVMCIGlobals::check_jvmci_flags_are_consistent() {4041#ifndef PRODUCT42#define APPLY_JVMCI_FLAGS(params3, params4) \43JVMCI_FLAGS(params4, params3, params4, params3, params4, IGNORE_RANGE, IGNORE_CONSTRAINT)44#define JVMCI_DECLARE_CHECK4(type, name, value, ...) bool name##checked = false;45#define JVMCI_DECLARE_CHECK3(type, name, ...) bool name##checked = false;46#define JVMCI_FLAG_CHECKED(name) name##checked = true;47APPLY_JVMCI_FLAGS(JVMCI_DECLARE_CHECK3, JVMCI_DECLARE_CHECK4)48#else49#define JVMCI_FLAG_CHECKED(name)50#endif5152// Checks that a given flag is not set if a given guard flag is false.53#define CHECK_NOT_SET(FLAG, GUARD) \54JVMCI_FLAG_CHECKED(FLAG) \55if (!GUARD && !FLAG_IS_DEFAULT(FLAG)) { \56jio_fprintf(defaultStream::error_stream(), \57"Improperly specified VM option '%s': '%s' must be enabled\n", #FLAG, #GUARD); \58return false; \59}6061if (EnableJVMCIProduct) {62if (FLAG_IS_DEFAULT(EnableJVMCI)) {63FLAG_SET_DEFAULT(EnableJVMCI, true);64}65if (EnableJVMCI && FLAG_IS_DEFAULT(UseJVMCICompiler)) {66FLAG_SET_DEFAULT(UseJVMCICompiler, true);67}68}6970JVMCI_FLAG_CHECKED(UseJVMCICompiler)71JVMCI_FLAG_CHECKED(EnableJVMCI)72JVMCI_FLAG_CHECKED(EnableJVMCIProduct)7374CHECK_NOT_SET(BootstrapJVMCI, UseJVMCICompiler)75CHECK_NOT_SET(PrintBootstrap, UseJVMCICompiler)76CHECK_NOT_SET(JVMCIThreads, UseJVMCICompiler)77CHECK_NOT_SET(JVMCIHostThreads, UseJVMCICompiler)7879if (UseJVMCICompiler) {80if (FLAG_IS_DEFAULT(UseJVMCINativeLibrary) && !UseJVMCINativeLibrary) {81char path[JVM_MAXPATHLEN];82if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), JVMCI_SHARED_LIBRARY_NAME)) {83// If a JVMCI native library is present,84// we enable UseJVMCINativeLibrary by default.85FLAG_SET_DEFAULT(UseJVMCINativeLibrary, true);86}87}88if (!FLAG_IS_DEFAULT(EnableJVMCI) && !EnableJVMCI) {89jio_fprintf(defaultStream::error_stream(),90"Improperly specified VM option UseJVMCICompiler: EnableJVMCI cannot be disabled\n");91return false;92}93FLAG_SET_DEFAULT(EnableJVMCI, true);94if (BootstrapJVMCI && UseJVMCINativeLibrary) {95jio_fprintf(defaultStream::error_stream(), "-XX:+BootstrapJVMCI is not compatible with -XX:+UseJVMCINativeLibrary\n");96return false;97}98if (BootstrapJVMCI && (TieredStopAtLevel < CompLevel_full_optimization)) {99jio_fprintf(defaultStream::error_stream(),100"-XX:+BootstrapJVMCI is not compatible with -XX:TieredStopAtLevel=%d\n", TieredStopAtLevel);101return false;102}103}104105if (!EnableJVMCI) {106// Switch off eager JVMCI initialization if JVMCI is disabled.107// Don't throw error if EagerJVMCI is set to allow testing.108if (EagerJVMCI) {109FLAG_SET_DEFAULT(EagerJVMCI, false);110}111}112JVMCI_FLAG_CHECKED(EagerJVMCI)113114CHECK_NOT_SET(JVMCIEventLogLevel, EnableJVMCI)115CHECK_NOT_SET(JVMCITraceLevel, EnableJVMCI)116CHECK_NOT_SET(JVMCICounterSize, EnableJVMCI)117CHECK_NOT_SET(JVMCICountersExcludeCompiler, EnableJVMCI)118CHECK_NOT_SET(JVMCIUseFastLocking, EnableJVMCI)119CHECK_NOT_SET(JVMCINMethodSizeLimit, EnableJVMCI)120CHECK_NOT_SET(JVMCIPrintProperties, EnableJVMCI)121CHECK_NOT_SET(UseJVMCINativeLibrary, EnableJVMCI)122CHECK_NOT_SET(JVMCILibPath, EnableJVMCI)123CHECK_NOT_SET(JVMCILibDumpJNIConfig, EnableJVMCI)124125#ifndef COMPILER2126JVMCI_FLAG_CHECKED(MaxVectorSize)127JVMCI_FLAG_CHECKED(ReduceInitialCardMarks)128JVMCI_FLAG_CHECKED(UseMultiplyToLenIntrinsic)129JVMCI_FLAG_CHECKED(UseSquareToLenIntrinsic)130JVMCI_FLAG_CHECKED(UseMulAddIntrinsic)131JVMCI_FLAG_CHECKED(UseMontgomeryMultiplyIntrinsic)132JVMCI_FLAG_CHECKED(UseMontgomerySquareIntrinsic)133#endif // !COMPILER2134135#ifndef PRODUCT136#define JVMCI_CHECK4(type, name, value, ...) assert(name##checked, #name " flag not checked");137#define JVMCI_CHECK3(type, name, ...) assert(name##checked, #name " flag not checked");138// Ensures that all JVMCI flags are checked by this method.139APPLY_JVMCI_FLAGS(JVMCI_CHECK3, JVMCI_CHECK4)140#undef APPLY_JVMCI_FLAGS141#undef JVMCI_DECLARE_CHECK3142#undef JVMCI_DECLARE_CHECK4143#undef JVMCI_CHECK3144#undef JVMCI_CHECK4145#undef JVMCI_FLAG_CHECKED146#endif // PRODUCT147#undef CHECK_NOT_SET148149if (JVMCILibDumpJNIConfig != NULL) {150_jni_config_file = new(ResourceObj::C_HEAP, mtJVMCI) fileStream(JVMCILibDumpJNIConfig);151if (_jni_config_file == NULL || !_jni_config_file->is_open()) {152jio_fprintf(defaultStream::error_stream(),153"Could not open file for dumping JVMCI shared library JNI config: %s\n", JVMCILibDumpJNIConfig);154return false;155}156}157158return true;159}160161// Convert JVMCI flags from experimental to product162bool JVMCIGlobals::enable_jvmci_product_mode(JVMFlagOrigin origin) {163const char *JVMCIFlags[] = {164"EnableJVMCI",165"EnableJVMCIProduct",166"UseJVMCICompiler",167"JVMCIPrintProperties",168"EagerJVMCI",169"JVMCIThreads",170"JVMCICounterSize",171"JVMCICountersExcludeCompiler",172"JVMCINMethodSizeLimit",173"JVMCIEventLogLevel",174"JVMCITraceLevel",175"JVMCILibPath",176"JVMCILibDumpJNIConfig",177"UseJVMCINativeLibrary",178NULL179};180181for (int i = 0; JVMCIFlags[i] != NULL; i++) {182JVMFlag *jvmciFlag = (JVMFlag *)JVMFlag::find_declared_flag(JVMCIFlags[i]);183if (jvmciFlag == NULL) {184return false;185}186jvmciFlag->clear_experimental();187jvmciFlag->set_product();188}189190bool value = true;191JVMFlag *jvmciEnableFlag = JVMFlag::find_flag("EnableJVMCIProduct");192if (JVMFlagAccess::set_bool(jvmciEnableFlag, &value, origin) != JVMFlag::SUCCESS) {193return false;194}195196// Effect of EnableJVMCIProduct on changing defaults of EnableJVMCI197// and UseJVMCICompiler is deferred to check_jvmci_flags_are_consistent198// so that setting these flags explicitly (e.g. on the command line)199// takes precedence.200201return true;202}203204bool JVMCIGlobals::gc_supports_jvmci() {205return UseSerialGC || UseParallelGC || UseG1GC;206}207208void JVMCIGlobals::check_jvmci_supported_gc() {209if (EnableJVMCI) {210// Check if selected GC is supported by JVMCI and Java compiler211if (!gc_supports_jvmci()) {212log_warning(gc, jvmci)("Setting EnableJVMCI to false as selected GC does not support JVMCI: %s", GCConfig::hs_err_name());213FLAG_SET_DEFAULT(EnableJVMCI, false);214FLAG_SET_DEFAULT(UseJVMCICompiler, false);215}216}217}218219220