8033565: Remove unused nativeNewStringPlatform
Summary: Remove also nativeGetStringPlatformChars
Reviewed-by: mchung, dholmes, alanb
--- a/jdk/src/share/native/common/jni_util.c Thu Feb 06 15:43:35 2014 +0000
+++ b/jdk/src/share/native/common/jni_util.c Thu Feb 06 11:01:27 2014 -0500
@@ -719,52 +719,49 @@
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,
- "<init>", "([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,
+ "<init>", "([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 @@
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 == 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 ((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 ((*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 (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 */
+ 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);
- }
+ (*env)->DeleteLocalRef(env, hab);
return result;
}
--- a/jdk/src/share/native/common/jni_util.h Thu Feb 06 15:43:35 2014 +0000
+++ b/jdk/src/share/native/common/jni_util.h Thu Feb 06 11:01:27 2014 -0500
@@ -363,10 +363,6 @@
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();
--- a/jdk/src/solaris/native/common/jni_util_md.c Thu Feb 06 15:43:35 2014 +0000
+++ b/jdk/src/solaris/native/common/jni_util_md.c Thu Feb 06 11:01:27 2014 -0500
@@ -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) {
--- a/jdk/src/windows/native/common/jni_util_md.c Thu Feb 06 15:43:35 2014 +0000
+++ b/jdk/src/windows/native/common/jni_util_md.c Thu Feb 06 11:01:27 2014 -0500
@@ -42,102 +42,6 @@
*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), "<init>", "([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);
}