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
|
@ -31,6 +31,7 @@ import java.nio.file.Path;
|
|||
import java.util.BitSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import jdk.internal.misc.Blocker;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
|
@ -459,7 +460,12 @@ class WinNTFileSystem extends FileSystem {
|
|||
return "" + ((char) (c-32)) + ':' + '\\';
|
||||
}
|
||||
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) {
|
||||
|
@ -576,38 +582,116 @@ class WinNTFileSystem extends FileSystem {
|
|||
/* -- Attribute accessors -- */
|
||||
|
||||
@Override
|
||||
public native int getBooleanAttributes(File f);
|
||||
public int getBooleanAttributes(File f) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return getBooleanAttributes0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private native int getBooleanAttributes0(File f);
|
||||
|
||||
@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 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 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);
|
||||
|
||||
@Override
|
||||
public boolean delete(File f) {
|
||||
|
@ -622,9 +706,13 @@ class WinNTFileSystem extends FileSystem {
|
|||
if (useCanonPrefixCache) {
|
||||
prefixCache.clear();
|
||||
}
|
||||
return delete0(f);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return delete0(f);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
|
||||
private native boolean delete0(File f);
|
||||
|
||||
@Override
|
||||
|
@ -640,9 +728,13 @@ class WinNTFileSystem extends FileSystem {
|
|||
if (useCanonPrefixCache) {
|
||||
prefixCache.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);
|
||||
|
||||
/* -- Filesystem interface -- */
|
||||
|
@ -656,7 +748,6 @@ class WinNTFileSystem extends FileSystem {
|
|||
.filter(f -> access(f.getPath()) && f.exists())
|
||||
.toArray(File[]::new);
|
||||
}
|
||||
|
||||
private static native int listRoots0();
|
||||
|
||||
private boolean access(String path) {
|
||||
|
@ -679,7 +770,6 @@ class WinNTFileSystem extends FileSystem {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private native long getSpace0(File f, int t);
|
||||
|
||||
/* -- Basic infrastructure -- */
|
||||
|
|
|
@ -47,6 +47,7 @@ import java.util.regex.Pattern;
|
|||
import jdk.internal.access.JavaIOFileDescriptorAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.ref.CleanerFactory;
|
||||
import jdk.internal.misc.Blocker;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/* This class is for the exclusive use of ProcessBuilder.start() to
|
||||
|
@ -563,7 +564,12 @@ final class ProcessImpl extends Process {
|
|||
private static native int getExitCodeProcess(long handle);
|
||||
|
||||
public int waitFor() throws InterruptedException {
|
||||
waitForInterruptibly(handle);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
waitForInterruptibly(handle);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
if (Thread.interrupted())
|
||||
throw new InterruptedException();
|
||||
return exitValue();
|
||||
|
@ -587,7 +593,12 @@ final class ProcessImpl extends Process {
|
|||
// if wraps around then wait a long while
|
||||
msTimeout = Integer.MAX_VALUE;
|
||||
}
|
||||
waitForTimeoutInterruptibly(handle, msTimeout);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
waitForTimeoutInterruptibly(handle, msTimeout);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
if (Thread.interrupted())
|
||||
throw new InterruptedException();
|
||||
if (getExitCodeProcess(handle) != STILL_ACTIVE) {
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Default PollerProvider for Windows based on wepoll.
|
||||
*/
|
||||
class DefaultPollerProvider extends PollerProvider {
|
||||
DefaultPollerProvider() { }
|
||||
|
||||
@Override
|
||||
Poller readPoller() throws IOException {
|
||||
return new WEPollPoller(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
Poller writePoller() throws IOException {
|
||||
return new WEPollPoller(false);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2012, 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
|
||||
|
@ -28,15 +28,52 @@ package sun.nio.ch;
|
|||
|
||||
// Signalling operations on native threads
|
||||
|
||||
public class NativeThread {
|
||||
private static final long VIRTUAL_THREAD_ID = -1L;
|
||||
|
||||
class NativeThread {
|
||||
/**
|
||||
* 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 {
|
||||
// no support for signalling threads on Windows
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static long current() {
|
||||
// return 0 to ensure that async close of blocking sockets will close
|
||||
// the underlying socket.
|
||||
/**
|
||||
* 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 0;
|
||||
}
|
||||
|
||||
static void signal(long nt) { }
|
||||
/**
|
||||
* Signals the given native thread.
|
||||
*
|
||||
* @throws IllegalArgumentException if tid is not a token to a native thread
|
||||
*/
|
||||
static void signal(long tid) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true the tid is the id of a native thread.
|
||||
*/
|
||||
static boolean isNativeThread(long tid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if tid is -1L.
|
||||
* @see #current()
|
||||
*/
|
||||
static boolean isVirtualThread(long tid) {
|
||||
return (tid == VIRTUAL_THREAD_ID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,9 +128,15 @@ class PipeImpl
|
|||
sa = ssc.getLocalAddress();
|
||||
}
|
||||
|
||||
// Establish connection (assume connections are eagerly
|
||||
// accepted)
|
||||
sc1 = SocketChannel.open(sa);
|
||||
// Establish connection (assume connection is eagerly accepted)
|
||||
if (sa instanceof InetSocketAddress
|
||||
&& Thread.currentThread().isVirtual()) {
|
||||
// workaround "lost event" issue on older releases of Windows
|
||||
sc1 = SocketChannel.open();
|
||||
sc1.socket().connect(sa, 10_000);
|
||||
} else {
|
||||
sc1 = SocketChannel.open(sa);
|
||||
}
|
||||
RANDOM_NUMBER_GENERATOR.nextBytes(secret.array());
|
||||
do {
|
||||
sc1.write(secret);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 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
|
||||
|
@ -52,6 +52,9 @@ class WEPoll {
|
|||
* epoll_data_t data;
|
||||
* }
|
||||
*/
|
||||
static {
|
||||
IOUtil.load();
|
||||
}
|
||||
private static final int SIZEOF_EPOLLEVENT = eventSize();
|
||||
private static final int OFFSETOF_EVENTS = eventsOffset();
|
||||
private static final int OFFSETOF_SOCK = dataOffset();
|
||||
|
@ -139,8 +142,4 @@ class WEPoll {
|
|||
throws IOException;
|
||||
|
||||
static native void close(long h);
|
||||
|
||||
static {
|
||||
IOUtil.load();
|
||||
}
|
||||
}
|
||||
|
|
76
src/java.base/windows/classes/sun/nio/ch/WEPollPoller.java
Normal file
76
src/java.base/windows/classes/sun/nio/ch/WEPollPoller.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.io.IOException;
|
||||
import static sun.nio.ch.WEPoll.*;
|
||||
|
||||
/**
|
||||
* Poller implementation based on wepoll.
|
||||
*/
|
||||
class WEPollPoller extends Poller {
|
||||
private static final int MAX_EVENTS_TO_POLL = 256;
|
||||
private static final int ENOENT = 2;
|
||||
|
||||
private final long handle;
|
||||
private final int event;
|
||||
private final long address;
|
||||
|
||||
WEPollPoller(boolean read) throws IOException {
|
||||
super(read);
|
||||
this.handle = WEPoll.create();
|
||||
this.event = (read) ? EPOLLIN : EPOLLOUT;
|
||||
this.address = WEPoll.allocatePollArray(MAX_EVENTS_TO_POLL);
|
||||
}
|
||||
|
||||
@Override
|
||||
void implRegister(int fdVal) throws IOException {
|
||||
// re-arm
|
||||
int err = WEPoll.ctl(handle, EPOLL_CTL_MOD, fdVal, (event | EPOLLONESHOT));
|
||||
if (err == ENOENT)
|
||||
err = WEPoll.ctl(handle, EPOLL_CTL_ADD, fdVal, (event | EPOLLONESHOT));
|
||||
if (err != 0)
|
||||
throw new IOException("epoll_ctl failed: " + err);
|
||||
}
|
||||
|
||||
@Override
|
||||
void implDeregister(int fdVal) {
|
||||
WEPoll.ctl(handle, EPOLL_CTL_DEL, fdVal, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
int poll(int timeout) throws IOException {
|
||||
int n = WEPoll.wait(handle, address, MAX_EVENTS_TO_POLL, timeout);
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
long event = WEPoll.getEvent(address, i);
|
||||
int fdVal = WEPoll.getDescriptor(event);
|
||||
polled(fdVal);
|
||||
i++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 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
|
||||
|
@ -38,6 +38,7 @@ import java.util.Deque;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import jdk.internal.misc.Blocker;
|
||||
|
||||
import static sun.nio.ch.WEPoll.*;
|
||||
|
||||
|
@ -108,7 +109,12 @@ class WEPollSelectorImpl extends SelectorImpl {
|
|||
processDeregisterQueue();
|
||||
try {
|
||||
begin(blocking);
|
||||
numEntries = WEPoll.wait(eph, pollArrayAddress, NUM_EPOLLEVENTS, to);
|
||||
long comp = Blocker.begin(blocking);
|
||||
try {
|
||||
numEntries = WEPoll.wait(eph, pollArrayAddress, NUM_EPOLLEVENTS, to);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
} finally {
|
||||
end(blocking);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 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
|
||||
|
@ -25,6 +25,7 @@
|
|||
|
||||
package sun.nio.fs;
|
||||
|
||||
import jdk.internal.misc.Blocker;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
|
||||
import static sun.nio.fs.WindowsConstants.*;
|
||||
|
@ -66,16 +67,18 @@ class WindowsNativeDispatcher {
|
|||
int dwFlagsAndAttributes)
|
||||
throws WindowsException
|
||||
{
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
return CreateFile0(buffer.address(),
|
||||
dwDesiredAccess,
|
||||
dwShareMode,
|
||||
lpSecurityAttributes,
|
||||
dwCreationDisposition,
|
||||
dwFlagsAndAttributes);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return CreateFile0(buffer.address(),
|
||||
dwDesiredAccess,
|
||||
dwShareMode,
|
||||
lpSecurityAttributes,
|
||||
dwCreationDisposition,
|
||||
dwFlagsAndAttributes);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
static long CreateFile(String path,
|
||||
|
@ -109,11 +112,13 @@ class WindowsNativeDispatcher {
|
|||
* )
|
||||
*/
|
||||
static void DeleteFile(String path) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
DeleteFile0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
DeleteFile0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void DeleteFile0(long lpFileName)
|
||||
|
@ -126,11 +131,13 @@ class WindowsNativeDispatcher {
|
|||
* )
|
||||
*/
|
||||
static void CreateDirectory(String path, long lpSecurityAttributes) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
CreateDirectory0(buffer.address(), lpSecurityAttributes);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
CreateDirectory0(buffer.address(), lpSecurityAttributes);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void CreateDirectory0(long lpFileName, long lpSecurityAttributes)
|
||||
|
@ -142,11 +149,13 @@ class WindowsNativeDispatcher {
|
|||
* )
|
||||
*/
|
||||
static void RemoveDirectory(String path) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
RemoveDirectory0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
RemoveDirectory0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void RemoveDirectory0(long lpFileName)
|
||||
|
@ -189,13 +198,15 @@ class WindowsNativeDispatcher {
|
|||
* )
|
||||
*/
|
||||
static FirstFile FindFirstFile(String path) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
FirstFile data = new FirstFile();
|
||||
FindFirstFile0(buffer.address(), data);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
FindFirstFile0(buffer.address(), data);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
return data;
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
static class FirstFile {
|
||||
|
@ -218,11 +229,13 @@ class WindowsNativeDispatcher {
|
|||
* )
|
||||
*/
|
||||
static long FindFirstFile(String path, long address) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
return FindFirstFile1(buffer.address(), address);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return FindFirstFile1(buffer.address(), address);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native long FindFirstFile1(long lpFileName, long address)
|
||||
|
@ -236,7 +249,15 @@ class WindowsNativeDispatcher {
|
|||
*
|
||||
* @return lpFindFileData->cFileName or null
|
||||
*/
|
||||
static native String FindNextFile(long handle, long address)
|
||||
static String FindNextFile(long handle, long address) throws WindowsException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return FindNextFile0(handle, address);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native String FindNextFile0(long handle, long address)
|
||||
throws WindowsException;
|
||||
|
||||
/**
|
||||
|
@ -248,15 +269,17 @@ class WindowsNativeDispatcher {
|
|||
* )
|
||||
*/
|
||||
static FirstStream FindFirstStream(String path) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
FirstStream data = new FirstStream();
|
||||
FindFirstStream0(buffer.address(), data);
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
FindFirstStream0(buffer.address(), data);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
if (data.handle() == WindowsConstants.INVALID_HANDLE_VALUE)
|
||||
return null;
|
||||
return data;
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
static class FirstStream {
|
||||
|
@ -276,7 +299,15 @@ class WindowsNativeDispatcher {
|
|||
* LPVOID lpFindStreamData
|
||||
* )
|
||||
*/
|
||||
static native String FindNextStream(long handle) throws WindowsException;
|
||||
static String FindNextStream(long handle) throws WindowsException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return FindNextStream0(handle);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native String FindNextStream0(long handle) throws WindowsException;
|
||||
|
||||
/**
|
||||
* FindClose(
|
||||
|
@ -291,7 +322,17 @@ class WindowsNativeDispatcher {
|
|||
* LPBY_HANDLE_FILE_INFORMATION lpFileInformation
|
||||
* )
|
||||
*/
|
||||
static native void GetFileInformationByHandle(long handle, long address)
|
||||
static void GetFileInformationByHandle(long handle, long address)
|
||||
throws WindowsException
|
||||
{
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
GetFileInformationByHandle0(handle, address);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native void GetFileInformationByHandle0(long handle, long address)
|
||||
throws WindowsException;
|
||||
|
||||
/**
|
||||
|
@ -308,14 +349,15 @@ class WindowsNativeDispatcher {
|
|||
long addressToPollForCancel)
|
||||
throws WindowsException
|
||||
{
|
||||
NativeBuffer sourceBuffer = asNativeBuffer(source);
|
||||
NativeBuffer targetBuffer = asNativeBuffer(target);
|
||||
try {
|
||||
CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
|
||||
try (NativeBuffer sourceBuffer = asNativeBuffer(source);
|
||||
NativeBuffer targetBuffer = asNativeBuffer(target)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
|
||||
addressToPollForCancel);
|
||||
} finally {
|
||||
targetBuffer.release();
|
||||
sourceBuffer.release();
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void CopyFileEx0(long existingAddress, long newAddress,
|
||||
|
@ -331,13 +373,14 @@ class WindowsNativeDispatcher {
|
|||
static void MoveFileEx(String source, String target, int flags)
|
||||
throws WindowsException
|
||||
{
|
||||
NativeBuffer sourceBuffer = asNativeBuffer(source);
|
||||
NativeBuffer targetBuffer = asNativeBuffer(target);
|
||||
try {
|
||||
MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags);
|
||||
} finally {
|
||||
targetBuffer.release();
|
||||
sourceBuffer.release();
|
||||
try (NativeBuffer sourceBuffer = asNativeBuffer(source);
|
||||
NativeBuffer targetBuffer = asNativeBuffer(target)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void MoveFileEx0(long existingAddress, long newAddress,
|
||||
|
@ -349,11 +392,13 @@ class WindowsNativeDispatcher {
|
|||
* )
|
||||
*/
|
||||
static int GetFileAttributes(String path) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
return GetFileAttributes0(buffer.address());
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
return GetFileAttributes0(buffer.address());
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native int GetFileAttributes0(long lpFileName)
|
||||
|
@ -367,11 +412,13 @@ class WindowsNativeDispatcher {
|
|||
static void SetFileAttributes(String path, int dwFileAttributes)
|
||||
throws WindowsException
|
||||
{
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
SetFileAttributes0(buffer.address(), dwFileAttributes);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
SetFileAttributes0(buffer.address(), dwFileAttributes);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void SetFileAttributes0(long lpFileName,
|
||||
|
@ -385,15 +432,18 @@ class WindowsNativeDispatcher {
|
|||
* );
|
||||
*/
|
||||
static void GetFileAttributesEx(String path, long address) throws WindowsException {
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
GetFileAttributesEx0(buffer.address(), address);
|
||||
} finally {
|
||||
buffer.release();
|
||||
try (NativeBuffer buffer = asNativeBuffer(path)) {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
GetFileAttributesEx0(buffer.address(), address);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void GetFileAttributesEx0(long lpFileName, long address)
|
||||
throws WindowsException;
|
||||
|
||||
/**
|
||||
* SetFileTime(
|
||||
* HANDLE hFile,
|
||||
|
@ -402,10 +452,20 @@ class WindowsNativeDispatcher {
|
|||
* CONST FILETIME *lpLastWriteTime
|
||||
* )
|
||||
*/
|
||||
static native void SetFileTime(long handle,
|
||||
long createTime,
|
||||
long lastAccessTime,
|
||||
long lastWriteTime)
|
||||
static void SetFileTime(long handle, long createTime, long lastAccessTime, long lastWriteTime)
|
||||
throws WindowsException
|
||||
{
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
SetFileTime0(handle, createTime, lastAccessTime, lastWriteTime);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
}
|
||||
private static native void SetFileTime0(long handle,
|
||||
long createTime,
|
||||
long lastAccessTime,
|
||||
long lastWriteTime)
|
||||
throws WindowsException;
|
||||
|
||||
/**
|
||||
|
@ -620,8 +680,8 @@ class WindowsNativeDispatcher {
|
|||
{
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
SetFileSecurity0(buffer.address(), securityInformation,
|
||||
pSecurityDescriptor);
|
||||
// may be called with elevated privileges so always run on current thread
|
||||
SetFileSecurity0(buffer.address(), securityInformation, pSecurityDescriptor);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 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
|
||||
|
@ -25,6 +25,9 @@
|
|||
|
||||
package sun.nio.fs;
|
||||
|
||||
import jdk.internal.misc.PreviewFeatures;
|
||||
import jdk.internal.vm.Continuation;
|
||||
|
||||
import static sun.nio.fs.WindowsNativeDispatcher.*;
|
||||
import static sun.nio.fs.WindowsConstants.*;
|
||||
|
||||
|
@ -102,6 +105,10 @@ class WindowsSecurity {
|
|||
final boolean stopImpersontating = impersontating;
|
||||
final boolean needToRevert = elevated;
|
||||
|
||||
// prevent yielding with privileges
|
||||
if (PreviewFeatures.isEnabled())
|
||||
Continuation.pin();
|
||||
|
||||
return () -> {
|
||||
try {
|
||||
if (token != 0L) {
|
||||
|
@ -119,6 +126,8 @@ class WindowsSecurity {
|
|||
}
|
||||
} finally {
|
||||
LocalFree(pLuid);
|
||||
if (PreviewFeatures.isEnabled())
|
||||
Continuation.unpin();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 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
|
||||
|
@ -411,8 +411,8 @@ static BOOL isReservedDeviceNameW(WCHAR* path) {
|
|||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_java_io_WinNTFileSystem_getBooleanAttributes(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_WinNTFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
jint rv = 0;
|
||||
|
||||
|
@ -436,8 +436,8 @@ Java_java_io_WinNTFileSystem_getBooleanAttributes(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jboolean
|
||||
JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this,
|
||||
jobject file, jint access)
|
||||
JNICALL Java_java_io_WinNTFileSystem_checkAccess0(JNIEnv *env, jobject this,
|
||||
jobject file, jint access)
|
||||
{
|
||||
DWORD attr;
|
||||
WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
|
||||
|
@ -466,11 +466,11 @@ JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this,
|
|||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this,
|
||||
jobject file,
|
||||
jint access,
|
||||
jboolean enable,
|
||||
jboolean owneronly)
|
||||
Java_java_io_WinNTFileSystem_setPermission0(JNIEnv *env, jobject this,
|
||||
jobject file,
|
||||
jint access,
|
||||
jboolean enable,
|
||||
jboolean owneronly)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
WCHAR *pathbuf;
|
||||
|
@ -512,8 +512,8 @@ Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this,
|
|||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_io_WinNTFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_WinNTFileSystem_getLastModifiedTime0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
jlong rv = 0;
|
||||
ULARGE_INTEGER modTime;
|
||||
|
@ -549,7 +549,7 @@ Java_java_io_WinNTFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
|
|||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_io_WinNTFileSystem_getLength(JNIEnv *env, jobject this, jobject file)
|
||||
Java_java_io_WinNTFileSystem_getLength0(JNIEnv *env, jobject this, jobject file)
|
||||
{
|
||||
jlong rv = 0;
|
||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||
|
@ -615,8 +615,8 @@ Java_java_io_WinNTFileSystem_getLength(JNIEnv *env, jobject this, jobject file)
|
|||
/* -- File operations -- */
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_WinNTFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
|
||||
jstring path)
|
||||
Java_java_io_WinNTFileSystem_createFileExclusively0(JNIEnv *env, jclass cls,
|
||||
jstring path)
|
||||
{
|
||||
HANDLE h = NULL;
|
||||
WCHAR *pathbuf = pathToNTPath(env, path, JNI_FALSE);
|
||||
|
@ -688,7 +688,7 @@ Java_java_io_WinNTFileSystem_delete0(JNIEnv *env, jobject this, jobject file)
|
|||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
|
||||
Java_java_io_WinNTFileSystem_list0(JNIEnv *env, jobject this, jobject file)
|
||||
{
|
||||
WCHAR *search_path;
|
||||
HANDLE handle;
|
||||
|
@ -810,8 +810,8 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
|
|||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_WinNTFileSystem_createDirectory(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_WinNTFileSystem_createDirectory0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
BOOL h = FALSE;
|
||||
WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
|
||||
|
@ -848,8 +848,8 @@ Java_java_io_WinNTFileSystem_rename0(JNIEnv *env, jobject this, jobject from,
|
|||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_WinNTFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
|
||||
jobject file, jlong time)
|
||||
Java_java_io_WinNTFileSystem_setLastModifiedTime0(JNIEnv *env, jobject this,
|
||||
jobject file, jlong time)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
|
||||
|
@ -881,8 +881,8 @@ Java_java_io_WinNTFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
|
|||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
Java_java_io_WinNTFileSystem_setReadOnly0(JNIEnv *env, jobject this,
|
||||
jobject file)
|
||||
{
|
||||
jboolean rv = JNI_FALSE;
|
||||
DWORD a;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 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
|
||||
|
@ -231,7 +231,6 @@ Java_sun_nio_fs_WindowsNativeDispatcher_CreateFile0(JNIEnv* env, jclass this,
|
|||
return ptr_to_jlong(handle);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlSetSparse(JNIEnv* env, jclass this,
|
||||
jlong handle)
|
||||
|
@ -358,7 +357,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile1(JNIEnv* env, jclass this,
|
|||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_FindNextFile(JNIEnv* env, jclass this,
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_FindNextFile0(JNIEnv* env, jclass this,
|
||||
jlong handle, jlong dataAddress)
|
||||
{
|
||||
HANDLE h = (HANDLE)jlong_to_ptr(handle);
|
||||
|
@ -401,7 +400,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0(JNIEnv* env, jclass thi
|
|||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream(JNIEnv* env, jclass this,
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream0(JNIEnv* env, jclass this,
|
||||
jlong handle)
|
||||
{
|
||||
WIN32_FIND_STREAM_DATA data;
|
||||
|
@ -429,7 +428,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_FindClose(JNIEnv* env, jclass this,
|
|||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_GetFileInformationByHandle(JNIEnv* env, jclass this,
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_GetFileInformationByHandle0(JNIEnv* env, jclass this,
|
||||
jlong handle, jlong address)
|
||||
{
|
||||
HANDLE h = (HANDLE)jlong_to_ptr(handle);
|
||||
|
@ -513,7 +512,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_GetFileAttributesEx0(JNIEnv* env, jclass
|
|||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_SetFileTime(JNIEnv* env, jclass this,
|
||||
Java_sun_nio_fs_WindowsNativeDispatcher_SetFileTime0(JNIEnv* env, jclass this,
|
||||
jlong handle, jlong createTime, jlong lastAccessTime, jlong lastWriteTime)
|
||||
{
|
||||
HANDLE h = (HANDLE)jlong_to_ptr(handle);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue