From baf59c0bd8876069bc565c39ec0564ade6fed6a8 Mon Sep 17 00:00:00 2001 From: Pavel Rappo Date: Mon, 16 May 2016 15:10:04 +0100 Subject: [PATCH 1/3] 8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer Reviewed-by: alanb, rriggs, chegar --- .../share/classes/java/nio/Buffer.java | 48 ++++++++++++++++++- .../classes/java/nio/X-Buffer.java.template | 5 +- .../java/nio/Buffer/Order-X.java.template | 3 -- jdk/test/java/nio/Buffer/Order.java | 24 ++++++---- jdk/test/java/nio/Buffer/OrderChar.java | 3 -- jdk/test/java/nio/Buffer/OrderDouble.java | 3 -- jdk/test/java/nio/Buffer/OrderFloat.java | 3 -- jdk/test/java/nio/Buffer/OrderInt.java | 3 -- jdk/test/java/nio/Buffer/OrderLong.java | 3 -- jdk/test/java/nio/Buffer/OrderShort.java | 3 -- 10 files changed, 65 insertions(+), 33 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/nio/Buffer.java b/jdk/src/java.base/share/classes/java/nio/Buffer.java index d534fb3ae73..1f6bef17960 100644 --- a/jdk/src/java.base/share/classes/java/nio/Buffer.java +++ b/jdk/src/java.base/share/classes/java/nio/Buffer.java @@ -111,7 +111,7 @@ import java.util.Spliterator; * to zero. * * - *

Clearing, flipping, and rewinding

+ *

Additional operations

* *

In addition to methods for accessing the position, limit, and capacity * values and for marking and resetting, this class also defines the following @@ -131,6 +131,12 @@ import java.util.Spliterator; * it already contains: It leaves the limit unchanged and sets the position * to zero.

