src/hotspot/share/services/writeableFlags.cpp
author dcubed
Wed, 18 Sep 2019 20:49:13 -0400
changeset 58223 778fc2dcbdaa
parent 57876 30db6422848b
permissions -rw-r--r--
8231210: [BACKOUT] JDK-8207266 ThreadMXBean::getThreadAllocatedBytes() can be quicker for self thread Reviewed-by: phh, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     1
/*
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     4
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     8
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    13
 * accompanied this code).
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    14
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    18
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    21
 * questions.
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    22
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    23
 */
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    24
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    25
#include "precompiled.hpp"
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    26
#include "classfile/javaClasses.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 47216
diff changeset
    27
#include "memory/allocation.inline.hpp"
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    28
#include "runtime/arguments.hpp"
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    29
#include "runtime/flags/jvmFlag.hpp"
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    30
#include "runtime/flags/jvmFlagRangeList.hpp"
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    31
#include "runtime/java.hpp"
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    32
#include "runtime/jniHandles.hpp"
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    33
#include "services/writeableFlags.hpp"
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    34
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    35
#define TEMP_BUF_SIZE 80
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    36
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    37
static void buffer_concat(char* buffer, const char* src) {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    38
  strncat(buffer, src, TEMP_BUF_SIZE - 1 - strlen(buffer));
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    39
}
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    40
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
    41
