use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class PosixJavaIOSubstitutions method setLastModifiedTime.
@Substitute
public boolean setLastModifiedTime(File f, long time) {
stat stat = StackValue.get(SizeOf.get(stat.class));
try (CCharPointerHolder pathPin = CTypeConversion.toCString(f.getPath())) {
CCharPointer pathPtr = pathPin.get();
if (stat(pathPtr, stat) == 0) {
timeval timeval = StackValue.get(2, SizeOf.get(timeval.class));
// preserve access time
timeval access = timeval.addressOf(0);
access.set_tv_sec(stat.st_atime());
access.set_tv_usec(0L);
// change last-modified time
timeval last = timeval.addressOf(1);
last.set_tv_sec(time / 1000);
last.set_tv_usec((time % 1000) * 1000);
if (utimes(pathPtr, timeval) == 0) {
return true;
}
}
}
return false;
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class PosixJavaIOSubstitutions method getFilePointer.
@Substitute
public long getFilePointer() throws IOException {
SignedWord ret;
int handle = PosixUtils.getFDHandle(fd);
if ((ret = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) {
throw new IOException(lastErrorString("Seek failed"));
}
return ret.rawValue();
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class PosixJavaLangSubstitutions method currentTimeMillis.
@Substitute
@Uninterruptible(reason = "Called from uninterruptible code.")
public static long currentTimeMillis() {
timeval timeval = StackValue.get(SizeOf.get(timeval.class));
timezone timezone = WordFactory.nullPointer();
gettimeofday(timeval, timezone);
return timeval.tv_sec() * 1_000L + timeval.tv_usec() / 1_000L;
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class PosixJavaLangSubstitutions method waitForProcessExit.
@Substitute
@SuppressWarnings({ "static-method" })
int waitForProcessExit(int ppid) {
CIntPointer statusptr = StackValue.get(SizeOf.get(CIntPointer.class));
while (Wait.waitpid(ppid, statusptr, 0) < 0) {
if (Errno.errno() == Errno.ECHILD()) {
return 0;
} else if (Errno.errno() != Errno.EINTR()) {
return -1;
}
}
int status = statusptr.read();
if (Wait.WIFEXITED(status)) {
return Wait.WEXITSTATUS(status);
} else if (Wait.WIFSIGNALED(status)) {
// Exited because of signal: return 0x80 + signal number like shells do
return 0x80 + Wait.WTERMSIG(status);
}
return status;
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class DarwinSubstitutions method nanoTime.
@Substitute
@Uninterruptible(reason = "Does basic math after a few simple system calls")
private static long nanoTime() {
final Util_java_lang_System utilJavaLangSystem = ImageSingletons.lookup(Util_java_lang_System.class);
if (utilJavaLangSystem.fastTime) {
return mach_absolute_time();
}
if (!utilJavaLangSystem.timeBaseValid) {
MachTimebaseInfo timeBaseInfo = StackValue.get(SizeOf.get(MachTimebaseInfo.class));
if (mach_timebase_info(timeBaseInfo) == 0) {
if (timeBaseInfo.getdenom() == 1 && timeBaseInfo.getnumer() == 1) {
utilJavaLangSystem.fastTime = true;
return mach_absolute_time();
}
utilJavaLangSystem.factor = (double) timeBaseInfo.getnumer() / (double) timeBaseInfo.getdenom();
}
utilJavaLangSystem.timeBaseValid = true;
}
if (utilJavaLangSystem.factor != 0) {
return (long) (mach_absolute_time() * utilJavaLangSystem.factor);
}
/* High precision time is not available, fall back to low precision. */
timeval timeval = StackValue.get(SizeOf.get(timeval.class));
timezone timezone = WordFactory.nullPointer();
gettimeofday(timeval, timezone);
return timeval.tv_sec() * 1_000_000_000L + timeval.tv_usec() * 1_000L;
}
Aggregations