src/hotspot/share/services/writeableFlags.cpp
author goetz
Wed, 11 Jul 2018 16:11:10 +0200
changeset 51070 2f4c3cac8556
parent 49902 3661f31c6df4
child 52417 439b4a9b5a2e
permissions -rw-r--r--
8206977: Minor improvements of runtime code. Reviewed-by: coleenp, lfoltan
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
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    41
static void print_flag_error_message_bounds(const char* name, char* buffer) {
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    42
  JVMFlagRange* range = JVMFlagRangeList::find(name);
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
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    62
static void print_flag_error_message_if_needed(JVMFlag::Error error, const char* name, FormatBuffer<80>& err_msg) {
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
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    67
  char buffer[TEMP_BUF_SIZE] = {'\0'};
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    68
  if ((error != JVMFlag::MISSING_NAME) && (name != NULL)) {
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    69
    buffer_concat(buffer, name);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    70
    buffer_concat(buffer, " error: ");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    71
  } else {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    72
    buffer_concat(buffer, "Error: ");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    73
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    74
  switch (error) {
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    75
    case JVMFlag::MISSING_NAME:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    76
      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
    77
    case JVMFlag::MISSING_VALUE:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    78
      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
    79
    case JVMFlag::NON_WRITABLE:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    80
      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
    81
    case JVMFlag::OUT_OF_BOUNDS:
51070
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49902
diff changeset
    82
      if (name != NULL) { print_flag_error_message_bounds(name, buffer); } break;
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    83
    case JVMFlag::VIOLATES_CONSTRAINT:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    84
      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
    85
    case JVMFlag::INVALID_FLAG:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    86
      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
    87
    case JVMFlag::ERR_OTHER:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    88
      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
    89
    case JVMFlag::SUCCESS:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    90
      break;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38942
diff changeset
    91
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38942
diff changeset
    92
      break;
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    93
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    94
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31371
diff changeset
    95
  err_msg.print("%s", buffer);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    96
}
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    97
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    98
// set a boolean global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
    99
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
   100
  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
   101
    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
   102
  } 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
   103
    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
   104
  }
38942
a4b3fc1ba095 8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
gziemski
parents: 33604
diff changeset
   105
  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
   106
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   107
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   108
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   109
JVMFlag::Error WriteableFlags::set_bool_flag(const char* name, bool value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   110
  JVMFlag::Error err = JVMFlag::boolAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   111
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   112
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   113
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   114
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   115
// set a int global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   116
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
   117
  int value;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   118
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   119
  if (sscanf(arg, "%d", &value)) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   120
    return set_int_flag(name, value, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   121
  }
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   122
  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
   123
  return JVMFlag::WRONG_FORMAT;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   124
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   125
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   126
JVMFlag::Error WriteableFlags::set_int_flag(const char* name, int value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   127
  JVMFlag::Error err = JVMFlag::intAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   128
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   129
  return err;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   130
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   131
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   132
// set a uint global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   133
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
   134
  uint value;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   135
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   136
  if (sscanf(arg, "%u", &value)) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   137
    return set_uint_flag(name, value, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   138
  }
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   139
  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
   140
  return JVMFlag::WRONG_FORMAT;
31236
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
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   143
JVMFlag::Error WriteableFlags::set_uint_flag(const char* name, uint value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   144
  JVMFlag::Error err = JVMFlag::uintAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   145
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   146
  return err;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   147
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   148
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   149
// set a intx global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   150
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
   151
  intx value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   152
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   153
  if (sscanf(arg, INTX_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   154
    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
   155
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   156
  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
   157
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   158
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   159
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   160
JVMFlag::Error WriteableFlags::set_intx_flag(const char* name, intx value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   161
  JVMFlag::Error err = JVMFlag::intxAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   162
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   163
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   164
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   165
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   166
// set a uintx global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   167
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
   168
  uintx value;
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
  if (sscanf(arg, UINTX_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   171
    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
   172
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   173
  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
   174
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   175
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   176
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   177
JVMFlag::Error WriteableFlags::set_uintx_flag(const char* name, uintx value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   178
  JVMFlag::Error err = JVMFlag::uintxAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   179
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   180
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   181
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   182
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   183
// set a uint64_t global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   184
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
   185
  uint64_t value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   186
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   187
  if (sscanf(arg, UINT64_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   188
    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
   189
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   190
  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
   191
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   192
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   193
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   194
JVMFlag::Error WriteableFlags::set_uint64_t_flag(const char* name, uint64_t value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   195
  JVMFlag::Error err = JVMFlag::uint64_tAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   196
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   197
  return err;
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
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   200
// set a size_t global flag
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   201
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
   202
  size_t value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   203
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   204
  if (sscanf(arg, SIZE_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   205
    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
   206
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   207
  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
   208
  return JVMFlag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   209
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   210
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   211
JVMFlag::Error WriteableFlags::set_size_t_flag(const char* name, size_t value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   212
  JVMFlag::Error err = JVMFlag::size_tAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   213
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   214
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   215
}
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
// 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
   218
JVMFlag::Error WriteableFlags::set_ccstr_flag(const char* name, const char* value, JVMFlag::Flags origin, FormatBuffer<80>& err_msg) {
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   219
  JVMFlag::Error err = JVMFlag::ccstrAtPut((char*)name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   220
  print_flag_error_message_if_needed(err, name, err_msg);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   221
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   222
}
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
/* 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
   225
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   226
 * - 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
   227
 * - 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
   228
 */
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   229
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
   230
  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
   231
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   232
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   233
/* 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
   234
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   235
 * - 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
   236
 * - 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
   237
 */
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   238
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
   239
  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
   240
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   241
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   242
// 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
   243
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
   244
  if (name == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   245
    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
   246
    return JVMFlag::MISSING_NAME;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   247
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   248
  if (value == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   249
    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
   250
    return JVMFlag::MISSING_VALUE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   251
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   252
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   253
  JVMFlag* f = JVMFlag::find_flag((char*)name, strlen(name));
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   254
  if (f) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   255
    // 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
   256
    if (f->is_writeable()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   257
      return setter(f, value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   258
    } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   259
      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
   260
      return JVMFlag::NON_WRITABLE;
28949
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
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   263
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   264
  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
   265
  return JVMFlag::INVALID_FLAG;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   266
}
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
// 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
   269
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
   270
  char* flag_value = *(char**)value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   271
  if (flag_value == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   272
    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
   273
    return JVMFlag::MISSING_VALUE;
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 (f->is_bool()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   276
    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
   277
  } else if (f->is_int()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   278
    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
   279
  } else if (f->is_uint()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   280
    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
   281
  } else if (f->is_intx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   282
    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
   283
  } else if (f->is_uintx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   284
    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
   285
  } else if (f->is_uint64_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   286
    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
   287
  } else if (f->is_size_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   288
    return set_size_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
   289
  } else if (f->is_ccstr()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   290
    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
   291
  } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   292
    ShouldNotReachHere();
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   293
  }
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   294
  return JVMFlag::ERR_OTHER;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   295
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   296
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   297
// 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
   298
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
   299
                                                 FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   300
  jvalue new_value = *(jvalue*)value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   301
  if (f->is_bool()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   302
    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
   303
    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
   304
  } else if (f->is_int()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   305
    int ivalue = (int)new_value.j;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   306
    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
   307
  } else if (f->is_uint()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   308
    uint uvalue = (uint)new_value.j;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   309
    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
   310
  } else if (f->is_intx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   311
    intx ivalue = (intx)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   312
    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
   313
  } else if (f->is_uintx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   314
    uintx uvalue = (uintx)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   315
    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
   316
  } else if (f->is_uint64_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   317
    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
   318
    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
   319
  } else if (f->is_size_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   320
    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
   321
    return set_size_t_flag(f->_name, svalue, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   322
  } else if (f->is_ccstr()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   323
    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
   324
    if (str == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   325
      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
   326
      return JVMFlag::MISSING_VALUE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   327
    }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   328
    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
   329
    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
   330
    if (ret != JVMFlag::SUCCESS) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   331
      FREE_C_HEAP_ARRAY(char, svalue);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   332
    }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   333
    return ret;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   334
  } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   335
    ShouldNotReachHere();
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   336
  }
49902
3661f31c6df4 8202150: [REDO] Split globals.hpp to factor out the Flag class
gziemski
parents: 49860
diff changeset
   337
  return JVMFlag::ERR_OTHER;
29068
683bef04fb20 8072935: Fix missing newline at end of file after 8067447
dholmes
parents: 28949
diff changeset
   338
}