From 81c4d4ed416f217ce6516f5d3d80e73a2db768b5 Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Thu, 6 Feb 2014 11:01:27 -0500 Subject: [PATCH] 8033565: Remove unused nativeNewStringPlatform Remove also nativeGetStringPlatformChars Reviewed-by: mchung, dholmes, alanb --- jdk/src/share/native/common/jni_util.c | 168 ++++++++++---------- jdk/src/share/native/common/jni_util.h | 4 - jdk/src/solaris/native/common/jni_util_md.c | 8 - jdk/src/windows/native/common/jni_util_md.c | 96 ----------- 4 files changed, 81 insertions(+), 195 deletions(-) diff --git a/jdk/src/share/native/common/jni_util.c b/jdk/src/share/native/common/jni_util.c index de3509b7a59..6837dd67983 100644 --- a/jdk/src/share/native/common/jni_util.c +++ b/jdk/src/share/native/common/jni_util.c @@ -719,52 +719,49 @@ NewStringPlatform(JNIEnv *env, const char *str) JNIEXPORT jstring JNICALL JNU_NewStringPlatform(JNIEnv *env, const char *str) { - jstring result; - result = nativeNewStringPlatform(env, str); - if (result == NULL) { - jbyteArray hab = 0; - int len; + jstring result = NULL; + jbyteArray hab = 0; + int len; - if (fastEncoding == NO_ENCODING_YET) { - initializeEncoding(env); - JNU_CHECK_EXCEPTION_RETURN(env, NULL); - } + if (fastEncoding == NO_ENCODING_YET) { + initializeEncoding(env); + JNU_CHECK_EXCEPTION_RETURN(env, NULL); + } - if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET)) - return newString8859_1(env, str); - if (fastEncoding == FAST_646_US) - return newString646_US(env, str); - if (fastEncoding == FAST_CP1252) - return newStringCp1252(env, str); + if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET)) + return newString8859_1(env, str); + if (fastEncoding == FAST_646_US) + return newString646_US(env, str); + if (fastEncoding == FAST_CP1252) + return newStringCp1252(env, str); - if ((*env)->EnsureLocalCapacity(env, 2) < 0) - return NULL; + if ((*env)->EnsureLocalCapacity(env, 2) < 0) + return NULL; - len = (int)strlen(str); - hab = (*env)->NewByteArray(env, len); - if (hab != 0) { - jclass strClazz = JNU_ClassString(env); - CHECK_NULL_RETURN(strClazz, 0); - (*env)->SetByteArrayRegion(env, hab, 0, len, (jbyte *)str); - if (jnuEncodingSupported(env)) { - result = (*env)->NewObject(env, strClazz, - String_init_ID, hab, jnuEncoding); - } else { - /*If the encoding specified in sun.jnu.encoding is not endorsed - by "Charset.isSupported" we have to fall back to use String(byte[]) - explicitly here without specifying the encoding name, in which the - StringCoding class will pickup the iso-8859-1 as the fallback - converter for us. - */ - jmethodID mid = (*env)->GetMethodID(env, strClazz, - "", "([B)V"); - if (mid != NULL) { - result = (*env)->NewObject(env, strClazz, mid, hab); - } + len = (int)strlen(str); + hab = (*env)->NewByteArray(env, len); + if (hab != 0) { + jclass strClazz = JNU_ClassString(env); + CHECK_NULL_RETURN(strClazz, 0); + (*env)->SetByteArrayRegion(env, hab, 0, len, (jbyte *)str); + if (jnuEncodingSupported(env)) { + result = (*env)->NewObject(env, strClazz, + String_init_ID, hab, jnuEncoding); + } else { + /*If the encoding specified in sun.jnu.encoding is not endorsed + by "Charset.isSupported" we have to fall back to use String(byte[]) + explicitly here without specifying the encoding name, in which the + StringCoding class will pickup the iso-8859-1 as the fallback + converter for us. + */ + jmethodID mid = (*env)->GetMethodID(env, strClazz, + "", "([B)V"); + if (mid != NULL) { + result = (*env)->NewObject(env, strClazz, mid, hab); } - (*env)->DeleteLocalRef(env, hab); - return result; } + (*env)->DeleteLocalRef(env, hab); + return result; } return NULL; } @@ -778,56 +775,53 @@ GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) JNIEXPORT const char * JNICALL JNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) { - char *result = nativeGetStringPlatformChars(env, jstr, isCopy); - if (result == NULL) { + char *result = NULL; + jbyteArray hab = 0; - jbyteArray hab = 0; + if (isCopy) + *isCopy = JNI_TRUE; - if (isCopy) - *isCopy = JNI_TRUE; - - if (fastEncoding == NO_ENCODING_YET) { - initializeEncoding(env); - JNU_CHECK_EXCEPTION_RETURN(env, 0); - } - - if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET)) - return getString8859_1Chars(env, jstr); - if (fastEncoding == FAST_646_US) - return getString646_USChars(env, jstr); - if (fastEncoding == FAST_CP1252) - return getStringCp1252Chars(env, jstr); - - if ((*env)->EnsureLocalCapacity(env, 2) < 0) - return 0; - - if (jnuEncodingSupported(env)) { - hab = (*env)->CallObjectMethod(env, jstr, String_getBytes_ID, jnuEncoding); - } else { - jmethodID mid; - jclass strClazz = JNU_ClassString(env); - CHECK_NULL_RETURN(strClazz, 0); - mid = (*env)->GetMethodID(env, strClazz, - "getBytes", "()[B"); - if (mid != NULL) { - hab = (*env)->CallObjectMethod(env, jstr, mid); - } - } - - if (!(*env)->ExceptionCheck(env)) { - jint len = (*env)->GetArrayLength(env, hab); - result = MALLOC_MIN4(len); - if (result == 0) { - JNU_ThrowOutOfMemoryError(env, 0); - (*env)->DeleteLocalRef(env, hab); - return 0; - } - (*env)->GetByteArrayRegion(env, hab, 0, len, (jbyte *)result); - result[len] = 0; /* NULL-terminate */ - } - - (*env)->DeleteLocalRef(env, hab); + if (fastEncoding == NO_ENCODING_YET) { + initializeEncoding(env); + JNU_CHECK_EXCEPTION_RETURN(env, 0); } + + if ((fastEncoding == FAST_8859_1) || (fastEncoding == NO_ENCODING_YET)) + return getString8859_1Chars(env, jstr); + if (fastEncoding == FAST_646_US) + return getString646_USChars(env, jstr); + if (fastEncoding == FAST_CP1252) + return getStringCp1252Chars(env, jstr); + + if ((*env)->EnsureLocalCapacity(env, 2) < 0) + return 0; + + if (jnuEncodingSupported(env)) { + hab = (*env)->CallObjectMethod(env, jstr, String_getBytes_ID, jnuEncoding); + } else { + jmethodID mid; + jclass strClazz = JNU_ClassString(env); + CHECK_NULL_RETURN(strClazz, 0); + mid = (*env)->GetMethodID(env, strClazz, + "getBytes", "()[B"); + if (mid != NULL) { + hab = (*env)->CallObjectMethod(env, jstr, mid); + } + } + + if (!(*env)->ExceptionCheck(env)) { + jint len = (*env)->GetArrayLength(env, hab); + result = MALLOC_MIN4(len); + if (result == 0) { + JNU_ThrowOutOfMemoryError(env, 0); + (*env)->DeleteLocalRef(env, hab); + return 0; + } + (*env)->GetByteArrayRegion(env, hab, 0, len, (jbyte *)result); + result[len] = 0; /* NULL-terminate */ + } + + (*env)->DeleteLocalRef(env, hab); return result; } diff --git a/jdk/src/share/native/common/jni_util.h b/jdk/src/share/native/common/jni_util.h index b8d23cd1c21..770934bdd5e 100644 --- a/jdk/src/share/native/common/jni_util.h +++ b/jdk/src/share/native/common/jni_util.h @@ -363,10 +363,6 @@ enum { FAST_646_US /* US-ASCII : ISO646-US */ }; -jstring nativeNewStringPlatform(JNIEnv *env, const char *str); - -char* nativeGetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy); - int getFastEncoding(); void initializeEncoding(); diff --git a/jdk/src/solaris/native/common/jni_util_md.c b/jdk/src/solaris/native/common/jni_util_md.c index 42ab2de0037..90b89676caa 100644 --- a/jdk/src/solaris/native/common/jni_util_md.c +++ b/jdk/src/solaris/native/common/jni_util_md.c @@ -29,14 +29,6 @@ #include "jni_util.h" #include "dlfcn.h" -jstring nativeNewStringPlatform(JNIEnv *env, const char *str) { - return NULL; -} - -char* nativeGetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) { - return NULL; -} - void* getProcessHandle() { static void *procHandle = NULL; if (procHandle != NULL) { diff --git a/jdk/src/windows/native/common/jni_util_md.c b/jdk/src/windows/native/common/jni_util_md.c index cdaaa2b5574..80f1b355fe5 100644 --- a/jdk/src/windows/native/common/jni_util_md.c +++ b/jdk/src/windows/native/common/jni_util_md.c @@ -42,102 +42,6 @@ static void getParent(const TCHAR *path, TCHAR *dest) { *lastSlash = 0; } -BOOL useNativeConverter(JNIEnv *env) { - static BOOL initialized; - static BOOL useNative; - if (!initialized) { - HMODULE jvm = GetModuleHandle("jvm"); - useNative = FALSE; - if (jvm != NULL) { - TCHAR *jvmPath = NULL; - int bufferSize = MAX_PATH; - while (jvmPath == NULL) { - DWORD result; - jvmPath = malloc(bufferSize); - if (jvmPath == NULL) - return FALSE; - result = GetModuleFileName(jvm, jvmPath, bufferSize); - if (result == 0) - return FALSE; - if (result == bufferSize) { // didn't fit - bufferSize += MAX_PATH; // increase buffer size, try again - free(jvmPath); - jvmPath = NULL; - } - } - - getParent(jvmPath, jvmPath); - useNative = (!strcmp("kernel", jvmPath + strlen(jvmPath) - - strlen("kernel"))); // true if jvm.dll lives in "kernel" - if (useNative) - setlocale(LC_ALL, ""); - free(jvmPath); - } - initialized = TRUE; - } - return useNative; -} - -jstring nativeNewStringPlatform(JNIEnv *env, const char *str) { - static jmethodID String_char_constructor; - if (useNativeConverter(env)) { - // use native Unicode conversion so Kernel isn't required during - // System.initProperties - jcharArray chars = 0; - wchar_t *utf16; - int len; - jstring result = NULL; - - if (getFastEncoding() == NO_ENCODING_YET) - initializeEncoding(env); - - len = mbstowcs(NULL, str, strlen(str)); - if (len == -1) - return NULL; - utf16 = calloc(len + 1, 2); - if (mbstowcs(utf16, str, len) == -1) - return NULL; - chars = (*env)->NewCharArray(env, len); - if (chars == NULL) - return NULL; - (*env)->SetCharArrayRegion(env, chars, 0, len, utf16); - if (String_char_constructor == NULL) - String_char_constructor = (*env)->GetMethodID(env, - JNU_ClassString(env), "", "([C)V"); - result = (*env)->NewObject(env, JNU_ClassString(env), - String_char_constructor, chars); - free(utf16); - return result; - } - else - return NULL; -} - - -char* nativeGetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy) { - if (useNativeConverter(env)) { - // use native Unicode conversion so Kernel isn't required during - // System.initProperties - char *result = NULL; - size_t len; - const jchar* utf16 = (*env)->GetStringChars(env, jstr, NULL); - len = wcstombs(NULL, utf16, (*env)->GetStringLength(env, jstr) * 4) + 1; - if (len == -1) - return NULL; - result = (char*) malloc(len); - if (result != NULL) { - if (wcstombs(result, utf16, len) == -1) - return NULL; - (*env)->ReleaseStringChars(env, jstr, utf16); - if (isCopy) - *isCopy = JNI_TRUE; - } - return result; - } - else - return NULL; -} - void* getProcessHandle() { return (void*)GetModuleHandle(NULL); }