Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8253119: Remove the legacy PlainSocketImpl and PlainDatagramSocketImp…
…l implementation

Reviewed-by: alanb, dfuchs, chegar
  • Loading branch information
pconcannon committed Jul 6, 2021
1 parent f485171 commit 326b2e1
Show file tree
Hide file tree
Showing 78 changed files with 206 additions and 10,923 deletions.

This file was deleted.

875 changes: 0 additions & 875 deletions src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java

This file was deleted.

15 changes: 1 addition & 14 deletions src/java.base/share/classes/java/net/DatagramPacket.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 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
Expand Down Expand Up @@ -52,14 +52,6 @@
public final
class DatagramPacket {

/**
* Perform class initialization
*/
static {
jdk.internal.loader.BootLoader.loadLibrary("net");
init();
}

/*
* The fields of this class are package-private since DatagramSocketImpl
* classes needs to access them.
Expand Down Expand Up @@ -424,9 +416,4 @@ public synchronized void setLength(int length) {
this.length = length;
this.bufLength = this.length;
}

/**
* Perform class load-time initializations.
*/
private static native void init();
}
20 changes: 5 additions & 15 deletions src/java.base/share/classes/java/net/DatagramSocket.java
Expand Up @@ -31,6 +31,7 @@
import java.nio.channels.MulticastChannel;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import java.util.Set;
import sun.net.NetProperties;
import sun.nio.ch.DefaultSelectorProvider;
Expand Down Expand Up @@ -1338,14 +1339,6 @@ public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)

// Temporary solution until JDK-8237352 is addressed
private static final SocketAddress NO_DELEGATE = new SocketAddress() {};
private static final boolean USE_PLAINDATAGRAMSOCKET = usePlainDatagramSocketImpl();

private static boolean usePlainDatagramSocketImpl() {
PrivilegedAction<String> pa = () -> NetProperties.get("jdk.net.usePlainDatagramSocketImpl");
@SuppressWarnings("removal")
String s = AccessController.doPrivileged(pa);
return (s != null) && (s.isEmpty() || s.equalsIgnoreCase("true"));
}

/**
* Best effort to convert an {@link IOException}
Expand Down Expand Up @@ -1398,14 +1391,11 @@ static <T extends DatagramSocket> T createDelegate(SocketAddress bindaddr, Class
boolean initialized = false;
try {
DatagramSocketImplFactory factory = DatagramSocket.factory;
if (USE_PLAINDATAGRAMSOCKET || factory != null) {
if (factory != null) {
// create legacy DatagramSocket delegate
DatagramSocketImpl impl;
if (factory != null) {
impl = factory.createDatagramSocketImpl();
} else {
impl = DefaultDatagramSocketImplFactory.createDatagramSocketImpl(multicast);
}
DatagramSocketImpl impl = factory.createDatagramSocketImpl();
Objects.requireNonNull(impl,
"Implementation returned by installed DatagramSocketImplFactory is null");
delegate = new NetMulticastSocket(impl);
((NetMulticastSocket) delegate).getImpl(); // ensure impl.create() is called.
} else {
Expand Down
20 changes: 1 addition & 19 deletions src/java.base/share/classes/java/net/DatagramSocketImpl.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
Expand Down Expand Up @@ -33,24 +33,6 @@
/**
* Abstract datagram and multicast socket implementation base class.
*
* @implNote Sockets created with the {@code DatagramSocket} and {@code
* MulticastSocket} public constructors historically delegated all socket
* operations to a {@code DatagramSocketImpl} implementation named
* "PlainDatagramSocketImpl". {@code DatagramSocket} and {@code MulticastSocket}
* have since been changed to a new implementation based on {@code DatagramChannel}.
* The JDK continues to ship with the older implementation to allow code to run
* that depends on unspecified behavior that differs between the old and new
* implementations. The old implementation will be used if the Java virtual
* machine is started with the system property {@systemProperty
* jdk.net.usePlainDatagramSocketImpl} set to use the old implementation. It may
* also be set in the JDK's network configuration file, located in {@code
* ${java.home}/conf/net.properties}. The value of the property is the string
* representation of a boolean. If set without a value then it defaults to {@code
* true}, hence running with {@code -Djdk.net.usePlainDatagramSocketImpl} or
* {@code -Djdk.net.usePlainDatagramSocketImpl=true} will configure the Java
* virtual machine to use the old implementation. The property and old
* implementation will be removed in a future version.
*
* @author Pavani Diwanji
* @since 1.1
*/
Expand Down
3 changes: 1 addition & 2 deletions src/java.base/share/classes/java/net/NetMulticastSocket.java
Expand Up @@ -136,8 +136,7 @@ private synchronized void connectInternal(InetAddress address, int port) throws
bind(new InetSocketAddress(0));

// old impls do not support connect/disconnect
if (oldImpl || (impl instanceof AbstractPlainDatagramSocketImpl &&
((AbstractPlainDatagramSocketImpl) impl).nativeConnectDisabled())) {
if (oldImpl) {
connectState = ST_CONNECTED_NO_IMPL;
} else {
try {
Expand Down
119 changes: 0 additions & 119 deletions src/java.base/share/classes/java/net/SocketCleanable.java

This file was deleted.

34 changes: 1 addition & 33 deletions src/java.base/share/classes/java/net/SocketImpl.java
Expand Up @@ -29,12 +29,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import java.util.Set;

import sun.net.NetProperties;
import sun.net.PlatformSocketImpl;
import sun.nio.ch.NioSocketImpl;

Expand All @@ -43,45 +40,16 @@
* of all classes that actually implement sockets. It is used to
* create both client and server sockets.
*
* @implNote Client and server sockets created with the {@code Socket} and
* {@code SocketServer} public constructors create a system-default
* {@code SocketImpl}. The JDK historically used a {@code SocketImpl}
* implementation type named "PlainSocketImpl" that has since been replaced by a
* newer implementation. The JDK continues to ship with the older implementation
* to allow code to run that depends on unspecified behavior that differs between
* the old and new implementations. The old implementation will be used if the
* Java virtual machine is started with the system property {@systemProperty
* jdk.net.usePlainSocketImpl} set to use the old implementation. It may also be
* set in the JDK's network configuration file, located in {@code
* ${java.home}/conf/net.properties}. The value of the property is the string
* representation of a boolean. If set without a value then it defaults to {@code
* true}, hence running with {@code -Djdk.net.usePlainSocketImpl} or {@code
* -Djdk.net.usePlainSocketImpl=true} will configure the Java virtual machine
* to use the old implementation. The property and old implementation will be
* removed in a future version.
*
* @since 1.0
*/
public abstract class SocketImpl implements SocketOptions {
private static final boolean USE_PLAINSOCKETIMPL = usePlainSocketImpl();

private static boolean usePlainSocketImpl() {
PrivilegedAction<String> pa = () -> NetProperties.get("jdk.net.usePlainSocketImpl");
@SuppressWarnings("removal")
String s = AccessController.doPrivileged(pa);
return (s != null) && !s.equalsIgnoreCase("false");
}

/**
* Creates an instance of platform's SocketImpl
*/
@SuppressWarnings("unchecked")
static <S extends SocketImpl & PlatformSocketImpl> S createPlatformSocketImpl(boolean server) {
if (USE_PLAINSOCKETIMPL) {
return (S) new PlainSocketImpl(server);
} else {
return (S) new NioSocketImpl(server);
}
return (S) new NioSocketImpl(server);
}

/**
Expand Down

1 comment on commit 326b2e1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.