1 /* 2 * Copyright (c) 2015, 2016, 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 #ifndef SHARE_VM_RUNTIME_COMMANDLINEFLAGCONSTRAINTLIST_HPP 26 #define SHARE_VM_RUNTIME_COMMANDLINEFLAGCONSTRAINTLIST_HPP 27 28 #include "runtime/globals.hpp" 29 #include "utilities/growableArray.hpp" 30 31 /* 32 * Here we have a mechanism for extracting constraints (as custom functions) for flags, 33 * which otherwise can not be expressed via simple range check, specified in flag macro tables. 34 * 35 * An example of a constraint is "flag1 < flag2" where both flag1 and flag2 can change. 36 * 37 * See runtime "runtime/commandLineFlagConstraintsCompiler.hpp", 38 * "runtime/commandLineFlagConstraintsGC.hpp" and 39 * "runtime/commandLineFlagConstraintsRuntime.hpp" for the functions themselves. 40 */ 41 42 typedef Flag::Error (*CommandLineFlagConstraintFunc_bool)(bool value, bool verbose); 43 typedef Flag::Error (*CommandLineFlagConstraintFunc_int)(int value, bool verbose); 44 typedef Flag::Error (*CommandLineFlagConstraintFunc_intx)(intx value, bool verbose); 45 typedef Flag::Error (*CommandLineFlagConstraintFunc_uint)(uint value, bool verbose); 46 typedef Flag::Error (*CommandLineFlagConstraintFunc_uintx)(uintx value, bool verbose); 47 typedef Flag::Error (*CommandLineFlagConstraintFunc_uint64_t)(uint64_t value, bool verbose); 48 typedef Flag::Error (*CommandLineFlagConstraintFunc_size_t)(size_t value, bool verbose); 49 typedef Flag::Error (*CommandLineFlagConstraintFunc_double)(double value, bool verbose); 50 51 class CommandLineFlagConstraint : public CHeapObj<mtArguments> { 52 public: 53 // During VM initialization, constraint validation will be done order of ConstraintType. 54 enum ConstraintType { 55 // Will be validated during argument processing (Arguments::parse_argument). 56 AtParse = 0, 57 // Will be validated inside Threads::create_vm(), right after Arguments::apply_ergo(). 58 AfterErgo = 1, 59 // Will be validated inside universe_init(), right after Metaspace::global_initialize(). 60 AfterMemoryInit = 2 61 }; 62 63 private: 64 const char* _name; 65 ConstraintType _validate_type; 66 67 public: 68 // the "name" argument must be a string literal 69 CommandLineFlagConstraint(const char* name, ConstraintType type) { _name=name; _validate_type=type; }; 70 ~CommandLineFlagConstraint() {}; 71 const char* name() const { return _name; } 72 ConstraintType type() const { return _validate_type; } 73 virtual Flag::Error apply(bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 74 virtual Flag::Error apply_bool(bool value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 75 virtual Flag::Error apply_int(int value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 76 virtual Flag::Error apply_intx(intx value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 77 virtual Flag::Error apply_uint(uint value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 78 virtual Flag::Error apply_uintx(uintx value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 79 virtual Flag::Error apply_uint64_t(uint64_t value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 80 virtual Flag::Error apply_size_t(size_t value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 81 virtual Flag::Error apply_double(double value, bool verbose = true) { ShouldNotReachHere(); return Flag::ERR_OTHER; }; 82 }; 83 84 class CommandLineFlagConstraintList : public AllStatic { 85 private: 86 static GrowableArray<CommandLineFlagConstraint*>* _constraints; 87 // Latest constraint validation type. 88 static CommandLineFlagConstraint::ConstraintType _validating_type; 89 public: 90 static void init(); 91 static int length() { return (_constraints != NULL) ? _constraints->length() : 0; } 92 static CommandLineFlagConstraint* at(int i) { return (_constraints != NULL) ? _constraints->at(i) : NULL; } 93 static CommandLineFlagConstraint* find(const char* name); 94 static CommandLineFlagConstraint* find_if_needs_check(const char* name); 95 static void add(CommandLineFlagConstraint* constraint) { _constraints->append(constraint); } 96 // True if 'AfterErgo' or later constraint functions are validated. 97 static bool validated_after_ergo() { return _validating_type >= CommandLineFlagConstraint::AfterErgo; }; 98 static bool check_constraints(CommandLineFlagConstraint::ConstraintType type); 99 }; 100 101 #endif /* SHARE_VM_RUNTIME_COMMANDLINEFLAGCONSTRAINTLIST_HPP */ | 1 /* 2 * Copyright (c) 2015, 2018, 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 #ifndef SHARE_VM_RUNTIME_JVMFLAGCONSTRAINTLIST_HPP 26 #define SHARE_VM_RUNTIME_JVMFLAGCONSTRAINTLIST_HPP 27 28 #include "utilities/growableArray.hpp" 29 30 /* 31 * Here we have a mechanism for extracting constraints (as custom functions) for flags, 32 * which otherwise can not be expressed via simple range check, specified in flag macro tables. 33 * 34 * An example of a constraint is "flag1 < flag2" where both flag1 and flag2 can change. 35 * 36 * See runtime "runtime/jvmFlagConstraintsCompiler.hpp", 37 * "runtime/jvmFlagConstraintsGC.hpp" and 38 * "runtime/jvmFlagConstraintsRuntime.hpp" for the functions themselves. 39 */ 40 41 typedef JVMFlag::Error (*JVMFlagConstraintFunc_bool)(bool value, bool verbose); 42 typedef JVMFlag::Error (*JVMFlagConstraintFunc_int)(int value, bool verbose); 43 typedef JVMFlag::Error (*JVMFlagConstraintFunc_intx)(intx value, bool verbose); 44 typedef JVMFlag::Error (*JVMFlagConstraintFunc_uint)(uint value, bool verbose); 45 typedef JVMFlag::Error (*JVMFlagConstraintFunc_uintx)(uintx value, bool verbose); 46 typedef JVMFlag::Error (*JVMFlagConstraintFunc_uint64_t)(uint64_t value, bool verbose); 47 typedef JVMFlag::Error (*JVMFlagConstraintFunc_size_t)(size_t value, bool verbose); 48 typedef JVMFlag::Error (*JVMFlagConstraintFunc_double)(double value, bool verbose); 49 50 class JVMFlagConstraint : public CHeapObj<mtArguments> { 51 public: 52 // During VM initialization, constraint validation will be done order of ConstraintType. 53 enum ConstraintType { 54 // Will be validated during argument processing (Arguments::parse_argument). 55 AtParse = 0, 56 // Will be validated inside Threads::create_vm(), right after Arguments::apply_ergo(). 57 AfterErgo = 1, 58 // Will be validated inside universe_init(), right after Metaspace::global_initialize(). 59 AfterMemoryInit = 2 60 }; 61 62 private: 63 const char* _name; 64 ConstraintType _validate_type; 65 66 public: 67 // the "name" argument must be a string literal 68 JVMFlagConstraint(const char* name, ConstraintType type) { _name=name; _validate_type=type; }; 69 ~JVMFlagConstraint() {}; 70 const char* name() const { return _name; } 71 ConstraintType type() const { return _validate_type; } 72 virtual JVMFlag::Error apply(bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 73 virtual JVMFlag::Error apply_bool(bool value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 74 virtual JVMFlag::Error apply_int(int value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 75 virtual JVMFlag::Error apply_intx(intx value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 76 virtual JVMFlag::Error apply_uint(uint value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 77 virtual JVMFlag::Error apply_uintx(uintx value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 78 virtual JVMFlag::Error apply_uint64_t(uint64_t value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 79 virtual JVMFlag::Error apply_size_t(size_t value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 80 virtual JVMFlag::Error apply_double(double value, bool verbose = true) { ShouldNotReachHere(); return JVMFlag::ERR_OTHER; }; 81 }; 82 83 class JVMFlagConstraintList : public AllStatic { 84 private: 85 static GrowableArray<JVMFlagConstraint*>* _constraints; 86 // Latest constraint validation type. 87 static JVMFlagConstraint::ConstraintType _validating_type; 88 public: 89 static void init(); 90 static int length() { return (_constraints != NULL) ? _constraints->length() : 0; } 91 static JVMFlagConstraint* at(int i) { return (_constraints != NULL) ? _constraints->at(i) : NULL; } 92 static JVMFlagConstraint* find(const char* name); 93 static JVMFlagConstraint* find_if_needs_check(const char* name); 94 static void add(JVMFlagConstraint* constraint) { _constraints->append(constraint); } 95 // True if 'AfterErgo' or later constraint functions are validated. 96 static bool validated_after_ergo() { return _validating_type >= JVMFlagConstraint::AfterErgo; }; 97 static bool check_constraints(JVMFlagConstraint::ConstraintType type); 98 }; 99 100 #endif /* SHARE_VM_RUNTIME_JVMFLAGCONSTRAINTLIST_HPP */ |