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 #include "precompiled.hpp"
  26 #include "gc/shared/plab.hpp"
  27 #include "runtime/flags/jvmFlagWriteableList.hpp"
  28 #include "runtime/os.hpp"
  29 #ifdef COMPILER1
  30 #include "c1/c1_globals.hpp"
  31 #endif // COMPILER1
  32 #ifdef COMPILER2
  33 #include "opto/c2_globals.hpp"
  34 #endif // COMPILER2
  35 #if INCLUDE_JVMCI
  36 #include "jvmci/jvmci_globals.hpp"
  37 #endif
  38 
  39 bool JVMFlagWriteable::is_writeable(void) {
  40   return _writeable;
  41 }
  42 
  43 void JVMFlagWriteable::mark_once(void) {
  44   if (_type == Once) {
  45     _writeable = false;
  46   }
  47 }
  48 
  49 void JVMFlagWriteable::mark_startup(void) {
  50   if (_type == JVMFlagWriteable::CommandLineOnly) {
  51     _writeable = false;
  52   }
  53 }
  54 
  55 // No control emitting
  56 void emit_writeable_no(...)                         { /* NOP */ }
  57 
  58 // No control emitting if type argument is NOT provided
  59 void emit_writeable_bool(const char* /*name*/)      { /* NOP */ }
  60 void emit_writeable_ccstr(const char* /*name*/)     { /* NOP */ }
  61 void emit_writeable_ccstrlist(const char* /*name*/) { /* NOP */ }
  62 void emit_writeable_int(const char* /*name*/)       { /* NOP */ }
  63 void emit_writeable_intx(const char* /*name*/)      { /* NOP */ }
  64 void emit_writeable_uint(const char* /*name*/)      { /* NOP */ }
  65 void emit_writeable_uintx(const char* /*name*/)     { /* NOP */ }
  66 void emit_writeable_uint64_t(const char* /*name*/)  { /* NOP */ }
  67 void emit_writeable_size_t(const char* /*name*/)    { /* NOP */ }
  68 void emit_writeable_double(const char* /*name*/)    { /* NOP */ }
  69 
  70 // JVMFlagWriteable emitting code functions if range arguments are provided
  71 void emit_writeable_bool(const char* name, JVMFlagWriteable::WriteableType type) {
  72   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  73 }
  74 void emit_writeable_int(const char* name, JVMFlagWriteable::WriteableType type) {
  75   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  76 }
  77 void emit_writeable_intx(const char* name, JVMFlagWriteable::WriteableType type) {
  78   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  79 }
  80 void emit_writeable_uint(const char* name, JVMFlagWriteable::WriteableType type) {
  81   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  82 }
  83 void emit_writeable_uintx(const char* name, JVMFlagWriteable::WriteableType type) {
  84   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  85 }
  86 void emit_writeable_uint64_t(const char* name, JVMFlagWriteable::WriteableType type) {
  87   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  88 }
  89 void emit_writeable_size_t(const char* name, JVMFlagWriteable::WriteableType type) {
  90   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  91 }
  92 void emit_writeable_double(const char* name, JVMFlagWriteable::WriteableType type) {
  93   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  94 }
  95 
  96 // Generate code to call emit_writeable_xxx function
  97 #define EMIT_WRITEABLE_PRODUCT_FLAG(type, name, value, doc)      ); emit_writeable_##type(#name
  98 #define EMIT_WRITEABLE_COMMERCIAL_FLAG(type, name, value, doc)   ); emit_writeable_##type(#name
  99 #define EMIT_WRITEABLE_DIAGNOSTIC_FLAG(type, name, value, doc)   ); emit_writeable_##type(#name
 100 #define EMIT_WRITEABLE_EXPERIMENTAL_FLAG(type, name, value, doc) ); emit_writeable_##type(#name
 101 #define EMIT_WRITEABLE_MANAGEABLE_FLAG(type, name, value, doc)   ); emit_writeable_##type(#name
 102 #define EMIT_WRITEABLE_PRODUCT_RW_FLAG(type, name, value, doc)   ); emit_writeable_##type(#name
 103 #define EMIT_WRITEABLE_PD_PRODUCT_FLAG(type, name, doc)          ); emit_writeable_##type(#name
 104 #define EMIT_WRITEABLE_DEVELOPER_FLAG(type, name, value, doc)    ); emit_writeable_##type(#name
 105 #define EMIT_WRITEABLE_PD_DEVELOPER_FLAG(type, name, doc)        ); emit_writeable_##type(#name
 106 #define EMIT_WRITEABLE_PD_DIAGNOSTIC_FLAG(type, name, doc)       ); emit_writeable_##type(#name
 107 #define EMIT_WRITEABLE_NOTPRODUCT_FLAG(type, name, value, doc)   ); emit_writeable_##type(#name
 108 #define EMIT_WRITEABLE_LP64_PRODUCT_FLAG(type, name, value, doc) ); emit_writeable_##type(#name
 109 
 110 // Generate type argument to pass into emit_writeable_xxx functions
 111 #define EMIT_WRITEABLE(a)                                      , JVMFlagWriteable::a
 112 
 113 #define INITIAL_WRITEABLES_SIZE 2
 114 GrowableArray<JVMFlagWriteable*>* JVMFlagWriteableList::_controls = NULL;
 115 
 116 void JVMFlagWriteableList::init(void) {
 117 
 118   _controls = new (ResourceObj::C_HEAP, mtArguments) GrowableArray<JVMFlagWriteable*>(INITIAL_WRITEABLES_SIZE, true);
 119 
 120   emit_writeable_no(NULL VM_FLAGS(EMIT_WRITEABLE_DEVELOPER_FLAG,
 121                                   EMIT_WRITEABLE_PD_DEVELOPER_FLAG,
 122                                   EMIT_WRITEABLE_PRODUCT_FLAG,
 123                                   EMIT_WRITEABLE_PD_PRODUCT_FLAG,
 124                                   EMIT_WRITEABLE_DIAGNOSTIC_FLAG,
 125                                   EMIT_WRITEABLE_PD_DIAGNOSTIC_FLAG,
 126                                   EMIT_WRITEABLE_EXPERIMENTAL_FLAG,
 127                                   EMIT_WRITEABLE_NOTPRODUCT_FLAG,
 128                                   EMIT_WRITEABLE_MANAGEABLE_FLAG,
 129                                   EMIT_WRITEABLE_PRODUCT_RW_FLAG,
 130                                   EMIT_WRITEABLE_LP64_PRODUCT_FLAG,
 131                                   IGNORE_RANGE,
 132                                   IGNORE_CONSTRAINT,
 133                                   EMIT_WRITEABLE));
 134 
 135   EMIT_WRITEABLES_FOR_GLOBALS_EXT
 136 
 137   emit_writeable_no(NULL ARCH_FLAGS(EMIT_WRITEABLE_DEVELOPER_FLAG,
 138                                 EMIT_WRITEABLE_PRODUCT_FLAG,
 139                                 EMIT_WRITEABLE_DIAGNOSTIC_FLAG,
 140                                 EMIT_WRITEABLE_EXPERIMENTAL_FLAG,
 141                                 EMIT_WRITEABLE_NOTPRODUCT_FLAG,
 142                                 IGNORE_RANGE,
 143                                 IGNORE_CONSTRAINT,
 144                                 EMIT_WRITEABLE));
 145 
 146 #if INCLUDE_JVMCI
 147   emit_writeable_no(NULL JVMCI_FLAGS(EMIT_WRITEABLE_DEVELOPER_FLAG,
 148                                  EMIT_WRITEABLE_PD_DEVELOPER_FLAG,
 149                                  EMIT_WRITEABLE_PRODUCT_FLAG,
 150                                  EMIT_WRITEABLE_PD_PRODUCT_FLAG,
 151                                  EMIT_WRITEABLE_DIAGNOSTIC_FLAG,
 152                                  EMIT_WRITEABLE_PD_DIAGNOSTIC_FLAG,
 153                                  EMIT_WRITEABLE_EXPERIMENTAL_FLAG,
 154                                  EMIT_WRITEABLE_NOTPRODUCT_FLAG,
 155                                  IGNORE_RANGE,
 156                                  IGNORE_CONSTRAINT,
 157                                  EMIT_WRITEABLE));
 158 #endif // INCLUDE_JVMCI
 159 
 160 #ifdef COMPILER1
 161   emit_writeable_no(NULL C1_FLAGS(EMIT_WRITEABLE_DEVELOPER_FLAG,
 162                               EMIT_WRITEABLE_PD_DEVELOPER_FLAG,
 163                               EMIT_WRITEABLE_PRODUCT_FLAG,
 164                               EMIT_WRITEABLE_PD_PRODUCT_FLAG,
 165                               EMIT_WRITEABLE_DIAGNOSTIC_FLAG,
 166                               EMIT_WRITEABLE_PD_DIAGNOSTIC_FLAG,
 167                               EMIT_WRITEABLE_NOTPRODUCT_FLAG,
 168                               IGNORE_RANGE,
 169                               IGNORE_CONSTRAINT,
 170                               EMIT_WRITEABLE));
 171 #endif // COMPILER1
 172 
 173 #ifdef COMPILER2
 174   emit_writeable_no(NULL C2_FLAGS(EMIT_WRITEABLE_DEVELOPER_FLAG,
 175                               EMIT_WRITEABLE_PD_DEVELOPER_FLAG,
 176                               EMIT_WRITEABLE_PRODUCT_FLAG,
 177                               EMIT_WRITEABLE_PD_PRODUCT_FLAG,
 178                               EMIT_WRITEABLE_DIAGNOSTIC_FLAG,
 179                               EMIT_WRITEABLE_PD_DIAGNOSTIC_FLAG,
 180                               EMIT_WRITEABLE_EXPERIMENTAL_FLAG,
 181                               EMIT_WRITEABLE_NOTPRODUCT_FLAG,
 182                               IGNORE_RANGE,
 183                               IGNORE_CONSTRAINT,
 184                               EMIT_WRITEABLE));
 185 #endif // COMPILER2
 186 }
 187 
 188 JVMFlagWriteable* JVMFlagWriteableList::find(const char* name) {
 189   JVMFlagWriteable* found = NULL;
 190   for (int i=0; i<length(); i++) {
 191     JVMFlagWriteable* writeable = at(i);
 192     if (strcmp(writeable->name(), name) == 0) {
 193       found = writeable;
 194       break;
 195     }
 196   }
 197   return found;
 198 }
 199 
 200 void JVMFlagWriteableList::mark_startup(void) {
 201   for (int i=0; i<length(); i++) {
 202     JVMFlagWriteable* writeable = at(i);
 203     writeable->mark_startup();
 204   }
 205 }