Skip to content
Permalink
Browse files
8081833: Clean up JVMFlag getter/setter code
Reviewed-by: gziemski, coleenp
  • Loading branch information
iklam committed Sep 22, 2020
1 parent 0e98fc1 commit 282b9dcfdc0adc8596abc4e758756e84d337b2f7
Show file tree
Hide file tree
Showing 26 changed files with 888 additions and 1,607 deletions.
@@ -279,11 +279,11 @@ TRACE_REQUEST_FUNC(ThreadContextSwitchRate) {
#define SEND_FLAGS_OF_TYPE(eventType, flagType) \
do { \
JVMFlag *flag = JVMFlag::flags; \
while (flag->_name != NULL) { \
while (flag->name() != NULL) { \
if (flag->is_ ## flagType()) { \
if (flag->is_unlocked()) { \
Event ## eventType event; \
event.set_name(flag->_name); \
event.set_name(flag->name()); \
event.set_value(flag->get_ ## flagType()); \
event.set_origin(flag->get_origin()); \
event.commit(); \
@@ -237,7 +237,7 @@ C2V_VMENTRY_NULL(jobject, getFlagValue, (JNIEnv* env, jobject c2vm, jobject name
} else if (flag->is_double()) {
RETURN_BOXED_DOUBLE(flag->get_double());
} else {
JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->_name, flag->_type);
JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->name(), flag->type_string());
}
#undef RETURN_BOXED_LONG
#undef RETURN_BOXED_DOUBLE
@@ -23,13 +23,14 @@
*/

#include "precompiled.hpp"
#include "gc/shared/gcConfig.hpp"
#include "jvm.h"
#include "jvmci/jvmci_globals.hpp"
#include "gc/shared/gcConfig.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/ostream.hpp"
#include "runtime/arguments.hpp"
#include "runtime/flags/jvmFlagAccess.hpp"
#include "runtime/globals_extension.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/ostream.hpp"

fileStream* JVMCIGlobals::_jni_config_file = NULL;

@@ -187,7 +188,7 @@ bool JVMCIGlobals::enable_jvmci_product_mode(JVMFlag::Flags origin) {

bool value = true;
JVMFlag *jvmciEnableFlag = JVMFlag::find_flag("EnableJVMCIProduct");
if (JVMFlag::boolAtPut(jvmciEnableFlag, &value, origin) != JVMFlag::SUCCESS) {
if (JVMFlagAccess::boolAtPut(jvmciEnableFlag, &value, origin) != JVMFlag::SUCCESS) {
return false;
}

@@ -59,7 +59,7 @@
#include "prims/resolvedMethodTable.hpp"
#include "runtime/arguments.hpp"
#include "runtime/atomic.hpp"
#include "runtime/flags/jvmFlagConstraintList.hpp"
#include "runtime/flags/jvmFlagLimit.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/init.hpp"
#include "runtime/java.hpp"
@@ -753,7 +753,7 @@ jint universe_init() {
AOTLoader::universe_init();

// Checks 'AfterMemoryInit' constraints.
if (!JVMFlagConstraintList::check_constraints(JVMFlagConstraint::AfterMemoryInit)) {
if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
return JNI_EINVAL;
}

@@ -66,6 +66,7 @@
#include "runtime/deoptimization.hpp"
#include "runtime/fieldDescriptor.inline.hpp"
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/flags/jvmFlagAccess.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/handshake.hpp"
@@ -1205,30 +1206,30 @@ WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
}
WB_END

template <typename T>
static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, JVMFlag::Error (*TAt)(const JVMFlag*, T*)) {
template <typename T, int type_enum>
static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value) {
if (name == NULL) {
return false;
}
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
const char* flag_name = env->GetStringUTFChars(name, NULL);
CHECK_JNI_EXCEPTION_(env, false);
const JVMFlag* flag = JVMFlag::find_declared_flag(flag_name);
JVMFlag::Error result = (*TAt)(flag, value);
JVMFlag::Error result = JVMFlagAccess::get<T, type_enum>(flag, value);
env->ReleaseStringUTFChars(name, flag_name);
return (result == JVMFlag::SUCCESS);
}

template <typename T>
static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, JVMFlag::Error (*TAtPut)(JVMFlag* flag, T*, JVMFlag::Flags)) {
template <typename T, int type_enum>
static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value) {
if (name == NULL) {
return false;
}
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
const char* flag_name = env->GetStringUTFChars(name, NULL);
CHECK_JNI_EXCEPTION_(env, false);
JVMFlag* flag = JVMFlag::find_flag(flag_name);
JVMFlag::Error result = (*TAtPut)(flag, value, JVMFlag::INTERNAL);
JVMFlag::Error result = JVMFlagAccess::set<T, type_enum>(flag, value, JVMFlag::INTERNAL);
env->ReleaseStringUTFChars(name, flag_name);
return (result == JVMFlag::SUCCESS);
}
@@ -1284,7 +1285,7 @@ WB_END

WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
bool result;
if (GetVMFlag <bool> (thread, env, name, &result, &JVMFlag::boolAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(bool)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return booleanBox(thread, env, result);
}
@@ -1293,7 +1294,7 @@ WB_END

WB_ENTRY(jobject, WB_GetIntVMFlag(JNIEnv* env, jobject o, jstring name))
int result;
if (GetVMFlag <int> (thread, env, name, &result, &JVMFlag::intAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(int)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
@@ -1302,7 +1303,7 @@ WB_END

WB_ENTRY(jobject, WB_GetUintVMFlag(JNIEnv* env, jobject o, jstring name))
uint result;
if (GetVMFlag <uint> (thread, env, name, &result, &JVMFlag::uintAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(uint)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
@@ -1311,7 +1312,7 @@ WB_END

WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name))
intx result;
if (GetVMFlag <intx> (thread, env, name, &result, &JVMFlag::intxAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(intx)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
@@ -1320,7 +1321,7 @@ WB_END

WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name))
uintx result;
if (GetVMFlag <uintx> (thread, env, name, &result, &JVMFlag::uintxAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(uintx)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
@@ -1329,7 +1330,7 @@ WB_END

WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name))
uint64_t result;
if (GetVMFlag <uint64_t> (thread, env, name, &result, &JVMFlag::uint64_tAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(uint64_t)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
@@ -1338,7 +1339,7 @@ WB_END

WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name))
size_t result;
if (GetVMFlag <size_t> (thread, env, name, &result, &JVMFlag::size_tAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(size_t)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
@@ -1347,7 +1348,7 @@ WB_END

WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name))
double result;
if (GetVMFlag <double> (thread, env, name, &result, &JVMFlag::doubleAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(double)> (thread, env, name, &result)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return doubleBox(thread, env, result);
}
@@ -1356,7 +1357,7 @@ WB_END

WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name))
ccstr ccstrResult;
if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &JVMFlag::ccstrAt)) {
if (GetVMFlag <JVM_FLAG_TYPE(ccstr)> (thread, env, name, &ccstrResult)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
jstring result = env->NewStringUTF(ccstrResult);
CHECK_JNI_EXCEPTION_(env, NULL);
@@ -1367,42 +1368,42 @@ WB_END

WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value))
bool result = value == JNI_TRUE ? true : false;
SetVMFlag <bool> (thread, env, name, &result, &JVMFlag::boolAtPut);
SetVMFlag <JVM_FLAG_TYPE(bool)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetIntVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
int result = value;
SetVMFlag <int> (thread, env, name, &result, &JVMFlag::intAtPut);
SetVMFlag <JVM_FLAG_TYPE(int)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetUintVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
uint result = value;
SetVMFlag <uint> (thread, env, name, &result, &JVMFlag::uintAtPut);
SetVMFlag <JVM_FLAG_TYPE(uint)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
intx result = value;
SetVMFlag <intx> (thread, env, name, &result, &JVMFlag::intxAtPut);
SetVMFlag <JVM_FLAG_TYPE(intx)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
uintx result = value;
SetVMFlag <uintx> (thread, env, name, &result, &JVMFlag::uintxAtPut);
SetVMFlag <JVM_FLAG_TYPE(uintx)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
uint64_t result = value;
SetVMFlag <uint64_t> (thread, env, name, &result, &JVMFlag::uint64_tAtPut);
SetVMFlag <JVM_FLAG_TYPE(uint64_t)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
size_t result = value;
SetVMFlag <size_t> (thread, env, name, &result, &JVMFlag::size_tAtPut);
SetVMFlag <JVM_FLAG_TYPE(size_t)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value))
double result = value;
SetVMFlag <double> (thread, env, name, &result, &JVMFlag::doubleAtPut);
SetVMFlag <JVM_FLAG_TYPE(double)> (thread, env, name, &result);
WB_END

WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
@@ -1419,7 +1420,7 @@ WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring
bool needFree;
{
ThreadInVMfromNative ttvfn(thread); // back to VM
needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &JVMFlag::ccstrAtPut);
needFree = SetVMFlag <JVM_FLAG_TYPE(ccstr)> (thread, env, name, &ccstrResult);
}
if (value != NULL) {
env->ReleaseStringUTFChars(value, ccstrValue);
@@ -41,8 +41,7 @@
#include "prims/jvmtiExport.hpp"
#include "runtime/arguments.hpp"
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/flags/jvmFlagConstraintList.hpp"
#include "runtime/flags/jvmFlagRangeList.hpp"
#include "runtime/flags/jvmFlagAccess.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/java.hpp"
#include "runtime/os.inline.hpp"
@@ -877,7 +876,7 @@ void Arguments::describe_range_error(ArgsRange errcode) {
}

static bool set_bool_flag(JVMFlag* flag, bool value, JVMFlag::Flags origin) {
if (JVMFlag::boolAtPut(flag, &value, origin) == JVMFlag::SUCCESS) {
if (JVMFlagAccess::boolAtPut(flag, &value, origin) == JVMFlag::SUCCESS) {
return true;
} else {
return false;
@@ -892,7 +891,7 @@ static bool set_fp_numeric_flag(JVMFlag* flag, char* value, JVMFlag::Flags origi
return false;
}

if (JVMFlag::doubleAtPut(flag, &v, origin) == JVMFlag::SUCCESS) {
if (JVMFlagAccess::doubleAtPut(flag, &v, origin) == JVMFlag::SUCCESS) {
return true;
}
return false;
@@ -924,43 +923,43 @@ static bool set_numeric_flag(JVMFlag* flag, char* value, JVMFlag::Flags origin)
if (is_neg) {
int_v = -int_v;
}
return JVMFlag::intAtPut(flag, &int_v, origin) == JVMFlag::SUCCESS;
return JVMFlagAccess::intAtPut(flag, &int_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_uint()) {
uint uint_v = (uint) v;
return JVMFlag::uintAtPut(flag, &uint_v, origin) == JVMFlag::SUCCESS;
return JVMFlagAccess::uintAtPut(flag, &uint_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_intx()) {
intx_v = (intx) v;
if (is_neg) {
intx_v = -intx_v;
}
return JVMFlag::intxAtPut(flag, &intx_v, origin) == JVMFlag::SUCCESS;
return JVMFlagAccess::intxAtPut(flag, &intx_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_uintx()) {
uintx uintx_v = (uintx) v;
return JVMFlag::uintxAtPut(flag, &uintx_v, origin) == JVMFlag::SUCCESS;
return JVMFlagAccess::uintxAtPut(flag, &uintx_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_uint64_t()) {
uint64_t uint64_t_v = (uint64_t) v;
return JVMFlag::uint64_tAtPut(flag, &uint64_t_v, origin) == JVMFlag::SUCCESS;
return JVMFlagAccess::uint64_tAtPut(flag, &uint64_t_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_size_t()) {
size_t size_t_v = (size_t) v;
return JVMFlag::size_tAtPut(flag, &size_t_v, origin) == JVMFlag::SUCCESS;
return JVMFlagAccess::size_tAtPut(flag, &size_t_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_double()) {
double double_v = (double) v;
return JVMFlag::doubleAtPut(flag, &double_v, origin) == JVMFlag::SUCCESS;
return JVMFlagAccess::doubleAtPut(flag, &double_v, origin) == JVMFlag::SUCCESS;
} else {
return false;
}
}

static bool set_string_flag(JVMFlag* flag, const char* value, JVMFlag::Flags origin) {
if (JVMFlag::ccstrAtPut(flag, &value, origin) != JVMFlag::SUCCESS) return false;
if (JVMFlagAccess::ccstrAtPut(flag, &value, origin) != JVMFlag::SUCCESS) return false;
// Contract: JVMFlag always returns a pointer that needs freeing.
FREE_C_HEAP_ARRAY(char, value);
return true;
}

static bool append_to_string_flag(JVMFlag* flag, const char* new_value, JVMFlag::Flags origin) {
const char* old_value = "";
if (JVMFlag::ccstrAt(flag, &old_value) != JVMFlag::SUCCESS) return false;
if (JVMFlagAccess::ccstrAt(flag, &old_value) != JVMFlag::SUCCESS) return false;
size_t old_len = old_value != NULL ? strlen(old_value) : 0;
size_t new_len = strlen(new_value);
const char* value;
@@ -977,7 +976,7 @@ static bool append_to_string_flag(JVMFlag* flag, const char* new_value, JVMFlag:
value = buf;
free_this_too = buf;
}
(void) JVMFlag::ccstrAtPut(flag, &value, origin);
(void) JVMFlagAccess::ccstrAtPut(flag, &value, origin);
// JVMFlag always returns a pointer that needs freeing.
FREE_C_HEAP_ARRAY(char, value);
// JVMFlag made its own copy, so I must delete my own temp. buffer.
@@ -1355,7 +1354,7 @@ bool Arguments::process_argument(const char* arg,
jio_fprintf(defaultStream::error_stream(),
"Did you mean '%s%s%s'? ",
(fuzzy_matched->is_bool()) ? "(+/-)" : "",
fuzzy_matched->_name,
fuzzy_matched->name(),
(fuzzy_matched->is_bool()) ? "" : "=<value>");
}
}

1 comment on commit 282b9dc

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 282b9dc Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.