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 ObjectAlignmentInBytesConstraintFunc(int value, bool verbose) { 36 if (!is_power_of_2(value)) { 37 JVMFlag::printError(verbose, 38 "ObjectAlignmentInBytes (%d) must be " 39 "power of 2\n", 40 value); 41 return JVMFlag::VIOLATES_CONSTRAINT; 42 } 43 // In case page size is very small. 44 if (value >= (intx)os::vm_page_size()) { 45 JVMFlag::printError(verbose, 46 "ObjectAlignmentInBytes (%d) must be " 47 "less than page size (" SIZE_FORMAT ")\n", 48 value, os::vm_page_size()); 49 return JVMFlag::VIOLATES_CONSTRAINT; 50 } 51 return JVMFlag::SUCCESS; 52 } 53 54 // Need to enforce the padding not to break the existing field alignments. 55 // It is sufficient to check against the largest type size. 56 JVMFlag::Error ContendedPaddingWidthConstraintFunc(int value, bool verbose) { 57 if ((value % BytesPerLong) != 0) { 58 JVMFlag::printError(verbose, 59 "ContendedPaddingWidth (%d) must be " 60 "a multiple of %d\n", 61 value, BytesPerLong); 62 return JVMFlag::VIOLATES_CONSTRAINT; 63 } else { 64 return JVMFlag::SUCCESS; 65 } 66 } 67 68 JVMFlag::Error PerfDataSamplingIntervalFunc(int value, bool verbose) { 69 if ((value % PeriodicTask::interval_gran != 0)) { 70 JVMFlag::printError(verbose, 71 "PerfDataSamplingInterval (%d) must be " 72 "evenly divisible by PeriodicTask::interval_gran (%d)\n", 73 value, PeriodicTask::interval_gran); 74 return JVMFlag::VIOLATES_CONSTRAINT; 75 } else { 76 return JVMFlag::SUCCESS; 77 } 78 } 79 80 JVMFlag::Error VMPageSizeConstraintFunc(uintx value, bool verbose) { 81 uintx min = (uintx)os::vm_page_size(); 82 if (value < min) { 83 JVMFlag::printError(verbose, 84 "%s %s=" UINTX_FORMAT " is outside the allowed range [ " UINTX_FORMAT 85 " ... " UINTX_FORMAT " ]\n", 86 JVMFlagLimit::last_checked_flag()->type_string(), 87 JVMFlagLimit::last_checked_flag()->name(), 88 value, min, max_uintx); 89 return JVMFlag::VIOLATES_CONSTRAINT; 90 } 91 92 return JVMFlag::SUCCESS; 93 } 94 95 JVMFlag::Error NUMAInterleaveGranularityConstraintFunc(size_t value, bool verbose) { 96 size_t min = os::vm_allocation_granularity(); 97 size_t max = NOT_LP64(2*G) LP64_ONLY(8192*G); 98 99 if (value < min || value > max) { 100 JVMFlag::printError(verbose, 101 "size_t NUMAInterleaveGranularity=" UINTX_FORMAT " is outside the allowed range [ " UINTX_FORMAT 102 " ... " UINTX_FORMAT " ]\n", value, min, max); 103 return JVMFlag::VIOLATES_CONSTRAINT; 104 } 105 106 return JVMFlag::SUCCESS; 107 }