From 3ceb080aaeb0c1f3c4367ad7398ec4f666a3493c Mon Sep 17 00:00:00 2001 From: Alexey Bakhtin Date: Tue, 1 Jun 2021 13:00:44 +0000 Subject: [PATCH 1/7] 8241248: NullPointerException in sun.security.ssl.HKDF.extract(HKDF.java:93) Backport-of: 1603ca23422b03157afb2bd1050524465474b60e --- .../security/ssl/PreSharedKeyExtension.java | 6 ++-- .../security/ssl/SSLSessionContextImpl.java | 9 ++++++ .../classes/sun/security/ssl/ServerHello.java | 3 -- .../classes/sun/security/util/Cache.java | 29 +++++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java b/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java index 0e0df0527fe..2d134f303fe 100644 --- a/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java +++ b/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java @@ -372,9 +372,11 @@ final class PreSharedKeyExtension { SSLSessionImpl s = null; for (PskIdentity requestedId : pskSpec.identities) { - // If we are keeping state, see if the identity is in the cache + // If we are keeping state, see if the identity is in the + // cache. Note that for TLS 1.3, we would also clean + // up the cached session if it is not rejoinable. if (requestedId.identity.length == SessionId.MAX_LENGTH) { - s = sessionCache.get(requestedId.identity); + s = sessionCache.pull(requestedId.identity); } // See if the identity is a stateless ticket if (s == null && diff --git a/src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java b/src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java index 04dba15a711..16704dc632a 100644 --- a/src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java +++ b/src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java @@ -175,6 +175,15 @@ final class SSLSessionContextImpl implements SSLSessionContext { return (SSLSessionImpl)getSession(id); } + // package-private method, find and remove session from cache + // return found session + SSLSessionImpl pull(byte[] id) { + if (id != null) { + return sessionCache.pull(new SessionId(id)); + } + return null; + } + // package-private method, used ONLY by ClientHandshaker SSLSessionImpl get(String hostname, int port) { /* diff --git a/src/java.base/share/classes/sun/security/ssl/ServerHello.java b/src/java.base/share/classes/sun/security/ssl/ServerHello.java index 419a9582e85..5615d9efd77 100644 --- a/src/java.base/share/classes/sun/security/ssl/ServerHello.java +++ b/src/java.base/share/classes/sun/security/ssl/ServerHello.java @@ -560,9 +560,6 @@ final class ServerHello { setUpPskKD(shc, shc.resumingSession.consumePreSharedKey()); - - // The session can't be resumed again---remove it from cache - sessionCache.remove(shc.resumingSession.getSessionId()); } // update the responders diff --git a/src/java.base/share/classes/sun/security/util/Cache.java b/src/java.base/share/classes/sun/security/util/Cache.java index 5e1eef17ee4..547bcc197a6 100644 --- a/src/java.base/share/classes/sun/security/util/Cache.java +++ b/src/java.base/share/classes/sun/security/util/Cache.java @@ -100,6 +100,11 @@ public abstract class Cache { */ public abstract void remove(Object key); + /** + * Pull an entry from the cache. + */ + public abstract V pull(Object key); + /** * Set the maximum size. */ @@ -224,6 +229,10 @@ class NullCache extends Cache { // empty } + public V pull(Object key) { + return null; + } + public void setCapacity(int size) { // empty } @@ -402,6 +411,26 @@ class MemoryCache extends Cache { } } + public synchronized V pull(Object key) { + emptyQueue(); + CacheEntry entry = cacheMap.remove(key); + if (entry == null) { + return null; + } + + long time = (lifetime == 0) ? 0 : System.currentTimeMillis(); + if (entry.isValid(time)) { + V value = entry.getValue(); + entry.invalidate(); + return value; + } else { + if (DEBUG) { + System.out.println("Ignoring expired entry"); + } + return null; + } + } + public synchronized void setCapacity(int size) { expungeExpiredEntries(); if (size > 0 && cacheMap.size() > size) { From a680794c00bafb8510a2b9af7c4504ddb6fec704 Mon Sep 17 00:00:00 2001 From: Christoph Langer Date: Wed, 2 Jun 2021 16:55:07 +0000 Subject: [PATCH 2/7] 8261354: SIGSEGV at MethodIteratorHost Backport-of: 24623167ffbf8e192ef539fd0a969412719f850c --- .../share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp index 6193c2109c9..43b78788e35 100644 --- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp +++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp @@ -809,12 +809,11 @@ class MethodIteratorHost { bool operator()(KlassPtr klass) { if (_method_used_predicate(klass)) { const InstanceKlass* ik = InstanceKlass::cast(klass); - const int len = ik->methods()->length(); - Filter filter(ik->previous_versions() != NULL ? len : 0); while (ik != NULL) { + const int len = ik->methods()->length(); for (int i = 0; i < len; ++i) { MethodPtr method = ik->methods()->at(i); - if (_method_flag_predicate(method) && filter(i)) { + if (_method_flag_predicate(method)) { _method_cb(method); } } From 53dd617e591b3b705fdbaa294d93ea5ab0aec1e6 Mon Sep 17 00:00:00 2001 From: Evan Whelan Date: Fri, 4 Jun 2021 08:55:22 +0000 Subject: [PATCH 3/7] 8260401: StackOverflowError on open WindowsPreferences Backport-of: 849390a11e4dd4001a4f8bf75250eef942d9da18 --- .../windows/classes/java/util/prefs/WindowsPreferences.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java.prefs/windows/classes/java/util/prefs/WindowsPreferences.java b/src/java.prefs/windows/classes/java/util/prefs/WindowsPreferences.java index 157c33c2bbe..e955d84779d 100644 --- a/src/java.prefs/windows/classes/java/util/prefs/WindowsPreferences.java +++ b/src/java.prefs/windows/classes/java/util/prefs/WindowsPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -432,7 +432,7 @@ class WindowsPreferences extends AbstractPreferences { if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not create windows registry node " + byteArrayToString(windowsAbsolutePath()) + - " at root 0x" + Long.toHexString(rootNativeHandle()) + + " at root 0x" + Long.toHexString(parentNativeHandle) + ". Windows RegCreateKeyEx(...) returned error code " + result[ERROR_CODE] + "."); isBackingStoreAvailable = false; @@ -458,7 +458,7 @@ class WindowsPreferences extends AbstractPreferences { if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not open/create prefs root node " + byteArrayToString(windowsAbsolutePath()) + - " at root 0x" + Long.toHexString(rootNativeHandle()) + + " at root 0x" + Long.toHexString(rootNativeHandle) + ". Windows RegCreateKeyEx(...) returned error code " + result[ERROR_CODE] + "."); isBackingStoreAvailable = false; From 6f948a7b02aac9c2e79e2ecba229ce402aecfa24 Mon Sep 17 00:00:00 2001 From: Martin Doerr Date: Fri, 4 Jun 2021 09:28:56 +0000 Subject: [PATCH 4/7] 8267842: SIGSEGV in get_current_contended_monitor Reviewed-by: dcubed Backport-of: 1e29005a22c7951242cf3b0d8cf2e6adc0b7b315 --- src/hotspot/share/runtime/thread.hpp | 16 ++++++++++------ src/hotspot/share/runtime/vmStructs.cpp | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp index 6f1f6f8b0a2..414dda70550 100644 --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -407,7 +407,7 @@ class Thread: public ThreadShadow { JFR_ONLY(DEFINE_THREAD_LOCAL_FIELD_JFR;) // Thread-local data for jfr - ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread + ObjectMonitor* volatile _current_pending_monitor; // ObjectMonitor this thread // is waiting to lock bool _current_pending_monitor_is_from_java; // locking is from Java code JvmtiRawMonitor* _current_pending_raw_monitor; // JvmtiRawMonitor this thread @@ -415,7 +415,7 @@ class Thread: public ThreadShadow { // ObjectMonitor on which this thread called Object.wait() - ObjectMonitor* _current_waiting_monitor; + ObjectMonitor* volatile _current_waiting_monitor; #ifdef ASSERT private: @@ -620,10 +620,13 @@ class Thread: public ThreadShadow { // For tracking the heavyweight monitor the thread is pending on. ObjectMonitor* current_pending_monitor() { - return _current_pending_monitor; + // Use Atomic::load() to prevent data race between concurrent modification and + // concurrent readers, e.g. ThreadService::get_current_contended_monitor(). + // Especially, reloading pointer from thread after NULL check must be prevented. + return Atomic::load(&_current_pending_monitor); } void set_current_pending_monitor(ObjectMonitor* monitor) { - _current_pending_monitor = monitor; + Atomic::store(&_current_pending_monitor, monitor); } void set_current_pending_monitor_is_from_java(bool from_java) { _current_pending_monitor_is_from_java = from_java; @@ -634,10 +637,11 @@ class Thread: public ThreadShadow { // For tracking the ObjectMonitor on which this thread called Object.wait() ObjectMonitor* current_waiting_monitor() { - return _current_waiting_monitor; + // See the comment in current_pending_monitor() above. + return Atomic::load(&_current_waiting_monitor); } void set_current_waiting_monitor(ObjectMonitor* monitor) { - _current_waiting_monitor = monitor; + Atomic::store(&_current_waiting_monitor, monitor); } // For tracking the Jvmti raw monitor the thread is pending on. diff --git a/src/hotspot/share/runtime/vmStructs.cpp b/src/hotspot/share/runtime/vmStructs.cpp index 6a8e24aaae7..c8574001ec6 100644 --- a/src/hotspot/share/runtime/vmStructs.cpp +++ b/src/hotspot/share/runtime/vmStructs.cpp @@ -738,9 +738,9 @@ typedef HashtableEntry KlassHashtableEntry; nonstatic_field(Thread, _active_handles, JNIHandleBlock*) \ nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \ nonstatic_field(Thread, _allocated_bytes, jlong) \ - nonstatic_field(Thread, _current_pending_monitor, ObjectMonitor*) \ + volatile_nonstatic_field(Thread, _current_pending_monitor, ObjectMonitor*) \ nonstatic_field(Thread, _current_pending_monitor_is_from_java, bool) \ - nonstatic_field(Thread, _current_waiting_monitor, ObjectMonitor*) \ + volatile_nonstatic_field(Thread, _current_waiting_monitor, ObjectMonitor*) \ nonstatic_field(NamedThread, _name, char*) \ nonstatic_field(NamedThread, _processed_thread, Thread*) \ nonstatic_field(JavaThread, _threadObj, OopHandle) \ From 375be1710acc1ba5388af1444cff414cddd75aa2 Mon Sep 17 00:00:00 2001 From: Christoph Langer Date: Fri, 4 Jun 2021 09:34:15 +0000 Subject: [PATCH 5/7] 8264786: [macos] All Swing/AWT apps cause Allow Notifications prompt to appear when app is launched Reviewed-by: vkempik, mdoerr, mbaesken Backport-of: 020236cb9825bf4fa91a495a179623e3fcdc0149 --- .../macosx/native/libawt_lwawt/awt/CTrayIcon.h | 4 ++-- .../macosx/native/libawt_lwawt/awt/CTrayIcon.m | 11 ++++++++++- .../macosx/native/libosxapp/NSApplicationAWT.h | 4 ++-- .../macosx/native/libosxapp/NSApplicationAWT.m | 11 +---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.h index 49e0e7d8645..85045170d18 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -42,7 +42,7 @@ extern "C" { /* * AWTTrayIcon */ -@interface AWTTrayIcon : NSObject { +@interface AWTTrayIcon : NSObject { jobject peer; AWTTrayIconView *view; NSStatusItem *theItem; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m index 23e17fb7b14..bfbdcd0e50e 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -69,11 +69,14 @@ static NSSize ScaledImageSizeForStatusBar(NSSize imageSize, BOOL autosize) { view = [[AWTTrayIconView alloc] initWithTrayIcon:self]; [theItem setView:view]; + [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; return self; } -(void) dealloc { + [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil]; + JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; JNFDeleteGlobalRef(env, peer); @@ -166,6 +169,12 @@ static NSSize ScaledImageSizeForStatusBar(NSSize imageSize, BOOL autosize) { (*env)->DeleteLocalRef(env, jEvent); } +- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center + shouldPresentNotification:(NSUserNotification *)notification +{ + return YES; // We always show notifications to the user +} + @end //AWTTrayIcon //================================================ diff --git a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h index 888621604f3..3b12e871bdb 100644 --- a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h +++ b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -32,7 +32,7 @@ #import #import -JNIEXPORT @interface NSApplicationAWT : NSApplication { +JNIEXPORT @interface NSApplicationAWT : NSApplication { NSString *fApplicationName; NSWindow *eventTransparentWindow; NSTimeInterval dummyEventTimestamp; diff --git a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m index 4cb5bc0ca57..10928202776 100644 --- a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m +++ b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -77,8 +77,6 @@ AWT_ASSERT_APPKIT_THREAD; - (void)dealloc { - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil]; - [fApplicationName release]; fApplicationName = nil; @@ -159,17 +157,10 @@ AWT_ASSERT_APPKIT_THREAD; [super finishLaunching]; - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; - // inform any interested parties that the AWT has arrived and is pumping [[NSNotificationCenter defaultCenter] postNotificationName:JNFRunLoopDidStartNotification object:self]; } -- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center - shouldPresentNotification:(NSUserNotification *)notification -{ - return YES; // We always show notifications to the user -} - (void) registerWithProcessManager { From 7616b2c053dd1125e1c553d91ca68e8efb2bc026 Mon Sep 17 00:00:00 2001 From: Evan Whelan Date: Fri, 4 Jun 2021 10:21:31 +0000 Subject: [PATCH 6/7] 8211227: Inconsistent TLS protocol version in debug output Backport-of: a86728850e9919d2bbeeef70093adbd87bc3bb26 --- .../sun/security/ssl/DTLSOutputRecord.java | 4 +- .../sun/security/ssl/HandshakeContext.java | 4 +- .../security/ssl/SSLEngineOutputRecord.java | 4 +- .../security/ssl/SSLSocketOutputRecord.java | 8 +- .../EngineArgs/DebugReportsOneExtraByte.java | 2 +- .../SSLLogger/LoggingFormatConsistency.java | 151 ++++++++++++++++++ 6 files changed, 162 insertions(+), 11 deletions(-) create mode 100644 test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java diff --git a/src/java.base/share/classes/sun/security/ssl/DTLSOutputRecord.java b/src/java.base/share/classes/sun/security/ssl/DTLSOutputRecord.java index 3cf2ca277d2..02fe95fe4af 100644 --- a/src/java.base/share/classes/sun/security/ssl/DTLSOutputRecord.java +++ b/src/java.base/share/classes/sun/security/ssl/DTLSOutputRecord.java @@ -271,7 +271,7 @@ final class DTLSOutputRecord extends OutputRecord implements DTLSRecord { if (SSLLogger.isOn && SSLLogger.isOn("record")) { SSLLogger.fine( - "WRITE: " + protocolVersion + " " + + "WRITE: " + protocolVersion.name + " " + ContentType.APPLICATION_DATA.name + ", length = " + destination.remaining()); } @@ -499,7 +499,7 @@ final class DTLSOutputRecord extends OutputRecord implements DTLSRecord { if (SSLLogger.isOn && SSLLogger.isOn("record")) { SSLLogger.fine( - "WRITE: " + protocolVersion + " " + + "WRITE: " + protocolVersion.name + " " + ContentType.nameOf(memo.contentType) + ", length = " + dstBuf.remaining()); } diff --git a/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java b/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java index 50ee421bae2..5c2456a2598 100644 --- a/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java +++ b/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java @@ -297,13 +297,13 @@ abstract class HandshakeContext implements ConnectionContext { } else if (SSLLogger.isOn && SSLLogger.isOn("verbose")) { SSLLogger.fine( "Ignore unsupported cipher suite: " + suite + - " for " + protocol); + " for " + protocol.name); } } if (!found && (SSLLogger.isOn) && SSLLogger.isOn("handshake")) { SSLLogger.fine( - "No available cipher suite for " + protocol); + "No available cipher suite for " + protocol.name); } } diff --git a/src/java.base/share/classes/sun/security/ssl/SSLEngineOutputRecord.java b/src/java.base/share/classes/sun/security/ssl/SSLEngineOutputRecord.java index 67a0f393359..a5764574699 100644 --- a/src/java.base/share/classes/sun/security/ssl/SSLEngineOutputRecord.java +++ b/src/java.base/share/classes/sun/security/ssl/SSLEngineOutputRecord.java @@ -269,7 +269,7 @@ final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord { if (SSLLogger.isOn && SSLLogger.isOn("record")) { SSLLogger.fine( - "WRITE: " + protocolVersion + " " + + "WRITE: " + protocolVersion.name + " " + ContentType.APPLICATION_DATA.name + ", length = " + destination.remaining()); } @@ -508,7 +508,7 @@ final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord { if (SSLLogger.isOn && SSLLogger.isOn("record")) { SSLLogger.fine( - "WRITE: " + protocolVersion + " " + + "WRITE: " + protocolVersion.name + " " + ContentType.nameOf(memo.contentType) + ", length = " + dstBuf.remaining()); } diff --git a/src/java.base/share/classes/sun/security/ssl/SSLSocketOutputRecord.java b/src/java.base/share/classes/sun/security/ssl/SSLSocketOutputRecord.java index 97a65ba987d..c98a40e6d50 100644 --- a/src/java.base/share/classes/sun/security/ssl/SSLSocketOutputRecord.java +++ b/src/java.base/share/classes/sun/security/ssl/SSLSocketOutputRecord.java @@ -69,7 +69,7 @@ final class SSLSocketOutputRecord extends OutputRecord implements SSLRecord { write(level); write(description); if (SSLLogger.isOn && SSLLogger.isOn("record")) { - SSLLogger.fine("WRITE: " + protocolVersion + + SSLLogger.fine("WRITE: " + protocolVersion.name + " " + ContentType.ALERT.name + "(" + Alert.nameOf(description) + ")" + ", length = " + (count - headerSize)); @@ -180,7 +180,7 @@ final class SSLSocketOutputRecord extends OutputRecord implements SSLRecord { if (SSLLogger.isOn && SSLLogger.isOn("record")) { SSLLogger.fine( - "WRITE: " + protocolVersion + + "WRITE: " + protocolVersion.name + " " + ContentType.HANDSHAKE.name + ", length = " + (count - headerSize)); } @@ -256,7 +256,7 @@ final class SSLSocketOutputRecord extends OutputRecord implements SSLRecord { if (SSLLogger.isOn && SSLLogger.isOn("record")) { SSLLogger.fine( - "WRITE: " + protocolVersion + + "WRITE: " + protocolVersion.name + " " + ContentType.HANDSHAKE.name + ", length = " + (count - headerSize)); } @@ -329,7 +329,7 @@ final class SSLSocketOutputRecord extends OutputRecord implements SSLRecord { if (SSLLogger.isOn && SSLLogger.isOn("record")) { SSLLogger.fine( - "WRITE: " + protocolVersion + + "WRITE: " + protocolVersion.name + " " + ContentType.APPLICATION_DATA.name + ", length = " + (count - position)); } diff --git a/test/jdk/sun/security/ssl/EngineArgs/DebugReportsOneExtraByte.java b/test/jdk/sun/security/ssl/EngineArgs/DebugReportsOneExtraByte.java index 4ced9a3ea7b..79405f5e6fa 100644 --- a/test/jdk/sun/security/ssl/EngineArgs/DebugReportsOneExtraByte.java +++ b/test/jdk/sun/security/ssl/EngineArgs/DebugReportsOneExtraByte.java @@ -131,7 +131,7 @@ public class DebugReportsOneExtraByte { OutputAnalyzer output = ProcessTools.executeTestJvm( "-Dtest.src=" + System.getProperty("test.src"), "-Djavax.net.debug=all", "DebugReportsOneExtraByte", "p"); - output.shouldContain("WRITE: TLS10 application_data, length = 8"); + output.shouldContain("WRITE: TLSv1 application_data, length = 8"); System.out.println("Test Passed."); } else { diff --git a/test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java b/test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java new file mode 100644 index 00000000000..9dd33845c64 --- /dev/null +++ b/test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 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. + * + * 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. + */ + +/** + * @test + * @bug 8211227 + * @library /test/lib /javax/net/ssl/templates ../../ + * @summary Tests for consistency in logging format of TLS Versions + * @run main/othervm LoggingFormatConsistency + */ + +/* + * This test runs in another process so we can monitor the debug + * results. The OutputAnalyzer must see correct debug output to return a + * success. + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.security.SecurityUtils; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocket; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.URL; + +import static java.nio.charset.StandardCharsets.UTF_8; + +public class LoggingFormatConsistency extends SSLSocketTemplate { + + LoggingFormatConsistency () { + serverAddress = InetAddress.getLoopbackAddress(); + SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1"); + } + + public static void main(String[] args) throws Exception { + if (args.length != 0) { + // A non-empty set of arguments occurs when the "runTest" argument + // is passed to the test via ProcessTools::executeTestJvm. + // + // This is done because an OutputAnalyzer is unable to read + // the output of the current running JVM, and must therefore create + // a test JVM. When this case occurs, it will inherit all specified + // properties passed to the test JVM - debug flags, tls version, etc. + new LoggingFormatConsistency().run(); + } else { + // We are in the test JVM that the test is being ran in. + var testSrc = "-Dtest.src=" + System.getProperty("test.src"); + var javaxNetDebug = "-Djavax.net.debug=all"; + + var correctTlsVersionsFormat = new String[]{"TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}; + var incorrectTLSVersionsFormat = new String[]{"TLS10", "TLS11", "TLS12", "TLS13"}; + + for (var i = 0; i < correctTlsVersionsFormat.length; i++) { + var expectedTLSVersion = correctTlsVersionsFormat[i]; + var incorrectTLSVersion = incorrectTLSVersionsFormat[i]; + + System.out.println("TESTING " + expectedTLSVersion); + var activeTLSProtocol = "-Djdk.tls.client.protocols=" + expectedTLSVersion; + var output = ProcessTools.executeTestJvm( + testSrc, + activeTLSProtocol, + javaxNetDebug, + "LoggingFormatConsistency", + "runTest"); // Ensuring args.length is greater than 0 when test JVM starts + + if (output.getExitValue() != 0) { + throw new RuntimeException("Test JVM process failed. JVM stderr= " + output.getStderr()); + } + + output.shouldContain(expectedTLSVersion); + output.shouldNotContain(incorrectTLSVersion); + } + } + } + + @Override + protected boolean isCustomizedClientConnection() { return true; } + + @Override + protected void runServerApplication(SSLSocket socket) throws Exception { + var response = "Hello World!"; + var out = new DataOutputStream(socket.getOutputStream()); + try { + // We don't need to process the data from the socket + // Simply sending a response right away is sufficient + // to generate the desired debug output + var responseBytes = response.getBytes(UTF_8); + + out.writeBytes("HTTP/1.0 200 OK\r\n"); + out.writeBytes("Content-Length: " + responseBytes.length + "\r\n"); + out.writeBytes("Content-Type: text/html\r\n\r\n"); + out.write(responseBytes); + out.flush(); + } catch (IOException e) { + out.writeBytes("HTTP/1.0 400 " + e.getMessage() + "\r\n"); + out.writeBytes("Content-Type: text/html\r\n\r\n"); + out.flush(); + } + } + + @Override + protected void runClientApplication(int serverPort) throws Exception { + var context = createClientSSLContext(); + HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); + HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); + + var host = serverAddress == null ? "localhost" : serverAddress.getHostAddress(); + var url = new URL("https://" + host + ":" + serverPort + "/"); + var httpsConnection = (HttpsURLConnection) url.openConnection(); + httpsConnection.disconnect(); + try (var in = new BufferedReader(new InputStreamReader(httpsConnection.getInputStream()))) { + // Getting the input stream from the BufferedReader is sufficient to generate the desired debug output + // We don't need to process the data + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static class NameVerifier implements HostnameVerifier { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + } +} From d2d95335667758c5be7a7f3d8150f8556b869dac Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Mon, 7 Jun 2021 09:06:49 +0000 Subject: [PATCH 7/7] 8267773: PhaseStringOpts::int_stringSize doesn't handle min_jint correctly Backport-of: d47a77d2d54ee8c41ef969b42b3336a646dffd7b --- src/hotspot/share/opto/stringopts.cpp | 5 ++ .../lang/String/concat/IntegerMinValue.java | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/jdk/java/lang/String/concat/IntegerMinValue.java diff --git a/src/hotspot/share/opto/stringopts.cpp b/src/hotspot/share/opto/stringopts.cpp index 7e1ca856fba..6de82375cce 100644 --- a/src/hotspot/share/opto/stringopts.cpp +++ b/src/hotspot/share/opto/stringopts.cpp @@ -1149,6 +1149,11 @@ Node* PhaseStringOpts::int_stringSize(GraphKit& kit, Node* arg) { int arg_val = arg->get_int(); int count = 1; if (arg_val < 0) { + // Special case for min_jint - it can't be negated. + if (arg_val == min_jint) { + return __ intcon(11); + } + arg_val = -arg_val; count++; } diff --git a/test/jdk/java/lang/String/concat/IntegerMinValue.java b/test/jdk/java/lang/String/concat/IntegerMinValue.java new file mode 100644 index 00000000000..6bc4c418c7d --- /dev/null +++ b/test/jdk/java/lang/String/concat/IntegerMinValue.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, Red Hat, Inc. 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. + * + * 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. + */ + +/** + * @test + * @bug 8267773 + * @summary Test + * + * @compile IntegerMinValue.java + * @run main/othervm -Xverify:all -Xbatch IntegerMinValue + * + * @compile -XDstringConcat=inline IntegerMinValue.java + * @run main/othervm -Xverify:all -Xbatch IntegerMinValue + * + * @compile -XDstringConcat=indy IntegerMinValue.java + * @run main/othervm -Xverify:all -Xbatch IntegerMinValue + * + * @compile -XDstringConcat=indyWithConstants IntegerMinValue.java + * @run main/othervm -Xverify:all -Xbatch IntegerMinValue +*/ + +public class IntegerMinValue { + + public void test() { + int i = Integer.MIN_VALUE; + String s = "" + i; + if (!"-2147483648".equals(s)) { + throw new IllegalStateException("Failed: " + s); + } + System.out.println(s); + } + + public static void main(String[] strArr) { + IntegerMinValue t = new IntegerMinValue(); + for (int i = 0; i < 100_000; i++ ) { + t.test(); + } + } + +}