mirror of
https://github.com/openjdk/jdk16u.git
synced 2025-12-11 03:01:15 -06:00
Merge
This commit is contained in:
commit
6d8f828dd6
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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++;
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -738,9 +738,9 @@ typedef HashtableEntry<InstanceKlass*, mtClass> 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) \
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 &&
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
/*
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -100,6 +100,11 @@ public abstract class Cache<K,V> {
|
||||
*/
|
||||
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<K,V> extends Cache<K,V> {
|
||||
// empty
|
||||
}
|
||||
|
||||
public V pull(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCapacity(int size) {
|
||||
// empty
|
||||
}
|
||||
@ -402,6 +411,26 @@ class MemoryCache<K,V> extends Cache<K,V> {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized V pull(Object key) {
|
||||
emptyQueue();
|
||||
CacheEntry<K,V> 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) {
|
||||
|
||||
@ -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 <NSUserNotificationCenterDelegate>{
|
||||
jobject peer;
|
||||
AWTTrayIconView *view;
|
||||
NSStatusItem *theItem;
|
||||
|
||||
@ -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
|
||||
//================================================
|
||||
|
||||
|
||||
@ -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 <Cocoa/Cocoa.h>
|
||||
#import <JavaNativeFoundation/JavaNativeFoundation.h>
|
||||
|
||||
JNIEXPORT @interface NSApplicationAWT : NSApplication <NSUserNotificationCenterDelegate> {
|
||||
JNIEXPORT @interface NSApplicationAWT : NSApplication {
|
||||
NSString *fApplicationName;
|
||||
NSWindow *eventTransparentWindow;
|
||||
NSTimeInterval dummyEventTimestamp;
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
60
test/jdk/java/lang/String/concat/IntegerMinValue.java
Normal file
60
test/jdk/java/lang/String/concat/IntegerMinValue.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user