Skip to content

Commit 0e6bf00

Browse files
author
Brent Christian
committed
Merge
Reviewed-by: jpai
2 parents e1926a6 + 121f5a7 commit 0e6bf00

File tree

21 files changed

+334
-83
lines changed

21 files changed

+334
-83
lines changed

src/hotspot/share/opto/phaseX.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ void PhaseCCP::push_more_uses(Unique_Node_List& worklist, Node* parent, const No
19541954
push_and(worklist, parent, use);
19551955
push_cast_ii(worklist, parent, use);
19561956
push_opaque_zero_trip_guard(worklist, use);
1957+
push_bool_with_cmpu_and_mask(worklist, use);
19571958
}
19581959

19591960

@@ -2000,6 +2001,57 @@ void PhaseCCP::push_cmpu(Unique_Node_List& worklist, const Node* use) const {
20002001
}
20012002
}
20022003

2004+
// Look for the following shape, which can be optimized by BoolNode::Value_cmpu_and_mask() (i.e. corresponds to case
2005+
// (1b): "(m & x) <u (m + 1))".
2006+
// If any of the inputs on the level (%%) change, we need to revisit Bool because we could have prematurely found that
2007+
// the Bool is constant (i.e. case (1b) can be applied) which could become invalid with new type information during CCP.
2008+
//
2009+
// m x m 1 (%%)
2010+
// \ / \ /
2011+
// AndI AddI
2012+
// \ /
2013+
// CmpU
2014+
// |
2015+
// Bool
2016+
//
2017+
void PhaseCCP::push_bool_with_cmpu_and_mask(Unique_Node_List& worklist, const Node* use) const {
2018+
uint use_op = use->Opcode();
2019+
if (use_op != Op_AndI && (use_op != Op_AddI || use->in(2)->find_int_con(0) != 1)) {
2020+
// Not "m & x" or "m + 1"
2021+
return;
2022+
}
2023+
for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
2024+
Node* cmpu = use->fast_out(i);
2025+
if (cmpu->Opcode() == Op_CmpU) {
2026+
push_bool_matching_case1b(worklist, cmpu);
2027+
}
2028+
}
2029+
}
2030+
2031+
// Push any Bool below 'cmpu' that matches case (1b) of BoolNode::Value_cmpu_and_mask().
2032+
void PhaseCCP::push_bool_matching_case1b(Unique_Node_List& worklist, const Node* cmpu) const {
2033+
assert(cmpu->Opcode() == Op_CmpU, "must be");
2034+
for (DUIterator_Fast imax, i = cmpu->fast_outs(imax); i < imax; i++) {
2035+
Node* bol = cmpu->fast_out(i);
2036+
if (!bol->is_Bool() || bol->as_Bool()->_test._test != BoolTest::lt) {
2037+
// Not a Bool with "<u"
2038+
continue;
2039+
}
2040+
Node* andI = cmpu->in(1);
2041+
Node* addI = cmpu->in(2);
2042+
if (andI->Opcode() != Op_AndI || addI->Opcode() != Op_AddI || addI->in(2)->find_int_con(0) != 1) {
2043+
// Not "m & x" and "m + 1"
2044+
continue;
2045+
}
2046+
2047+
Node* m = addI->in(1);
2048+
if (m == andI->in(1) || m == andI->in(2)) {
2049+
// Is "m" shared? Matched (1b) and thus we revisit Bool.
2050+
push_if_not_bottom_type(worklist, bol);
2051+
}
2052+
}
2053+
}
2054+
20032055
// If n is used in a counted loop exit condition, then the type of the counted loop's Phi depends on the type of 'n'.
20042056
// Seem PhiNode::Value().
20052057
void PhaseCCP::push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use) {

src/hotspot/share/opto/phaseX.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ class PhaseCCP : public PhaseIterGVN {
627627
void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
628628
void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
629629
void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const;
630+
void push_bool_with_cmpu_and_mask(Unique_Node_List& worklist, const Node* use) const;
631+
void push_bool_matching_case1b(Unique_Node_List& worklist, const Node* cmpu) const;
630632

631633
public:
632634
PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants

src/hotspot/share/opto/subnode.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ const Type* BoolNode::Value_cmpu_and_mask(PhaseValues* phase) const {
18851885
// (1b) "(x & m) <u m + 1" and "(m & x) <u m + 1", cmp2 = m + 1
18861886
Node* rhs_m = cmp2->in(1);
18871887
const TypeInt* rhs_m_type = phase->type(rhs_m)->isa_int();
1888-
if (rhs_m_type->_lo > -1 || rhs_m_type->_hi < -1) {
1888+
if (rhs_m_type != nullptr && (rhs_m_type->_lo > -1 || rhs_m_type->_hi < -1)) {
18891889
// Exclude any case where m == -1 is possible.
18901890
m = rhs_m;
18911891
}
@@ -1903,12 +1903,16 @@ const Type* BoolNode::Value_cmpu_and_mask(PhaseValues* phase) const {
19031903
// Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
19041904
// based on local information. If the input is constant, do it.
19051905
const Type* BoolNode::Value(PhaseGVN* phase) const {
1906+
const Type* input_type = phase->type(in(1));
1907+
if (input_type == Type::TOP) {
1908+
return Type::TOP;
1909+
}
19061910
const Type* t = Value_cmpu_and_mask(phase);
19071911
if (t != nullptr) {
19081912
return t;
19091913
}
19101914

1911-
return _test.cc2logical( phase->type( in(1) ) );
1915+
return _test.cc2logical(input_type);
19121916
}
19131917

19141918
#ifndef PRODUCT

src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,8 +24,6 @@
2424
*/
2525
package sun.net.ftp.impl;
2626

27-
28-
2927
import java.io.BufferedInputStream;
3028
import java.io.BufferedOutputStream;
3129
import java.io.BufferedReader;
@@ -61,13 +59,15 @@
6159
import java.util.regex.Pattern;
6260
import javax.net.ssl.SSLSocket;
6361
import javax.net.ssl.SSLSocketFactory;
62+
6463
import sun.net.ftp.FtpDirEntry;
6564
import sun.net.ftp.FtpDirParser;
6665
import sun.net.ftp.FtpProtocolException;
6766
import sun.net.ftp.FtpReplyCode;
6867
import sun.net.util.IPAddressUtil;
6968
import sun.util.logging.PlatformLogger;
7069

70+
import static sun.net.util.ProxyUtil.copyProxy;
7171

7272
public class FtpClient extends sun.net.ftp.FtpClient {
7373

@@ -954,7 +954,7 @@ public int getReadTimeout() {
954954
}
955955

956956
public sun.net.ftp.FtpClient setProxy(Proxy p) {
957-
proxy = p;
957+
proxy = copyProxy(p);
958958
return this;
959959
}
960960

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package sun.net.util;
27+
28+
import sun.net.ApplicationProxy;
29+
30+
import java.net.Proxy;
31+
32+
public final class ProxyUtil {
33+
34+
private ProxyUtil() {}
35+
36+
/**
37+
* Creates a new {@link Proxy} instance for the given proxy iff it is
38+
* neither null, {@link Proxy#NO_PROXY Proxy.NO_PROXY}, an
39+
* {@link ApplicationProxy} instance, nor already a {@code Proxy} instance.
40+
*/
41+
public static Proxy copyProxy(Proxy proxy) {
42+
return proxy == null
43+
|| proxy.getClass() == Proxy.class
44+
|| proxy instanceof ApplicationProxy
45+
? proxy
46+
: new Proxy(proxy.type(), proxy.address());
47+
}
48+
49+
}

src/java.base/share/classes/sun/net/www/http/HttpClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1994, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,8 @@
4141
import sun.net.www.protocol.http.AuthCacheImpl;
4242
import sun.net.www.protocol.http.HttpURLConnection;
4343
import sun.util.logging.PlatformLogger;
44+
45+
import static sun.net.util.ProxyUtil.copyProxy;
4446
import static sun.net.www.protocol.http.HttpURLConnection.TunnelState.*;
4547

4648
/**
@@ -261,7 +263,7 @@ public HttpClient(URL url, String proxyHost, int proxyPort)
261263
}
262264

263265
protected HttpClient(URL url, Proxy p, int to) throws IOException {
264-
proxy = (p == null) ? Proxy.NO_PROXY : p;
266+
proxy = p == null ? Proxy.NO_PROXY : copyProxy(p);
265267
this.host = url.getHost();
266268
this.url = url;
267269
port = url.getPort();
@@ -326,9 +328,7 @@ public static HttpClient New(URL url, boolean useCache)
326328
public static HttpClient New(URL url, Proxy p, int to, boolean useCache,
327329
HttpURLConnection httpuc) throws IOException
328330
{
329-
if (p == null) {
330-
p = Proxy.NO_PROXY;
331-
}
331+
p = p == null ? Proxy.NO_PROXY : copyProxy(p);
332332
HttpClient ret = null;
333333
/* see if one's already around */
334334
if (useCache) {

src/java.base/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.List;
4444
import java.util.StringTokenizer;
4545
import java.security.Permission;
46+
4647
import sun.net.NetworkClient;
4748
import sun.net.util.IPAddressUtil;
4849
import sun.net.www.MessageHeader;
@@ -53,6 +54,7 @@
5354
import sun.net.ftp.FtpProtocolException;
5455
import sun.net.www.ParseUtil;
5556

57+
import static sun.net.util.ProxyUtil.copyProxy;
5658

5759
/**
5860
* This class Opens an FTP input (or output) stream given a URL.
@@ -234,7 +236,7 @@ public synchronized void connect() throws IOException {
234236
throw new IOException("Failed to select a proxy", iae);
235237
}
236238
for (Proxy proxy : proxies) {
237-
p = proxy;
239+
p = copyProxy(proxy);
238240
if (p == null || p == Proxy.NO_PROXY ||
239241
p.type() == Proxy.Type.SOCKS) {
240242
break;

src/java.base/share/classes/sun/net/www/protocol/ftp/Handler.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1994, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,11 +33,9 @@
3333
import java.net.MalformedURLException;
3434
import java.net.URL;
3535
import java.net.Proxy;
36-
import java.util.Map;
37-
import java.util.HashMap;
3836
import java.util.Objects;
39-
import sun.net.ftp.FtpClient;
40-
import sun.net.www.protocol.http.HttpURLConnection;
37+
38+
import static sun.net.util.ProxyUtil.copyProxy;
4139

4240
/** open an ftp connection given a URL */
4341
public class Handler extends java.net.URLStreamHandler {
@@ -57,11 +55,11 @@ protected java.net.URLConnection openConnection(URL u)
5755
return openConnection(u, null);
5856
}
5957

60-
protected java.net.URLConnection openConnection(URL u, Proxy p)
58+
protected java.net.URLConnection openConnection(URL u, Proxy proxy)
6159
throws IOException {
62-
FtpURLConnection connection = null;
60+
FtpURLConnection connection;
6361
try {
64-
connection = new FtpURLConnection(u, p);
62+
connection = new FtpURLConnection(u, copyProxy(proxy));
6563
} catch (IllegalArgumentException e) {
6664
var mfue = new MalformedURLException(e.getMessage());
6765
mfue.initCause(e);

src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import java.util.Objects;
7878
import java.util.concurrent.locks.ReentrantLock;
7979

80+
import static sun.net.util.ProxyUtil.copyProxy;
8081
import static sun.net.www.protocol.http.AuthScheme.BASIC;
8182
import static sun.net.www.protocol.http.AuthScheme.DIGEST;
8283
import static sun.net.www.protocol.http.AuthScheme.NTLM;
@@ -854,7 +855,7 @@ protected HttpURLConnection(URL u, Proxy p, Handler handler)
854855
responses = new MessageHeader(maxHeaderSize);
855856
userHeaders = new MessageHeader();
856857
this.handler = handler;
857-
instProxy = p;
858+
instProxy = copyProxy(p);
858859
cookieHandler = CookieHandler.getDefault();
859860
cacheHandler = ResponseCache.getDefault();
860861
}
@@ -956,7 +957,7 @@ protected void plainConnect0() throws IOException {
956957
final Iterator<Proxy> it = proxies.iterator();
957958
Proxy p;
958959
while (it.hasNext()) {
959-
p = it.next();
960+
p = copyProxy(it.next());
960961
try {
961962
if (!failedOnce) {
962963
http = getNewHttpClient(url, p, connectTimeout);

src/java.base/share/classes/sun/security/ssl/CertificateMessage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,15 @@ public void consume(ConnectionContext context,
10971097

10981098
// clean up this consumer
10991099
hc.handshakeConsumers.remove(SSLHandshake.CERTIFICATE.id);
1100+
1101+
// Ensure that the Certificate message has not been sent w/o
1102+
// an EncryptedExtensions preceding
1103+
if (hc.handshakeConsumers.containsKey(
1104+
SSLHandshake.ENCRYPTED_EXTENSIONS.id)) {
1105+
throw hc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
1106+
"Unexpected Certificate handshake message");
1107+
}
1108+
11001109
T13CertificateMessage cm = new T13CertificateMessage(hc, message);
11011110
if (hc.sslConfig.isClientMode) {
11021111
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {

0 commit comments

Comments
 (0)