1 /* 2 * Copyright (c) 1997, 2020, 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_RUNTIME_FLAGS_JVMFLAG_HPP 26 #define SHARE_RUNTIME_FLAGS_JVMFLAG_HPP 27 28 #include "utilities/globalDefinitions.hpp" 29 #include "utilities/macros.hpp" 30 31 class outputStream; 32 33 // function type that will construct default range string 34 typedef const char* (*RangeStrFunc)(void); 35 36 struct JVMFlag { 37 enum Flags { 38 // latest value origin 39 DEFAULT = 0, 40 COMMAND_LINE = 1, 41 ENVIRON_VAR = 2, 42 CONFIG_FILE = 3, 43 MANAGEMENT = 4, 44 ERGONOMIC = 5, 45 ATTACH_ON_DEMAND = 6, 46 INTERNAL = 7, 47 JIMAGE_RESOURCE = 8, 48 49 LAST_VALUE_ORIGIN = JIMAGE_RESOURCE, 50 VALUE_ORIGIN_BITS = 4, 51 VALUE_ORIGIN_MASK = right_n_bits(VALUE_ORIGIN_BITS), 52 53 // flag kind 54 KIND_PRODUCT = 1 << 4, 55 KIND_MANAGEABLE = 1 << 5, 56 KIND_DIAGNOSTIC = 1 << 6, 57 KIND_EXPERIMENTAL = 1 << 7, 58 KIND_NOT_PRODUCT = 1 << 8, 59 KIND_DEVELOP = 1 << 9, 60 KIND_PLATFORM_DEPENDENT = 1 << 10, 61 KIND_READ_WRITE = 1 << 11, 62 KIND_C1 = 1 << 12, 63 KIND_C2 = 1 << 13, 64 KIND_ARCH = 1 << 14, 65 KIND_LP64_PRODUCT = 1 << 15, 66 KIND_JVMCI = 1 << 16, 67 68 // set this bit if the flag was set on the command line 69 ORIG_COMMAND_LINE = 1 << 17, 70 71 KIND_MASK = ~(VALUE_ORIGIN_MASK | ORIG_COMMAND_LINE) 72 }; 73 74 enum Error { 75 // no error 76 SUCCESS = 0, 77 // flag name is missing 78 MISSING_NAME, 79 // flag value is missing 80 MISSING_VALUE, 81 // error parsing the textual form of the value 82 WRONG_FORMAT, 83 // flag is not writable 84 NON_WRITABLE, 85 // flag value is outside of its bounds 86 OUT_OF_BOUNDS, 87 // flag value violates its constraint 88 VIOLATES_CONSTRAINT, 89 // there is no flag with the given name 90 INVALID_FLAG, 91 // the flag can only be set only on command line during invocation of the VM 92 COMMAND_LINE_ONLY, 93 // the flag may only be set once 94 SET_ONLY_ONCE, 95 // the flag is not writable in this combination of product/debug build 96 CONSTANT, 97 // other, unspecified error related to setting the flag 98 ERR_OTHER 99 }; 100 101 enum MsgType { 102 NONE = 0, 103 DIAGNOSTIC_FLAG_BUT_LOCKED, 104 EXPERIMENTAL_FLAG_BUT_LOCKED, 105 DEVELOPER_FLAG_BUT_PRODUCT_BUILD, 106 NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD 107 }; 108 109 const char* _type; 110 const char* _name; 111 void* _addr; 112 NOT_PRODUCT(const char* _doc;) 113 Flags _flags; 114 size_t _name_len; 115 116 // points to all Flags static array 117 static JVMFlag* flags; 118 119 // number of flags 120 static size_t numFlags; 121 122 private: 123 static JVMFlag* find_flag(const char* name, size_t length, bool allow_locked, bool return_flag); 124 125 public: 126 static JVMFlag* find_flag(const char* name) { 127 return find_flag(name, strlen(name), false, false); 128 } 129 static const JVMFlag* find_declared_flag(const char* name, size_t length) { 130 return find_flag(name, length, true, true); 131 } 132 static const JVMFlag* find_declared_flag(const char* name) { 133 return find_declared_flag(name, strlen(name)); 134 } 135 136 static JVMFlag* fuzzy_match(const char* name, size_t length, bool allow_locked = false); 137 138 static const char* get_int_default_range_str(); 139 static const char* get_uint_default_range_str(); 140 static const char* get_intx_default_range_str(); 141 static const char* get_uintx_default_range_str(); 142 static const char* get_uint64_t_default_range_str(); 143 static const char* get_size_t_default_range_str(); 144 static const char* get_double_default_range_str(); 145 146 bool is_bool() const; 147 bool get_bool() const { return *((bool*) _addr); } 148 void set_bool(bool value) { *((bool*) _addr) = value; } 149 150 bool is_int() const; 151 int get_int() const { return *((int*) _addr); } 152 void set_int(int value) { *((int*) _addr) = value; } 153 154 bool is_uint() const; 155 uint get_uint() const { return *((uint*) _addr); } 156 void set_uint(uint value) { *((uint*) _addr) = value; } 157 158 bool is_intx() const; 159 intx get_intx() const { return *((intx*) _addr); } 160 void set_intx(intx value) { *((intx*) _addr) = value; } 161 162 bool is_uintx() const; 163 uintx get_uintx() const { return *((uintx*) _addr); } 164 void set_uintx(uintx value) { *((uintx*) _addr) = value; } 165 166 bool is_uint64_t() const; 167 uint64_t get_uint64_t() const { return *((uint64_t*) _addr); } 168 void set_uint64_t(uint64_t value) { *((uint64_t*) _addr) = value; } 169 170 bool is_size_t() const; 171 size_t get_size_t() const { return *((size_t*) _addr); } 172 void set_size_t(size_t value) { *((size_t*) _addr) = value; } 173 174 bool is_double() const; 175 double get_double() const { return *((double*) _addr); } 176 void set_double(double value) { *((double*) _addr) = value; } 177 178 bool is_ccstr() const; 179 bool ccstr_accumulates() const; 180 ccstr get_ccstr() const { return *((ccstr*) _addr); } 181 void set_ccstr(ccstr value) { *((ccstr*) _addr) = value; } 182 183 Flags get_origin(); 184 void set_origin(Flags origin); 185 186 size_t get_name_length(); 187 188 bool is_default(); 189 bool is_ergonomic(); 190 bool is_jimage_resource(); 191 bool is_command_line(); 192 void set_command_line(); 193 194 bool is_product() const; 195 bool is_manageable() const; 196 bool is_diagnostic() const; 197 bool is_experimental() const; 198 bool is_notproduct() const; 199 bool is_develop() const; 200 bool is_read_write() const; 201 202 bool is_constant_in_binary() const; 203 204 bool is_unlocker() const; 205 bool is_unlocked() const; 206 bool is_writeable() const; 207 bool is_external() const; 208 209 void clear_diagnostic(); 210 void clear_experimental(); 211 void set_product(); 212 213 JVMFlag::MsgType get_locked_message(char*, int) const; 214 JVMFlag::MsgType get_locked_message_ext(char*, int) const; 215 216 // printRanges will print out flags type, name and range values as expected by -XX:+PrintFlagsRanges 217 void print_on(outputStream* st, bool withComments = false, bool printRanges = false); 218 void print_kind(outputStream* st, unsigned int width); 219 void print_origin(outputStream* st, unsigned int width); 220 void print_as_flag(outputStream* st); 221 222 static const char* flag_error_str(JVMFlag::Error error); 223 224 public: 225 static JVMFlag::Error boolAt(const JVMFlag* flag, bool* value); 226 static JVMFlag::Error boolAtPut(JVMFlag* flag, bool* value, JVMFlag::Flags origin); 227 228 static JVMFlag::Error intAt(const JVMFlag* flag, int* value); 229 static JVMFlag::Error intAtPut(JVMFlag* flag, int* value, JVMFlag::Flags origin); 230 231 static JVMFlag::Error uintAt(const JVMFlag* flag, uint* value); 232 static JVMFlag::Error uintAtPut(JVMFlag* flag, uint* value, JVMFlag::Flags origin); 233 234 static JVMFlag::Error intxAt(const JVMFlag* flag, intx* value); 235 static JVMFlag::Error intxAtPut(JVMFlag* flag, intx* value, JVMFlag::Flags origin); 236 237 static JVMFlag::Error uintxAt(const JVMFlag* flag, uintx* value); 238 static JVMFlag::Error uintxAtPut(JVMFlag* flag, uintx* value, JVMFlag::Flags origin); 239 240 static JVMFlag::Error size_tAt(const JVMFlag* flag, size_t* value); 241 static JVMFlag::Error size_tAtPut(JVMFlag* flag, size_t* value, JVMFlag::Flags origin); 242 243 static JVMFlag::Error uint64_tAt(const JVMFlag* flag, uint64_t* value); 244 static JVMFlag::Error uint64_tAtPut(JVMFlag* flag, uint64_t* value, JVMFlag::Flags origin); 245 246 static JVMFlag::Error doubleAt(const JVMFlag* flag, double* value); 247 static JVMFlag::Error doubleAtPut(JVMFlag* flag, double* value, JVMFlag::Flags origin); 248 249 static JVMFlag::Error ccstrAt(const JVMFlag* flag, ccstr* value); 250 // Contract: JVMFlag will make private copy of the incoming value. 251 // Outgoing value is always malloc-ed, and caller MUST call free. 252 static JVMFlag::Error ccstrAtPut(JVMFlag* flag, ccstr* value, JVMFlag::Flags origin); 253 254 static void printSetFlags(outputStream* out); 255 256 // printRanges will print out flags type, name and range values as expected by -XX:+PrintFlagsRanges 257 static void printFlags(outputStream* out, bool withComments, bool printRanges = false, bool skipDefaults = false); 258 static void printError(bool verbose, const char* msg, ...) ATTRIBUTE_PRINTF(2, 3); 259 260 static void verify() PRODUCT_RETURN; 261 }; 262 263 #endif // SHARE_RUNTIME_FLAGS_JVMFLAG_HPP