hotspot/src/share/vm/classfile/javaClasses.cpp
changeset 195 9193828514c4
parent 1 489c9b5090e2
child 345 8a4c345e460c
equal deleted inserted replaced
194:8cdd3d9a4c99 195:9193828514c4
   141   }
   141   }
   142 
   142 
   143   jstring js = NULL;
   143   jstring js = NULL;
   144   { JavaThread* thread = (JavaThread*)THREAD;
   144   { JavaThread* thread = (JavaThread*)THREAD;
   145     assert(thread->is_Java_thread(), "must be java thread");
   145     assert(thread->is_Java_thread(), "must be java thread");
       
   146     HandleMark hm(thread);
   146     ThreadToNativeFromVM ttn(thread);
   147     ThreadToNativeFromVM ttn(thread);
       
   148     js = (_to_java_string_fn)(thread->jni_environment(), str);
       
   149   }
       
   150   return Handle(THREAD, JNIHandles::resolve(js));
       
   151 }
       
   152 
       
   153 // Converts a Java String to a native C string that can be used for
       
   154 // native OS calls.
       
   155 char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) {
       
   156 
       
   157   typedef char* (*to_platform_string_fn_t)(JNIEnv*, jstring, bool*);
       
   158   static to_platform_string_fn_t _to_platform_string_fn = NULL;
       
   159 
       
   160   if (_to_platform_string_fn == NULL) {
       
   161     void *lib_handle = os::native_java_library();
       
   162     _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, hpi::dll_lookup(lib_handle, "GetStringPlatformChars"));
       
   163     if (_to_platform_string_fn == NULL) {
       
   164       fatal("GetStringPlatformChars missing");
       
   165     }
       
   166   }
       
   167 
       
   168   char *native_platform_string;
       
   169   { JavaThread* thread = (JavaThread*)THREAD;
       
   170     assert(thread->is_Java_thread(), "must be java thread");
       
   171     JNIEnv *env = thread->jni_environment();
       
   172     jstring js = (jstring) JNIHandles::make_local(env, java_string());
       
   173     bool is_copy;
   147     HandleMark hm(thread);
   174     HandleMark hm(thread);
   148     js = (_to_java_string_fn)(thread->jni_environment(), str);
   175     ThreadToNativeFromVM ttn(thread);
   149   }
   176     native_platform_string = (_to_platform_string_fn)(env, js, &is_copy);
   150   return Handle(THREAD, JNIHandles::resolve(js));
   177     assert(is_copy == JNI_TRUE, "is_copy value changed");
       
   178     JNIHandles::destroy_local(js);
       
   179   }
       
   180   return native_platform_string;
   151 }
   181 }
   152 
   182 
   153 Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) {
   183 Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) {
   154   oop          obj    = java_string();
   184   oop          obj    = java_string();
   155   // Typical usage is to convert all '/' to '.' in string.
   185   // Typical usage is to convert all '/' to '.' in string.