提交 a8020e81 编写于 作者: I iignatyev

8038756: new WB API :: get/setVMFlag

Reviewed-by: vlivanov, sla
上级 0008f1fc
...@@ -501,6 +501,159 @@ WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) ...@@ -501,6 +501,159 @@ WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
} }
WB_END WB_END
template <typename T>
static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAt)(const char*, T*)) {
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);
bool result = (*TAt)(flag_name, value);
env->ReleaseStringUTFChars(name, flag_name);
return result;
}
template <typename T>
static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAtPut)(const char*, T*, Flag::Flags)) {
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);
bool result = (*TAtPut)(flag_name, value, Flag::INTERNAL);
env->ReleaseStringUTFChars(name, flag_name);
return result;
}
template <typename T>
static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) {
ResourceMark rm(thread);
jclass clazz = env->FindClass(name->as_C_string());
CHECK_JNI_EXCEPTION_(env, NULL);
jmethodID methodID = env->GetStaticMethodID(clazz,
vmSymbols::valueOf_name()->as_C_string(),
sig->as_C_string());
CHECK_JNI_EXCEPTION_(env, NULL);
jobject result = env->CallStaticObjectMethod(clazz, methodID, value);
CHECK_JNI_EXCEPTION_(env, NULL);
return result;
}
static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) {
return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value);
}
static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) {
return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value);
}
static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) {
return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value);
}
/* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) {
return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value);
}*/
static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) {
return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value);
}
WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
bool result;
if (GetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAt)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return booleanBox(thread, env, result);
}
return NULL;
WB_END
WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name))
intx result;
if (GetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAt)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
return NULL;
WB_END
WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name))
uintx result;
if (GetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAt)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
return NULL;
WB_END
WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name))
uint64_t result;
if (GetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAt)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return longBox(thread, env, result);
}
return NULL;
WB_END
WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name))
double result;
if (GetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAt)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
return doubleBox(thread, env, result);
}
return NULL;
WB_END
WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name))
ccstr ccstrResult;
if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAt)) {
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
jstring result = env->NewStringUTF(ccstrResult);
CHECK_JNI_EXCEPTION_(env, NULL);
return result;
}
return NULL;
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, &CommandLineFlags::boolAtPut);
WB_END
WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
intx result = value;
SetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAtPut);
WB_END
WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
uintx result = value;
SetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAtPut);
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, &CommandLineFlags::uint64_tAtPut);
WB_END
WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value))
double result = value;
SetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAtPut);
WB_END
WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
const char* ccstrValue = (value == NULL) ? NULL : env->GetStringUTFChars(value, NULL);
ccstr ccstrResult = ccstrValue;
bool needFree;
{
ThreadInVMfromNative ttvfn(thread); // back to VM
needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAtPut);
}
if (value != NULL) {
env->ReleaseStringUTFChars(value, ccstrValue);
}
if (needFree) {
FREE_C_HEAP_ARRAY(char, ccstrResult, mtInternal);
}
WB_END
WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
ResourceMark rm(THREAD); ResourceMark rm(THREAD);
int len; int len;
...@@ -559,11 +712,7 @@ WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jbo ...@@ -559,11 +712,7 @@ WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jbo
return result; return result;
} }
clazz = env->FindClass(vmSymbols::java_lang_Integer()->as_C_string()); jobject obj = integerBox(thread, env, code->comp_level());
CHECK_JNI_EXCEPTION_(env, NULL);
jmethodID constructor = env->GetMethodID(clazz, vmSymbols::object_initializer_name()->as_C_string(), vmSymbols::int_void_signature()->as_C_string());
CHECK_JNI_EXCEPTION_(env, NULL);
jobject obj = env->NewObject(clazz, constructor, code->comp_level());
CHECK_JNI_EXCEPTION_(env, NULL); CHECK_JNI_EXCEPTION_(env, NULL);
env->SetObjectArrayElement(result, 0, obj); env->SetObjectArrayElement(result, 0, obj);
...@@ -684,7 +833,26 @@ static JNINativeMethod methods[] = { ...@@ -684,7 +833,26 @@ static JNINativeMethod methods[] = {
CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation},
{CC"clearMethodState", {CC"clearMethodState",
CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState},
{CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, {CC"setBooleanVMFlag", CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag},
{CC"setIntxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag},
{CC"setUintxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag},
{CC"setUint64VMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag},
{CC"setDoubleVMFlag", CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag},
{CC"setStringVMFlag", CC"(Ljava/lang/String;Ljava/lang/String;)V",
(void*)&WB_SetStringVMFlag},
{CC"getBooleanVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Boolean;",
(void*)&WB_GetBooleanVMFlag},
{CC"getIntxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;",
(void*)&WB_GetIntxVMFlag},
{CC"getUintxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;",
(void*)&WB_GetUintxVMFlag},
{CC"getUint64VMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;",
(void*)&WB_GetUint64VMFlag},
{CC"getDoubleVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Double;",
(void*)&WB_GetDoubleVMFlag},
{CC"getStringVMFlag", CC"(Ljava/lang/String;)Ljava/lang/String;",
(void*)&WB_GetStringVMFlag},
{CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
{CC"fullGC", CC"()V", (void*)&WB_FullGC }, {CC"fullGC", CC"()V", (void*)&WB_FullGC },
{CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
{CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
......
...@@ -611,7 +611,7 @@ static void trace_flag_changed(const char* name, const T old_value, const T new_ ...@@ -611,7 +611,7 @@ static void trace_flag_changed(const char* name, const T old_value, const T new_
e.commit(); e.commit();
} }
bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) { bool CommandLineFlags::boolAt(const char* name, size_t len, bool* value) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_bool()) return false; if (!result->is_bool()) return false;
...@@ -619,7 +619,7 @@ bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) { ...@@ -619,7 +619,7 @@ bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
return true; return true;
} }
bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, Flag::Flags origin) { bool CommandLineFlags::boolAtPut(const char* name, size_t len, bool* value, Flag::Flags origin) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_bool()) return false; if (!result->is_bool()) return false;
...@@ -639,7 +639,7 @@ void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, Fla ...@@ -639,7 +639,7 @@ void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, Fla
faddr->set_origin(origin); faddr->set_origin(origin);
} }
bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) { bool CommandLineFlags::intxAt(const char* name, size_t len, intx* value) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_intx()) return false; if (!result->is_intx()) return false;
...@@ -647,7 +647,7 @@ bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) { ...@@ -647,7 +647,7 @@ bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
return true; return true;
} }
bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, Flag::Flags origin) { bool CommandLineFlags::intxAtPut(const char* name, size_t len, intx* value, Flag::Flags origin) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_intx()) return false; if (!result->is_intx()) return false;
...@@ -667,7 +667,7 @@ void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Fla ...@@ -667,7 +667,7 @@ void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Fla
faddr->set_origin(origin); faddr->set_origin(origin);
} }
bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) { bool CommandLineFlags::uintxAt(const char* name, size_t len, uintx* value) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_uintx()) return false; if (!result->is_uintx()) return false;
...@@ -675,7 +675,7 @@ bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) { ...@@ -675,7 +675,7 @@ bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
return true; return true;
} }
bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, Flag::Flags origin) { bool CommandLineFlags::uintxAtPut(const char* name, size_t len, uintx* value, Flag::Flags origin) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_uintx()) return false; if (!result->is_uintx()) return false;
...@@ -695,7 +695,7 @@ void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, F ...@@ -695,7 +695,7 @@ void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, F
faddr->set_origin(origin); faddr->set_origin(origin);
} }
bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) { bool CommandLineFlags::uint64_tAt(const char* name, size_t len, uint64_t* value) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_uint64_t()) return false; if (!result->is_uint64_t()) return false;
...@@ -703,7 +703,7 @@ bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) { ...@@ -703,7 +703,7 @@ bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
return true; return true;
} }
bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, Flag::Flags origin) { bool CommandLineFlags::uint64_tAtPut(const char* name, size_t len, uint64_t* value, Flag::Flags origin) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_uint64_t()) return false; if (!result->is_uint64_t()) return false;
...@@ -723,7 +723,7 @@ void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t va ...@@ -723,7 +723,7 @@ void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t va
faddr->set_origin(origin); faddr->set_origin(origin);
} }
bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) { bool CommandLineFlags::doubleAt(const char* name, size_t len, double* value) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_double()) return false; if (!result->is_double()) return false;
...@@ -731,7 +731,7 @@ bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) { ...@@ -731,7 +731,7 @@ bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
return true; return true;
} }
bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, Flag::Flags origin) { bool CommandLineFlags::doubleAtPut(const char* name, size_t len, double* value, Flag::Flags origin) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_double()) return false; if (!result->is_double()) return false;
...@@ -751,7 +751,7 @@ void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, ...@@ -751,7 +751,7 @@ void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value,
faddr->set_origin(origin); faddr->set_origin(origin);
} }
bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) { bool CommandLineFlags::ccstrAt(const char* name, size_t len, ccstr* value) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_ccstr()) return false; if (!result->is_ccstr()) return false;
...@@ -759,7 +759,7 @@ bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) { ...@@ -759,7 +759,7 @@ bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
return true; return true;
} }
bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin) { bool CommandLineFlags::ccstrAtPut(const char* name, size_t len, ccstr* value, Flag::Flags origin) {
Flag* result = Flag::find_flag(name, len); Flag* result = Flag::find_flag(name, len);
if (result == NULL) return false; if (result == NULL) return false;
if (!result->is_ccstr()) return false; if (!result->is_ccstr()) return false;
......
...@@ -363,37 +363,37 @@ class DoubleFlagSetting { ...@@ -363,37 +363,37 @@ class DoubleFlagSetting {
class CommandLineFlags { class CommandLineFlags {
public: public:
static bool boolAt(char* name, size_t len, bool* value); static bool boolAt(const char* name, size_t len, bool* value);
static bool boolAt(char* name, bool* value) { return boolAt(name, strlen(name), value); } static bool boolAt(const char* name, bool* value) { return boolAt(name, strlen(name), value); }
static bool boolAtPut(char* name, size_t len, bool* value, Flag::Flags origin); static bool boolAtPut(const char* name, size_t len, bool* value, Flag::Flags origin);
static bool boolAtPut(char* name, bool* value, Flag::Flags origin) { return boolAtPut(name, strlen(name), value, origin); } static bool boolAtPut(const char* name, bool* value, Flag::Flags origin) { return boolAtPut(name, strlen(name), value, origin); }
static bool intxAt(char* name, size_t len, intx* value); static bool intxAt(const char* name, size_t len, intx* value);
static bool intxAt(char* name, intx* value) { return intxAt(name, strlen(name), value); } static bool intxAt(const char* name, intx* value) { return intxAt(name, strlen(name), value); }
static bool intxAtPut(char* name, size_t len, intx* value, Flag::Flags origin); static bool intxAtPut(const char* name, size_t len, intx* value, Flag::Flags origin);
static bool intxAtPut(char* name, intx* value, Flag::Flags origin) { return intxAtPut(name, strlen(name), value, origin); } static bool intxAtPut(const char* name, intx* value, Flag::Flags origin) { return intxAtPut(name, strlen(name), value, origin); }
static bool uintxAt(char* name, size_t len, uintx* value); static bool uintxAt(const char* name, size_t len, uintx* value);
static bool uintxAt(char* name, uintx* value) { return uintxAt(name, strlen(name), value); } static bool uintxAt(const char* name, uintx* value) { return uintxAt(name, strlen(name), value); }
static bool uintxAtPut(char* name, size_t len, uintx* value, Flag::Flags origin); static bool uintxAtPut(const char* name, size_t len, uintx* value, Flag::Flags origin);
static bool uintxAtPut(char* name, uintx* value, Flag::Flags origin) { return uintxAtPut(name, strlen(name), value, origin); } static bool uintxAtPut(const char* name, uintx* value, Flag::Flags origin) { return uintxAtPut(name, strlen(name), value, origin); }
static bool uint64_tAt(char* name, size_t len, uint64_t* value); static bool uint64_tAt(const char* name, size_t len, uint64_t* value);
static bool uint64_tAt(char* name, uint64_t* value) { return uint64_tAt(name, strlen(name), value); } static bool uint64_tAt(const char* name, uint64_t* value) { return uint64_tAt(name, strlen(name), value); }
static bool uint64_tAtPut(char* name, size_t len, uint64_t* value, Flag::Flags origin); static bool uint64_tAtPut(const char* name, size_t len, uint64_t* value, Flag::Flags origin);
static bool uint64_tAtPut(char* name, uint64_t* value, Flag::Flags origin) { return uint64_tAtPut(name, strlen(name), value, origin); } static bool uint64_tAtPut(const char* name, uint64_t* value, Flag::Flags origin) { return uint64_tAtPut(name, strlen(name), value, origin); }
static bool doubleAt(char* name, size_t len, double* value); static bool doubleAt(const char* name, size_t len, double* value);
static bool doubleAt(char* name, double* value) { return doubleAt(name, strlen(name), value); } static bool doubleAt(const char* name, double* value) { return doubleAt(name, strlen(name), value); }
static bool doubleAtPut(char* name, size_t len, double* value, Flag::Flags origin); static bool doubleAtPut(const char* name, size_t len, double* value, Flag::Flags origin);
static bool doubleAtPut(char* name, double* value, Flag::Flags origin) { return doubleAtPut(name, strlen(name), value, origin); } static bool doubleAtPut(const char* name, double* value, Flag::Flags origin) { return doubleAtPut(name, strlen(name), value, origin); }
static bool ccstrAt(char* name, size_t len, ccstr* value); static bool ccstrAt(const char* name, size_t len, ccstr* value);
static bool ccstrAt(char* name, ccstr* value) { return ccstrAt(name, strlen(name), value); } static bool ccstrAt(const char* name, ccstr* value) { return ccstrAt(name, strlen(name), value); }
// Contract: Flag will make private copy of the incoming value. // Contract: Flag will make private copy of the incoming value.
// Outgoing value is always malloc-ed, and caller MUST call free. // Outgoing value is always malloc-ed, and caller MUST call free.
static bool ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin); static bool ccstrAtPut(const char* name, size_t len, ccstr* value, Flag::Flags origin);
static bool ccstrAtPut(char* name, ccstr* value, Flag::Flags origin) { return ccstrAtPut(name, strlen(name), value, origin); } static bool ccstrAtPut(const char* name, ccstr* value, Flag::Flags origin) { return ccstrAtPut(name, strlen(name), value, origin); }
// Returns false if name is not a command line flag. // Returns false if name is not a command line flag.
static bool wasSetOnCmdline(const char* name, bool* value); static bool wasSetOnCmdline(const char* name, bool* value);
......
...@@ -129,7 +129,7 @@ public class WhiteBox { ...@@ -129,7 +129,7 @@ public class WhiteBox {
} }
public native int getCompileQueueSize(int compLevel); public native int getCompileQueueSize(int compLevel);
public native boolean testSetForceInlineMethod(Executable method, boolean value); public native boolean testSetForceInlineMethod(Executable method, boolean value);
public boolean enqueueMethodForCompilation(Executable method, int compLevel) { public boolean enqueueMethodForCompilation(Executable method, int compLevel) {
return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/); return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
} }
public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci); public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci);
...@@ -154,4 +154,17 @@ public class WhiteBox { ...@@ -154,4 +154,17 @@ public class WhiteBox {
// CPU features // CPU features
public native String getCPUFeatures(); public native String getCPUFeatures();
// VM flags
public native void setBooleanVMFlag(String name, boolean value);
public native void setIntxVMFlag(String name, long value);
public native void setUintxVMFlag(String name, long value);
public native void setUint64VMFlag(String name, long value);
public native void setStringVMFlag(String name, String value);
public native void setDoubleVMFlag(String name, double value);
public native Boolean getBooleanVMFlag(String name);
public native Long getIntxVMFlag(String name);
public native Long getUintxVMFlag(String name);
public native Long getUint64VMFlag(String name);
public native String getStringVMFlag(String name);
public native Double getDoubleVMFlag(String name);
} }
/*
* Copyright (c) 2014, 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.
*/
/*
* @test BooleanTest
* @bug 8028756
* @library /testlibrary /testlibrary/whitebox
* @build BooleanTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI BooleanTest
* @summary testing of WB::set/getBooleanVMFlag()
* @author igor.ignatyev@oracle.com
*/
import sun.hotspot.WhiteBox;
import com.oracle.java.testlibrary.*;
import sun.management.*;
import com.sun.management.*;
public class BooleanTest {
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
private static final Boolean[] TESTS = {true, false, true, true, false};
private static final String TEST_NAME = "BooleanTest";
private static final String FLAG_NAME = "PrintCompilation";
private static final String METHOD = TEST_NAME + "::method";
private static final String METHOD1 = METHOD + "1";
private static final String METHOD2 = METHOD + "2";
public static void main(String[] args) throws Exception {
if (args.length == 0) {
VmFlagTest.runTest(FLAG_NAME, TESTS,
VmFlagTest.WHITE_BOX::setBooleanVMFlag,
VmFlagTest.WHITE_BOX::getBooleanVMFlag);
testFunctional(false);
testFunctional(true);
} else {
boolean value = Boolean.valueOf(args[0]);
method1();
VmFlagTest.WHITE_BOX.setBooleanVMFlag(FLAG_NAME, value);
method2();
}
}
private static void testFunctional(boolean value) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-Xcomp",
"-XX:CompileCommand=compileonly," + METHOD + "*",
"-XX:" + (value ? "-" : "+") + FLAG_NAME,
TEST_NAME,
"" + value);
OutputAnalyzer out = new OutputAnalyzer(pb.start());
if (value) {
out.shouldNotContain(METHOD1);
out.shouldContain(METHOD2);
} else {
out.shouldContain(METHOD1);
out.shouldNotContain(METHOD2);
}
}
private static void method1() { }
private static void method2() { }
}
/*
* Copyright (c) 2014, 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.
*/
/*
* @test DoubleTest
* @bug 8028756
* @library /testlibrary /testlibrary/whitebox
* @build DoubleTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI DoubleTest
* @summary testing of WB::set/getDoubleVMFlag()
* @author igor.ignatyev@oracle.com
*/
public class DoubleTest {
private static final String FLAG_NAME = null;
private static final Double[] TESTS = {0d, -0d, -1d, 1d,
Double.MAX_VALUE, Double.MIN_VALUE, Double.NaN,
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY};
public static void main(String[] args) throws Exception {
VmFlagTest.runTest(FLAG_NAME, TESTS,
VmFlagTest.WHITE_BOX::setDoubleVMFlag,
VmFlagTest.WHITE_BOX::getDoubleVMFlag);
}
}
/*
* Copyright (c) 2014, 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.
*/
/*
* @test IntxTest
* @bug 8028756
* @library /testlibrary /testlibrary/whitebox
* @build IntxTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI IntxTest
* @summary testing of WB::set/getIntxVMFlag()
* @author igor.ignatyev@oracle.com
*/
public class IntxTest {
private static final String FLAG_NAME = "OnStackReplacePercentage";
private static final Long[] TESTS = {0L, 100L, -1L,
(long) Integer.MAX_VALUE, (long) Integer.MIN_VALUE};
public static void main(String[] args) throws Exception {
VmFlagTest.runTest(FLAG_NAME, TESTS,
VmFlagTest.WHITE_BOX::setIntxVMFlag,
VmFlagTest.WHITE_BOX::getIntxVMFlag);
}
}
/*
* Copyright (c) 2014, 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.
*/
/*
* @test StringTest
* @bug 8028756
* @library /testlibrary /testlibrary/whitebox
* @build StringTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI StringTest
* @summary testing of WB::set/getStringVMFlag()
* @author igor.ignatyev@oracle.com
*/
public class StringTest {
private static final String FLAG_NAME = "CompileOnly";
private static final String[] TESTS = {"StringTest::*", ""};
public static void main(String[] args) throws Exception {
VmFlagTest.runTest(FLAG_NAME, TESTS,
VmFlagTest.WHITE_BOX::setStringVMFlag,
VmFlagTest.WHITE_BOX::getStringVMFlag);
}
}
/*
* Copyright (c) 2014, 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.
*/
/*
* @test Uint64Test
* @bug 8028756
* @library /testlibrary /testlibrary/whitebox
* @build Uint64Test
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI Uint64Test
* @summary testing of WB::set/getUint64VMFlag()
* @author igor.ignatyev@oracle.com
*/
public class Uint64Test {
private static final String FLAG_NAME = "MaxRAM";
private static final Long[] TESTS = {0L, 100L, (long) Integer.MAX_VALUE,
-1L, Long.MAX_VALUE, Long.MIN_VALUE};
public static void main(String[] args) throws Exception {
VmFlagTest.runTest(FLAG_NAME, TESTS,
VmFlagTest.WHITE_BOX::setUint64VMFlag,
VmFlagTest.WHITE_BOX::getUint64VMFlag);
}
}
/*
* Copyright (c) 2014, 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.
*/
/*
* @test UintxTest
* @bug 8028756
* @library /testlibrary /testlibrary/whitebox
* @build UintxTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI UintxTest
* @summary testing of WB::set/getUintxVMFlag()
* @author igor.ignatyev@oracle.com
*/
import com.oracle.java.testlibrary.Platform;
public class UintxTest {
private static final String FLAG_NAME = "TypeProfileLevel";
private static final Long[] TESTS = {0L, 100L, (long) Integer.MAX_VALUE,
(1L << 32L) - 1L, 1L << 32L};
private static final Long[] EXPECTED_64 = TESTS;
private static final Long[] EXPECTED_32 = {0L, 100L,
(long) Integer.MAX_VALUE, (1L << 32L) - 1L, 0L};
public static void main(String[] args) throws Exception {
VmFlagTest.runTest(FLAG_NAME, TESTS,
Platform.is64bit() ? EXPECTED_64 : EXPECTED_32,
VmFlagTest.WHITE_BOX::setUintxVMFlag,
VmFlagTest.WHITE_BOX::getUintxVMFlag);
}
}
/*
* Copyright (c) 2014, 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.
*/
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Function;
import sun.hotspot.WhiteBox;
import sun.management.*;
import com.sun.management.*;
import com.oracle.java.testlibrary.*;
public final class VmFlagTest<T> {
public static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
private static final String NONEXISTENT_FLAG = "NonexistentFlag";
private final String flagName;
private final BiConsumer<T, T> test;
private final BiConsumer<String, T> set;
private final Function<String, T> get;
protected VmFlagTest(String flagName, BiConsumer<String, T> set,
Function<String, T> get, boolean isPositive) {
this.flagName = flagName;
this.set = set;
this.get = get;
if (isPositive) {
test = this::testPositive;
} else {
test = this::testNegative;
}
}
private void setNewValue(T value) {
set.accept(flagName, value);
}
private T getValue() {
T t = get.apply(flagName);
System.out.println("T = " + t);
return t;
}
protected static <T> void runTest(String existentFlag, T[] tests,
BiConsumer<String, T> set, Function<String, T> get) {
runTest(existentFlag, tests, tests, set, get);
}
protected static <T> void runTest(String existentFlag, T[] tests,
T[] results, BiConsumer<String, T> set, Function<String, T> get) {
if (existentFlag != null) {
new VmFlagTest(existentFlag, set, get, true).test(tests, results);
}
new VmFlagTest(NONEXISTENT_FLAG, set, get, false).test(tests, results);
}
public final void test(T[] tests, T[] results) {
Asserts.assertEQ(tests.length, results.length, "[TESTBUG] tests.length != results.length");
for (int i = 0, n = tests.length ; i < n; ++i) {
test.accept(tests[i], results[i]);
}
}
protected String getVMOptionAsString() {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption(flagName);
} catch (IllegalArgumentException e) {
tmp = null;
}
return tmp == null ? null : tmp.getValue();
}
private void testPositive(T value, T expected) {
Asserts.assertEQ(getVMOptionAsString(), asString(getValue()));
setNewValue(value);
String newValue = getVMOptionAsString();
Asserts.assertEQ(newValue, asString(expected));
Asserts.assertEQ(getVMOptionAsString(), asString(getValue()));
}
private void testNegative(T value, T expected) {
String oldValue = getVMOptionAsString();
Asserts.assertEQ(oldValue, asString(getValue()));
setNewValue(value);
String newValue = getVMOptionAsString();
Asserts.assertEQ(oldValue, newValue);
}
private String asString(Object value) {
return value == null ? null : "" + value;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册