* + *
  • {@link #slice} creates a subsequence of a buffer: It leaves the + * limit and the position unchanged.

  • + * + *
  • {@link #duplicate} creates a shallow copy of a buffer: It leaves + * the limit and the position unchanged.

  • + * * * * @@ -567,6 +573,46 @@ public abstract class Buffer { */ public abstract boolean isDirect(); + /** + * Creates a new buffer whose content is a shared subsequence of + * this buffer's content. + * + *

    The content of the new buffer will start at this buffer's current + * position. Changes to this buffer's content will be visible in the new + * buffer, and vice versa; the two buffers' position, limit, and mark + * values will be independent. + * + *

    The new buffer's position will be zero, its capacity and its limit + * will be the number of elements remaining in this buffer, its mark will be + * undefined. The new buffer will be direct if, and only if, this buffer is + * direct, and it will be read-only if, and only if, this buffer is + * read-only.

    + * + * @return The new buffer + * + * @since 9 + */ + public abstract Buffer slice(); + + /** + * Creates a new buffer that shares this buffer's content. + * + *

    The content of the new buffer will be that of this buffer. Changes + * to this buffer's content will be visible in the new buffer, and vice + * versa; the two buffers' position, limit, and mark values will be + * independent. + * + *

    The new buffer's capacity, limit, position and mark values will be + * identical to those of this buffer. The new buffer will be direct if, and + * only if, this buffer is direct, and it will be read-only if, and only if, + * this buffer is read-only.

    + * + * @return The new buffer + * + * @since 9 + */ + public abstract Buffer duplicate(); + // -- Package-private methods for bounds checking, etc. -- diff --git a/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template b/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template index 104f504b551..1292ca458c6 100644 --- a/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template +++ b/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template @@ -70,8 +70,7 @@ import java.util.stream.$Streamtype$Stream; * #end[byte] * - *
  • Methods for {@link #compact compacting}, {@link - * #duplicate duplicating}, and {@link #slice slicing} + *

  • A method for {@link #compact compacting} * $a$ $type$ buffer.

  • * * @@ -535,6 +534,7 @@ public abstract class $Type$Buffer * @see #alignedSlice(int) #end[byte] */ + @Override public abstract $Type$Buffer slice(); /** @@ -557,6 +557,7 @@ public abstract class $Type$Buffer * * @return The new $type$ buffer */ + @Override public abstract $Type$Buffer duplicate(); /** diff --git a/jdk/test/java/nio/Buffer/Order-X.java.template b/jdk/test/java/nio/Buffer/Order-X.java.template index a8753a5f8a9..97313a841f6 100644 --- a/jdk/test/java/nio/Buffer/Order-X.java.template +++ b/jdk/test/java/nio/Buffer/Order-X.java.template @@ -52,8 +52,5 @@ public class Order$Type$ extends Order { buf = $Type$Buffer.allocate(LENGTH); ck(buf.order(), nord); ck$Type$Buffer(buf, nord); - - ck$Type$Buffer(ByteBuffer.allocate(LENGTH).as$Type$Buffer(), be); - ck$Type$Buffer(ByteBuffer.allocateDirect(LENGTH).as$Type$Buffer(), be); } } diff --git a/jdk/test/java/nio/Buffer/Order.java b/jdk/test/java/nio/Buffer/Order.java index 0232992525b..33ae418bb56 100644 --- a/jdk/test/java/nio/Buffer/Order.java +++ b/jdk/test/java/nio/Buffer/Order.java @@ -51,25 +51,31 @@ public class Order { ck(bb.asDoubleBuffer().order(), bb.order()); } + private static void ckCopyViews(ByteBuffer bb) { + ck(bb.asReadOnlyBuffer().order(), be); + ck(bb.duplicate().order(), be); + ck(bb.slice().order(), be); + } + private static void ckByteBuffer(ByteBuffer bb) { ckViews(bb); + ckCopyViews(bb); bb.order(be); ckViews(bb); + ckCopyViews(bb); bb.order(le); ckViews(bb); - - if (bb.hasArray()) { - byte[] array = bb.array(); - ck(ByteBuffer.wrap(array, LENGTH/2, LENGTH/2).order(), be); - ck(ByteBuffer.wrap(array).order(), be); - ck(bb.asReadOnlyBuffer().order(), be); - ck(bb.duplicate().order(), be); - ck(bb.slice().order(), be); - } + ckCopyViews(bb); } public static void main(String args[]) throws Exception { + ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(), be); + ck(ByteBuffer.wrap(new byte[LENGTH]).order(), be); + ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(be).order(), be); + ck(ByteBuffer.wrap(new byte[LENGTH]).order(be).order(), be); + ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(le).order(), le); + ck(ByteBuffer.wrap(new byte[LENGTH]).order(le).order(), le); ck(ByteBuffer.allocate(LENGTH).order(), be); ck(ByteBuffer.allocateDirect(LENGTH).order(), be); ck(ByteBuffer.allocate(LENGTH).order(be).order(), be); diff --git a/jdk/test/java/nio/Buffer/OrderChar.java b/jdk/test/java/nio/Buffer/OrderChar.java index ebf9faad79c..f72828bd0de 100644 --- a/jdk/test/java/nio/Buffer/OrderChar.java +++ b/jdk/test/java/nio/Buffer/OrderChar.java @@ -52,8 +52,5 @@ public class OrderChar extends Order { buf = CharBuffer.allocate(LENGTH); ck(buf.order(), nord); ckCharBuffer(buf, nord); - - ckCharBuffer(ByteBuffer.allocate(LENGTH).asCharBuffer(), be); - ckCharBuffer(ByteBuffer.allocateDirect(LENGTH).asCharBuffer(), be); } } diff --git a/jdk/test/java/nio/Buffer/OrderDouble.java b/jdk/test/java/nio/Buffer/OrderDouble.java index deaa6a3eb27..4100695cab5 100644 --- a/jdk/test/java/nio/Buffer/OrderDouble.java +++ b/jdk/test/java/nio/Buffer/OrderDouble.java @@ -52,8 +52,5 @@ public class OrderDouble extends Order { buf = DoubleBuffer.allocate(LENGTH); ck(buf.order(), nord); ckDoubleBuffer(buf, nord); - - ckDoubleBuffer(ByteBuffer.allocate(LENGTH).asDoubleBuffer(), be); - ckDoubleBuffer(ByteBuffer.allocateDirect(LENGTH).asDoubleBuffer(), be); } } diff --git a/jdk/test/java/nio/Buffer/OrderFloat.java b/jdk/test/java/nio/Buffer/OrderFloat.java index 6a65eaa8e4f..905d531d434 100644 --- a/jdk/test/java/nio/Buffer/OrderFloat.java +++ b/jdk/test/java/nio/Buffer/OrderFloat.java @@ -52,8 +52,5 @@ public class OrderFloat extends Order { buf = FloatBuffer.allocate(LENGTH); ck(buf.order(), nord); ckFloatBuffer(buf, nord); - - ckFloatBuffer(ByteBuffer.allocate(LENGTH).asFloatBuffer(), be); - ckFloatBuffer(ByteBuffer.allocateDirect(LENGTH).asFloatBuffer(), be); } } diff --git a/jdk/test/java/nio/Buffer/OrderInt.java b/jdk/test/java/nio/Buffer/OrderInt.java index 5d3843ffec7..700fc07110a 100644 --- a/jdk/test/java/nio/Buffer/OrderInt.java +++ b/jdk/test/java/nio/Buffer/OrderInt.java @@ -52,8 +52,5 @@ public class OrderInt extends Order { buf = IntBuffer.allocate(LENGTH); ck(buf.order(), nord); ckIntBuffer(buf, nord); - - ckIntBuffer(ByteBuffer.allocate(LENGTH).asIntBuffer(), be); - ckIntBuffer(ByteBuffer.allocateDirect(LENGTH).asIntBuffer(), be); } } diff --git a/jdk/test/java/nio/Buffer/OrderLong.java b/jdk/test/java/nio/Buffer/OrderLong.java index abda8b22932..9e507ffc18e 100644 --- a/jdk/test/java/nio/Buffer/OrderLong.java +++ b/jdk/test/java/nio/Buffer/OrderLong.java @@ -52,8 +52,5 @@ public class OrderLong extends Order { buf = LongBuffer.allocate(LENGTH); ck(buf.order(), nord); ckLongBuffer(buf, nord); - - ckLongBuffer(ByteBuffer.allocate(LENGTH).asLongBuffer(), be); - ckLongBuffer(ByteBuffer.allocateDirect(LENGTH).asLongBuffer(), be); } } diff --git a/jdk/test/java/nio/Buffer/OrderShort.java b/jdk/test/java/nio/Buffer/OrderShort.java index d19b43a1b60..f385b62d6dd 100644 --- a/jdk/test/java/nio/Buffer/OrderShort.java +++ b/jdk/test/java/nio/Buffer/OrderShort.java @@ -52,8 +52,5 @@ public class OrderShort extends Order { buf = ShortBuffer.allocate(LENGTH); ck(buf.order(), nord); ckShortBuffer(buf, nord); - - ckShortBuffer(ByteBuffer.allocate(LENGTH).asShortBuffer(), be); - ckShortBuffer(ByteBuffer.allocateDirect(LENGTH).asShortBuffer(), be); } } From fc86d03190d3bf585459ec9057978272e6ab5900 Mon Sep 17 00:00:00 2001 From: Michael McMahon Date: Mon, 16 May 2016 16:04:14 +0100 Subject: [PATCH 2/3] 8156825: java/net/httpclient/BasicWebSocketAPITest.java failed with java.lang.AssertionError Reviewed-by: rriggs --- .../classes/java/net/http/HttpClientImpl.java | 17 +++++++++++ .../classes/java/net/http/HttpHeaders1.java | 29 ------------------- .../java/net/http/HttpResponseImpl.java | 2 +- .../classes/java/net/http/RawChannel.java | 15 +++++++++- .../java/net/http/WSOpeningHandshake.java | 11 ++++++- 5 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 jdk/src/java.httpclient/share/classes/java/net/http/HttpHeaders1.java diff --git a/jdk/src/java.httpclient/share/classes/java/net/http/HttpClientImpl.java b/jdk/src/java.httpclient/share/classes/java/net/http/HttpClientImpl.java index 446987d6b5d..226cee95c55 100644 --- a/jdk/src/java.httpclient/share/classes/java/net/http/HttpClientImpl.java +++ b/jdk/src/java.httpclient/share/classes/java/net/http/HttpClientImpl.java @@ -35,6 +35,7 @@ import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Iterator; @@ -155,6 +156,15 @@ class HttpClientImpl extends HttpClient implements BufferHandler { selmgr.register(exchange); } + /** + * Only used from RawChannel to disconnect the channel from + * the selector + */ + void cancelRegistration(SocketChannel s) { + selmgr.cancel(s); + } + + Http2ClientImpl client2() { return client2; } @@ -220,6 +230,13 @@ class HttpClientImpl extends HttpClient implements BufferHandler { selector.wakeup(); } + synchronized void cancel(SocketChannel e) { + SelectionKey key = e.keyFor(selector); + if (key != null) + key.cancel(); + selector.wakeup(); + } + void wakeupSelector() { selector.wakeup(); } diff --git a/jdk/src/java.httpclient/share/classes/java/net/http/HttpHeaders1.java b/jdk/src/java.httpclient/share/classes/java/net/http/HttpHeaders1.java deleted file mode 100644 index c9ff689a931..00000000000 --- a/jdk/src/java.httpclient/share/classes/java/net/http/HttpHeaders1.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015, 2016, 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 - */ - -package java.net.http; - -public interface HttpHeaders1 extends HttpHeaders { - public void makeUnmodifiable(); -} diff --git a/jdk/src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java b/jdk/src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java index 10758d6db99..dcbfbdb8f1a 100644 --- a/jdk/src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java +++ b/jdk/src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java @@ -176,7 +176,7 @@ class HttpResponseImpl extends HttpResponse { * * @return */ - RawChannel rawChannel() { + RawChannel rawChannel() throws IOException { if (rawchan == null) { rawchan = new RawChannel(request.client(), connection); } diff --git a/jdk/src/java.httpclient/share/classes/java/net/http/RawChannel.java b/jdk/src/java.httpclient/share/classes/java/net/http/RawChannel.java index e4dc3b00b8d..5f6fb4df6c0 100644 --- a/jdk/src/java.httpclient/share/classes/java/net/http/RawChannel.java +++ b/jdk/src/java.httpclient/share/classes/java/net/http/RawChannel.java @@ -29,6 +29,7 @@ import java.nio.channels.ByteChannel; import java.nio.channels.GatheringByteChannel; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; +import java.nio.channels.SocketChannel; // // Used to implement WebSocket. Each RawChannel corresponds to a TCP connection @@ -56,9 +57,21 @@ final class RawChannel implements ByteChannel, GatheringByteChannel { interface NonBlockingEvent extends RawEvent { } - RawChannel(HttpClientImpl client, HttpConnection connection) { + RawChannel(HttpClientImpl client, HttpConnection connection) + throws IOException { this.client = client; this.connection = connection; + SocketChannel chan = connection.channel(); + client.cancelRegistration(chan); + chan.configureBlocking(false); + } + + SocketChannel socketChannel() { + return connection.channel(); + } + + ByteBuffer getRemaining() { + return connection.getRemaining(); } private class RawAsyncEvent extends AsyncEvent { diff --git a/jdk/src/java.httpclient/share/classes/java/net/http/WSOpeningHandshake.java b/jdk/src/java.httpclient/share/classes/java/net/http/WSOpeningHandshake.java index 6a7ddaa882c..d3cc7da3520 100644 --- a/jdk/src/java.httpclient/share/classes/java/net/http/WSOpeningHandshake.java +++ b/jdk/src/java.httpclient/share/classes/java/net/http/WSOpeningHandshake.java @@ -24,6 +24,8 @@ */ package java.net.http; +import java.io.UncheckedIOException; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; @@ -126,6 +128,8 @@ final class WSOpeningHandshake { return CompletableFuture.completedFuture(result); } catch (WebSocketHandshakeException e) { return CompletableFuture.failedFuture(e); + } catch (UncheckedIOException ee) { + return CompletableFuture.failedFuture(ee.getCause()); } }); } @@ -149,7 +153,12 @@ final class WSOpeningHandshake { checkAccept(response, h); checkExtensions(response, h); String subprotocol = checkAndReturnSubprotocol(response, h); - RawChannel channel = ((HttpResponseImpl) response).rawChannel(); + RawChannel channel = null; + try { + channel = ((HttpResponseImpl) response).rawChannel(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } return new Result(subprotocol, channel); } From 5cd35e69e24863a9b52c78c787f7df6a0485170c Mon Sep 17 00:00:00 2001 From: Rajan Halade Date: Mon, 16 May 2016 10:36:51 -0700 Subject: [PATCH 3/3] 8155049: New tests from 8144566 fail with "No expected Server Name Indication" Reviewed-by: xuelei --- .../javax/net/ssl/ServerName/BestEffortOnLazyConnected.java | 4 +--- .../www/protocol/https/HttpsURLConnection/ImpactOnSNI.java | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/jdk/test/javax/net/ssl/ServerName/BestEffortOnLazyConnected.java b/jdk/test/javax/net/ssl/ServerName/BestEffortOnLazyConnected.java index ba3e5f10e50..bda0710f61e 100644 --- a/jdk/test/javax/net/ssl/ServerName/BestEffortOnLazyConnected.java +++ b/jdk/test/javax/net/ssl/ServerName/BestEffortOnLazyConnected.java @@ -34,9 +34,6 @@ */ import java.io.*; -import java.nio.*; -import java.nio.channels.*; -import java.util.*; import java.net.*; import javax.net.ssl.*; @@ -197,6 +194,7 @@ public class BestEffortOnLazyConnected { hostname); // Ignore the test if the hostname does not sound like a domain name. if ((hostname == null) || hostname.isEmpty() || + !hostname.contains(".") || hostname.endsWith(".") || hostname.startsWith("localhost") || Character.isDigit(hostname.charAt(hostname.length() - 1))) { diff --git a/jdk/test/sun/net/www/protocol/https/HttpsURLConnection/ImpactOnSNI.java b/jdk/test/sun/net/www/protocol/https/HttpsURLConnection/ImpactOnSNI.java index 4e0f0bdac59..d90d9478e2a 100644 --- a/jdk/test/sun/net/www/protocol/https/HttpsURLConnection/ImpactOnSNI.java +++ b/jdk/test/sun/net/www/protocol/https/HttpsURLConnection/ImpactOnSNI.java @@ -235,6 +235,7 @@ public class ImpactOnSNI { hostname); // Ignore the test if the hostname does not sound like a domain name. if ((hostname == null) || hostname.isEmpty() || + !hostname.contains(".") || hostname.endsWith(".") || hostname.startsWith("localhost") || Character.isDigit(hostname.charAt(hostname.length() - 1))) {