Skip to content

Commit

Permalink
Implement JVM_GetTemporaryDirectory.
Browse files Browse the repository at this point in the history
  • Loading branch information
teshull committed Mar 23, 2022
1 parent d90dff1 commit ce28fae
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class DarwinSystemPropertiesSupport extends PosixSystemPropertiesSupport {

@Override
protected String tmpdirValue() {
protected String javaIoTmpdirValue() {
/* Darwin has a per-user temp dir */
int buflen = Limits.PATH_MAX();
CCharPointer tmpPath = StackValue.get(buflen);
Expand All @@ -56,8 +56,7 @@ protected String tmpdirValue() {
return CTypeConversion.toJavaString(tmpPath);
} else {
/*
* Default as defined in JDK source/jdk/src/solaris/native/java/lang/java_props_md.c
* line 135.
* Default as defined in JDK src/java.base/unix/native/libjava/java_props_md.c line 90.
*/
return "/var/tmp";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class LinuxSystemPropertiesSupport extends PosixSystemPropertiesSupport {

@Override
protected String tmpdirValue() {
protected String javaIoTmpdirValue() {
/*
* The initial value of `java.io.tmpdir` is hard coded in libjava when building the JDK. So
* to be completely correct, we would have to use the value from libjava, but since it is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected String userDirValue() {
}

@Override
protected String tmpdirValue() {
protected String javaIoTmpdirValue() {
int maxLength = WinBase.MAX_PATH + 1;
WCharPointer tmpdir = StackValue.get(maxLength, WCharPointer.class);
int length = FileAPI.GetTempPathW(maxLength, tmpdir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public abstract class PlatformNativeLibrarySupport {
"jdk_internal_misc",
"jdk_internal_util",
"jdk_internal_jimage",
"jdk_internal_vm",
"jdk_net",
"sun_invoke",
"sun_launcher",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import com.oracle.svm.core.VM;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.util.VMError;

/**
* This class maintains the system properties at run time.
Expand Down Expand Up @@ -123,7 +124,7 @@ protected SystemPropertiesSupport() {
lazyRuntimeValues.put("user.name", this::userName);
lazyRuntimeValues.put("user.home", this::userHome);
lazyRuntimeValues.put("user.dir", this::userDir);
lazyRuntimeValues.put("java.io.tmpdir", this::tmpDir);
lazyRuntimeValues.put("java.io.tmpdir", this::javaIoTmpDir);
lazyRuntimeValues.put("java.library.path", this::javaLibraryPath);
lazyRuntimeValues.put("os.version", this::osVersionValue);

Expand Down Expand Up @@ -249,13 +250,13 @@ String userDir() {
return cachedUserDir;
}

private String cachedtmpDir;
private String cachedJavaIoTmpdir;

String tmpDir() {
if (cachedtmpDir == null) {
cachedtmpDir = tmpdirValue();
String javaIoTmpDir() {
if (cachedJavaIoTmpdir == null) {
cachedJavaIoTmpdir = javaIoTmpdirValue();
}
return cachedtmpDir;
return cachedJavaIoTmpdir;
}

private String cachedJavaLibraryPath;
Expand All @@ -275,7 +276,13 @@ String javaLibraryPath() {

protected abstract String userDirValue();

protected abstract String tmpdirValue();
protected String javaIoTmpdirValue() {
return tmpdirValue();
}

protected String tmpdirValue() {
throw VMError.unimplemented();
}

protected String javaLibraryPathValue() {
/* Default implementation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static String userName() {
@Substitute
@TargetElement(onlyWith = JDK17OrLater.class)
private static String javaIoTmpDir() {
return ImageSingletons.lookup(SystemPropertiesSupport.class).tmpDir();
return ImageSingletons.lookup(SystemPropertiesSupport.class).javaIoTmpDir();
}

@Substitute
Expand Down
22 changes: 22 additions & 0 deletions substratevm/src/com.oracle.svm.native.jvm.posix/src/JvmFuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <limits.h>

#include <jni.h>

Expand Down Expand Up @@ -319,6 +320,27 @@ JNIEXPORT jobject JNICALL JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject acti
return NULL;
}

#ifdef __APPLE__
char temp_path_storage[PATH_MAX];
JNIEXPORT jstring JNICALL JVM_GetTemporaryDirectory(JNIEnv *env) {
// see os_bsd.cpp line 910
static char *temp_path = NULL;
if (temp_path == NULL) {
int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, temp_path_storage, PATH_MAX);
if (pathSize == 0 || pathSize > PATH_MAX) {
strlcpy(temp_path_storage, "/tmp/", sizeof(temp_path_storage));
}
temp_path = temp_path_storage;
}
return (*env)->NewStringUTF(env, temp_path);
}
#else
JNIEXPORT jstring JNICALL JVM_GetTemporaryDirectory(JNIEnv *env) {
// see os_linux.cpp line 1380
return (*env)->NewStringUTF(env, "/tmp");
}
#endif /* __APPLE__ */

JNIEXPORT jobject JNICALL Java_sun_nio_ch_sctp_SctpChannelImpl_initIDs(JNIEnv *env) {
(*env)->FatalError(env, "Currently SCTP not supported for native-images");
return NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ JNIEXPORT jobject JNICALL JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject acti
return NULL;
}

JNIEXPORT jstring JNICALL JVM_GetTemporaryDirectory(JNIEnv *env) {
// see os_windows.cpp line 1367
static char path_buf[MAX_PATH];
if (GetTempPath(MAX_PATH, path_buf) <= 0) {
path_buf[0] = '\0';
}
return (*env)->NewStringUTF(env, path_buf);
}

jboolean VerifyFixClassname(char *utf_name) {
fprintf(stderr, "VerifyFixClassname(%s) called: Unimplemented\n", utf_name);
abort();
Expand Down

0 comments on commit ce28fae

Please sign in to comment.