Add support for Unicode versions of JNI_CreateJavaVM and JNI_GetDefaultJavaVMInitArgs on Windows platforms
John Platts
john_platts at hotmail.com
Fri May 5 03:04:04 UTC 2017
The JNI_CreateJavaVM and JNI_GetDefaultJavaVMInitArgs methods in the JNI invocation API expect ANSI strings on Windows platforms instead of Unicode-encoded strings. This is an issue on Windows-based platforms since some of the option strings that are passed into JNI_CreateJavaVM might contain Unicode characters that are not in the ANSI encoding on Windows platforms.
There is support for UTF-16 literals on Windows platforms with wchar_t and wide character literals prefixed with the L prefix, and on platforms that support C11 and C++11 with char16_t and UTF-16 character literals that are prefixed with the u prefix.
jchar is currently defined to be a typedef for unsigned short on all platforms, but char16_t is a separate type and not a typedef for unsigned short or jchar in C++11 and later. jchar should be changed to be a typedef for wchar_t on Windows platforms and to be a typedef for char16_t on non-Windows platforms that support the char16_t type. This change will make it possible to define jchar character and string literals on Windows platforms and on non-Windows platforms that support the C11 or C++11 standard.
The JCHAR_LITERAL macro should be added to the JNI header and defined as follows on Windows:
#define JCHAR_LITERAL(x) L ## x
The JCHAR_LITERAL macro should be added to the JNI header and defined as follows on non-Windows platforms:
#define JCHAR_LITERAL(x) u ## x
Here is how the Unicode version of JNI_CreateJavaVM and JNI_GetDefaultJavaVMInitArgs could be defined:
typedef struct JavaVMUnicodeOption {
const jchar *optionString; /* the option as a string in UTF-16 encoding */
void *extraInfo;
} JavaVMUnicodeOption;
typedef struct JavaVMUnicodeInitArgs {
jint version;
jint nOptions;
JavaVMUnicodeOption *options;
jboolean ignoreUnrecognized;
} JavaVMUnicodeInitArgs;
jint JNI_CreateJavaVMUnicode(JavaVM **pvm, void **penv, void *args);
jint JNI_GetDefaultJavaVMInitArgs(void *args);
The java.exe wrapper should use wmain instead of main on Windows platforms, and the javaw.exe wrapper should use wWinMain instead of WinMain on Windows platforms. This change, along with the support for Unicode-enabled version of the JNI_CreateJavaVM and JNI_GetDefaultJavaVMInitArgs methods, would allow the JVM to be launched with arguments that contain Unicode characters that are not in the platform-default encoding.
All of the Windows platforms that Java SE 10 and later VMs would be supported on do support Unicode. Adding support for Unicode versions of JNI_CreateJavaVM and JNI_GetDefaultJavaVMInitArgs will allow Unicode characters that are not in the platform-default encoding on Windows platforms to be supported in command-line arguments that are passed to the JVM.
More information about the jdk10-dev
mailing list