static void print_flag_error_message_bounds(const JVMFlag* flag, char* buffer) {
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
    42
  JVMFlagRange* range = JVMFlagRangeList::find(flag);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    43
  if (range != NULL) {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    44
    buffer_concat(buffer, "must have value in range ");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    45
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    46
    stringStream stream;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    47
    range->print(&stream);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    48
    const char* range_string = stream.as_string();
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    49
    size_t j = strlen(buffer);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    50
    for (size_t i=0; j<TEMP_BUF_SIZE-1; i++) {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    51
      if (range_string[i] == '\0') {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    52
        break;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    53
      } else if (range_string[i] != ' ') {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    54
        buffer[j] = range_string[i];
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    55
        j++;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    56
      }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    57
    }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    58
    buffer[j] = '\0';
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    59
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    60
}
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    61
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
    62
static void print_flag_error_message_if_needed(JVMFlag::Error error, const JVMFlag* flag, FormatBuffer<80>& err_msg) {
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    63
  if (error == JVMFlag::SUCCESS) {
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    64
    return;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    65
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    66
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
    67
  const char* name = flag->_name;
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    68
  char buffer[TEMP_BUF_SIZE] = {'\0'};
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    69
  if ((error != JVMFlag::MISSING_NAME) && (name != NULL)) {
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    70
    buffer_concat(buffer, name);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    71
    buffer_concat(buffer, " error: ");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    72
  } else {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    73
    buffer_concat(buffer, "Error: ");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    74
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    75
  switch (error) {
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    76
    case JVMFlag::MISSING_NAME:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    77
      buffer_concat(buffer, "flag name is missing."); break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    78
    case JVMFlag::MISSING_VALUE:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    79
      buffer_concat(buffer, "parsing the textual form of the value."); break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    80
    case JVMFlag::NON_WRITABLE:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    81
      buffer_concat(buffer, "flag is not writeable."); break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    82
    case JVMFlag::OUT_OF_BOUNDS:
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
    83
      if (name != NULL) { print_flag_error_message_bounds(flag, buffer); } break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    84
    case JVMFlag::VIOLATES_CONSTRAINT:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    85
      buffer_concat(buffer, "value violates its flag's constraint."); break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    86
    case JVMFlag::INVALID_FLAG:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    87
      buffer_concat(buffer, "there is no flag with the given name."); break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    88
    case JVMFlag::ERR_OTHER:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    89
      buffer_concat(buffer, "other, unspecified error related to setting the flag."); break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    90
    case JVMFlag::SUCCESS:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    91
      break;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38942
diff changeset
    92
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38942
diff changeset
    93
      break;
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    94
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    95
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31371
diff changeset
    96
  err_msg.print("%s", buffer);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    97
}
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    98
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    99
// set a boolean global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   100
JVMFlag::Error WriteableFlags::set_bool_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
38942
a4b3fc1ba095 8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
gziemski
parents: 33604
diff changeset
   101
  if ((strcasecmp(arg, "true") == 0) || (*arg == '1' && *(arg + 1) == 0)) {
a4b3fc1ba095 8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
gziemski
parents: 33604
diff changeset
   102
    return set_bool_flag(name, true, origin, err_msg);
a4b3fc1ba095 8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
gziemski
parents: 33604
diff changeset
   103
  } else if ((strcasecmp(arg, "false") == 0) || (*arg == '0' && *(arg + 1) == 0)) {
a4b3fc1ba095 8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
gziemski
parents: 33604
diff changeset
   104
    return set_bool_flag(name, false, origin, err_msg);
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   105
  }
38942
a4b3fc1ba095 8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
gziemski
parents: 33604
diff changeset
   106
  err_msg.print("flag value must be a boolean (1/0 or true/false)");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   107
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   108
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   109
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   110
JVMFlag::Error WriteableFlags::set_bool_flag(const char* name, bool value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   111
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   112
  JVMFlag::Error err = JVMFlag::boolAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   113
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   114
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   115
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   116
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   117
// set a int global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   118
JVMFlag::Error WriteableFlags::set_int_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   119
  int value;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   120
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   121
  if (sscanf(arg, "%d", &value) == 1) {
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   122
    return set_int_flag(name, value, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   123
  }
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   124
  err_msg.print("flag value must be an integer");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   125
  return JVMFlag::WRONG_FORMAT;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   126
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   127
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   128
JVMFlag::Error WriteableFlags::set_int_flag(const char* name, int value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   129
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   130
  JVMFlag::Error err = JVMFlag::intAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   131
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   132
  return err;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   133
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   134
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   135
// set a uint global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   136
JVMFlag::Error WriteableFlags::set_uint_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   137
  uint value;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   138
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   139
  if (sscanf(arg, "%u", &value) == 1) {
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   140
    return set_uint_flag(name, value, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   141
  }
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   142
  err_msg.print("flag value must be an unsigned integer");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   143
  return JVMFlag::WRONG_FORMAT;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   144
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   145
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   146
JVMFlag::Error WriteableFlags::set_uint_flag(const char* name, uint value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   147
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   148
  JVMFlag::Error err = JVMFlag::uintAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   149
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   150
  return err;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   151
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   152
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   153
// set a intx global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   154
JVMFlag::Error WriteableFlags::set_intx_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   155
  intx value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   156
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   157
  if (sscanf(arg, INTX_FORMAT, &value) == 1) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   158
    return set_intx_flag(name, value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   159
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   160
  err_msg.print("flag value must be an integer");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   161
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   162
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   163
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   164
JVMFlag::Error WriteableFlags::set_intx_flag(const char* name, intx value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   165
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   166
  JVMFlag::Error err = JVMFlag::intxAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   167
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   168
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   169
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   170
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   171
// set a uintx global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   172
JVMFlag::Error WriteableFlags::set_uintx_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   173
  uintx value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   174
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   175
  if (sscanf(arg, UINTX_FORMAT, &value) == 1) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   176
    return set_uintx_flag(name, value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   177
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   178
  err_msg.print("flag value must be an unsigned integer");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   179
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   180
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   181
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   182
JVMFlag::Error WriteableFlags::set_uintx_flag(const char* name, uintx value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   183
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   184
  JVMFlag::Error err = JVMFlag::uintxAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   185
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   186
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   187
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   188
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   189
// set a uint64_t global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   190
JVMFlag::Error WriteableFlags::set_uint64_t_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   191
  uint64_t value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   192
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   193
  if (sscanf(arg, UINT64_FORMAT, &value) == 1) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   194
    return set_uint64_t_flag(name, value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   195
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   196
  err_msg.print("flag value must be an unsigned 64-bit integer");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   197
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   198
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   199
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   200
JVMFlag::Error WriteableFlags::set_uint64_t_flag(const char* name, uint64_t value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   201
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   202
  JVMFlag::Error err = JVMFlag::uint64_tAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   203
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   204
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   205
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   206
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   207
// set a size_t global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   208
JVMFlag::Error WriteableFlags::set_size_t_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   209
  size_t value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   210
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   211
  if (sscanf(arg, SIZE_FORMAT, &value) == 1) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   212
    return set_size_t_flag(name, value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   213
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   214
  err_msg.print("flag value must be an unsigned integer");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   215
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   216
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   217
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   218
JVMFlag::Error WriteableFlags::set_size_t_flag(const char* name, size_t value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   219
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   220
  JVMFlag::Error err = JVMFlag::size_tAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   221
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   222
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   223
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   224
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   225
// set a double global flag
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   226
JVMFlag::Error WriteableFlags::set_double_flag(const char* name, const char* arg, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   227
  double value;
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   228
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   229
  if (sscanf(arg, "%lf", &value) == 1) {
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   230
    return set_double_flag(name, value, origin, err_msg);
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   231
  }
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   232
  err_msg.print("flag value must be a double");
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   233
  return JVMFlag::WRONG_FORMAT;
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   234
}
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   235
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   236
JVMFlag::Error WriteableFlags::set_double_flag(const char* name, double value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   237
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   238
  JVMFlag::Error err = JVMFlag::doubleAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   239
  print_flag_error_message_if_needed(err, flag, err_msg);
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   240
  return err;
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   241
}
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   242
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   243
// set a string global flag using value from AttachOperation
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   244
JVMFlag::Error WriteableFlags::set_ccstr_flag(const char* name, const char* value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   245
  JVMFlag* flag = JVMFlag::find_flag(name);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   246
  JVMFlag::Error err = JVMFlag::ccstrAtPut(flag, &value, origin);
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   247
  print_flag_error_message_if_needed(err, flag, err_msg);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   248
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   249
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   250
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   251
/* sets a writeable flag to the provided value
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   252
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   253
 * - return status is one of the WriteableFlags::err enum values
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   254
 * - an eventual error message will be generated to the provided err_msg buffer
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   255
 */
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   256
JVMFlag::Error WriteableFlags::set_flag(const char* flag_name, const char* flag_value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   257
  return set_flag(flag_name, &flag_value, set_flag_from_char, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   258
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   259
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   260
/* sets a writeable flag to the provided value
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   261
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   262
 * - return status is one of the WriteableFlags::err enum values
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   263
 * - an eventual error message will be generated to the provided err_msg buffer
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   264
 */
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   265
JVMFlag::Error WriteableFlags::set_flag(const char* flag_name, jvalue flag_value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   266
  return set_flag(flag_name, &flag_value, set_flag_from_jvalue, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   267
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   268
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   269
// a writeable flag setter accepting either 'jvalue' or 'char *' values
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   270
JVMFlag::Error WriteableFlags::set_flag(const char* name, const void* value, JVMFlag::Error(*setter)(JVMFlag*,const void*,JVMFlag::Flags,FormatBuffer<80>&), JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   271
  if (name == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   272
    err_msg.print("flag name is missing");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   273
    return JVMFlag::MISSING_NAME;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   274
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   275
  if (value == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   276
    err_msg.print("flag value is missing");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   277
    return JVMFlag::MISSING_VALUE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   278
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   279
57876
30db6422848b 8224878: Use JVMFlag parameters instead of name strings
stefank
parents: 52417
diff changeset
   280
  JVMFlag* f = JVMFlag::find_flag(name);
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   281
  if (f) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   282
    // only writeable flags are allowed to be set
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   283
    if (f->is_writeable()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   284
      return setter(f, value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   285
    } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   286
      err_msg.print("only 'writeable' flags can be set");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   287
      return JVMFlag::NON_WRITABLE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   288
    }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   289
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   290
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   291
  err_msg.print("flag %s does not exist", name);
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   292
  return JVMFlag::INVALID_FLAG;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   293
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   294
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   295
// a writeable flag setter accepting 'char *' values
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   296
JVMFlag::Error WriteableFlags::set_flag_from_char(JVMFlag* f, const void* value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   297
  char* flag_value = *(char**)value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   298
  if (flag_value == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   299
    err_msg.print("flag value is missing");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   300
    return JVMFlag::MISSING_VALUE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   301
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   302
  if (f->is_bool()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   303
    return set_bool_flag(f->_name, flag_value, origin, err_msg);
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   304
  } else if (f->is_int()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   305
    return set_int_flag(f->_name, flag_value, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   306
  } else if (f->is_uint()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   307
    return set_uint_flag(f->_name, flag_value, origin, err_msg);
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   308
  } else if (f->is_intx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   309
    return set_intx_flag(f->_name, flag_value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   310
  } else if (f->is_uintx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   311
    return set_uintx_flag(f->_name, flag_value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   312
  } else if (f->is_uint64_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   313
    return set_uint64_t_flag(f->_name, flag_value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   314
  } else if (f->is_size_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   315
    return set_size_t_flag(f->_name, flag_value, origin, err_msg);
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   316
  } else if (f->is_double()) {
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   317
    return set_double_flag(f->_name, flag_value, origin, err_msg);
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   318
  } else if (f->is_ccstr()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   319
    return set_ccstr_flag(f->_name, flag_value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   320
  } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   321
    ShouldNotReachHere();
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   322
  }
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   323
  return JVMFlag::ERR_OTHER;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   324
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   325
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   326
// a writeable flag setter accepting 'jvalue' values
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   327
JVMFlag::Error WriteableFlags::set_flag_from_jvalue(JVMFlag* f, const void* value, JVMFlag::Flags origin,
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31371
diff changeset
   328
                                                 FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   329
  jvalue new_value = *(jvalue*)value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   330
  if (f->is_bool()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   331
    bool bvalue = (new_value.z == JNI_TRUE ? true : false);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   332
    return set_bool_flag(f->_name, bvalue, origin, err_msg);
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   333
  } else if (f->is_int()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   334
    int ivalue = (int)new_value.j;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   335
    return set_int_flag(f->_name, ivalue, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   336
  } else if (f->is_uint()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   337
    uint uvalue = (uint)new_value.j;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   338
    return set_uint_flag(f->_name, uvalue, origin, err_msg);
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   339
  } else if (f->is_intx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   340
    intx ivalue = (intx)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   341
    return set_intx_flag(f->_name, ivalue, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   342
  } else if (f->is_uintx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   343
    uintx uvalue = (uintx)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   344
    return set_uintx_flag(f->_name, uvalue, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   345
  } else if (f->is_uint64_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   346
    uint64_t uvalue = (uint64_t)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   347
    return set_uint64_t_flag(f->_name, uvalue, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   348
  } else if (f->is_size_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   349
    size_t svalue = (size_t)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   350
    return set_size_t_flag(f->_name, svalue, origin, err_msg);
52417
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   351
  } else if (f->is_double()) {
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   352
    double dvalue = (double)new_value.d;
439b4a9b5a2e 8212883: Setting a double manageable flag with jcmd/jinfo crashes the JVM
tonyp
parents: 51070
diff changeset
   353
    return set_double_flag(f->_name, dvalue, origin, err_msg);
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   354
  } else if (f->is_ccstr()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   355
    oop str = JNIHandles::resolve_external_guard(new_value.l);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   356
    if (str == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   357
      err_msg.print("flag value is missing");
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   358
      return JVMFlag::MISSING_VALUE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   359
    }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   360
    ccstr svalue = java_lang_String::as_utf8_string(str);
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   361
    JVMFlag::Error ret = WriteableFlags::set_ccstr_flag(f->_name, svalue, origin, err_msg);
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   362
    if (ret != JVMFlag::SUCCESS) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   363
      FREE_C_HEAP_ARRAY(char, svalue);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   364
    }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   365
    return ret;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   366
  } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   367
    ShouldNotReachHere();
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   368
  }
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   369
  return JVMFlag::ERR_OTHER;
29068
683bef04fb20 8072935: Fix missing newline at end of file after 8067447
dholmes
parents: 28949
diff changeset
   370
}