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 #include "precompiled.hpp"
  26 #include "runtime/flags/jvmFlagWriteableList.hpp"
  27 #include "runtime/os.hpp"
  28 
  29 bool JVMFlagWriteable::is_writeable(void) {
  30   return _writeable;
  31 }
  32 
  33 void JVMFlagWriteable::mark_once(void) {
  34   if (_type == Once) {
  35     _writeable = false;
  36   }
  37 }
  38 
  39 void JVMFlagWriteable::mark_startup(void) {
  40   if (_type == JVMFlagWriteable::CommandLineOnly) {
  41     _writeable = false;
  42   }
  43 }
  44 
  45 // No control emitting
  46 void emit_writeable_no(...)                         { /* NOP */ }
  47 
  48 // No control emitting if type argument is NOT provided
  49 void emit_writeable_bool(const char* /*name*/)      { /* NOP */ }
  50 void emit_writeable_ccstr(const char* /*name*/)     { /* NOP */ }
  51 void emit_writeable_ccstrlist(const char* /*name*/) { /* NOP */ }
  52 void emit_writeable_int(const char* /*name*/)       { /* NOP */ }
  53 void emit_writeable_intx(const char* /*name*/)      { /* NOP */ }
  54 void emit_writeable_uint(const char* /*name*/)      { /* NOP */ }
  55 void emit_writeable_uintx(const char* /*name*/)     { /* NOP */ }
  56 void emit_writeable_uint64_t(const char* /*name*/)  { /* NOP */ }
  57 void emit_writeable_size_t(const char* /*name*/)    { /* NOP */ }
  58 void emit_writeable_double(const char* /*name*/)    { /* NOP */ }
  59 
  60 // JVMFlagWriteable emitting code functions if range arguments are provided
  61 void emit_writeable_bool(const char* name, JVMFlagWriteable::WriteableType type) {
  62   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  63 }
  64 void emit_writeable_int(const char* name, JVMFlagWriteable::WriteableType type) {
  65   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  66 }
  67 void emit_writeable_intx(const char* name, JVMFlagWriteable::WriteableType type) {
  68   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  69 }
  70 void emit_writeable_uint(const char* name, JVMFlagWriteable::WriteableType type) {
  71   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  72 }
  73 void emit_writeable_uintx(const char* name, JVMFlagWriteable::WriteableType type) {
  74   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  75 }
  76 void emit_writeable_uint64_t(const char* name, JVMFlagWriteable::WriteableType type) {
  77   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  78 }
  79 void emit_writeable_size_t(const char* name, JVMFlagWriteable::WriteableType type) {
  80   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  81 }
  82 void emit_writeable_double(const char* name, JVMFlagWriteable::WriteableType type) {
  83   JVMFlagWriteableList::add(new JVMFlagWriteable(name, type));
  84 }
  85 
  86 // Generate code to call emit_writeable_xxx function
  87 #define EMIT_WRITEABLE_START       (void)(0
  88 #define EMIT_WRITEABLE(type, name) ); emit_writeable_##type(#name
  89 #define EMIT_WRITEABLE_PRODUCT_FLAG(type, name, value, doc)      EMIT_WRITEABLE(type, name)
  90 #define EMIT_WRITEABLE_DIAGNOSTIC_FLAG(type, name, value, doc)   EMIT_WRITEABLE(type, name)
  91 #define EMIT_WRITEABLE_EXPERIMENTAL_FLAG(type, name, value, doc) EMIT_WRITEABLE(type, name)
  92 #define EMIT_WRITEABLE_MANAGEABLE_FLAG(type, name, value, doc)   EMIT_WRITEABLE(type, name)
  93 #define EMIT_WRITEABLE_PRODUCT_RW_FLAG(type, name, value, doc)   EMIT_WRITEABLE(type, name)
  94 #define EMIT_WRITEABLE_PD_PRODUCT_FLAG(type, name, doc)          EMIT_WRITEABLE(type, name)
  95 #define EMIT_WRITEABLE_DEVELOPER_FLAG(type, name, value, doc)    EMIT_WRITEABLE(type, name)
  96 #define EMIT_WRITEABLE_PD_DEVELOPER_FLAG(type, name, doc)        EMIT_WRITEABLE(type, name)
  97 #define EMIT_WRITEABLE_PD_DIAGNOSTIC_FLAG(type, name, doc)       EMIT_WRITEABLE(type, name)
  98 #define EMIT_WRITEABLE_NOTPRODUCT_FLAG(type, name, value, doc)   EMIT_WRITEABLE(type, name)
  99 #define EMIT_WRITEABLE_LP64_PRODUCT_FLAG(type, name, value, doc) EMIT_WRITEABLE(type, name)
 100 #define EMIT_WRITEABLE_END         );
 101 
 102 // Generate type argument to pass into emit_writeable_xxx functions
 103 #define EMIT_WRITEABLE_CHECK(a)                                  , JVMFlagWriteable::a
 104 
 105 #define INITIAL_WRITEABLES_SIZE 2
 106 GrowableArray<JVMFlagWriteable*>* JVMFlagWriteableList::_controls = NULL;
 107 
 108 void JVMFlagWriteableList::init(void) {
 109 
 110   _controls = new (ResourceObj::C_HEAP, mtArguments) GrowableArray<JVMFlagWriteable*>(INITIAL_WRITEABLES_SIZE, true);
 111 
 112   EMIT_WRITEABLE_START
 113 
 114   ALL_FLAGS(EMIT_WRITEABLE_DEVELOPER_FLAG,
 115             EMIT_WRITEABLE_PD_DEVELOPER_FLAG,
 116             EMIT_WRITEABLE_PRODUCT_FLAG,
 117             EMIT_WRITEABLE_PD_PRODUCT_FLAG,
 118             EMIT_WRITEABLE_DIAGNOSTIC_FLAG,
 119             EMIT_WRITEABLE_PD_DIAGNOSTIC_FLAG,
 120             EMIT_WRITEABLE_EXPERIMENTAL_FLAG,
 121             EMIT_WRITEABLE_NOTPRODUCT_FLAG,
 122             EMIT_WRITEABLE_MANAGEABLE_FLAG,
 123             EMIT_WRITEABLE_PRODUCT_RW_FLAG,
 124             EMIT_WRITEABLE_LP64_PRODUCT_FLAG,
 125             IGNORE_RANGE,
 126             IGNORE_CONSTRAINT,
 127             EMIT_WRITEABLE_CHECK)
 128 
 129   EMIT_WRITEABLE_END
 130 }
 131 
 132 JVMFlagWriteable* JVMFlagWriteableList::find(const char* name) {
 133   JVMFlagWriteable* found = NULL;
 134   for (int i=0; i<length(); i++) {
 135     JVMFlagWriteable* writeable = at(i);
 136     if (strcmp(writeable->name(), name) == 0) {
 137       found = writeable;
 138       break;
 139     }
 140   }
 141   return found;
 142 }
 143 
 144 void JVMFlagWriteableList::mark_startup(void) {
 145   for (int i=0; i<length(); i++) {
 146     JVMFlagWriteable* writeable = at(i);
 147     writeable->mark_startup();
 148   }
 149 }