mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8284161: Implementation of Virtual Threads (Preview)
Co-authored-by: Ron Pressler <rpressler@openjdk.org> Co-authored-by: Alan Bateman <alanb@openjdk.org> Co-authored-by: Erik Österlund <eosterlund@openjdk.org> Co-authored-by: Andrew Haley <aph@openjdk.org> Co-authored-by: Rickard Bäckman <rbackman@openjdk.org> Co-authored-by: Markus Grönlund <mgronlun@openjdk.org> Co-authored-by: Leonid Mesnik <lmesnik@openjdk.org> Co-authored-by: Serguei Spitsyn <sspitsyn@openjdk.org> Co-authored-by: Chris Plummer <cjplummer@openjdk.org> Co-authored-by: Coleen Phillimore <coleenp@openjdk.org> Co-authored-by: Robbin Ehn <rehn@openjdk.org> Co-authored-by: Stefan Karlsson <stefank@openjdk.org> Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org> Co-authored-by: Sergey Kuksenko <skuksenko@openjdk.org> Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
This commit is contained in:
parent
5212535a27
commit
9583e3657e
1133 changed files with 95935 additions and 8335 deletions
|
@ -26,11 +26,10 @@
|
|||
package java.io;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import jdk.internal.misc.Blocker;
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
|
||||
class UnixFileSystem extends FileSystem {
|
||||
|
||||
private final char slash;
|
||||
|
@ -172,7 +171,12 @@ class UnixFileSystem extends FileSystem {
|
|||
@Override
|
||||
public String canonicalize(String path) throws IOException {
|
||||
if (!useCanonCaches) {
|
||||
return canonicalize0(path);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return canonicalize0(path);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
} else {
|
||||
String res = cache.get(path);
|
||||
if (res == null) {
|
||||
|
@ -194,7 +198,12 @@ class UnixFileSystem extends FileSystem {
|
|||
}
|
||||
}
|
||||
if (res == null) {
|
||||
res = canonicalize0(path);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
res = canonicalize0(path);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
cache.put(path, res);
|
||||
if (useCanonPrefixCache &&
|
||||
dir != null && dir.startsWith(javaHome)) {
|
||||
|
@ -261,17 +270,29 @@ class UnixFileSystem extends FileSystem {
|
|||
|
||||
/* -- Attribute accessors -- */
|
||||
|
||||
public native int getBooleanAttributes0(File f);
|
||||
private native int getBooleanAttributes0(File f);
|
||||
|
||||
@Override
|
||||
public int getBooleanAttributes(File f) {
|
||||
int rv = getBooleanAttributes0(f);
|
||||
int rv;
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
rv = getBooleanAttributes0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
return rv | isHidden(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBooleanAttributes(File f, int attributes) {
|
||||
int rv = getBooleanAttributes0(f);
|
||||
int rv;
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
rv = getBooleanAttributes0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
if ((attributes & BA_HIDDEN) != 0) {
|
||||
rv |= isHidden(f);
|
||||
}
|
||||
|
@ -283,22 +304,61 @@ class UnixFileSystem extends FileSystem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public native boolean checkAccess(File f, int access);
|
||||
public boolean checkAccess(File f, int access) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return checkAccess0(f, access);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean checkAccess0(File f, int access);
|
||||
|
||||
@Override
|
||||
public native long getLastModifiedTime(File f);
|
||||
public long getLastModifiedTime(File f) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return getLastModifiedTime0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native long getLastModifiedTime0(File f);
|
||||
|
||||
@Override
|
||||
public native long getLength(File f);
|
||||
public long getLength(File f) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return getLength0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native long getLength0(File f);
|
||||
|
||||
@Override
|
||||
public native boolean setPermission(File f, int access, boolean enable, boolean owneronly);
|
||||
public boolean setPermission(File f, int access, boolean enable, boolean owneronly) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return setPermission0(f, access, enable, owneronly);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean setPermission0(File f, int access, boolean enable, boolean owneronly);
|
||||
|
||||
/* -- File operations -- */
|
||||
|
||||
@Override
|
||||
public native boolean createFileExclusively(String path)
|
||||
throws IOException;
|
||||
public boolean createFileExclusively(String path) throws IOException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return createFileExclusively0(path);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean createFileExclusively0(String path) throws IOException;
|
||||
|
||||
@Override
|
||||
public boolean delete(File f) {
|
||||
|
@ -313,15 +373,36 @@ class UnixFileSystem extends FileSystem {
|
|||
if (useCanonPrefixCache) {
|
||||
javaHomePrefixCache.clear();
|
||||
}
|
||||
return delete0(f);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return delete0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean delete0(File f);
|
||||
|
||||
@Override
|
||||
public native String[] list(File f);
|
||||
public String[] list(File f) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return list0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native String[] list0(File f);
|
||||
|
||||
@Override
|
||||
public native boolean createDirectory(File f);
|
||||
public boolean createDirectory(File f) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return createDirectory0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean createDirectory0(File f);
|
||||
|
||||
@Override
|
||||
public boolean rename(File f1, File f2) {
|
||||
|
@ -336,15 +417,36 @@ class UnixFileSystem extends FileSystem {
|
|||
if (useCanonPrefixCache) {
|
||||
javaHomePrefixCache.clear();
|
||||
}
|
||||
return rename0(f1, f2);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return rename0(f1, f2);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean rename0(File f1, File f2);
|
||||
|
||||
@Override
|
||||
public native boolean setLastModifiedTime(File f, long time);
|
||||
public boolean setLastModifiedTime(File f, long time) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return setLastModifiedTime0(f, time);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean setLastModifiedTime0(File f, long time);
|
||||
|
||||
@Override
|
||||
public native boolean setReadOnly(File f);
|
||||
public boolean setReadOnly(File f) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return setReadOnly0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native boolean setReadOnly0(File f);
|
||||
|
||||
/* -- Filesystem interface -- */
|
||||
|
||||
|
@ -365,7 +467,15 @@ class UnixFileSystem extends FileSystem {
|
|||
/* -- Disk usage -- */
|
||||
|
||||
@Override
|
||||
public native long getSpace(File f, int t);
|
||||
public long getSpace(File f, int t) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return getSpace0(f, t);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native long getSpace0(File f, int t);
|
||||
|
||||
/* -- Basic infrastructure -- */
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ import java.util.Locale;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
|
@ -71,6 +73,9 @@ final class ProcessImpl extends Process {
|
|||
private int exitcode;
|
||||
private boolean hasExited;
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final Condition condition = lock.newCondition();
|
||||
|
||||
private /* final */ OutputStream stdin;
|
||||
private /* final */ InputStream stdout;
|
||||
private /* final */ InputStream stderr;
|
||||
|
@ -360,10 +365,13 @@ final class ProcessImpl extends Process {
|
|||
new ProcessPipeInputStream(fds[2]);
|
||||
|
||||
ProcessHandleImpl.completion(pid, true).handle((exitcode, throwable) -> {
|
||||
synchronized (this) {
|
||||
lock.lock();
|
||||
try {
|
||||
this.exitcode = (exitcode == null) ? -1 : exitcode.intValue();
|
||||
this.hasExited = true;
|
||||
this.notifyAll();
|
||||
condition.signalAll();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
if (stdout instanceof ProcessPipeInputStream)
|
||||
|
@ -393,10 +401,13 @@ final class ProcessImpl extends Process {
|
|||
new DeferredCloseProcessPipeInputStream(fds[2]);
|
||||
|
||||
ProcessHandleImpl.completion(pid, true).handle((exitcode, throwable) -> {
|
||||
synchronized (this) {
|
||||
lock.lock();
|
||||
try {
|
||||
this.exitcode = (exitcode == null) ? -1 : exitcode.intValue();
|
||||
this.hasExited = true;
|
||||
this.notifyAll();
|
||||
condition.signalAll();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
if (stdout instanceof DeferredCloseProcessPipeInputStream)
|
||||
|
@ -428,37 +439,43 @@ final class ProcessImpl extends Process {
|
|||
return stderr;
|
||||
}
|
||||
|
||||
public synchronized int waitFor() throws InterruptedException {
|
||||
while (!hasExited) {
|
||||
wait();
|
||||
public int waitFor() throws InterruptedException {
|
||||
lock.lock();
|
||||
try {
|
||||
while (!hasExited) {
|
||||
condition.await();
|
||||
}
|
||||
return exitcode;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean waitFor(long timeout, TimeUnit unit)
|
||||
public boolean waitFor(long timeout, TimeUnit unit)
|
||||
throws InterruptedException
|
||||
{
|
||||
long remainingNanos = unit.toNanos(timeout); // throw NPE before other conditions
|
||||
if (hasExited) return true;
|
||||
if (timeout <= 0) return false;
|
||||
|
||||
long deadline = System.nanoTime() + remainingNanos;
|
||||
do {
|
||||
TimeUnit.NANOSECONDS.timedWait(this, remainingNanos);
|
||||
if (hasExited) {
|
||||
return true;
|
||||
lock.lock();
|
||||
try {
|
||||
long remainingNanos = unit.toNanos(timeout); // throw NPE before other conditions
|
||||
while (remainingNanos > 0 && !hasExited) {
|
||||
remainingNanos = condition.awaitNanos(remainingNanos);
|
||||
}
|
||||
remainingNanos = deadline - System.nanoTime();
|
||||
} while (remainingNanos > 0);
|
||||
return hasExited;
|
||||
return hasExited;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized int exitValue() {
|
||||
if (!hasExited) {
|
||||
throw new IllegalThreadStateException("process hasn't exited");
|
||||
public int exitValue() {
|
||||
lock.lock();
|
||||
try {
|
||||
if (!hasExited) {
|
||||
throw new IllegalThreadStateException("process hasn't exited");
|
||||
}
|
||||
return exitcode;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
private void destroy(boolean force) {
|
||||
|
@ -472,9 +489,12 @@ final class ProcessImpl extends Process {
|
|||
// there is an unavoidable race condition here, but the window
|
||||
// is very small, and OSes try hard to not recycle pids too
|
||||
// soon, so this is quite safe.
|
||||
synchronized (this) {
|
||||
lock.lock();
|
||||
try {
|
||||
if (!hasExited)
|
||||
processHandle.destroyProcess(force);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
try { stdin.close(); } catch (IOException ignored) {}
|
||||
try { stdout.close(); } catch (IOException ignored) {}
|
||||
|
@ -538,8 +558,13 @@ final class ProcessImpl extends Process {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAlive() {
|
||||
return !hasExited;
|
||||
public boolean isAlive() {
|
||||
lock.lock();
|
||||
try {
|
||||
return !hasExited;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -36,20 +36,67 @@ package sun.nio.ch;
|
|||
// On systems that do not require this type of signalling, the current() method
|
||||
// always returns -1 and the signal(long) method has no effect.
|
||||
|
||||
|
||||
public class NativeThread {
|
||||
private static final long VIRTUAL_THREAD_ID = -1L;
|
||||
|
||||
/**
|
||||
* Returns the id of the current native thread if the platform can signal
|
||||
* native threads, 0 if the platform can not signal native threads, or
|
||||
* -1L if the current thread is a virtual thread.
|
||||
*/
|
||||
public static long current() {
|
||||
if (Thread.currentThread().isVirtual()) {
|
||||
return VIRTUAL_THREAD_ID;
|
||||
} else {
|
||||
return current0();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the current native thread if the platform can signal
|
||||
* native threads, 0 if the platform can not signal native threads.
|
||||
*/
|
||||
static long currentNativeThread() {
|
||||
return current0();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signals the given native thread.
|
||||
*
|
||||
* @throws IllegalArgumentException if tid is not a token to a native thread
|
||||
*/
|
||||
public static void signal(long tid) {
|
||||
if (tid == 0 || tid == VIRTUAL_THREAD_ID)
|
||||
throw new IllegalArgumentException();
|
||||
signal0(tid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true the tid is the id of a native thread.
|
||||
*/
|
||||
static boolean isNativeThread(long tid) {
|
||||
return (tid != 0 && tid != VIRTUAL_THREAD_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if tid is -1L.
|
||||
* @see #current()
|
||||
*/
|
||||
static boolean isVirtualThread(long tid) {
|
||||
return (tid == VIRTUAL_THREAD_ID);
|
||||
}
|
||||
|
||||
// Returns an opaque token representing the native thread underlying the
|
||||
// invoking Java thread. On systems that do not require signalling, this
|
||||
// method always returns -1.
|
||||
// method always returns 0.
|
||||
//
|
||||
public static native long current();
|
||||
private static native long current0();
|
||||
|
||||
// Signals the given native thread so as to release it from a blocking I/O
|
||||
// operation. On systems that do not require signalling, this method has
|
||||
// no effect.
|
||||
//
|
||||
public static native void signal(long nt);
|
||||
private static native void signal0(long tid);
|
||||
|
||||
private static native void init();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.util.Deque;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jdk.internal.misc.Blocker;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
|
||||
/**
|
||||
|
@ -111,7 +111,12 @@ class PollSelectorImpl extends SelectorImpl {
|
|||
int numPolled;
|
||||
do {
|
||||
long startTime = timedPoll ? System.nanoTime() : 0;
|
||||
numPolled = poll(pollArray.address(), pollArraySize, to);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
numPolled = poll(pollArray.address(), pollArraySize, to);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
if (numPolled == IOStatus.INTERRUPTED && timedPoll) {
|
||||
// timed poll interrupted so need to adjust timeout
|
||||
long adjust = System.nanoTime() - startTime;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -77,8 +77,9 @@ class SinkChannelImpl
|
|||
return fdVal;
|
||||
}
|
||||
|
||||
SinkChannelImpl(SelectorProvider sp, FileDescriptor fd) {
|
||||
SinkChannelImpl(SelectorProvider sp, FileDescriptor fd) throws IOException {
|
||||
super(sp);
|
||||
IOUtil.configureBlocking(fd, false);
|
||||
this.fd = fd;
|
||||
this.fdVal = IOUtil.fdVal(fd);
|
||||
}
|
||||
|
@ -123,8 +124,12 @@ class SinkChannelImpl
|
|||
if (!tryClose()) {
|
||||
long th = thread;
|
||||
if (th != 0) {
|
||||
nd.preClose(fd);
|
||||
NativeThread.signal(th);
|
||||
if (NativeThread.isVirtualThread(th)) {
|
||||
Poller.stopPoll(fdVal);
|
||||
} else {
|
||||
nd.preClose(fd);
|
||||
NativeThread.signal(th);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -77,8 +77,9 @@ class SourceChannelImpl
|
|||
return fdVal;
|
||||
}
|
||||
|
||||
SourceChannelImpl(SelectorProvider sp, FileDescriptor fd) {
|
||||
SourceChannelImpl(SelectorProvider sp, FileDescriptor fd) throws IOException {
|
||||
super(sp);
|
||||
IOUtil.configureBlocking(fd, false);
|
||||
this.fd = fd;
|
||||
this.fdVal = IOUtil.fdVal(fd);
|
||||
}
|
||||
|
@ -123,8 +124,12 @@ class SourceChannelImpl
|
|||
if (!tryClose()) {
|
||||
long th = thread;
|
||||
if (th != 0) {
|
||||
nd.preClose(fd);
|
||||
NativeThread.signal(th);
|
||||
if (NativeThread.isVirtualThread(th)) {
|
||||
Poller.stopPoll(fdVal);
|
||||
} else {
|
||||
nd.preClose(fd);
|
||||
NativeThread.signal(th);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,10 @@ import java.nio.file.LinkPermission;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jdk.internal.misc.Blocker;
|
||||
import static sun.nio.fs.UnixNativeDispatcher.*;
|
||||
import static sun.nio.fs.UnixConstants.*;
|
||||
|
||||
|
||||
/**
|
||||
* Unix implementation of Path#copyTo and Path#moveTo methods.
|
||||
*/
|
||||
|
@ -251,7 +250,12 @@ class UnixCopyFile {
|
|||
try {
|
||||
// transfer bytes to target file
|
||||
try {
|
||||
transfer(fo, fi, addressToPollForCancel);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
transfer(fo, fi, addressToPollForCancel);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
} catch (UnixException x) {
|
||||
x.rethrowAsIOException(source, target);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
package sun.nio.fs;
|
||||
|
||||
import java.util.function.Function;
|
||||
import jdk.internal.misc.Blocker;
|
||||
|
||||
/**
|
||||
* Unix system and library calls.
|
||||
|
@ -65,11 +66,13 @@ class UnixNativeDispatcher {
|
|||
* int open(const char* path, int oflag, mode_t mode)
|
||||
*/
|
||||
static int open(UnixPath path, int flags, int mode) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
return open0(buffer.address(), flags, mode);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return open0(buffer.address(), flags, mode);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native int open0(long pathAddress, int flags, int mode)
|
||||
|
@ -79,11 +82,13 @@ class UnixNativeDispatcher {
|
|||
* int openat(int dfd, const char* path, int oflag, mode_t mode)
|
||||
*/
|
||||
static int openat(int dfd, byte[] path, int flags, int mode) throws UnixException {
|
||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(path);
|
||||
try {
|
||||
return openat0(dfd, buffer.address(), flags, mode);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return openat0(dfd, buffer.address(), flags, mode);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native int openat0(int dfd, long pathAddress, int flags, int mode)
|
||||
|
@ -131,13 +136,14 @@ class UnixNativeDispatcher {
|
|||
* link(const char* existing, const char* new)
|
||||
*/
|
||||
static void link(UnixPath existing, UnixPath newfile) throws UnixException {
|
||||
NativeBuffer existingBuffer = copyToNativeBuffer(existing);
|
||||
NativeBuffer newBuffer = copyToNativeBuffer(newfile);
|
||||
try {
|
||||
link0(existingBuffer.address(), newBuffer.address());
|
||||
} finally {
|
||||
newBuffer.release();
|
||||
existingBuffer.release();
|
||||
try (NativeBuffer existingBuffer = copyToNativeBuffer(existing);
|
||||
NativeBuffer newBuffer = copyToNativeBuffer(newfile)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
link0(existingBuffer.address(), newBuffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void link0(long existingAddress, long newAddress)
|
||||
|
@ -147,11 +153,13 @@ class UnixNativeDispatcher {
|
|||
* unlink(const char* path)
|
||||
*/
|
||||
static void unlink(UnixPath path) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
unlink0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
unlink0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void unlink0(long pathAddress) throws UnixException;
|
||||
|
@ -160,11 +168,13 @@ class UnixNativeDispatcher {
|
|||
* unlinkat(int dfd, const char* path, int flag)
|
||||
*/
|
||||
static void unlinkat(int dfd, byte[] path, int flag) throws UnixException {
|
||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(path);
|
||||
try {
|
||||
unlinkat0(dfd, buffer.address(), flag);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
unlinkat0(dfd, buffer.address(), flag);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void unlinkat0(int dfd, long pathAddress, int flag)
|
||||
|
@ -174,11 +184,13 @@ class UnixNativeDispatcher {
|
|||
* mknod(const char* path, mode_t mode, dev_t dev)
|
||||
*/
|
||||
static void mknod(UnixPath path, int mode, long dev) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
mknod0(buffer.address(), mode, dev);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
mknod0(buffer.address(), mode, dev);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void mknod0(long pathAddress, int mode, long dev)
|
||||
|
@ -188,13 +200,14 @@ class UnixNativeDispatcher {
|
|||
* rename(const char* old, const char* new)
|
||||
*/
|
||||
static void rename(UnixPath from, UnixPath to) throws UnixException {
|
||||
NativeBuffer fromBuffer = copyToNativeBuffer(from);
|
||||
NativeBuffer toBuffer = copyToNativeBuffer(to);
|
||||
try {
|
||||
rename0(fromBuffer.address(), toBuffer.address());
|
||||
} finally {
|
||||
toBuffer.release();
|
||||
fromBuffer.release();
|
||||
try (NativeBuffer fromBuffer = copyToNativeBuffer(from);
|
||||
NativeBuffer toBuffer = copyToNativeBuffer(to)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
rename0(fromBuffer.address(), toBuffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void rename0(long fromAddress, long toAddress)
|
||||
|
@ -204,13 +217,14 @@ class UnixNativeDispatcher {
|
|||
* renameat(int fromfd, const char* old, int tofd, const char* new)
|
||||
*/
|
||||
static void renameat(int fromfd, byte[] from, int tofd, byte[] to) throws UnixException {
|
||||
NativeBuffer fromBuffer = NativeBuffers.asNativeBuffer(from);
|
||||
NativeBuffer toBuffer = NativeBuffers.asNativeBuffer(to);
|
||||
try {
|
||||
renameat0(fromfd, fromBuffer.address(), tofd, toBuffer.address());
|
||||
} finally {
|
||||
toBuffer.release();
|
||||
fromBuffer.release();
|
||||
try (NativeBuffer fromBuffer = NativeBuffers.asNativeBuffer(from);
|
||||
NativeBuffer toBuffer = NativeBuffers.asNativeBuffer(to)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
renameat0(fromfd, fromBuffer.address(), tofd, toBuffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void renameat0(int fromfd, long fromAddress, int tofd, long toAddress)
|
||||
|
@ -220,11 +234,13 @@ class UnixNativeDispatcher {
|
|||
* mkdir(const char* path, mode_t mode)
|
||||
*/
|
||||
static void mkdir(UnixPath path, int mode) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
mkdir0(buffer.address(), mode);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
mkdir0(buffer.address(), mode);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void mkdir0(long pathAddress, int mode) throws UnixException;
|
||||
|
@ -233,11 +249,13 @@ class UnixNativeDispatcher {
|
|||
* rmdir(const char* path)
|
||||
*/
|
||||
static void rmdir(UnixPath path) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
rmdir0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
rmdir0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void rmdir0(long pathAddress) throws UnixException;
|
||||
|
@ -248,11 +266,13 @@ class UnixNativeDispatcher {
|
|||
* @return link target
|
||||
*/
|
||||
static byte[] readlink(UnixPath path) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
return readlink0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return readlink0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native byte[] readlink0(long pathAddress) throws UnixException;
|
||||
|
@ -263,11 +283,13 @@ class UnixNativeDispatcher {
|
|||
* @return resolved path
|
||||
*/
|
||||
static byte[] realpath(UnixPath path) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
return realpath0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return realpath0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native byte[] realpath0(long pathAddress) throws UnixException;
|
||||
|
@ -276,13 +298,14 @@ class UnixNativeDispatcher {
|
|||
* symlink(const char* name1, const char* name2)
|
||||
*/
|
||||
static void symlink(byte[] name1, UnixPath name2) throws UnixException {
|
||||
NativeBuffer targetBuffer = NativeBuffers.asNativeBuffer(name1);
|
||||
NativeBuffer linkBuffer = copyToNativeBuffer(name2);
|
||||
try {
|
||||
symlink0(targetBuffer.address(), linkBuffer.address());
|
||||
} finally {
|
||||
linkBuffer.release();
|
||||
targetBuffer.release();
|
||||
try (NativeBuffer targetBuffer = NativeBuffers.asNativeBuffer(name1);
|
||||
NativeBuffer linkBuffer = copyToNativeBuffer(name2)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
symlink0(targetBuffer.address(), linkBuffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void symlink0(long name1, long name2)
|
||||
|
@ -292,11 +315,13 @@ class UnixNativeDispatcher {
|
|||
* stat(const char* path, struct stat* buf)
|
||||
*/
|
||||
static void stat(UnixPath path, UnixFileAttributes attrs) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
stat0(buffer.address(), attrs);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
stat0(buffer.address(), attrs);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void stat0(long pathAddress, UnixFileAttributes attrs)
|
||||
|
@ -309,11 +334,13 @@ class UnixNativeDispatcher {
|
|||
* @return st_mode (file type and mode) or 0 if an error occurs.
|
||||
*/
|
||||
static int stat(UnixPath path) {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
return stat1(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return stat1(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native int stat1(long pathAddress);
|
||||
|
@ -323,11 +350,13 @@ class UnixNativeDispatcher {
|
|||
* lstat(const char* path, struct stat* buf)
|
||||
*/
|
||||
static void lstat(UnixPath path, UnixFileAttributes attrs) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
lstat0(buffer.address(), attrs);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
lstat0(buffer.address(), attrs);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void lstat0(long pathAddress, UnixFileAttributes attrs)
|
||||
|
@ -336,7 +365,16 @@ class UnixNativeDispatcher {
|
|||
/**
|
||||
* fstat(int filedes, struct stat* buf)
|
||||
*/
|
||||
static native void fstat(int fd, UnixFileAttributes attrs) throws UnixException;
|
||||
static void fstat(int fd, UnixFileAttributes attrs) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
fstat0(fd, attrs);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native void fstat0(int fd, UnixFileAttributes attrs)
|
||||
throws UnixException;
|
||||
|
||||
/**
|
||||
* fstatat(int filedes,const char* path, struct stat* buf, int flag)
|
||||
|
@ -344,11 +382,13 @@ class UnixNativeDispatcher {
|
|||
static void fstatat(int dfd, byte[] path, int flag, UnixFileAttributes attrs)
|
||||
throws UnixException
|
||||
{
|
||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(path);
|
||||
try {
|
||||
fstatat0(dfd, buffer.address(), flag, attrs);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
fstatat0(dfd, buffer.address(), flag, attrs);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void fstatat0(int dfd, long pathAddress, int flag,
|
||||
|
@ -358,11 +398,13 @@ class UnixNativeDispatcher {
|
|||
* chown(const char* path, uid_t owner, gid_t group)
|
||||
*/
|
||||
static void chown(UnixPath path, int uid, int gid) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
chown0(buffer.address(), uid, gid);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
chown0(buffer.address(), uid, gid);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void chown0(long pathAddress, int uid, int gid)
|
||||
|
@ -372,11 +414,13 @@ class UnixNativeDispatcher {
|
|||
* lchown(const char* path, uid_t owner, gid_t group)
|
||||
*/
|
||||
static void lchown(UnixPath path, int uid, int gid) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
lchown0(buffer.address(), uid, gid);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
lchown0(buffer.address(), uid, gid);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void lchown0(long pathAddress, int uid, int gid)
|
||||
|
@ -385,17 +429,27 @@ class UnixNativeDispatcher {
|
|||
/**
|
||||
* fchown(int filedes, uid_t owner, gid_t group)
|
||||
*/
|
||||
static native void fchown(int fd, int uid, int gid) throws UnixException;
|
||||
static void fchown(int fd, int uid, int gid) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
fchown0(fd, uid, gid);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
static native void fchown0(int fd, int uid, int gid) throws UnixException;
|
||||
|
||||
/**
|
||||
* chmod(const char* path, mode_t mode)
|
||||
*/
|
||||
static void chmod(UnixPath path, int mode) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
chmod0(buffer.address(), mode);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
chmod0(buffer.address(), mode);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void chmod0(long pathAddress, int mode)
|
||||
|
@ -404,7 +458,15 @@ class UnixNativeDispatcher {
|
|||
/**
|
||||
* fchmod(int fildes, mode_t mode)
|
||||
*/
|
||||
static native void fchmod(int fd, int mode) throws UnixException;
|
||||
static void fchmod(int fd, int mode) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
fchmod0(fd, mode);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native void fchmod0(int fd, int mode) throws UnixException;
|
||||
|
||||
/**
|
||||
* utimes(const char* path, const struct timeval times[2])
|
||||
|
@ -412,11 +474,13 @@ class UnixNativeDispatcher {
|
|||
static void utimes(UnixPath path, long times0, long times1)
|
||||
throws UnixException
|
||||
{
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
utimes0(buffer.address(), times0, times1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
utimes0(buffer.address(), times0, times1);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void utimes0(long pathAddress, long times0, long times1)
|
||||
|
@ -425,12 +489,30 @@ class UnixNativeDispatcher {
|
|||
/**
|
||||
* futimes(int fildes, const struct timeval times[2])
|
||||
*/
|
||||
static native void futimes(int fd, long times0, long times1) throws UnixException;
|
||||
static void futimes(int fd, long times0, long times1) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
futimes0(fd, times0, times1);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native void futimes0(int fd, long times0, long times1)
|
||||
throws UnixException;
|
||||
|
||||
/**
|
||||
* futimens(int fildes, const struct timespec times[2])
|
||||
*/
|
||||
static native void futimens(int fd, long times0, long times1) throws UnixException;
|
||||
static void futimens(int fd, long times0, long times1) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
futimens0(fd, times0, times1);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native void futimens0(int fd, long times0, long times1)
|
||||
throws UnixException;
|
||||
|
||||
/**
|
||||
* lutimes(const char* path, const struct timeval times[2])
|
||||
|
@ -438,11 +520,13 @@ class UnixNativeDispatcher {
|
|||
static void lutimes(UnixPath path, long times0, long times1)
|
||||
throws UnixException
|
||||
{
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
lutimes0(buffer.address(), times0, times1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
lutimes0(buffer.address(), times0, times1);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void lutimes0(long pathAddress, long times0, long times1)
|
||||
|
@ -452,11 +536,13 @@ class UnixNativeDispatcher {
|
|||
* DIR *opendir(const char* dirname)
|
||||
*/
|
||||
static long opendir(UnixPath path) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
return opendir0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return opendir0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native long opendir0(long pathAddress) throws UnixException;
|
||||
|
@ -477,27 +563,53 @@ class UnixNativeDispatcher {
|
|||
*
|
||||
* @return dirent->d_name
|
||||
*/
|
||||
static native byte[] readdir(long dir) throws UnixException;
|
||||
static byte[] readdir(long dir) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return readdir0(dir);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
static native byte[] readdir0(long dir) throws UnixException;
|
||||
|
||||
/**
|
||||
* size_t read(int fildes, void* buf, size_t nbyte)
|
||||
*/
|
||||
static native int read(int fildes, long buf, int nbyte) throws UnixException;
|
||||
static int read(int fildes, long buf, int nbyte) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return read0(fildes, buf, nbyte);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native int read0(int fildes, long buf, int nbyte) throws UnixException;
|
||||
|
||||
/**
|
||||
* size_t writeint fildes, void* buf, size_t nbyte)
|
||||
*/
|
||||
static native int write(int fildes, long buf, int nbyte) throws UnixException;
|
||||
static int write(int fildes, long buf, int nbyte) throws UnixException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return write0(fildes, buf, nbyte);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native int write0(int fildes, long buf, int nbyte) throws UnixException;
|
||||
|
||||
/**
|
||||
* access(const char* path, int amode);
|
||||
*/
|
||||
static void access(UnixPath path, int amode) throws UnixException {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
access0(buffer.address(), amode);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
access0(buffer.address(), amode);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void access0(long pathAddress, int amode) throws UnixException;
|
||||
|
@ -508,16 +620,17 @@ class UnixNativeDispatcher {
|
|||
* @return true if the file exists, false otherwise
|
||||
*/
|
||||
static boolean exists(UnixPath path) {
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
return exists0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return exists0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native boolean exists0(long pathAddress);
|
||||
|
||||
|
||||
/**
|
||||
* struct passwd *getpwuid(uid_t uid);
|
||||
*
|
||||
|
@ -538,11 +651,13 @@ class UnixNativeDispatcher {
|
|||
* @return passwd->pw_uid
|
||||
*/
|
||||
static int getpwnam(String name) throws UnixException {
|
||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name));
|
||||
try {
|
||||
return getpwnam0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name))) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return getpwnam0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native int getpwnam0(long nameAddress) throws UnixException;
|
||||
|
@ -553,11 +668,13 @@ class UnixNativeDispatcher {
|
|||
* @return group->gr_name
|
||||
*/
|
||||
static int getgrnam(String name) throws UnixException {
|
||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name));
|
||||
try {
|
||||
return getgrnam0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name))) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return getgrnam0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native int getgrnam0(long nameAddress) throws UnixException;
|
||||
|
@ -568,11 +685,13 @@ class UnixNativeDispatcher {
|
|||
static void statvfs(UnixPath path, UnixFileStoreAttributes attrs)
|
||||
throws UnixException
|
||||
{
|
||||
NativeBuffer buffer = copyToNativeBuffer(path);
|
||||
try {
|
||||
statvfs0(buffer.address(), attrs);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = copyToNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
statvfs0(buffer.address(), attrs);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void statvfs0(long pathAddress, UnixFileStoreAttributes attrs)
|
||||
|
@ -586,11 +705,16 @@ class UnixNativeDispatcher {
|
|||
/**
|
||||
* ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size);
|
||||
*/
|
||||
static int fgetxattr(int filedes, byte[] name, long valueAddress,
|
||||
int valueLen) throws UnixException
|
||||
static int fgetxattr(int filedes, byte[] name, long valueAddress, int valueLen)
|
||||
throws UnixException
|
||||
{
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
|
||||
return fgetxattr0(filedes, buffer.address(), valueAddress, valueLen);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return fgetxattr0(filedes, buffer.address(), valueAddress, valueLen);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -600,11 +724,16 @@ class UnixNativeDispatcher {
|
|||
/**
|
||||
* fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags);
|
||||
*/
|
||||
static void fsetxattr(int filedes, byte[] name, long valueAddress,
|
||||
int valueLen) throws UnixException
|
||||
static void fsetxattr(int filedes, byte[] name, long valueAddress, int valueLen)
|
||||
throws UnixException
|
||||
{
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
|
||||
fsetxattr0(filedes, buffer.address(), valueAddress, valueLen);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
fsetxattr0(filedes, buffer.address(), valueAddress, valueLen);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -616,7 +745,12 @@ class UnixNativeDispatcher {
|
|||
*/
|
||||
static void fremovexattr(int filedes, byte[] name) throws UnixException {
|
||||
try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
|
||||
fremovexattr0(filedes, buffer.address());
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
fremovexattr0(filedes, buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -145,8 +145,8 @@ Java_java_io_UnixFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this,
|
|||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this,
|
||||
jobject file, jint a)
|
||||
Java_java_io_UnixFileSystem_checkAccess0(JNIEnv *env, jobject this,
|
||||
jobject file, jint a)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
int mode = 0;
|
||||
|
@ -174,11 +174,11 @@ Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
|
||||
jobject file,
|
||||
jint access,
|
||||
jboolean enable,
|
||||
jboolean owneronly)
|
||||
Java_java_io_UnixFileSystem_setPermission0(JNIEnv *env, jobject this,
|
||||
jobject file,
|
||||
jint access,
|
||||
jboolean enable,
|
||||
jboolean owneronly)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
|
||||
|
@ -223,8 +223,8 @@ Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
|
|||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_UnixFileSystem_getLastModifiedTime0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
jlong rv = 0;
|
||||
|
||||
|
@ -248,8 +248,8 @@ Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_UnixFileSystem_getLength0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
jlong rv = 0;
|
||||
|
||||
|
@ -267,8 +267,8 @@ Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
|
||||
jstring pathname)
|
||||
Java_java_io_UnixFileSystem_createFileExclusively0(JNIEnv *env, jclass cls,
|
||||
jstring pathname)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
|
||||
|
@ -307,8 +307,7 @@ Java_java_io_UnixFileSystem_delete0(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_UnixFileSystem_list0(JNIEnv *env, jobject this, jobject file)
|
||||
{
|
||||
DIR *dir = NULL;
|
||||
struct dirent *ptr;
|
||||
|
@ -373,8 +372,8 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_UnixFileSystem_createDirectory(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_UnixFileSystem_createDirectory0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
|
||||
|
@ -404,8 +403,8 @@ Java_java_io_UnixFileSystem_rename0(JNIEnv *env, jobject this,
|
|||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
|
||||
jobject file, jlong time)
|
||||
Java_java_io_UnixFileSystem_setLastModifiedTime0(JNIEnv *env, jobject this,
|
||||
jobject file, jlong time)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
|
||||
|
@ -440,8 +439,8 @@ Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_UnixFileSystem_setReadOnly0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
|
||||
|
@ -459,8 +458,8 @@ Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this,
|
|||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
|
||||
jobject file, jint t)
|
||||
Java_java_io_UnixFileSystem_getSpace0(JNIEnv *env, jobject this,
|
||||
jobject file, jint t)
|
||||
{
|
||||
jlong rv = 0L;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -72,13 +72,13 @@ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
|
|||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
|
||||
Java_sun_nio_ch_NativeThread_current0(JNIEnv *env, jclass cl)
|
||||
{
|
||||
return (jlong)pthread_self();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
|
||||
Java_sun_nio_ch_NativeThread_signal0(JNIEnv *env, jclass cl, jlong thread)
|
||||
{
|
||||
int ret;
|
||||
ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);
|
||||
|
|
|
@ -465,7 +465,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_close0(JNIEnv* env, jclass this, jint fd) {
|
|||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd,
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_read0(JNIEnv* env, jclass this, jint fd,
|
||||
jlong address, jint nbytes)
|
||||
{
|
||||
ssize_t n;
|
||||
|
@ -478,7 +478,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd,
|
|||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_write(JNIEnv* env, jclass this, jint fd,
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_write0(JNIEnv* env, jclass this, jint fd,
|
||||
jlong address, jint nbytes)
|
||||
{
|
||||
ssize_t n;
|
||||
|
@ -568,7 +568,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this,
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_fstat(JNIEnv* env, jclass this, jint fd,
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_fstat0(JNIEnv* env, jclass this, jint fd,
|
||||
jobject attrs)
|
||||
{
|
||||
int err;
|
||||
|
@ -616,7 +616,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_chmod0(JNIEnv* env, jclass this,
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_fchmod(JNIEnv* env, jclass this, jint filedes,
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_fchmod0(JNIEnv* env, jclass this, jint filedes,
|
||||
jint mode)
|
||||
{
|
||||
int err;
|
||||
|
@ -627,7 +627,6 @@ Java_sun_nio_fs_UnixNativeDispatcher_fchmod(JNIEnv* env, jclass this, jint filed
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_chown0(JNIEnv* env, jclass this,
|
||||
jlong pathAddress, jint uid, jint gid)
|
||||
|
@ -654,7 +653,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_lchown0(JNIEnv* env, jclass this, jlong pat
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_fchown(JNIEnv* env, jclass this, jint filedes, jint uid, jint gid)
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_fchown0(JNIEnv* env, jclass this, jint filedes, jint uid, jint gid)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -685,7 +684,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_utimes0(JNIEnv* env, jclass this,
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_futimes(JNIEnv* env, jclass this, jint filedes,
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_futimes0(JNIEnv* env, jclass this, jint filedes,
|
||||
jlong accessTime, jlong modificationTime)
|
||||
{
|
||||
struct timeval times[2];
|
||||
|
@ -712,7 +711,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_futimes(JNIEnv* env, jclass this, jint file
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_futimens(JNIEnv* env, jclass this, jint filedes,
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_futimens0(JNIEnv* env, jclass this, jint filedes,
|
||||
jlong accessTime, jlong modificationTime)
|
||||
{
|
||||
struct timespec times[2];
|
||||
|
@ -804,7 +803,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong di
|
|||
}
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) {
|
||||
Java_sun_nio_fs_UnixNativeDispatcher_readdir0(JNIEnv* env, jclass this, jlong value) {
|
||||
DIR* dirp = jlong_to_ptr(value);
|
||||
struct dirent* ptr;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue