8344184: Remove sun.net.ResourceManager after JEP 486 integration
Reviewed-by: alanb
This commit is contained in:
parent
1d5587b887
commit
7ae6069ee8
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011, 2021, 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.net;
|
|
||||||
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import sun.security.action.GetPropertyAction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages count of total number of UDP sockets and ensures
|
|
||||||
* that exception is thrown if we try to create more than the
|
|
||||||
* configured limit.
|
|
||||||
*
|
|
||||||
* This functionality could be put in NetHooks some time in future.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ResourceManager {
|
|
||||||
|
|
||||||
/* default maximum number of udp sockets per VM
|
|
||||||
* when a security manager is enabled.
|
|
||||||
* The default is 25 which is high enough to be useful
|
|
||||||
* but low enough to be well below the maximum number
|
|
||||||
* of port numbers actually available on all OSes
|
|
||||||
* when multiplied by the maximum feasible number of VM processes
|
|
||||||
* that could practically be spawned.
|
|
||||||
*/
|
|
||||||
|
|
||||||
private static final int DEFAULT_MAX_SOCKETS = 25;
|
|
||||||
private static final int maxSockets;
|
|
||||||
private static final AtomicInteger numSockets;
|
|
||||||
|
|
||||||
static {
|
|
||||||
String prop = GetPropertyAction
|
|
||||||
.privilegedGetProperty("sun.net.maxDatagramSockets");
|
|
||||||
int defmax = DEFAULT_MAX_SOCKETS;
|
|
||||||
try {
|
|
||||||
if (prop != null) {
|
|
||||||
defmax = Integer.parseInt(prop);
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {}
|
|
||||||
maxSockets = defmax;
|
|
||||||
numSockets = new AtomicInteger();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static void beforeUdpCreate() throws SocketException {
|
|
||||||
if (System.getSecurityManager() != null) {
|
|
||||||
if (numSockets.incrementAndGet() > maxSockets) {
|
|
||||||
numSockets.decrementAndGet();
|
|
||||||
throw new SocketException("maximum number of DatagramSockets reached");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static void afterUdpClose() {
|
|
||||||
if (System.getSecurityManager() != null) {
|
|
||||||
numSockets.decrementAndGet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -73,7 +73,6 @@ import jdk.internal.access.JavaNioAccess;
|
|||||||
import jdk.internal.access.SharedSecrets;
|
import jdk.internal.access.SharedSecrets;
|
||||||
import jdk.internal.ref.CleanerFactory;
|
import jdk.internal.ref.CleanerFactory;
|
||||||
import jdk.internal.invoke.MhUtil;
|
import jdk.internal.invoke.MhUtil;
|
||||||
import sun.net.ResourceManager;
|
|
||||||
import sun.net.ext.ExtendedSocketOptions;
|
import sun.net.ext.ExtendedSocketOptions;
|
||||||
import sun.net.util.IPAddressUtil;
|
import sun.net.util.IPAddressUtil;
|
||||||
|
|
||||||
@ -194,7 +193,6 @@ class DatagramChannelImpl
|
|||||||
FileDescriptor fd = null;
|
FileDescriptor fd = null;
|
||||||
NativeSocketAddress[] sockAddrs = null;
|
NativeSocketAddress[] sockAddrs = null;
|
||||||
|
|
||||||
ResourceManager.beforeUdpCreate();
|
|
||||||
boolean initialized = false;
|
boolean initialized = false;
|
||||||
try {
|
try {
|
||||||
this.interruptible = interruptible;
|
this.interruptible = interruptible;
|
||||||
@ -217,7 +215,6 @@ class DatagramChannelImpl
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
if (sockAddrs != null) NativeSocketAddress.freeAll(sockAddrs);
|
if (sockAddrs != null) NativeSocketAddress.freeAll(sockAddrs);
|
||||||
if (fd != null) nd.close(fd);
|
if (fd != null) nd.close(fd);
|
||||||
ResourceManager.afterUdpClose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +229,6 @@ class DatagramChannelImpl
|
|||||||
|
|
||||||
NativeSocketAddress[] sockAddrs = null;
|
NativeSocketAddress[] sockAddrs = null;
|
||||||
|
|
||||||
ResourceManager.beforeUdpCreate();
|
|
||||||
boolean initialized = false;
|
boolean initialized = false;
|
||||||
try {
|
try {
|
||||||
this.interruptible = true;
|
this.interruptible = true;
|
||||||
@ -257,7 +253,6 @@ class DatagramChannelImpl
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
if (sockAddrs != null) NativeSocketAddress.freeAll(sockAddrs);
|
if (sockAddrs != null) NativeSocketAddress.freeAll(sockAddrs);
|
||||||
nd.close(fd);
|
nd.close(fd);
|
||||||
ResourceManager.afterUdpClose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1909,8 +1904,7 @@ class DatagramChannelImpl
|
|||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new UncheckedIOException(ioe);
|
throw new UncheckedIOException(ioe);
|
||||||
} finally {
|
} finally {
|
||||||
// decrement socket count and release memory
|
// release memory
|
||||||
ResourceManager.afterUdpClose();
|
|
||||||
NativeSocketAddress.freeAll(sockAddrs);
|
NativeSocketAddress.freeAll(sockAddrs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -57,7 +57,6 @@ import jdk.internal.ref.CleanerFactory;
|
|||||||
import sun.net.ConnectionResetException;
|
import sun.net.ConnectionResetException;
|
||||||
import sun.net.NetHooks;
|
import sun.net.NetHooks;
|
||||||
import sun.net.PlatformSocketImpl;
|
import sun.net.PlatformSocketImpl;
|
||||||
import sun.net.ResourceManager;
|
|
||||||
import sun.net.ext.ExtendedSocketOptions;
|
import sun.net.ext.ExtendedSocketOptions;
|
||||||
import sun.net.util.SocketExceptions;
|
import sun.net.util.SocketExceptions;
|
||||||
|
|
||||||
@ -455,20 +454,12 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
|||||||
synchronized (stateLock) {
|
synchronized (stateLock) {
|
||||||
if (state != ST_NEW)
|
if (state != ST_NEW)
|
||||||
throw new IOException("Already created");
|
throw new IOException("Already created");
|
||||||
if (!stream)
|
|
||||||
ResourceManager.beforeUdpCreate();
|
|
||||||
FileDescriptor fd;
|
FileDescriptor fd;
|
||||||
try {
|
if (server) {
|
||||||
if (server) {
|
assert stream;
|
||||||
assert stream;
|
fd = Net.serverSocket(true);
|
||||||
fd = Net.serverSocket(true);
|
} else {
|
||||||
} else {
|
fd = Net.socket(stream);
|
||||||
fd = Net.socket(stream);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
if (!stream)
|
|
||||||
ResourceManager.afterUdpClose();
|
|
||||||
throw ioe;
|
|
||||||
}
|
}
|
||||||
Runnable closer = closerFor(fd, stream);
|
Runnable closer = closerFor(fd, stream);
|
||||||
this.fd = fd;
|
this.fd = fd;
|
||||||
@ -1221,9 +1212,6 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
|||||||
nd.close(fd);
|
nd.close(fd);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new UncheckedIOException(ioe);
|
throw new UncheckedIOException(ioe);
|
||||||
} finally {
|
|
||||||
// decrement
|
|
||||||
ResourceManager.afterUdpClose();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user