< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page




 366 #endif
 367 
 368   return h_obj;
 369 }
 370 
 371 // Converts a C string to a Java String based on current encoding
 372 Handle java_lang_String::create_from_platform_dependent_str(const char* str, TRAPS) {
 373   assert(str != NULL, "bad arguments");
 374 
 375   typedef jstring (*to_java_string_fn_t)(JNIEnv*, const char *);
 376   static to_java_string_fn_t _to_java_string_fn = NULL;
 377 
 378   if (_to_java_string_fn == NULL) {
 379     void *lib_handle = os::native_java_library();
 380     _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "JNU_NewStringPlatform"));
 381     if (_to_java_string_fn == NULL) {
 382       fatal("NewStringPlatform missing");
 383     }
 384   }
 385 
 386   jstring js = NULL;
 387   { JavaThread* thread = (JavaThread*)THREAD;
 388     assert(thread->is_Java_thread(), "must be java thread");



 389     HandleMark hm(thread);
 390     ThreadToNativeFromVM ttn(thread);
 391     js = (_to_java_string_fn)(thread->jni_environment(), str);
 392   }
 393   return Handle(THREAD, JNIHandles::resolve(js));



 394 }
 395 
 396 // Converts a Java String to a native C string that can be used for
 397 // native OS calls.
 398 char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) {
 399   typedef char* (*to_platform_string_fn_t)(JNIEnv*, jstring, bool*);
 400   static to_platform_string_fn_t _to_platform_string_fn = NULL;
 401 
 402   if (_to_platform_string_fn == NULL) {
 403     void *lib_handle = os::native_java_library();
 404     _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, os::dll_lookup(lib_handle, "GetStringPlatformChars"));
 405     if (_to_platform_string_fn == NULL) {
 406       fatal("GetStringPlatformChars missing");
 407     }
 408   }
 409 
 410   char *native_platform_string;
 411   { JavaThread* thread = (JavaThread*)THREAD;
 412     assert(thread->is_Java_thread(), "must be java thread");
 413     JNIEnv *env = thread->jni_environment();




 366 #endif
 367 
 368   return h_obj;
 369 }
 370 
 371 // Converts a C string to a Java String based on current encoding
 372 Handle java_lang_String::create_from_platform_dependent_str(const char* str, TRAPS) {
 373   assert(str != NULL, "bad arguments");
 374 
 375   typedef jstring (*to_java_string_fn_t)(JNIEnv*, const char *);
 376   static to_java_string_fn_t _to_java_string_fn = NULL;
 377 
 378   if (_to_java_string_fn == NULL) {
 379     void *lib_handle = os::native_java_library();
 380     _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "JNU_NewStringPlatform"));
 381     if (_to_java_string_fn == NULL) {
 382       fatal("NewStringPlatform missing");
 383     }
 384   }
 385 
 386   JavaThread* thread = (JavaThread*)THREAD;

 387   assert(thread->is_Java_thread(), "must be java thread");
 388 
 389   jstring js = NULL;
 390   {
 391     HandleMark hm(thread);
 392     ThreadToNativeFromVM ttn(thread);
 393     js = (_to_java_string_fn)(thread->jni_environment(), str);
 394   }
 395 
 396   Handle native_platform_string(THREAD, JNIHandles::resolve(js));
 397   JNIHandles::destroy_local(js);  // destroy local JNIHandle.
 398   return native_platform_string;
 399 }
 400 
 401 // Converts a Java String to a native C string that can be used for
 402 // native OS calls.
 403 char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) {
 404   typedef char* (*to_platform_string_fn_t)(JNIEnv*, jstring, bool*);
 405   static to_platform_string_fn_t _to_platform_string_fn = NULL;
 406 
 407   if (_to_platform_string_fn == NULL) {
 408     void *lib_handle = os::native_java_library();
 409     _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, os::dll_lookup(lib_handle, "GetStringPlatformChars"));
 410     if (_to_platform_string_fn == NULL) {
 411       fatal("GetStringPlatformChars missing");
 412     }
 413   }
 414 
 415   char *native_platform_string;
 416   { JavaThread* thread = (JavaThread*)THREAD;
 417     assert(thread->is_Java_thread(), "must be java thread");
 418     JNIEnv *env = thread->jni_environment();


< prev index next >