Skip to content

Commit daf2bc9

Browse files
authoredMar 7, 2025
Merge pull request eclipse-openj9#21313 from eclipse-openj9/revert-21200-sysprops
Revert "Implement JVM_GetProperties for jdk17+"
2 parents 4f09a6d + f12ef36 commit daf2bc9

22 files changed

+859
-920
lines changed
 

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

+63-17
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@
6565

6666
/*[IF JAVA_SPEC_VERSION >= 20]*/
6767
import java.lang.reflect.Field;
68-
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */
69-
/*[IF JAVA_SPEC_VERSION >= 17]*/
7068
import jdk.internal.util.SystemProps;
71-
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
69+
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */
7270

7371
/*[IF JAVA_SPEC_VERSION >= 24]*/
7472
import java.net.URL;
@@ -174,6 +172,10 @@ public final class System {
174172
*/
175173
private static Charset consoleDefaultCharset;
176174
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
175+
/*[IF JAVA_SPEC_VERSION >= 19]*/
176+
private static String stdoutProp;
177+
private static String stderrProp;
178+
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
177179

178180
/*[IF JAVA_SPEC_VERSION >= 9]*/
179181
static java.lang.ModuleLayer bootLayer;
@@ -234,7 +236,7 @@ public final class System {
234236
*/
235237
static Charset getCharset(boolean isStdout, boolean fallback) {
236238
/*[IF JAVA_SPEC_VERSION >= 19]*/
237-
String primary = internalGetProperties().getProperty(isStdout ? "stdout.encoding" : "stderr.encoding"); //$NON-NLS-1$ //$NON-NLS-2$
239+
String primary = isStdout ? stdoutProp : stderrProp;
238240
/*[ELSE] JAVA_SPEC_VERSION >= 19 */
239241
String primary = internalGetProperties().getProperty(isStdout ? "sun.stdout.encoding" : "sun.stderr.encoding"); //$NON-NLS-1$ //$NON-NLS-2$
240242
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
@@ -277,6 +279,20 @@ static PrintStream createConsole(FileDescriptor desc, Charset charset) {
277279
BufferedOutputStream bufStream = new BufferedOutputStream(new FileOutputStream(desc));
278280
Charset consoleCharset = charset == null ? consoleDefaultCharset : charset;
279281

282+
/*[IF JAVA_SPEC_VERSION >= 19]*/
283+
Properties props = internalGetProperties();
284+
// If the user didn't set the encoding property, set it now.
285+
if (FileDescriptor.out == desc) {
286+
if (null == stdoutProp) {
287+
props.put("stdout.encoding", consoleCharset.name()); //$NON-NLS-1$
288+
}
289+
} else if (FileDescriptor.err == desc) {
290+
if (null == stderrProp) {
291+
props.put("stderr.encoding", consoleCharset.name()); //$NON-NLS-1$
292+
}
293+
}
294+
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
295+
280296
/*[IF PLATFORM-mz31 | PLATFORM-mz64]*/
281297
return ConsolePrintStream.localize(bufStream, true, consoleCharset);
282298
/*[ELSE]*/
@@ -307,6 +323,12 @@ static void finalizeConsoleEncoding() {
307323
setOut(createConsole(FileDescriptor.out, stdoutCharset));
308324
}
309325
}
326+
327+
/*[IF JAVA_SPEC_VERSION >= 19]*/
328+
// Cache the final system property values so they can be restored if ensureProperties(false) is called.
329+
stdoutProp = systemProperties.getProperty("stdout.encoding"); //$NON-NLS-1$
330+
stderrProp = systemProperties.getProperty("stderr.encoding"); //$NON-NLS-1$
331+
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
310332
}
311333
/*[ELSE]*/
312334
/*[IF Sidecar18-SE-OpenJ9]*/
@@ -367,9 +389,9 @@ static void afterClinitInitialization() {
367389
// Fill in the properties from the VM information.
368390
ensureProperties(true);
369391

370-
/*[IF JAVA_SPEC_VERSION == 11]*/
392+
/*[IF JAVA_SPEC_VERSION >= 11]*/
371393
initJCLPlatformEncoding();
372-
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
394+
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
373395

374396
/*[REM] Initialize the JITHelpers needed in J9VMInternals since the class can't do it itself */
375397
try {
@@ -707,7 +729,7 @@ private static void ensureProperties(boolean isInitialization) {
707729
/*[ENDIF] OpenJ9-RawBuild */
708730

709731
/*[IF JAVA_SPEC_VERSION > 11]*/
710-
Map<String, String> initializedProperties = new HashMap<>();
732+
Map<String, String> initializedProperties = new Hashtable<String, String>();
711733
/*[ELSE] JAVA_SPEC_VERSION > 11
712734
Properties initializedProperties = new Properties();
713735
/*[ENDIF] JAVA_SPEC_VERSION > 11 */
@@ -719,11 +741,9 @@ private static void ensureProperties(boolean isInitialization) {
719741
if (osEncoding != null) {
720742
initializedProperties.put("os.encoding", osEncoding); //$NON-NLS-1$
721743
}
722-
initializedProperties.put("ibm.system.encoding", platformEncoding); //$NON-NLS-1$
723-
/*[IF JAVA_SPEC_VERSION < 17]*/
724744
/*[PR The launcher apparently needs sun.jnu.encoding property or it does not work]*/
745+
initializedProperties.put("ibm.system.encoding", platformEncoding); //$NON-NLS-1$
725746
initializedProperties.put("sun.jnu.encoding", platformEncoding); //$NON-NLS-1$
726-
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
727747
/*[IF JAVA_SPEC_VERSION == 8]*/
728748
initializedProperties.put("file.encoding.pkg", "sun.io"); //$NON-NLS-1$ //$NON-NLS-2$
729749
/*[ENDIF] JJAVA_SPEC_VERSION == 8 */
@@ -749,9 +769,6 @@ private static void ensureProperties(boolean isInitialization) {
749769
initializedProperties.put("jfr.unsupported.vm", "true"); //$NON-NLS-1$ //$NON-NLS-2$
750770
/*[ENDIF] JFR_SUPPORT */
751771

752-
/*[IF JAVA_SPEC_VERSION >= 17]*/
753-
initializedProperties.putAll(SystemProps.initProperties());
754-
/*[ELSE] JAVA_SPEC_VERSION >= 17 */
755772
String[] list = getPropertyList();
756773
for (int i = 0; i < list.length; i += 2) {
757774
String key = list[i];
@@ -762,12 +779,43 @@ private static void ensureProperties(boolean isInitialization) {
762779
initializedProperties.put(key, list[i+1]);
763780
}
764781
initializedProperties.put("file.encoding", fileEncoding); //$NON-NLS-1$
782+
783+
/*[IF JAVA_SPEC_VERSION >= 17]*/
784+
/* Set native.encoding after setting all the defined properties, it can't be modified by using -D on the command line */
785+
initializedProperties.put("native.encoding", platformEncoding); //$NON-NLS-1$
765786
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
766787

767788
/*[IF (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64)]*/
768789
initializedProperties.put("com.ibm.autocvt", zOSAutoConvert); //$NON-NLS-1$
769790
/*[ENDIF] (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64) */
770791

792+
/*[IF JAVA_SPEC_VERSION >= 19]*/
793+
if (null != stdoutProp) {
794+
// Reinitialize required properties if ensureProperties(false) is called.
795+
initializedProperties.put("stdout.encoding", stdoutProp); //$NON-NLS-1$
796+
} else {
797+
stdoutProp = initializedProperties.get("stdout.encoding"); //$NON-NLS-1$
798+
if (null == stdoutProp) {
799+
stdoutProp = initializedProperties.get("sun.stdout.encoding"); //$NON-NLS-1$
800+
if (null != stdoutProp) {
801+
initializedProperties.put("stdout.encoding", stdoutProp); //$NON-NLS-1$
802+
}
803+
}
804+
}
805+
if (null != stderrProp) {
806+
// Reinitialize required properties if ensureProperties(false) is called.
807+
initializedProperties.put("stderr.encoding", stderrProp); //$NON-NLS-1$
808+
} else {
809+
stderrProp = initializedProperties.get("stderr.encoding");
810+
if (null == stderrProp) { //$NON-NLS-1$
811+
stderrProp = initializedProperties.get("sun.stderr.encoding"); //$NON-NLS-1$
812+
if (null != stderrProp) {
813+
initializedProperties.put("stderr.encoding", stderrProp); //$NON-NLS-1$
814+
}
815+
}
816+
}
817+
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
818+
771819
/* java.lang.VersionProps.init() eventually calls into System.setProperty() where propertiesInitialized needs to be true */
772820
propertiesInitialized = true;
773821

@@ -1040,7 +1088,6 @@ public static String setProperty(String prop, String value) {
10401088
return (String)systemProperties.setProperty(prop, value);
10411089
}
10421090

1043-
/*[IF JAVA_SPEC_VERSION < 17]*/
10441091
/**
10451092
* Answers an array of Strings containing key..value pairs
10461093
* (in consecutive array elements) which represent the
@@ -1050,14 +1097,13 @@ public static String setProperty(String prop, String value) {
10501097
* @return the default values for the system properties.
10511098
*/
10521099
private static native String [] getPropertyList();
1053-
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
10541100

1055-
/*[IF JAVA_SPEC_VERSION == 11]*/
1101+
/*[IF JAVA_SPEC_VERSION >= 11]*/
10561102
/**
10571103
* Invoke JCL native to initialize platform encoding explicitly.
10581104
*/
10591105
private static native void initJCLPlatformEncoding();
1060-
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
1106+
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
10611107

10621108
/**
10631109
* Before propertiesInitialized is set to true,

‎runtime/j9vm/java11vmi.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,7 @@ JVM_IsUseContainerSupport(void)
19001900
JNIEXPORT jobjectArray JNICALL
19011901
JVM_GetProperties(JNIEnv *env)
19021902
{
1903-
return ((J9VMThread *)env)->javaVM->internalVMFunctions->getSystemPropertyList(env);
1903+
assert(!"JVM_GetProperties");
1904+
return NULL;
19041905
}
19051906
#endif /* JAVA_SPEC_VERSION >= 17 */

0 commit comments

Comments
 (0)
Please sign in to comment.