1 /* 2 * Copyright (c) 2015, 2023, 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 "runtime/flags/jvmFlag.hpp" 27 #include "runtime/flags/jvmFlagLimit.hpp" 28 #include "runtime/flags/jvmFlagConstraintsRuntime.hpp" 29 #include "runtime/globals.hpp" 30 #include "runtime/os.hpp" 31 #include "runtime/safepointMechanism.hpp" 32 #include "runtime/task.hpp" 33 #include "utilities/powerOfTwo.hpp" 34 35 JVMFlag::Error AOTModeConstraintFunc(ccstr value, bool verbose) { 36 if (strcmp(value, "off") != 0 && 37 strcmp(value, "record") != 0 && 38 strcmp(value, "create") != 0 && 39 strcmp(value, "auto") != 0 && 40 strcmp(value, "on")) { 41 JVMFlag::printError(verbose, 42 "Unrecognized value %s for AOTMode. Must be one of the following: " 43 "off, record, create, auto, on\n", 44 value); 45 return JVMFlag::VIOLATES_CONSTRAINT; 46 } 47 48 return JVMFlag::SUCCESS; 49 } 50 JVMFlag::Error ObjectAlignmentInBytesConstraintFunc(int value, bool verbose) { 51 if (!is_power_of_2(value)) { 52 JVMFlag::printError(verbose, 53 "ObjectAlignmentInBytes (%d) must be " 54 "power of 2\n", 55 value); 56 return JVMFlag::VIOLATES_CONSTRAINT; 57 } 58 // In case page size is very small. 59 if (value >= (intx)os::vm_page_size()) { 60 JVMFlag::printError(verbose, 61 "ObjectAlignmentInBytes (%d) must be " 62 "less than page size (" SIZE_FORMAT ")\n", 63 value, os::vm_page_size()); 64 return JVMFlag::VIOLATES_CONSTRAINT; 65 } 66 return JVMFlag::SUCCESS; 67 } 68 69 // Need to enforce the padding not to break the existing field alignments. 70 // It is sufficient to check against the largest type size. 71 JVMFlag::Error ContendedPaddingWidthConstraintFunc(int value, bool verbose) { 72 if ((value % BytesPerLong) != 0) { 73 JVMFlag::printError(verbose, 74 "ContendedPaddingWidth (%d) must be " 75 "a multiple of %d\n", 76 value, BytesPerLong); 77 return JVMFlag::VIOLATES_CONSTRAINT; 78 } else { 79 return JVMFlag::SUCCESS; 80 } 81 } 82 83 JVMFlag::Error PerfDataSamplingIntervalFunc(int value, bool verbose) { 84 if ((value % PeriodicTask::interval_gran != 0)) { 85 JVMFlag::printError(verbose, 86 "PerfDataSamplingInterval (%d) must be " 87 "evenly divisible by PeriodicTask::interval_gran (%d)\n", 88 value, PeriodicTask::interval_gran); 89 return JVMFlag::VIOLATES_CONSTRAINT; 90 } else { 91 return JVMFlag::SUCCESS; 92 } 93 } 94 95 JVMFlag::Error VMPageSizeConstraintFunc(uintx value, bool verbose) { 96 uintx min = (uintx)os::vm_page_size(); 97 if (value < min) { 98 JVMFlag::printError(verbose, 99 "%s %s=" UINTX_FORMAT " is outside the allowed range [ " UINTX_FORMAT 100 " ... " UINTX_FORMAT " ]\n", 101 JVMFlagLimit::last_checked_flag()->type_string(), 102 JVMFlagLimit::last_checked_flag()->name(), 103 value, min, max_uintx); 104 return JVMFlag::VIOLATES_CONSTRAINT; 105 } 106 107 return JVMFlag::SUCCESS; 108 } 109 110 JVMFlag::Error NUMAInterleaveGranularityConstraintFunc(size_t value, bool verbose) { 111 size_t min = os::vm_allocation_granularity(); 112 size_t max = NOT_LP64(2*G) LP64_ONLY(8192*G); 113 114 if (value < min || value > max) { 115 JVMFlag::printError(verbose, 116 "size_t NUMAInterleaveGranularity=" UINTX_FORMAT " is outside the allowed range [ " UINTX_FORMAT 117 " ... " UINTX_FORMAT " ]\n", value, min, max); 118 return JVMFlag::VIOLATES_CONSTRAINT; 119 } 120 121 return JVMFlag::SUCCESS; 122 }