diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp index 115f45231e78b511635adcbd7853f7e92c65ae2c..f2f3cb5869dfe5b0abcbd27a90893d888b84e96b 100644 --- a/src/share/vm/classfile/javaClasses.cpp +++ b/src/share/vm/classfile/javaClasses.cpp @@ -143,13 +143,43 @@ Handle java_lang_String::create_from_platform_dependent_str(const char* str, TRA jstring js = NULL; { JavaThread* thread = (JavaThread*)THREAD; assert(thread->is_Java_thread(), "must be java thread"); - ThreadToNativeFromVM ttn(thread); HandleMark hm(thread); + ThreadToNativeFromVM ttn(thread); js = (_to_java_string_fn)(thread->jni_environment(), str); } return Handle(THREAD, JNIHandles::resolve(js)); } +// Converts a Java String to a native C string that can be used for +// native OS calls. +char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) { + + typedef char* (*to_platform_string_fn_t)(JNIEnv*, jstring, bool*); + static to_platform_string_fn_t _to_platform_string_fn = NULL; + + if (_to_platform_string_fn == NULL) { + void *lib_handle = os::native_java_library(); + _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, hpi::dll_lookup(lib_handle, "GetStringPlatformChars")); + if (_to_platform_string_fn == NULL) { + fatal("GetStringPlatformChars missing"); + } + } + + char *native_platform_string; + { JavaThread* thread = (JavaThread*)THREAD; + assert(thread->is_Java_thread(), "must be java thread"); + JNIEnv *env = thread->jni_environment(); + jstring js = (jstring) JNIHandles::make_local(env, java_string()); + bool is_copy; + HandleMark hm(thread); + ThreadToNativeFromVM ttn(thread); + native_platform_string = (_to_platform_string_fn)(env, js, &is_copy); + assert(is_copy == JNI_TRUE, "is_copy value changed"); + JNIHandles::destroy_local(js); + } + return native_platform_string; +} + Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) { oop obj = java_string(); // Typical usage is to convert all '/' to '.' in string. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp index 45acae2bd9872beca2fcd87b7200f4d0c419e253..8ac7cf883fd29f9a7170ddd9079c232d0bdae243 100644 --- a/src/share/vm/classfile/javaClasses.hpp +++ b/src/share/vm/classfile/javaClasses.hpp @@ -96,6 +96,7 @@ class java_lang_String : AllStatic { // String converters static char* as_utf8_string(oop java_string); static char* as_utf8_string(oop java_string, int start, int len); + static char* as_platform_dependent_str(Handle java_string, TRAPS); static jchar* as_unicode_string(oop java_string, int& length); static bool equals(oop java_string, jchar* chars, int len); diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp index d71f63a6c120ec05528f323accca39ace804babe..a714ef583a6170ef9151eecef1df60ac79043975 100644 --- a/src/share/vm/classfile/systemDictionary.cpp +++ b/src/share/vm/classfile/systemDictionary.cpp @@ -1242,7 +1242,9 @@ static instanceKlassHandle download_and_retry_class_load( oop obj = (oop) result.get_jobject(); if (obj == NULL) { return nk; } - char* new_class_name = java_lang_String::as_utf8_string(obj); + Handle h_obj(THREAD, obj); + char* new_class_name = java_lang_String::as_platform_dependent_str(h_obj, + CHECK_(nk)); // lock the loader // we use this lock because JVMTI does.