1 /*
  2  * Copyright (c) 2015, 2021, 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(intx value, bool verbose) {
 36   if (!is_power_of_2(value)) {
 37     JVMFlag::printError(verbose,
 38                         "ObjectAlignmentInBytes (" INTX_FORMAT ") 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 (" INTX_FORMAT ") must be "
 47                         "less than page size (%d)\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(intx value, bool verbose) {
 57   if ((value % BytesPerLong) != 0) {
 58     JVMFlag::printError(verbose,
 59                         "ContendedPaddingWidth (" INTX_FORMAT ") 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(intx value, bool verbose) {
 69   if ((value % PeriodicTask::interval_gran != 0)) {
 70     JVMFlag::printError(verbose,
 71                         "PerfDataSamplingInterval (" INTX_FORMAT ") 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 ScopeLocalCacheSizeConstraintFunc(intx value, bool verbose) {
 96   if (!is_power_of_2(value)) {
 97     JVMFlag::printError(verbose,
 98                         "ScopeLocalCacheSize (" INTX_FORMAT ") must be "
 99                         "power of 2\n",
100                         value);
101     return JVMFlag::VIOLATES_CONSTRAINT;
102   }
103 
104   return JVMFlag::SUCCESS;
105 }
106 
107 JVMFlag::Error NUMAInterleaveGranularityConstraintFunc(size_t value, bool verbose) {
108   size_t min = os::vm_allocation_granularity();
109   size_t max = NOT_LP64(2*G) LP64_ONLY(8192*G);
110 
111   if (value < min || value > max) {
112     JVMFlag::printError(verbose,
113                         "size_t NUMAInterleaveGranularity=" UINTX_FORMAT " is outside the allowed range [ " UINTX_FORMAT
114                         " ... " UINTX_FORMAT " ]\n", value, min, max);
115     return JVMFlag::VIOLATES_CONSTRAINT;
116   }
117 
118   return JVMFlag::SUCCESS;
119 }
--- EOF ---