Skip to content

Commit f613aae

Browse files
committed
Use extensions System.initProperties to help init jdk11 properties
Depends on ibmruntimes/openj9-openjdk-jdk11#880 Related to eclipse-openj9#21189 Signed-off-by: Peter Shipton <Peter_Shipton@ca.ibm.com>
1 parent eac2531 commit f613aae

File tree

6 files changed

+39
-106
lines changed

6 files changed

+39
-106
lines changed

jcl/src/java.base/share/classes/java/lang/System.java

+17-32
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@ static void afterClinitInitialization() {
363363
// Fill in the properties from the VM information.
364364
ensureProperties(true);
365365

366-
/*[IF JAVA_SPEC_VERSION == 11]*/
367-
initJCLPlatformEncoding();
368-
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
369-
370366
/*[REM] Initialize the JITHelpers needed in J9VMInternals since the class can't do it itself */
371367
try {
372368
java.lang.reflect.Field f1 = J9VMInternals.class.getDeclaredField("jitHelpers"); //$NON-NLS-1$
@@ -681,32 +677,26 @@ private static void arraycopy(Object[] A1, int offset1, Object[] A2, int offset2
681677
*/
682678
public static native long currentTimeMillis();
683679

684-
/*[IF OpenJ9-RawBuild]*/
685-
/* This is a JCL native required only by OpenJ9 raw build.
686-
* OpenJ9 raw build is a combination of OpenJ9 and OpenJDK binaries without JCL patches within extension repo.
687-
* Currently OpenJ9 depends on a JCL patch to initialize platform encoding which is not available to raw build.
688-
* A workaround for raw build is to invoke this JCL native which initializes platform encoding.
689-
* This workaround can be removed if that JCL patch is not required.
690-
*/
680+
/*[IF JAVA_SPEC_VERSION == 11]*/
691681
private static native Properties initProperties(Properties props);
692-
/*[ENDIF] OpenJ9-RawBuild */
682+
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
693683

694684
/**
695685
* If systemProperties is unset, then create a new one based on the values
696686
* provided by the virtual machine.
697687
*/
698688
@SuppressWarnings("nls")
699689
private static void ensureProperties(boolean isInitialization) {
700-
/*[IF OpenJ9-RawBuild]*/
701-
// invoke JCL native to initialize platform encoding
702-
initProperties(new Properties());
703-
/*[ENDIF] OpenJ9-RawBuild */
690+
/*[IF JAVA_SPEC_VERSION == 11]*/
691+
Properties jclProps = new Properties();
692+
initProperties(jclProps);
693+
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
704694

705-
/*[IF JAVA_SPEC_VERSION > 11]*/
695+
/*[IF JAVA_SPEC_VERSION > 11]*/
706696
Map<String, String> initializedProperties = new HashMap<>();
707-
/*[ELSE] JAVA_SPEC_VERSION > 11
697+
/*[ELSE] JAVA_SPEC_VERSION > 11
708698
Properties initializedProperties = new Properties();
709-
/*[ENDIF] JAVA_SPEC_VERSION > 11 */
699+
/*[ENDIF] JAVA_SPEC_VERSION > 11 */
710700

711701
/*[IF JAVA_SPEC_VERSION >= 17]*/
712702
initializedProperties.put("os.version", sysPropOSVersion); //$NON-NLS-1$
@@ -716,17 +706,13 @@ private static void ensureProperties(boolean isInitialization) {
716706
initializedProperties.put("os.encoding", osEncoding); //$NON-NLS-1$
717707
}
718708
initializedProperties.put("ibm.system.encoding", platformEncoding); //$NON-NLS-1$
719-
/*[IF JAVA_SPEC_VERSION < 17]*/
709+
/*[IF JAVA_SPEC_VERSION == 8]*/
720710
/*[PR The launcher apparently needs sun.jnu.encoding property or it does not work]*/
721711
initializedProperties.put("sun.jnu.encoding", platformEncoding); //$NON-NLS-1$
722-
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
723-
/*[IF JAVA_SPEC_VERSION == 8]*/
724712
initializedProperties.put("file.encoding.pkg", "sun.io"); //$NON-NLS-1$ //$NON-NLS-2$
725-
/*[ENDIF] JJAVA_SPEC_VERSION == 8 */
726-
/*[IF JAVA_SPEC_VERSION < 12]*/
727713
/* System property java.specification.vendor is set via VersionProps.init(systemProperties) since JDK12 */
728714
initializedProperties.put("java.specification.vendor", "Oracle Corporation"); //$NON-NLS-1$ //$NON-NLS-2$
729-
/*[ENDIF] JAVA_SPEC_VERSION < 12 */
715+
/*[ENDIF] JAVA_SPEC_VERSION == 8 */
730716
initializedProperties.put("java.specification.name", "Java Platform API Specification"); //$NON-NLS-1$ //$NON-NLS-2$
731717
initializedProperties.put("com.ibm.oti.configuration", "scar"); //$NON-NLS-1$
732718

@@ -757,7 +743,13 @@ private static void ensureProperties(boolean isInitialization) {
757743
}
758744
initializedProperties.put(key, list[i+1]);
759745
}
746+
/*[IF JAVA_SPEC_VERSION == 11]*/
747+
for (Map.Entry<?, ?> entry : jclProps.entrySet()) {
748+
initializedProperties.putIfAbsent(entry.getKey(), entry.getValue());
749+
}
750+
/*[ELSE] JAVA_SPEC_VERSION == 11 */
760751
initializedProperties.put("file.encoding", fileEncoding); //$NON-NLS-1$
752+
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
761753
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
762754

763755
/*[IF (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64)]*/
@@ -1047,13 +1039,6 @@ public static String setProperty(String prop, String value) {
10471039
private static native String [] getPropertyList();
10481040
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
10491041

1050-
/*[IF JAVA_SPEC_VERSION == 11]*/
1051-
/**
1052-
* Invoke JCL native to initialize platform encoding explicitly.
1053-
*/
1054-
private static native void initJCLPlatformEncoding();
1055-
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
1056-
10571042
/**
10581043
* Before propertiesInitialized is set to true,
10591044
* this returns the requested system property according to sysPropID:

runtime/jcl/common/system.c

-32
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,6 @@
4343
#include <_Ccsid.h>
4444
#endif
4545

46-
47-
#if JAVA_SPEC_VERSION == 11
48-
void JNICALL
49-
Java_java_lang_System_initJCLPlatformEncoding(JNIEnv *env, jclass clazz)
50-
{
51-
UDATA handle = 0;
52-
J9JavaVM * const vm = ((J9VMThread*)env)->javaVM;
53-
char dllPath[EsMaxPath] = {0};
54-
UDATA written = 0;
55-
const char *encoding = NULL;
56-
PORT_ACCESS_FROM_ENV(env);
57-
58-
#if defined(OSX)
59-
encoding = "UTF-8";
60-
#else
61-
char property[128] = {0};
62-
encoding = getPlatformFileEncoding(env, property, sizeof(property), 1); /* platform encoding */
63-
#endif /* defined(OSX) */
64-
/* libjava.[so|dylib] is in the jdk/lib/ directory, one level up from the default/ & compressedrefs/ directories */
65-
written = j9str_printf(dllPath, sizeof(dllPath), "%s/../java", vm->j2seRootDirectory);
66-
/* Assert the number of characters written (not including the null) fit within the dllPath buffer */
67-
Assert_JCL_true(written < (sizeof(dllPath) - 1));
68-
if (0 == j9sl_open_shared_library(dllPath, &handle, J9PORT_SLOPEN_DECORATE)) {
69-
void (JNICALL *nativeFuncAddrJNU)(JNIEnv *env, const char *str) = NULL;
70-
if (0 == j9sl_lookup_name(handle, "InitializeEncoding", (UDATA*) &nativeFuncAddrJNU, "VLL")) {
71-
/* invoke JCL native to initialize platform encoding explicitly */
72-
nativeFuncAddrJNU(env, encoding);
73-
}
74-
}
75-
}
76-
#endif /* JAVA_SPEC_VERSION == 11 */
77-
7846
/**
7947
* sysPropID
8048
* 0 - os.version

runtime/jcl/exports.cmake

-6
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,6 @@ if(NOT JAVA_SPEC_VERSION LESS 9)
599599
)
600600
endif()
601601

602-
if(JAVA_SPEC_VERSION EQUAL 11)
603-
omr_add_exports(jclse
604-
Java_java_lang_System_initJCLPlatformEncoding
605-
)
606-
endif()
607-
608602
# java 11+
609603
if(NOT JAVA_SPEC_VERSION LESS 11)
610604
omr_add_exports(jclse

runtime/jcl/uma/se11_exports.xml

-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
2323
<export name="Java_java_lang_Class_getNestHostImpl"/>
2424
<export name="Java_java_lang_Class_getNestMembersImpl"/>
2525
<export name="Java_java_lang_invoke_MethodHandleResolver_getCPConstantDynamicAt"/>
26-
<export name="Java_java_lang_System_initJCLPlatformEncoding">
27-
<exclude-if condition="spec.java12"/>
28-
</export>
2926
</exports>

runtime/oti/jclprots.h

-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ Java_com_ibm_java_lang_management_internal_MemoryManagerMXBeanImpl_isManagedPool
190190
/* BBjclNativesCommonSystem*/
191191
void JNICALL Java_java_lang_System_setFieldImpl (JNIEnv * env, jclass cls, jstring name, jobject stream);
192192
jobject createSystemPropertyList (JNIEnv *env, const char *defaultValues[], int defaultCount);
193-
#if JAVA_SPEC_VERSION == 11
194-
void JNICALL Java_java_lang_System_initJCLPlatformEncoding (JNIEnv *env, jclass clazz);
195-
#endif /* JAVA_SPEC_VERSION == 11 */
196193
jstring JNICALL Java_java_lang_System_getSysPropBeforePropertiesInitialized(JNIEnv *env, jclass clazz, jint sysPropID);
197194
#if JAVA_SPEC_VERSION < 17
198195
jobject JNICALL Java_java_lang_System_getPropertyList (JNIEnv *env, jclass clazz);

runtime/vm/vmprops.c

+22-30
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ convertToUTF8(J9PortLibrary *portLibrary, const wchar_t *unicodeString, char *ut
16091609
return 0;
16101610
}
16111611

1612-
jobject
1612+
static jobject
16131613
getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
16141614
{
16151615
PORT_ACCESS_FROM_ENV(env);
@@ -1623,9 +1623,9 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
16231623
char userhome[EsMaxPath];
16241624
wchar_t unicodeTemp[EsMaxPath];
16251625
int i = 0;
1626-
#if JAVA_SPEC_VERSION < 17
1626+
#if JAVA_SPEC_VERSION < 11
16271627
char userdir[EsMaxPath];
1628-
#endif /* JAVA_SPEC_VERSION < 17 */
1628+
#endif /* JAVA_SPEC_VERSION < 11 */
16291629
wchar_t unicodeHome[EsMaxPath];
16301630
HANDLE process = 0;
16311631
HANDLE token = 0;
@@ -1634,7 +1634,7 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
16341634

16351635
/* Hard coded file/path separators and other values */
16361636

1637-
#if JAVA_SPEC_VERSION < 17
1637+
#if JAVA_SPEC_VERSION < 11
16381638
strings[propIndex++] = "file.separator";
16391639
strings[propIndex++] = "\\";
16401640

@@ -1644,7 +1644,7 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
16441644
/* Get the Temp Dir name */
16451645
strings[propIndex++] = "java.io.tmpdir";
16461646
strings[propIndex++] = getTmpDir(env, &tempdir);
1647-
#endif /* JAVA_SPEC_VERSION < 17 */
1647+
#endif /* JAVA_SPEC_VERSION < 11 */
16481648

16491649
strings[propIndex++] = "user.home";
16501650
i = propIndex;
@@ -1711,7 +1711,7 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
17111711
}
17121712
}
17131713

1714-
#if JAVA_SPEC_VERSION < 17
1714+
#if JAVA_SPEC_VERSION < 11
17151715
/* Get the directory where the executable was started */
17161716
strings[propIndex++] = "user.dir";
17171717
if (0 == GetCurrentDirectoryW(EsMaxPath, unicodeTemp)) {
@@ -1720,13 +1720,7 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
17201720
convertToUTF8(PORTLIB, unicodeTemp, userdir, EsMaxPath);
17211721
strings[propIndex++] = userdir;
17221722
}
1723-
#endif /* JAVA_SPEC_VERSION < 17 */
1724-
1725-
if (JAVA_SPEC_VERSION < 12) {
1726-
/* Get the timezone */
1727-
strings[propIndex++] = "user.timezone";
1728-
strings[propIndex++] = "";
1729-
}
1723+
#endif /* JAVA_SPEC_VERSION < 11 */
17301724

17311725
result = createSystemPropertyList(env, strings, propIndex);
17321726
j9mem_free_memory(tempdir);
@@ -1736,16 +1730,16 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
17361730

17371731
#else /* defined(WIN32) */
17381732

1739-
jobject
1733+
static jobject
17401734
getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
17411735
{
17421736
PORT_ACCESS_FROM_ENV(env);
17431737
char *charResult = NULL;
17441738
char *envSpace = NULL;
17451739
jobject plist = NULL;
1746-
#if JAVA_SPEC_VERSION < 17
1740+
#if JAVA_SPEC_VERSION < 11
17471741
char userdir[EsMaxPath] = {0};
1748-
#endif /* JAVA_SPEC_VERSION < 17 */
1742+
#endif /* JAVA_SPEC_VERSION < 11 */
17491743
char home[EsMaxPath] = {0};
17501744
char *homeAlloc = NULL;
17511745
J9VMThread *currentThread = (J9VMThread*)env;
@@ -1764,7 +1758,7 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
17641758
}
17651759
#endif /* defined(J9ZOS390) */
17661760

1767-
#if JAVA_SPEC_VERSION < 17
1761+
#if JAVA_SPEC_VERSION < 11
17681762
strings[propIndex++] = "file.separator";
17691763
strings[propIndex++] = "/";
17701764

@@ -1779,7 +1773,7 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
17791773
} else {
17801774
strings[propIndex++] = charResult;
17811775
}
1782-
#endif /* JAVA_SPEC_VERSION < 17 */
1776+
#endif /* JAVA_SPEC_VERSION < 11 */
17831777

17841778
strings[propIndex++] = "user.home";
17851779
charResult = NULL;
@@ -1850,17 +1844,11 @@ getPlatformPropertyList(JNIEnv *env, const char *strings[], int propIndex)
18501844
propIndex += 1;
18511845
}
18521846

