src/hotspot/share/services/writeableFlags.cpp
author gziemski
Mon, 23 Apr 2018 14:51:16 -0500
changeset 49860 ca5216a2a2cc
parent 49857 31e07291ae29
child 49902 3661f31c6df4
permissions -rw-r--r--
8202151: [BACKOUT] Split globals.hpp to factor out the Flag class Summary: Backed out JDK-8081519 Reviewed-by: kvn
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"
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    29
#include "runtime/commandLineFlagRangeList.hpp"
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    30
#include "runtime/java.hpp"
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    31
#include "runtime/jniHandles.hpp"
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    32
#include "services/writeableFlags.hpp"
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    33
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    34
#define TEMP_BUF_SIZE 80
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    35
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    36
static void buffer_concat(char* buffer, const char* src) {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    37
  strncat(buffer, src, TEMP_BUF_SIZE - 1 - strlen(buffer));
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    38
}
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
static void print_flag_error_message_bounds(const char* name, char* buffer) {
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    41
  CommandLineFlagRange* range = CommandLineFlagRangeList::find(name);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    42
  if (range != NULL) {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    43
    buffer_concat(buffer, "must have value in range ");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    44
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    45
    stringStream stream;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    46
    range->print(&stream);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    47
    const char* range_string = stream.as_string();
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    48
    size_t j = strlen(buffer);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    49
    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
    50
      if (range_string[i] == '\0') {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    51
        break;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    52
      } else if (range_string[i] != ' ') {
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    53
        buffer[j] = range_string[i];
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    54
        j++;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    55
      }
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
    buffer[j] = '\0';
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    58
  }
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
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    61
static void print_flag_error_message_if_needed(Flag::Error error, const char* name, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    62
  if (error == Flag::SUCCESS) {
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    63
    return;
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    64
  }
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
  char buffer[TEMP_BUF_SIZE] = {'\0'};
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    67
  if ((error != Flag::MISSING_NAME) && (name != NULL)) {
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    68
    buffer_concat(buffer, name);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    69
    buffer_concat(buffer, " error: ");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    70
  } else {
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
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    73
  switch (error) {
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    74
    case Flag::MISSING_NAME:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    75
      buffer_concat(buffer, "flag name is missing."); break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    76
    case Flag::MISSING_VALUE:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    77
      buffer_concat(buffer, "parsing the textual form of the value."); break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    78
    case Flag::NON_WRITABLE:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    79
      buffer_concat(buffer, "flag is not writeable."); break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    80
    case Flag::OUT_OF_BOUNDS:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    81
      print_flag_error_message_bounds(name, buffer); break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    82
    case Flag::VIOLATES_CONSTRAINT:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    83
      buffer_concat(buffer, "value violates its flag's constraint."); break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    84
    case Flag::INVALID_FLAG:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    85
      buffer_concat(buffer, "there is no flag with the given name."); break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    86
    case Flag::ERR_OTHER:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    87
      buffer_concat(buffer, "other, unspecified error related to setting the flag."); break;
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    88
    case Flag::SUCCESS:
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    89
      break;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38942
diff changeset
    90
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38942
diff changeset
    91
      break;
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    92
  }
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    93
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31371
diff changeset
    94
  err_msg.print("%s", buffer);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    95
}
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
    96
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
    97
// set a boolean global flag
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
    98
Flag::Error WriteableFlags::set_bool_flag(const char* name, const char* arg, Flag::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
    99
  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
   100
    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
   101
  } 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
   102
    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
   103
  }
38942
a4b3fc1ba095 8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
gziemski
parents: 33604
diff changeset
   104
  err_msg.print("flag value must be a boolean (1/0 or true/false)");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   105
  return Flag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   106
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   107
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   108
Flag::Error WriteableFlags::set_bool_flag(const char* name, bool value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   109
  Flag::Error err = CommandLineFlags::boolAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   110
  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
   111
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   112
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   113
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   114
// set a int global flag
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   115
Flag::Error WriteableFlags::set_int_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   116
  int value;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   117
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   118
  if (sscanf(arg, "%d", &value)) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   119
    return set_int_flag(name, value, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   120
  }
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   121
  err_msg.print("flag value must be an integer");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   122
  return Flag::WRONG_FORMAT;
31236
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
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   125
Flag::Error WriteableFlags::set_int_flag(const char* name, int value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   126
  Flag::Error err = CommandLineFlags::intAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   127
  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
   128
  return err;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   129
}
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
// set a uint global flag
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   132
Flag::Error WriteableFlags::set_uint_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   133
  uint value;
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
  if (sscanf(arg, "%u", &value)) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   136
    return set_uint_flag(name, value, origin, err_msg);
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   137
  }
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   138
  err_msg.print("flag value must be an unsigned integer");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   139
  return Flag::WRONG_FORMAT;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   140
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   141
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   142
Flag::Error WriteableFlags::set_uint_flag(const char* name, uint value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   143
  Flag::Error err = CommandLineFlags::uintAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   144
  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
   145
  return err;
31236
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   146
}
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   147
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   148
// set a intx global flag
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   149
Flag::Error WriteableFlags::set_intx_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   150
  intx value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   151
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   152
  if (sscanf(arg, INTX_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   153
    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
   154
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   155
  err_msg.print("flag value must be an integer");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   156
  return Flag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   157
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   158
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   159
Flag::Error WriteableFlags::set_intx_flag(const char* name, intx value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   160
  Flag::Error err = CommandLineFlags::intxAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   161
  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
   162
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   163
}
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
// set a uintx global flag
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   166
Flag::Error WriteableFlags::set_uintx_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   167
  uintx value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   168
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   169
  if (sscanf(arg, UINTX_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   170
    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
   171
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   172
  err_msg.print("flag value must be an unsigned integer");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   173
  return Flag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   174
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   175
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   176
Flag::Error WriteableFlags::set_uintx_flag(const char* name, uintx value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   177
  Flag::Error err = CommandLineFlags::uintxAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   178
  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
   179
  return err;
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
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   182
// set a uint64_t global flag
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   183
Flag::Error WriteableFlags::set_uint64_t_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   184
  uint64_t value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   185
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   186
  if (sscanf(arg, UINT64_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   187
    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
   188
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   189
  err_msg.print("flag value must be an unsigned 64-bit integer");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   190
  return Flag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   191
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   192
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   193
Flag::Error WriteableFlags::set_uint64_t_flag(const char* name, uint64_t value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   194
  Flag::Error err = CommandLineFlags::uint64_tAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   195
  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
   196
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   197
}
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
// set a size_t global flag
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   200
Flag::Error WriteableFlags::set_size_t_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   201
  size_t value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   202
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   203
  if (sscanf(arg, SIZE_FORMAT, &value)) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   204
    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
   205
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   206
  err_msg.print("flag value must be an unsigned integer");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   207
  return Flag::WRONG_FORMAT;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   208
}
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   209
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   210
Flag::Error WriteableFlags::set_size_t_flag(const char* name, size_t value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   211
  Flag::Error err = CommandLineFlags::size_tAtPut(name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   212
  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
   213
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   214
}
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
// set a string global flag using value from AttachOperation
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   217
Flag::Error WriteableFlags::set_ccstr_flag(const char* name, const char* value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   218
  Flag::Error err = CommandLineFlags::ccstrAtPut((char*)name, &value, origin);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 31236
diff changeset
   219
  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
   220
  return err;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   221
}
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
/* 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
   224
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   225
 * - 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
   226
 * - 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
   227
 */
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   228
Flag::Error WriteableFlags::set_flag(const char* flag_name, const char* flag_value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   229
  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
   230
}
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
/* 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
   233
 *
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   234
 * - 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
   235
 * - 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
   236
 */
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   237
Flag::Error WriteableFlags::set_flag(const char* flag_name, jvalue flag_value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   238
  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
   239
}
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
// a writeable flag setter accepting either 'jvalue' or 'char *' values
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   242
Flag::Error WriteableFlags::set_flag(const char* name, const void* value, Flag::Error(*setter)(Flag*,const void*,Flag::Flags,FormatBuffer<80>&), Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   243
  if (name == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   244
    err_msg.print("flag name is missing");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   245
    return Flag::MISSING_NAME;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   246
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   247
  if (value == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   248
    err_msg.print("flag value is missing");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   249
    return Flag::MISSING_VALUE;
28949
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
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   252
  Flag* f = Flag::find_flag((char*)name, strlen(name));
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   253
  if (f) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   254
    // 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
   255
    if (f->is_writeable()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   256
      return setter(f, value, origin, err_msg);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   257
    } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   258
      err_msg.print("only 'writeable' flags can be set");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   259
      return Flag::NON_WRITABLE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   260
    }
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
  err_msg.print("flag %s does not exist", name);
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   264
  return Flag::INVALID_FLAG;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   265
}
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
// a writeable flag setter accepting 'char *' values
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   268
Flag::Error WriteableFlags::set_flag_from_char(Flag* f, const void* value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   269
  char* flag_value = *(char**)value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   270
  if (flag_value == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   271
    err_msg.print("flag value is missing");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   272
    return Flag::MISSING_VALUE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   273
  }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   274
  if (f->is_bool()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   275
    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
   276
  } else if (f->is_int()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   277
    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
   278
  } else if (f->is_uint()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   279
    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
   280
  } else if (f->is_intx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   281
    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
   282
  } else if (f->is_uintx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   283
    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
   284
  } else if (f->is_uint64_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   285
    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
   286
  } else if (f->is_size_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   287
    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
   288
  } else if (f->is_ccstr()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   289
    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
   290
  } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   291
    ShouldNotReachHere();
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   292
  }
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   293
  return Flag::ERR_OTHER;
28949
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
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   296
// a writeable flag setter accepting 'jvalue' values
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   297
Flag::Error WriteableFlags::set_flag_from_jvalue(Flag* f, const void* value, Flag::Flags origin,
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31371
diff changeset
   298
                                                 FormatBuffer<80>& err_msg) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   299
  jvalue new_value = *(jvalue*)value;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   300
  if (f->is_bool()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   301
    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
   302
    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
   303
  } else if (f->is_int()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   304
    int ivalue = (int)new_value.j;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   305
    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
   306
  } else if (f->is_uint()) {
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   307
    uint uvalue = (uint)new_value.j;
d4d3011aa98e 8080947: Add uint as a valid VM flag type
david
parents: 29068
diff changeset
   308
    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
   309
  } else if (f->is_intx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   310
    intx ivalue = (intx)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   311
    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
   312
  } else if (f->is_uintx()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   313
    uintx uvalue = (uintx)new_value.j;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   314
    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
   315
  } else if (f->is_uint64_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   316
    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
   317
    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
   318
  } else if (f->is_size_t()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   319
    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
   320
    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
   321
  } else if (f->is_ccstr()) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   322
    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
   323
    if (str == NULL) {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   324
      err_msg.print("flag value is missing");
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   325
      return Flag::MISSING_VALUE;
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   326
    }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   327
    ccstr svalue = java_lang_String::as_utf8_string(str);
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   328
    Flag::Error ret = WriteableFlags::set_ccstr_flag(f->_name, svalue, origin, err_msg);
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   329
    if (ret != Flag::SUCCESS) {
28949
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   330
      FREE_C_HEAP_ARRAY(char, svalue);
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   331
    }
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   332
    return ret;
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   333
  } else {
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   334
    ShouldNotReachHere();
c6f50d62ecef 8067447: Factor out the shared implementation of the VM flags manipulation code
jbachorik
parents:
diff changeset
   335
  }
49860
ca5216a2a2cc 8202151: [BACKOUT] Split globals.hpp to factor out the Flag class
gziemski
parents: 49857
diff changeset
   336
  return Flag::ERR_OTHER;
29068
683bef04fb20 8072935: Fix missing newline at end of file after 8067447
dholmes
parents: 28949
diff changeset
   337
}