Path: blob/master/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp
40957 views
/*1* Copyright (c) 2015, 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 "code/relocInfo.hpp"26#include "compiler/compilerDefinitions.hpp"27#include "compiler/compilerDirectives.hpp"28#include "oops/metadata.hpp"29#include "runtime/os.hpp"30#include "interpreter/invocationCounter.hpp"31#include "runtime/arguments.hpp"32#include "runtime/flags/jvmFlag.hpp"33#include "runtime/flags/jvmFlagConstraintsCompiler.hpp"34#include "runtime/globals.hpp"35#include "runtime/globals_extension.hpp"36#include "utilities/powerOfTwo.hpp"3738JVMFlag::Error AliasLevelConstraintFunc(intx value, bool verbose) {39if ((value <= 1) && (Arguments::mode() == Arguments::_comp || Arguments::mode() == Arguments::_mixed)) {40JVMFlag::printError(verbose,41"AliasLevel (" INTX_FORMAT ") is not "42"compatible with -Xcomp or -Xmixed\n",43value);44return JVMFlag::VIOLATES_CONSTRAINT;45} else {46return JVMFlag::SUCCESS;47}48}4950/**51* Validate the minimum number of compiler threads needed to run the JVM.52*/53JVMFlag::Error CICompilerCountConstraintFunc(intx value, bool verbose) {54int min_number_of_compiler_threads = 0;55#if COMPILER1_OR_COMPILER256if (CompilerConfig::is_tiered()) {57min_number_of_compiler_threads = 2;58} else if (!CompilerConfig::is_interpreter_only()) {59min_number_of_compiler_threads = 1;60}61#else62if (value > 0) {63JVMFlag::printError(verbose,64"CICompilerCount (" INTX_FORMAT ") cannot be "65"greater than 0 because there are no compilers\n", value);66return JVMFlag::VIOLATES_CONSTRAINT;67}68#endif6970if (value < (intx)min_number_of_compiler_threads) {71JVMFlag::printError(verbose,72"CICompilerCount (" INTX_FORMAT ") must be "73"at least %d \n",74value, min_number_of_compiler_threads);75return JVMFlag::VIOLATES_CONSTRAINT;76} else {77return JVMFlag::SUCCESS;78}79}8081JVMFlag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) {82if (value < 0 || value > 512) {83JVMFlag::printError(verbose,84"AllocatePrefetchDistance (" INTX_FORMAT ") must be "85"between 0 and %d\n",86AllocatePrefetchDistance, 512);87return JVMFlag::VIOLATES_CONSTRAINT;88}8990return JVMFlag::SUCCESS;91}9293JVMFlag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) {94if (AllocatePrefetchStyle == 3) {95if (value % wordSize != 0) {96JVMFlag::printError(verbose,97"AllocatePrefetchStepSize (" INTX_FORMAT ") must be multiple of %d\n",98value, wordSize);99return JVMFlag::VIOLATES_CONSTRAINT;100}101}102return JVMFlag::SUCCESS;103}104105JVMFlag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) {106intx max_value = max_intx;107#if defined(X86)108max_value = 3;109#endif110if (value < 0 || value > max_value) {111JVMFlag::printError(verbose,112"AllocatePrefetchInstr (" INTX_FORMAT ") must be "113"between 0 and " INTX_FORMAT "\n", value, max_value);114return JVMFlag::VIOLATES_CONSTRAINT;115}116117return JVMFlag::SUCCESS;118}119120JVMFlag::Error CompileThresholdConstraintFunc(intx value, bool verbose) {121if (value < 0 || value > INT_MAX >> InvocationCounter::count_shift) {122JVMFlag::printError(verbose,123"CompileThreshold (" INTX_FORMAT ") "124"must be between 0 and %d\n",125value,126INT_MAX >> InvocationCounter::count_shift);127return JVMFlag::VIOLATES_CONSTRAINT;128}129130return JVMFlag::SUCCESS;131}132133JVMFlag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose) {134// We depend on CompileThreshold being valid, verify it first.135if (CompileThresholdConstraintFunc(CompileThreshold, false) == JVMFlag::VIOLATES_CONSTRAINT) {136JVMFlag::printError(verbose, "OnStackReplacePercentage cannot be validated because CompileThreshold value is invalid\n");137return JVMFlag::VIOLATES_CONSTRAINT;138}139140int64_t max_percentage_limit = INT_MAX;141if (!ProfileInterpreter) {142max_percentage_limit = (max_percentage_limit>>InvocationCounter::count_shift);143}144max_percentage_limit = CompileThreshold == 0 ? max_percentage_limit*100 : max_percentage_limit*100/CompileThreshold;145146if (ProfileInterpreter) {147if (value < InterpreterProfilePercentage) {148JVMFlag::printError(verbose,149"OnStackReplacePercentage (" INTX_FORMAT ") must be "150"larger than InterpreterProfilePercentage (" INTX_FORMAT ")\n",151value, InterpreterProfilePercentage);152return JVMFlag::VIOLATES_CONSTRAINT;153}154155max_percentage_limit += InterpreterProfilePercentage;156if (value > max_percentage_limit) {157JVMFlag::printError(verbose,158"OnStackReplacePercentage (" INTX_FORMAT ") must be between 0 and " INT64_FORMAT "\n",159value,160max_percentage_limit);161return JVMFlag::VIOLATES_CONSTRAINT;162}163} else {164if (value < 0) {165JVMFlag::printError(verbose,166"OnStackReplacePercentage (" INTX_FORMAT ") must be "167"non-negative\n", value);168return JVMFlag::VIOLATES_CONSTRAINT;169}170171if (value > max_percentage_limit) {172JVMFlag::printError(verbose,173"OnStackReplacePercentage (" INTX_FORMAT ") must be between 0 and " INT64_FORMAT "\n",174value,175max_percentage_limit);176return JVMFlag::VIOLATES_CONSTRAINT;177}178}179return JVMFlag::SUCCESS;180}181182JVMFlag::Error CodeCacheSegmentSizeConstraintFunc(uintx value, bool verbose) {183if (CodeCacheSegmentSize < (uintx)CodeEntryAlignment) {184JVMFlag::printError(verbose,185"CodeCacheSegmentSize (" UINTX_FORMAT ") must be "186"larger than or equal to CodeEntryAlignment (" INTX_FORMAT ") "187"to align entry points\n",188CodeCacheSegmentSize, CodeEntryAlignment);189return JVMFlag::VIOLATES_CONSTRAINT;190}191192if (CodeCacheSegmentSize < sizeof(jdouble)) {193JVMFlag::printError(verbose,194"CodeCacheSegmentSize (" UINTX_FORMAT ") must be "195"at least " SIZE_FORMAT " to align constants\n",196CodeCacheSegmentSize, sizeof(jdouble));197return JVMFlag::VIOLATES_CONSTRAINT;198}199200#ifdef COMPILER2201if (CodeCacheSegmentSize < (uintx)OptoLoopAlignment) {202JVMFlag::printError(verbose,203"CodeCacheSegmentSize (" UINTX_FORMAT ") must be "204"larger than or equal to OptoLoopAlignment (" INTX_FORMAT ") "205"to align inner loops\n",206CodeCacheSegmentSize, OptoLoopAlignment);207return JVMFlag::VIOLATES_CONSTRAINT;208}209#endif210211return JVMFlag::SUCCESS;212}213214JVMFlag::Error CodeEntryAlignmentConstraintFunc(intx value, bool verbose) {215if (!is_power_of_2(value)) {216JVMFlag::printError(verbose,217"CodeEntryAlignment (" INTX_FORMAT ") must be "218"a power of two\n", CodeEntryAlignment);219return JVMFlag::VIOLATES_CONSTRAINT;220}221222if (CodeEntryAlignment < 16) {223JVMFlag::printError(verbose,224"CodeEntryAlignment (" INTX_FORMAT ") must be "225"greater than or equal to %d\n",226CodeEntryAlignment, 16);227return JVMFlag::VIOLATES_CONSTRAINT;228}229230return JVMFlag::SUCCESS;231}232233JVMFlag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) {234if (!is_power_of_2(value)) {235JVMFlag::printError(verbose,236"OptoLoopAlignment (" INTX_FORMAT ") "237"must be a power of two\n",238value);239return JVMFlag::VIOLATES_CONSTRAINT;240}241242// Relevant on ppc, s390. Will be optimized where243// addr_unit() == 1.244if (OptoLoopAlignment % relocInfo::addr_unit() != 0) {245JVMFlag::printError(verbose,246"OptoLoopAlignment (" INTX_FORMAT ") must be "247"multiple of NOP size (%d)\n",248value, relocInfo::addr_unit());249return JVMFlag::VIOLATES_CONSTRAINT;250}251252return JVMFlag::SUCCESS;253}254255JVMFlag::Error ArraycopyDstPrefetchDistanceConstraintFunc(uintx value, bool verbose) {256if (value >= 4032) {257JVMFlag::printError(verbose,258"ArraycopyDstPrefetchDistance (" UINTX_FORMAT ") must be"259"between 0 and 4031\n", value);260return JVMFlag::VIOLATES_CONSTRAINT;261}262263return JVMFlag::SUCCESS;264}265266JVMFlag::Error AVX3ThresholdConstraintFunc(int value, bool verbose) {267if (value != 0 && !is_power_of_2(value)) {268JVMFlag::printError(verbose,269"AVX3Threshold ( %d ) must be 0 or "270"a power of two value between 0 and MAX_INT\n", value);271return JVMFlag::VIOLATES_CONSTRAINT;272}273274return JVMFlag::SUCCESS;275}276277JVMFlag::Error ArraycopySrcPrefetchDistanceConstraintFunc(uintx value, bool verbose) {278if (value >= 4032) {279JVMFlag::printError(verbose,280"ArraycopySrcPrefetchDistance (" UINTX_FORMAT ") must be"281"between 0 and 4031\n", value);282return JVMFlag::VIOLATES_CONSTRAINT;283}284285return JVMFlag::SUCCESS;286}287288JVMFlag::Error TypeProfileLevelConstraintFunc(uintx value, bool verbose) {289for (int i = 0; i < 3; i++) {290if (value % 10 > 2) {291JVMFlag::printError(verbose,292"Invalid value (" UINTX_FORMAT ") "293"in TypeProfileLevel at position %d\n", value, i);294return JVMFlag::VIOLATES_CONSTRAINT;295}296value = value / 10;297}298299return JVMFlag::SUCCESS;300}301302JVMFlag::Error InitArrayShortSizeConstraintFunc(intx value, bool verbose) {303if (value % BytesPerLong != 0) {304JVMFlag::printError(verbose,305"InitArrayShortSize (" INTX_FORMAT ") must be "306"a multiple of %d\n", value, BytesPerLong);307return JVMFlag::VIOLATES_CONSTRAINT;308} else {309return JVMFlag::SUCCESS;310}311}312313#ifdef COMPILER2314JVMFlag::Error InteriorEntryAlignmentConstraintFunc(intx value, bool verbose) {315if (InteriorEntryAlignment > CodeEntryAlignment) {316JVMFlag::printError(verbose,317"InteriorEntryAlignment (" INTX_FORMAT ") must be "318"less than or equal to CodeEntryAlignment (" INTX_FORMAT ")\n",319InteriorEntryAlignment, CodeEntryAlignment);320return JVMFlag::VIOLATES_CONSTRAINT;321}322323if (!is_power_of_2(value)) {324JVMFlag::printError(verbose,325"InteriorEntryAlignment (" INTX_FORMAT ") must be "326"a power of two\n", InteriorEntryAlignment);327return JVMFlag::VIOLATES_CONSTRAINT;328}329330int minimum_alignment = 16;331#if defined(X86) && !defined(AMD64)332minimum_alignment = 4;333#elif defined(S390)334minimum_alignment = 2;335#endif336337if (InteriorEntryAlignment < minimum_alignment) {338JVMFlag::printError(verbose,339"InteriorEntryAlignment (" INTX_FORMAT ") must be "340"greater than or equal to %d\n",341InteriorEntryAlignment, minimum_alignment);342return JVMFlag::VIOLATES_CONSTRAINT;343}344345return JVMFlag::SUCCESS;346}347348JVMFlag::Error NodeLimitFudgeFactorConstraintFunc(intx value, bool verbose) {349if (value < MaxNodeLimit * 2 / 100 || value > MaxNodeLimit * 40 / 100) {350JVMFlag::printError(verbose,351"NodeLimitFudgeFactor must be between 2%% and 40%% "352"of MaxNodeLimit (" INTX_FORMAT ")\n",353MaxNodeLimit);354return JVMFlag::VIOLATES_CONSTRAINT;355}356357return JVMFlag::SUCCESS;358}359#endif // COMPILER2360361JVMFlag::Error RTMTotalCountIncrRateConstraintFunc(int value, bool verbose) {362#if INCLUDE_RTM_OPT363if (UseRTMLocking && !is_power_of_2(RTMTotalCountIncrRate)) {364JVMFlag::printError(verbose,365"RTMTotalCountIncrRate (%d) must be "366"a power of 2, resetting it to 64\n",367RTMTotalCountIncrRate);368FLAG_SET_DEFAULT(RTMTotalCountIncrRate, 64);369}370#endif371372return JVMFlag::SUCCESS;373}374375#ifdef COMPILER2376JVMFlag::Error LoopStripMiningIterConstraintFunc(uintx value, bool verbose) {377if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) {378if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {379JVMFlag::printError(verbose,380"When counted loop safepoints are enabled, "381"LoopStripMiningIter must be at least 1 "382"(a safepoint every 1 iteration): setting it to 1\n");383}384LoopStripMiningIter = 1;385} else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) {386if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {387JVMFlag::printError(verbose,388"Disabling counted safepoints implies no loop strip mining: "389"setting LoopStripMiningIter to 0\n");390}391LoopStripMiningIter = 0;392}393394return JVMFlag::SUCCESS;395}396#endif // COMPILER2397398JVMFlag::Error DisableIntrinsicConstraintFunc(ccstrlist value, bool verbose) {399ControlIntrinsicValidator validator(value, true/*disabled_all*/);400if (!validator.is_valid()) {401JVMFlag::printError(verbose,402"Unrecognized intrinsic detected in DisableIntrinsic: %s\n",403validator.what());404return JVMFlag::VIOLATES_CONSTRAINT;405}406407return JVMFlag::SUCCESS;408}409410JVMFlag::Error ControlIntrinsicConstraintFunc(ccstrlist value, bool verbose) {411ControlIntrinsicValidator validator(value, false/*disabled_all*/);412if (!validator.is_valid()) {413JVMFlag::printError(verbose,414"Unrecognized intrinsic detected in ControlIntrinsic: %s\n",415validator.what());416return JVMFlag::VIOLATES_CONSTRAINT;417}418419return JVMFlag::SUCCESS;420}421422423424