1853-
#if JAVA_SPEC_VERSION < 17
1847+
#if JAVA_SPEC_VERSION < 11
18541848
/* Get the Temp Dir name */
18551849
strings[propIndex++] = "java.io.tmpdir";
18561850
strings[propIndex++] = getTmpDir(env, &envSpace);
1857-
#endif /* JAVA_SPEC_VERSION < 17 */
1858-
1859-
if (JAVA_SPEC_VERSION < 12) {
1860-
/* Get the timezone */
1861-
strings[propIndex++] = "user.timezone";
1862-
strings[propIndex++] = "";
1863-
}
1851+
#endif /* JAVA_SPEC_VERSION < 11 */
18641852

18651853
plist = createSystemPropertyList(env, strings, propIndex);
18661854
if (NULL != envSpace) {
@@ -1888,12 +1876,12 @@ getSystemPropertyList(JNIEnv *env)
18881876
int propIndex = 0;
18891877
jobject propertyList = NULL;
18901878
#define PROPERTY_COUNT 137
1891-
#if JAVA_SPEC_VERSION < 17
1879+
#if JAVA_SPEC_VERSION < 11
18921880
char *propertyKey = NULL;
18931881
const char *language = NULL;
18941882
const char *region = NULL;
18951883
const char *variant = NULL;
1896-
#endif /* JAVA_SPEC_VERSION < 17 */
1884+
#endif /* JAVA_SPEC_VERSION < 11 */
18971885
const char *strings[PROPERTY_COUNT] = {0};
18981886
#define USERNAME_LENGTH 128
18991887
char username[USERNAME_LENGTH] = {0};
@@ -1967,7 +1955,7 @@ getSystemPropertyList(JNIEnv *env)
19671955
strings[propIndex++] = "big";
19681956
#endif /* defined(J9VM_ENV_LITTLE_ENDIAN) */
19691957

1970-
#if JAVA_SPEC_VERSION < 17
1958+
#if JAVA_SPEC_VERSION < 11
19711959
strings[propIndex++] = "sun.cpu.endian";
19721960
#if defined(J9VM_ENV_LITTLE_ENDIAN)
19731961
strings[propIndex++] = "little";
@@ -1998,7 +1986,11 @@ getSystemPropertyList(JNIEnv *env)
19981986
/* Get the variant */
19991987
strings[propIndex++] = "user.variant";
20001988
strings[propIndex++] = variant;
2001-
#endif /* JAVA_SPEC_VERSION < 17 */
1989+
1990+
/* Get the timezone */
1991+
strings[propIndex++] = "user.timezone";
1992+
strings[propIndex++] = "";
1993+
#endif /* JAVA_SPEC_VERSION < 11 */
20021994

20031995
/* Get the User name */
20041996
strings[propIndex++] = "user.name";

0 commit comments

Comments
 (0)