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