8067447: Factor out the shared implementation of the VM flags manipulation code
Reviewed-by: sla, dholmes
This commit is contained in:
parent
fbf10d39fa
commit
c6b7e46d0d
hotspot/src/share/vm/services
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -35,6 +35,7 @@
|
||||
#include "runtime/os.hpp"
|
||||
#include "services/attachListener.hpp"
|
||||
#include "services/diagnosticCommand.hpp"
|
||||
#include "services/writeableFlags.hpp"
|
||||
#include "services/heapDumper.hpp"
|
||||
|
||||
volatile bool AttachListener::_initialized;
|
||||
@ -229,133 +230,6 @@ static jint heap_inspection(AttachOperation* op, outputStream* out) {
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
// set a boolean global flag using value from AttachOperation
|
||||
static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) {
|
||||
bool value = true;
|
||||
const char* arg1;
|
||||
if ((arg1 = op->arg(1)) != NULL) {
|
||||
int tmp;
|
||||
int n = sscanf(arg1, "%d", &tmp);
|
||||
if (n != 1) {
|
||||
out->print_cr("flag value must be a boolean (1 or 0)");
|
||||
return JNI_ERR;
|
||||
}
|
||||
value = (tmp != 0);
|
||||
}
|
||||
bool res = CommandLineFlags::boolAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
|
||||
if (! res) {
|
||||
out->print_cr("setting flag %s failed", name);
|
||||
}
|
||||
return res? JNI_OK : JNI_ERR;
|
||||
}
|
||||
|
||||
// set a intx global flag using value from AttachOperation
|
||||
static jint set_intx_flag(const char* name, AttachOperation* op, outputStream* out) {
|
||||
intx value;
|
||||
const char* arg1;
|
||||
if ((arg1 = op->arg(1)) != NULL) {
|
||||
int n = sscanf(arg1, INTX_FORMAT, &value);
|
||||
if (n != 1) {
|
||||
out->print_cr("flag value must be an integer");
|
||||
return JNI_ERR;
|
||||
}
|
||||
}
|
||||
bool res = CommandLineFlags::intxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
|
||||
if (! res) {
|
||||
out->print_cr("setting flag %s failed", name);
|
||||
}
|
||||
|
||||
return res? JNI_OK : JNI_ERR;
|
||||
}
|
||||
|
||||
// set a uintx global flag using value from AttachOperation
|
||||
static jint set_uintx_flag(const char* name, AttachOperation* op, outputStream* out) {
|
||||
uintx value;
|
||||
const char* arg1;
|
||||
if ((arg1 = op->arg(1)) != NULL) {
|
||||
int n = sscanf(arg1, UINTX_FORMAT, &value);
|
||||
if (n != 1) {
|
||||
out->print_cr("flag value must be an unsigned integer");
|
||||
return JNI_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (strncmp(name, "MaxHeapFreeRatio", 17) == 0) {
|
||||
FormatBuffer<80> err_msg("%s", "");
|
||||
if (!Arguments::verify_MaxHeapFreeRatio(err_msg, value)) {
|
||||
out->print_cr("%s", err_msg.buffer());
|
||||
return JNI_ERR;
|
||||
}
|
||||
} else if (strncmp(name, "MinHeapFreeRatio", 17) == 0) {
|
||||
FormatBuffer<80> err_msg("%s", "");
|
||||
if (!Arguments::verify_MinHeapFreeRatio(err_msg, value)) {
|
||||
out->print_cr("%s", err_msg.buffer());
|
||||
return JNI_ERR;
|
||||
}
|
||||
}
|
||||
bool res = CommandLineFlags::uintxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
|
||||
if (! res) {
|
||||
out->print_cr("setting flag %s failed", name);
|
||||
}
|
||||
|
||||
return res? JNI_OK : JNI_ERR;
|
||||
}
|
||||
|
||||
// set a uint64_t global flag using value from AttachOperation
|
||||
static jint set_uint64_t_flag(const char* name, AttachOperation* op, outputStream* out) {
|
||||
uint64_t value;
|
||||
const char* arg1;
|
||||
if ((arg1 = op->arg(1)) != NULL) {
|
||||
int n = sscanf(arg1, UINT64_FORMAT, &value);
|
||||
if (n != 1) {
|
||||
out->print_cr("flag value must be an unsigned 64-bit integer");
|
||||
return JNI_ERR;
|
||||
}
|
||||
}
|
||||
bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
|
||||
if (! res) {
|
||||
out->print_cr("setting flag %s failed", name);
|
||||
}
|
||||
|
||||
return res? JNI_OK : JNI_ERR;
|
||||
}
|
||||
|
||||
// set a size_t global flag using value from AttachOperation
|
||||
static jint set_size_t_flag(const char* name, AttachOperation* op, outputStream* out) {
|
||||
size_t value;
|
||||
const char* arg1;
|
||||
if ((arg1 = op->arg(1)) != NULL) {
|
||||
int n = sscanf(arg1, SIZE_FORMAT, &value);
|
||||
if (n != 1) {
|
||||
out->print_cr("flag value must be an unsigned integer");
|
||||
return JNI_ERR;
|
||||
}
|
||||
}
|
||||
bool res = CommandLineFlags::size_tAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
|
||||
if (! res) {
|
||||
out->print_cr("setting flag %s failed", name);
|
||||
}
|
||||
|
||||
return res? JNI_OK : JNI_ERR;
|
||||
}
|
||||
|
||||
// set a string global flag using value from AttachOperation
|
||||
static jint set_ccstr_flag(const char* name, AttachOperation* op, outputStream* out) {
|
||||
const char* value;
|
||||
if ((value = op->arg(1)) == NULL) {
|
||||
out->print_cr("flag value must be a string");
|
||||
return JNI_ERR;
|
||||
}
|
||||
bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
|
||||
if (res) {
|
||||
FREE_C_HEAP_ARRAY(char, value);
|
||||
} else {
|
||||
out->print_cr("setting flag %s failed", name);
|
||||
}
|
||||
|
||||
return res? JNI_OK : JNI_ERR;
|
||||
}
|
||||
|
||||
// Implementation of "setflag" command
|
||||
static jint set_flag(AttachOperation* op, outputStream* out) {
|
||||
|
||||
@ -365,27 +239,21 @@ static jint set_flag(AttachOperation* op, outputStream* out) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
Flag* f = Flag::find_flag((char*)name, strlen(name));
|
||||
if (f && f->is_external() && f->is_writeable()) {
|
||||
if (f->is_bool()) {
|
||||
return set_bool_flag(name, op, out);
|
||||
} else if (f->is_intx()) {
|
||||
return set_intx_flag(name, op, out);
|
||||
} else if (f->is_uintx()) {
|
||||
return set_uintx_flag(name, op, out);
|
||||
} else if (f->is_uint64_t()) {
|
||||
return set_uint64_t_flag(name, op, out);
|
||||
} else if (f->is_size_t()) {
|
||||
return set_size_t_flag(name, op, out);
|
||||
} else if (f->is_ccstr()) {
|
||||
return set_ccstr_flag(name, op, out);
|
||||
FormatBuffer<80> err_msg("%s", "");
|
||||
|
||||
int ret = WriteableFlags::set_flag(op->arg(0), op->arg(1), Flag::ATTACH_ON_DEMAND, err_msg);
|
||||
if (ret != WriteableFlags::SUCCESS) {
|
||||
if (ret == WriteableFlags::NON_WRITABLE) {
|
||||
// if the flag is not manageable try to change it through
|
||||
// the platform dependent implementation
|
||||
return AttachListener::pd_set_flag(op, out);
|
||||
} else {
|
||||
ShouldNotReachHere();
|
||||
return JNI_ERR;
|
||||
out->print_cr("%s", err_msg.buffer());
|
||||
}
|
||||
} else {
|
||||
return AttachListener::pd_set_flag(op, out);
|
||||
|
||||
return JNI_ERR;
|
||||
}
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
// Implementation of "printflag" command
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -43,6 +43,7 @@
|
||||
#include "services/classLoadingService.hpp"
|
||||
#include "services/diagnosticCommand.hpp"
|
||||
#include "services/diagnosticFramework.hpp"
|
||||
#include "services/writeableFlags.hpp"
|
||||
#include "services/heapDumper.hpp"
|
||||
#include "services/jmm.h"
|
||||
#include "services/lowMemoryDetector.hpp"
|
||||
@ -1698,56 +1699,21 @@ JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value
|
||||
"The flag name cannot be null.");
|
||||
}
|
||||
char* name = java_lang_String::as_utf8_string(fn);
|
||||
Flag* flag = Flag::find_flag(name, strlen(name));
|
||||
if (flag == NULL) {
|
||||
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
|
||||
"Flag does not exist.");
|
||||
}
|
||||
if (!flag->is_writeable()) {
|
||||
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
|
||||
"This flag is not writeable.");
|
||||
}
|
||||
|
||||
bool succeed = false;
|
||||
if (flag->is_bool()) {
|
||||
bool bvalue = (new_value.z == JNI_TRUE ? true : false);
|
||||
succeed = CommandLineFlags::boolAtPut(name, &bvalue, Flag::MANAGEMENT);
|
||||
} else if (flag->is_intx()) {
|
||||
intx ivalue = (intx)new_value.j;
|
||||
succeed = CommandLineFlags::intxAtPut(name, &ivalue, Flag::MANAGEMENT);
|
||||
} else if (flag->is_uintx()) {
|
||||
uintx uvalue = (uintx)new_value.j;
|
||||
FormatBuffer<80> err_msg("%s", "");
|
||||
int succeed = WriteableFlags::set_flag(name, new_value, Flag::MANAGEMENT, err_msg);
|
||||
|
||||
if (strncmp(name, "MaxHeapFreeRatio", 17) == 0) {
|
||||
FormatBuffer<80> err_msg("%s", "");
|
||||
if (!Arguments::verify_MaxHeapFreeRatio(err_msg, uvalue)) {
|
||||
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), err_msg.buffer());
|
||||
}
|
||||
} else if (strncmp(name, "MinHeapFreeRatio", 17) == 0) {
|
||||
FormatBuffer<80> err_msg("%s", "");
|
||||
if (!Arguments::verify_MinHeapFreeRatio(err_msg, uvalue)) {
|
||||
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), err_msg.buffer());
|
||||
}
|
||||
}
|
||||
succeed = CommandLineFlags::uintxAtPut(name, &uvalue, Flag::MANAGEMENT);
|
||||
} else if (flag->is_uint64_t()) {
|
||||
uint64_t uvalue = (uint64_t)new_value.j;
|
||||
succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, Flag::MANAGEMENT);
|
||||
} else if (flag->is_size_t()) {
|
||||
size_t svalue = (size_t)new_value.j;
|
||||
succeed = CommandLineFlags::size_tAtPut(name, &svalue, Flag::MANAGEMENT);
|
||||
} else if (flag->is_ccstr()) {
|
||||
oop str = JNIHandles::resolve_external_guard(new_value.l);
|
||||
if (str == NULL) {
|
||||
if (succeed != WriteableFlags::SUCCESS) {
|
||||
if (succeed == WriteableFlags::MISSING_VALUE) {
|
||||
// missing value causes NPE to be thrown
|
||||
THROW(vmSymbols::java_lang_NullPointerException());
|
||||
}
|
||||
ccstr svalue = java_lang_String::as_utf8_string(str);
|
||||
succeed = CommandLineFlags::ccstrAtPut(name, &svalue, Flag::MANAGEMENT);
|
||||
if (succeed) {
|
||||
FREE_C_HEAP_ARRAY(char, svalue);
|
||||
} else {
|
||||
// all the other errors are reported as IAE with the appropriate error message
|
||||
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
|
||||
err_msg.buffer());
|
||||
}
|
||||
}
|
||||
assert(succeed, "Setting flag should succeed");
|
||||
assert(succeed == WriteableFlags::SUCCESS, "Setting flag should succeed");
|
||||
JVM_END
|
||||
|
||||
class ThreadTimesClosure: public ThreadClosure {
|
||||
|
226
hotspot/src/share/vm/services/writeableFlags.cpp
Normal file
226
hotspot/src/share/vm/services/writeableFlags.cpp
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "classfile/javaClasses.hpp"
|
||||
#include "runtime/arguments.hpp"
|
||||
#include "runtime/java.hpp"
|
||||
#include "runtime/jniHandles.hpp"
|
||||
#include "services/writeableFlags.hpp"
|
||||
|
||||
// set a boolean global flag
|
||||
int WriteableFlags::set_bool_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
int value = true;
|
||||
|
||||
if (sscanf(arg, "%d", &value)) {
|
||||
return set_bool_flag(name, value != 0, origin, err_msg);
|
||||
}
|
||||
err_msg.print("flag value must be a boolean (1 or 0)");
|
||||
return WRONG_FORMAT;
|
||||
}
|
||||
|
||||
int WriteableFlags::set_bool_flag(const char* name, bool value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
return CommandLineFlags::boolAtPut((char*)name, &value, origin) ? SUCCESS : ERR_OTHER;
|
||||
}
|
||||
|
||||
// set a intx global flag
|
||||
int WriteableFlags::set_intx_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
intx value;
|
||||
|
||||
if (sscanf(arg, INTX_FORMAT, &value)) {
|
||||
return set_intx_flag(name, value, origin, err_msg);
|
||||
}
|
||||
err_msg.print("flag value must be an integer");
|
||||
return WRONG_FORMAT;
|
||||
}
|
||||
|
||||
int WriteableFlags::set_intx_flag(const char* name, intx value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
return CommandLineFlags::intxAtPut((char*)name, &value, origin) ? SUCCESS : ERR_OTHER;
|
||||
}
|
||||
|
||||
// set a uintx global flag
|
||||
int WriteableFlags::set_uintx_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
uintx value;
|
||||
|
||||
if (sscanf(arg, UINTX_FORMAT, &value)) {
|
||||
return set_uintx_flag(name, value, origin, err_msg);
|
||||
}
|
||||
err_msg.print("flag value must be an unsigned integer");
|
||||
return WRONG_FORMAT;
|
||||
}
|
||||
|
||||
int WriteableFlags::set_uintx_flag(const char* name, uintx value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
if (strncmp(name, "MaxHeapFreeRatio", 17) == 0) {
|
||||
if (!Arguments::verify_MaxHeapFreeRatio(err_msg, value)) {
|
||||
return OUT_OF_BOUNDS;
|
||||
}
|
||||
} else if (strncmp(name, "MinHeapFreeRatio", 17) == 0) {
|
||||
if (!Arguments::verify_MinHeapFreeRatio(err_msg, value)) {
|
||||
return OUT_OF_BOUNDS;
|
||||
}
|
||||
}
|
||||
return CommandLineFlags::uintxAtPut((char*)name, &value, origin) ? SUCCESS : ERR_OTHER;
|
||||
}
|
||||
|
||||
// set a uint64_t global flag
|
||||
int WriteableFlags::set_uint64_t_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
uint64_t value;
|
||||
|
||||
if (sscanf(arg, UINT64_FORMAT, &value)) {
|
||||
return set_uint64_t_flag(name, value, origin, err_msg);
|
||||
}
|
||||
err_msg.print("flag value must be an unsigned 64-bit integer");
|
||||
return WRONG_FORMAT;
|
||||
}
|
||||
|
||||
int WriteableFlags::set_uint64_t_flag(const char* name, uint64_t value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
return CommandLineFlags::uint64_tAtPut((char*)name, &value, origin) ? SUCCESS : ERR_OTHER;
|
||||
}
|
||||
|
||||
// set a size_t global flag
|
||||
int WriteableFlags::set_size_t_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
size_t value;
|
||||
|
||||
if (sscanf(arg, SIZE_FORMAT, &value)) {
|
||||
return set_size_t_flag(name, value, origin, err_msg);
|
||||
}
|
||||
err_msg.print("flag value must be an unsigned integer");
|
||||
return WRONG_FORMAT;
|
||||
}
|
||||
|
||||
int WriteableFlags::set_size_t_flag(const char* name, size_t value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
return CommandLineFlags::size_tAtPut((char*)name, &value, origin) ? SUCCESS : ERR_OTHER;
|
||||
}
|
||||
|
||||
// set a string global flag using value from AttachOperation
|
||||
int WriteableFlags::set_ccstr_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
bool res = CommandLineFlags::ccstrAtPut((char*)name, &arg, origin);
|
||||
|
||||
return res? SUCCESS : ERR_OTHER;
|
||||
}
|
||||
|
||||
/* sets a writeable flag to the provided value
|
||||
*
|
||||
* - return status is one of the WriteableFlags::err enum values
|
||||
* - an eventual error message will be generated to the provided err_msg buffer
|
||||
*/
|
||||
int WriteableFlags::set_flag(const char* flag_name, const char* flag_value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
return set_flag(flag_name, &flag_value, set_flag_from_char, origin, err_msg);
|
||||
}
|
||||
|
||||
/* sets a writeable flag to the provided value
|
||||
*
|
||||
* - return status is one of the WriteableFlags::err enum values
|
||||
* - an eventual error message will be generated to the provided err_msg buffer
|
||||
*/
|
||||
int WriteableFlags::set_flag(const char* flag_name, jvalue flag_value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
return set_flag(flag_name, &flag_value, set_flag_from_jvalue, origin, err_msg);
|
||||
}
|
||||
|
||||
// a writeable flag setter accepting either 'jvalue' or 'char *' values
|
||||
int WriteableFlags::set_flag(const char* name, const void* value, int(*setter)(Flag*,const void*,Flag::Flags,FormatBuffer<80>&), Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
if (name == NULL) {
|
||||
err_msg.print("flag name is missing");
|
||||
return MISSING_NAME;
|
||||
}
|
||||
if (value == NULL) {
|
||||
err_msg.print("flag value is missing");
|
||||
return MISSING_VALUE;
|
||||
}
|
||||
|
||||
Flag* f = Flag::find_flag((char*)name, strlen(name));
|
||||
if (f) {
|
||||
// only writeable flags are allowed to be set
|
||||
if (f->is_writeable()) {
|
||||
return setter(f, value, origin, err_msg);
|
||||
} else {
|
||||
err_msg.print("only 'writeable' flags can be set");
|
||||
return NON_WRITABLE;
|
||||
}
|
||||
}
|
||||
|
||||
err_msg.print("flag %s does not exist", name);
|
||||
return INVALID_FLAG;
|
||||
}
|
||||
|
||||
// a writeable flag setter accepting 'char *' values
|
||||
int WriteableFlags::set_flag_from_char(Flag* f, const void* value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
char* flag_value = *(char**)value;
|
||||
if (flag_value == NULL) {
|
||||
err_msg.print("flag value is missing");
|
||||
return MISSING_VALUE;
|
||||
}
|
||||
if (f->is_bool()) {
|
||||
return set_bool_flag(f->_name, flag_value, origin, err_msg);
|
||||
} else if (f->is_intx()) {
|
||||
return set_intx_flag(f->_name, flag_value, origin, err_msg);
|
||||
} else if (f->is_uintx()) {
|
||||
return set_uintx_flag(f->_name, flag_value, origin, err_msg);
|
||||
} else if (f->is_uint64_t()) {
|
||||
return set_uint64_t_flag(f->_name, flag_value, origin, err_msg);
|
||||
} else if (f->is_size_t()) {
|
||||
return set_size_t_flag(f->_name, flag_value, origin, err_msg);
|
||||
} else if (f->is_ccstr()) {
|
||||
return set_ccstr_flag(f->_name, flag_value, origin, err_msg);
|
||||
} else {
|
||||
ShouldNotReachHere();
|
||||
}
|
||||
return ERR_OTHER;
|
||||
}
|
||||
|
||||
// a writeable flag setter accepting 'jvalue' values
|
||||
int WriteableFlags::set_flag_from_jvalue(Flag* f, const void* value, Flag::Flags origin, FormatBuffer<80>& err_msg) {
|
||||
jvalue new_value = *(jvalue*)value;
|
||||
if (f->is_bool()) {
|
||||
bool bvalue = (new_value.z == JNI_TRUE ? true : false);
|
||||
return set_bool_flag(f->_name, bvalue, origin, err_msg);
|
||||
} else if (f->is_intx()) {
|
||||
intx ivalue = (intx)new_value.j;
|
||||
return set_intx_flag(f->_name, ivalue, origin, err_msg);
|
||||
} else if (f->is_uintx()) {
|
||||
uintx uvalue = (uintx)new_value.j;
|
||||
return set_uintx_flag(f->_name, uvalue, origin, err_msg);
|
||||
} else if (f->is_uint64_t()) {
|
||||
uint64_t uvalue = (uint64_t)new_value.j;
|
||||
return set_uint64_t_flag(f->_name, uvalue, origin, err_msg);
|
||||
} else if (f->is_size_t()) {
|
||||
size_t svalue = (size_t)new_value.j;
|
||||
return set_size_t_flag(f->_name, svalue, origin, err_msg);
|
||||
} else if (f->is_ccstr()) {
|
||||
oop str = JNIHandles::resolve_external_guard(new_value.l);
|
||||
if (str == NULL) {
|
||||
err_msg.print("flag value is missing");
|
||||
return MISSING_VALUE;
|
||||
}
|
||||
ccstr svalue = java_lang_String::as_utf8_string(str);
|
||||
int ret = WriteableFlags::set_ccstr_flag(f->_name, svalue, origin, err_msg);
|
||||
if (ret != SUCCESS) {
|
||||
FREE_C_HEAP_ARRAY(char, svalue);
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
ShouldNotReachHere();
|
||||
}
|
||||
return ERR_OTHER;
|
||||
}
|
97
hotspot/src/share/vm/services/writeableFlags.hpp
Normal file
97
hotspot/src/share/vm/services/writeableFlags.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHARE_VM_SERVICES_WRITEABLEFLAG_HPP
|
||||
#define SHARE_VM_SERVICES_WRITEABLEFLAG_HPP
|
||||
|
||||
class WriteableFlags : AllStatic {
|
||||
public:
|
||||
enum error {
|
||||
// no error
|
||||
SUCCESS,
|
||||
// flag name is missing
|
||||
MISSING_NAME,
|
||||
// flag value is missing
|
||||
MISSING_VALUE,
|
||||
// error parsing the textual form of the value
|
||||
WRONG_FORMAT,
|
||||
// flag is not writeable
|
||||
NON_WRITABLE,
|
||||
// flag value is outside of its bounds
|
||||
OUT_OF_BOUNDS,
|
||||
// there is no flag with the given name
|
||||
INVALID_FLAG,
|
||||
// other, unspecified error related to setting the flag
|
||||
ERR_OTHER
|
||||
} err;
|
||||
|
||||
private:
|
||||
// a writeable flag setter accepting either 'jvalue' or 'char *' values
|
||||
static int set_flag(const char* name, const void* value, int(*setter)(Flag*, const void*, Flag::Flags, FormatBuffer<80>&), Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// a writeable flag setter accepting 'char *' values
|
||||
static int set_flag_from_char(Flag* f, const void* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// a writeable flag setter accepting 'jvalue' values
|
||||
static int set_flag_from_jvalue(Flag* f, const void* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
|
||||
// set a boolean global flag
|
||||
static int set_bool_flag(const char* name, const char* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a intx global flag
|
||||
static int set_intx_flag(const char* name, const char* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a uintx global flag
|
||||
static int set_uintx_flag(const char* name, const char* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a uint64_t global flag
|
||||
static int set_uint64_t_flag(const char* name, const char* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a size_t global flag using value from AttachOperation
|
||||
static int set_size_t_flag(const char* name, const char* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a boolean global flag
|
||||
static int set_bool_flag(const char* name, bool value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a intx global flag
|
||||
static int set_intx_flag(const char* name, intx value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a uintx global flag
|
||||
static int set_uintx_flag(const char* name, uintx value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a uint64_t global flag
|
||||
static int set_uint64_t_flag(const char* name, uint64_t value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a size_t global flag using value from AttachOperation
|
||||
static int set_size_t_flag(const char* name, size_t value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
// set a string global flag
|
||||
static int set_ccstr_flag(const char* name, const char* value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
|
||||
public:
|
||||
/* sets a writeable flag to the provided value
|
||||
*
|
||||
* - return status is one of the WriteableFlags::err enum values
|
||||
* - an eventual error message will be generated to the provided err_msg buffer
|
||||
*/
|
||||
static int set_flag(const char* flag_name, const char* flag_value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
|
||||
/* sets a writeable flag to the provided value
|
||||
*
|
||||
* - return status is one of the WriteableFlags::err enum values
|
||||
* - an eventual error message will be generated to the provided err_msg buffer
|
||||
*/
|
||||
static int set_flag(const char* flag_name, jvalue flag_value, Flag::Flags origin, FormatBuffer<80>& err_msg);
|
||||
};
|
||||
|
||||
#endif /* SHARE_VM_SERVICES_WRITEABLEFLAG_HPP */
|
||||
|
Loading…
x
Reference in New Issue
Block a user