Skip to content

Commit 5eb8d0f

Browse files
authored
Merge pull request eclipse-openj9#21320 from pshipton/sysprops6
Implement JVM_GetProperties for jdk17+ (again)
2 parents 7cba308 + 94f4a9e commit 5eb8d0f

File tree

25 files changed

+934
-904
lines changed

25 files changed

+934
-904
lines changed

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

+20-80
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@
6565

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

7173
/*[IF JAVA_SPEC_VERSION >= 24]*/
7274
import java.net.URL;
@@ -152,11 +154,8 @@ public final class System {
152154
private static final int sysPropID_OSEncoding = 3;
153155
private static String osEncoding;
154156

155-
private static final int sysPropID_DefaultTmpDir = 4;
156-
private static String defaultTmpDir;
157-
158157
/*[IF (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64)]*/
159-
private static final int sysPropID_zOSAutoConvert = 5;
158+
private static final int sysPropID_zOSAutoConvert = 4;
160159
private static String zOSAutoConvert;
161160
/*[ENDIF] (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64) */
162161

@@ -172,10 +171,6 @@ public final class System {
172171
*/
173172
private static Charset consoleDefaultCharset;
174173
/*[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 */
179174

180175
/*[IF JAVA_SPEC_VERSION >= 9]*/
181176
static java.lang.ModuleLayer bootLayer;
@@ -213,7 +208,6 @@ public final class System {
213208
if (osEncoding == null) {
214209
osEncoding = definedOSEncoding;
215210
}
216-
defaultTmpDir = getSysPropBeforePropertiesInitialized(sysPropID_DefaultTmpDir);
217211

218212
/*[IF (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64)]*/
219213
/* As part of better handling of JEP400 constraints on z/OS, the com.ibm.autocvt property
@@ -236,7 +230,7 @@ public final class System {
236230
*/
237231
static Charset getCharset(boolean isStdout, boolean fallback) {
238232
/*[IF JAVA_SPEC_VERSION >= 19]*/
239-
String primary = isStdout ? stdoutProp : stderrProp;
233+
String primary = internalGetProperties().getProperty(isStdout ? "stdout.encoding" : "stderr.encoding"); //$NON-NLS-1$ //$NON-NLS-2$
240234
/*[ELSE] JAVA_SPEC_VERSION >= 19 */
241235
String primary = internalGetProperties().getProperty(isStdout ? "sun.stdout.encoding" : "sun.stderr.encoding"); //$NON-NLS-1$ //$NON-NLS-2$
242236
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
@@ -279,20 +273,6 @@ static PrintStream createConsole(FileDescriptor desc, Charset charset) {
279273
BufferedOutputStream bufStream = new BufferedOutputStream(new FileOutputStream(desc));
280274
Charset consoleCharset = charset == null ? consoleDefaultCharset : charset;
281275

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-
296276
/*[IF PLATFORM-mz31 | PLATFORM-mz64]*/
297277
return ConsolePrintStream.localize(bufStream, true, consoleCharset);
298278
/*[ELSE]*/
@@ -323,12 +303,6 @@ static void finalizeConsoleEncoding() {
323303
setOut(createConsole(FileDescriptor.out, stdoutCharset));
324304
}
325305
}
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 */
332306
}
333307
/*[ELSE]*/
334308
/*[IF Sidecar18-SE-OpenJ9]*/
@@ -389,9 +363,9 @@ static void afterClinitInitialization() {
389363
// Fill in the properties from the VM information.
390364
ensureProperties(true);
391365

392-
/*[IF JAVA_SPEC_VERSION >= 11]*/
366+
/*[IF JAVA_SPEC_VERSION == 11]*/
393367
initJCLPlatformEncoding();
394-
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
368+
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
395369

396370
/*[REM] Initialize the JITHelpers needed in J9VMInternals since the class can't do it itself */
397371
try {
@@ -729,7 +703,7 @@ private static void ensureProperties(boolean isInitialization) {
729703
/*[ENDIF] OpenJ9-RawBuild */
730704

731705
/*[IF JAVA_SPEC_VERSION > 11]*/
732-
Map<String, String> initializedProperties = new Hashtable<String, String>();
706+
Map<String, String> initializedProperties = new HashMap<>();
733707
/*[ELSE] JAVA_SPEC_VERSION > 11
734708
Properties initializedProperties = new Properties();
735709
/*[ENDIF] JAVA_SPEC_VERSION > 11 */
@@ -741,9 +715,11 @@ private static void ensureProperties(boolean isInitialization) {
741715
if (osEncoding != null) {
742716
initializedProperties.put("os.encoding", osEncoding); //$NON-NLS-1$
743717
}
744-
/*[PR The launcher apparently needs sun.jnu.encoding property or it does not work]*/
745718
initializedProperties.put("ibm.system.encoding", platformEncoding); //$NON-NLS-1$
719+
/*[IF JAVA_SPEC_VERSION < 17]*/
720+
/*[PR The launcher apparently needs sun.jnu.encoding property or it does not work]*/
746721
initializedProperties.put("sun.jnu.encoding", platformEncoding); //$NON-NLS-1$
722+
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
747723
/*[IF JAVA_SPEC_VERSION == 8]*/
748724
initializedProperties.put("file.encoding.pkg", "sun.io"); //$NON-NLS-1$ //$NON-NLS-2$
749725
/*[ENDIF] JJAVA_SPEC_VERSION == 8 */
@@ -769,6 +745,9 @@ private static void ensureProperties(boolean isInitialization) {
769745
initializedProperties.put("jfr.unsupported.vm", "true"); //$NON-NLS-1$ //$NON-NLS-2$
770746
/*[ENDIF] JFR_SUPPORT */
771747

748+
/*[IF JAVA_SPEC_VERSION >= 17]*/
749+
initializedProperties.putAll(SystemProps.initProperties());
750+
/*[ELSE] JAVA_SPEC_VERSION >= 17 */
772751
String[] list = getPropertyList();
773752
for (int i = 0; i < list.length; i += 2) {
774753
String key = list[i];
@@ -779,43 +758,12 @@ private static void ensureProperties(boolean isInitialization) {
779758
initializedProperties.put(key, list[i+1]);
780759
}
781760
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$
786761
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
787762

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

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-
819767
/* java.lang.VersionProps.init() eventually calls into System.setProperty() where propertiesInitialized needs to be true */
820768
propertiesInitialized = true;
821769

@@ -1087,6 +1035,7 @@ public static String setProperty(String prop, String value) {
10871035
return (String)systemProperties.setProperty(prop, value);
10881036
}
10891037

1038+
/*[IF JAVA_SPEC_VERSION < 17]*/
10901039
/**
10911040
* Answers an array of Strings containing key..value pairs
10921041
* (in consecutive array elements) which represent the
@@ -1096,13 +1045,14 @@ public static String setProperty(String prop, String value) {
10961045
* @return the default values for the system properties.
10971046
*/
10981047
private static native String [] getPropertyList();
1048+
/*[ENDIF] JAVA_SPEC_VERSION < 17 */
10991049

1100-
/*[IF JAVA_SPEC_VERSION >= 11]*/
1050+
/*[IF JAVA_SPEC_VERSION == 11]*/
11011051
/**
11021052
* Invoke JCL native to initialize platform encoding explicitly.
11031053
*/
11041054
private static native void initJCLPlatformEncoding();
1105-
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
1055+
/*[ENDIF] JAVA_SPEC_VERSION == 11 */
11061056

11071057
/**
11081058
* Before propertiesInitialized is set to true,
@@ -1319,18 +1269,8 @@ public static void setProperties(Properties p) {
13191269

13201270
static void checkTmpDir() {
13211271
/*[IF JAVA_SPEC_VERSION >= 20]*/
1322-
String tmpDir = internalGetProperties().getProperty("java.io.tmpdir"); //$NON-NLS-1$
1323-
if (!defaultTmpDir.equals(tmpDir)) {
1324-
try {
1325-
Field systemProps = SystemProps.class.getDeclaredField("customTmpdir"); //$NON-NLS-1$
1326-
systemProps.setAccessible(true);
1327-
systemProps.set(null, tmpDir);
1328-
if (SystemProps.isBadIoTmpdir()) {
1329-
System.err.println("WARNING: java.io.tmpdir directory does not exist"); //$NON-NLS-1$
1330-
}
1331-
} catch (IllegalAccessException | NoSuchFieldException e) {
1332-
throw new InternalError(e);
1333-
}
1272+
if (SystemProps.isBadIoTmpdir()) {
1273+
System.err.println("WARNING: java.io.tmpdir directory does not exist"); //$NON-NLS-1$
13341274
}
13351275
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */
13361276
}

runtime/j9vm/j8vmi.c

+4-15
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cb, jint index) {
7272

7373
/**
7474
* Returns platform specific temporary directory used by the system.
75-
* Same as getTmpDir() defined in jcl/unix/syshelp.c and jcl/win32/syshelp.c.
7675
*
7776
* @param [in] env Pointer to JNI environment.
7877
*
@@ -82,20 +81,10 @@ jstring JNICALL
8281
JVM_GetTemporaryDirectory(JNIEnv *env)
8382
{
8483
PORT_ACCESS_FROM_ENV(env);
85-
jstring result = NULL;
86-
IDATA size = j9sysinfo_get_tmp(NULL, 0, TRUE);
87-
if (0 <= size) {
88-
char *buffer = (char *)j9mem_allocate_memory(size, OMRMEM_CATEGORY_VM);
89-
if (NULL == buffer) {
90-
return NULL;
91-
}
92-
if (0 == j9sysinfo_get_tmp(buffer, size, TRUE)) {
93-
result = (*env)->NewStringUTF(env, buffer);
94-
}
95-
96-
j9mem_free_memory(buffer);
97-
}
98-
84+
char *tempBuf = NULL;
85+
char *tempDir = getTmpDir(env, &tempBuf);
86+
jstring result = (*env)->NewStringUTF(env, tempDir);
87+
j9mem_free_memory(tempBuf);
9988
return result;
10089
}
10190

runtime/j9vm/java11vmi.c

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

runtime/jcl/common/attach.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#include "stackwalk.h"
2727
#include "jclglob.h"
2828
#include "jclprots.h"
29-
30-
extern char * getTmpDir(JNIEnv *env, char**envSpace);
29+
#include "util_api.h"
3130

3231
/**
3332
* Test if the file is owned by this process's owner or the process is running as root.

0 commit comments

Comments
 (0)