mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
Merge
This commit is contained in:
commit
44ab590f44
218 changed files with 9553 additions and 71543 deletions
|
@ -63,7 +63,8 @@ public abstract class InputStream implements Closeable {
|
|||
*
|
||||
* <p> While the stream is open, the {@code available()}, {@code read()},
|
||||
* {@code read(byte[])}, {@code read(byte[], int, int)},
|
||||
* {@code readAllBytes()}, {@code readNBytes()}, {@code skip()}, and
|
||||
* {@code readAllBytes()}, {@code readNBytes(byte[], int, int)},
|
||||
* {@code readNBytes(int)}, {@code skip(long)}, and
|
||||
* {@code transferTo()} methods all behave as if end of stream has been
|
||||
* reached. After the stream has been closed, these methods all throw
|
||||
* {@code IOException}.
|
||||
|
@ -122,6 +123,15 @@ public abstract class InputStream implements Closeable {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readNBytes(int len) throws IOException {
|
||||
if (len < 0) {
|
||||
throw new IllegalArgumentException("len < 0");
|
||||
}
|
||||
ensureOpen();
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
ensureOpen();
|
||||
|
@ -233,8 +243,8 @@ public abstract class InputStream implements Closeable {
|
|||
* <code>b</code> and the number of bytes read before the exception
|
||||
* occurred is returned. The default implementation of this method blocks
|
||||
* until the requested amount of input data <code>len</code> has been read,
|
||||
* end of file is detected, or an exception is thrown. Subclasses are encouraged
|
||||
* to provide a more efficient implementation of this method.
|
||||
* end of file is detected, or an exception is thrown. Subclasses are
|
||||
* encouraged to provide a more efficient implementation of this method.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset in array <code>b</code>
|
||||
|
@ -308,26 +318,85 @@ public abstract class InputStream implements Closeable {
|
|||
* It is strongly recommended that the stream be promptly closed if an I/O
|
||||
* error occurs.
|
||||
*
|
||||
* @implSpec
|
||||
* This method invokes {@link #readNBytes(int)} with a length of
|
||||
* {@link Integer#MAX_VALUE}.
|
||||
*
|
||||
* @return a byte array containing the bytes read from this input stream
|
||||
* @throws IOException if an I/O error occurs
|
||||
* @throws OutOfMemoryError if an array of the required size cannot be
|
||||
* allocated. For example, if an array larger than {@code 2GB} would
|
||||
* be required to store the bytes.
|
||||
* allocated.
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public byte[] readAllBytes() throws IOException {
|
||||
return readNBytes(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads up to a specified number of bytes from the input stream. This
|
||||
* method blocks until the requested number of bytes have been read, end
|
||||
* of stream is detected, or an exception is thrown. This method does not
|
||||
* close the input stream.
|
||||
*
|
||||
* <p> The length of the returned array equals the number of bytes read
|
||||
* from the stream. If {@code len} is zero, then no bytes are read and
|
||||
* an empty byte array is returned. Otherwise, up to {@code len} bytes
|
||||
* are read from the stream. Fewer than {@code len} bytes may be read if
|
||||
* end of stream is encountered.
|
||||
*
|
||||
* <p> When this stream reaches end of stream, further invocations of this
|
||||
* method will return an empty byte array.
|
||||
*
|
||||
* <p> Note that this method is intended for simple cases where it is
|
||||
* convenient to read the specified number of bytes into a byte array. The
|
||||
* total amount of memory allocated by this method is proportional to the
|
||||
* number of bytes read from the stream which is bounded by {@code len}.
|
||||
* Therefore, the method may be safely called with very large values of
|
||||
* {@code len} provided sufficient memory is available.
|
||||
*
|
||||
* <p> The behavior for the case where the input stream is <i>asynchronously
|
||||
* closed</i>, or the thread interrupted during the read, is highly input
|
||||
* stream specific, and therefore not specified.
|
||||
*
|
||||
* <p> If an I/O error occurs reading from the input stream, then it may do
|
||||
* so after some, but not all, bytes have been read. Consequently the input
|
||||
* stream may not be at end of stream and may be in an inconsistent state.
|
||||
* It is strongly recommended that the stream be promptly closed if an I/O
|
||||
* error occurs.
|
||||
*
|
||||
* @implNote
|
||||
* The number of bytes allocated to read data from this stream and return
|
||||
* the result is bounded by {@code 2*(long)len}, inclusive.
|
||||
*
|
||||
* @param len the maximum number of bytes to read
|
||||
* @return a byte array containing the bytes read from this input stream
|
||||
* @throws IllegalArgumentException if {@code length} is negative
|
||||
* @throws IOException if an I/O error occurs
|
||||
* @throws OutOfMemoryError if an array of the required size cannot be
|
||||
* allocated.
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
public byte[] readNBytes(int len) throws IOException {
|
||||
if (len < 0) {
|
||||
throw new IllegalArgumentException("len < 0");
|
||||
}
|
||||
|
||||
List<byte[]> bufs = null;
|
||||
byte[] result = null;
|
||||
int total = 0;
|
||||
int remaining = len;
|
||||
int n;
|
||||
do {
|
||||
byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
|
||||
byte[] buf = new byte[Math.min(remaining, DEFAULT_BUFFER_SIZE)];
|
||||
int nread = 0;
|
||||
|
||||
// read to EOF which may read more or less than buffer size
|
||||
while ((n = read(buf, nread, buf.length - nread)) > 0) {
|
||||
while ((n = read(buf, nread,
|
||||
Math.min(buf.length - nread, remaining))) > 0) {
|
||||
nread += n;
|
||||
remaining -= n;
|
||||
}
|
||||
|
||||
if (nread > 0) {
|
||||
|
@ -345,7 +414,9 @@ public abstract class InputStream implements Closeable {
|
|||
bufs.add(buf);
|
||||
}
|
||||
}
|
||||
} while (n >= 0); // if the last call to read returned -1, then break
|
||||
// if the last call to read returned -1 or the number of bytes
|
||||
// requested have been read then break
|
||||
} while (n >= 0 && remaining > 0);
|
||||
|
||||
if (bufs == null) {
|
||||
if (result == null) {
|
||||
|
@ -357,12 +428,12 @@ public abstract class InputStream implements Closeable {
|
|||
|
||||
result = new byte[total];
|
||||
int offset = 0;
|
||||
int remaining = total;
|
||||
remaining = total;
|
||||
for (byte[] b : bufs) {
|
||||
int len = Math.min(b.length, remaining);
|
||||
System.arraycopy(b, 0, result, offset, len);
|
||||
offset += len;
|
||||
remaining -= len;
|
||||
int count = Math.min(b.length, remaining);
|
||||
System.arraycopy(b, 0, result, offset, count);
|
||||
offset += count;
|
||||
remaining -= count;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2018, 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
|
||||
|
@ -534,7 +534,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ get(ByteBufferHandle handle, Object obb, int index) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
#if[floatingPoint]
|
||||
$rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -551,7 +551,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static void set(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
#if[floatingPoint]
|
||||
UNSAFE.put$RawType$Unaligned(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -569,7 +569,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getVolatile(ByteBufferHandle handle, Object obb, int index) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.get$RawType$Volatile(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -578,7 +578,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static void setVolatile(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
UNSAFE.put$RawType$Volatile(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -587,7 +587,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAcquire(ByteBufferHandle handle, Object obb, int index) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.get$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -596,7 +596,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static void setRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
UNSAFE.put$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -605,7 +605,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getOpaque(ByteBufferHandle handle, Object obb, int index) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.get$RawType$Opaque(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -614,7 +614,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static void setOpaque(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
UNSAFE.put$RawType$Opaque(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -624,7 +624,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static boolean compareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return UNSAFE.compareAndSet$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -633,7 +633,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ compareAndExchange(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.compareAndExchange$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -643,7 +643,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ compareAndExchangeAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.compareAndExchange$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -653,7 +653,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ compareAndExchangeRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.compareAndExchange$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -663,7 +663,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static boolean weakCompareAndSetPlain(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return UNSAFE.weakCompareAndSet$RawType$Plain(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -672,7 +672,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static boolean weakCompareAndSet(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return UNSAFE.weakCompareAndSet$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -681,7 +681,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static boolean weakCompareAndSetAcquire(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return UNSAFE.weakCompareAndSet$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -690,7 +690,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static boolean weakCompareAndSetRelease(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return UNSAFE.weakCompareAndSet$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
address(bb, indexRO(bb, index)),
|
||||
|
@ -699,7 +699,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndSet(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.getAndSet$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -709,7 +709,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndSetAcquire(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.getAndSet$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -719,7 +719,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndSetRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
return convEndian(handle.be,
|
||||
UNSAFE.getAndSet$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -731,7 +731,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndAdd(ByteBufferHandle handle, Object obb, int index, $type$ delta) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndAdd$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -744,7 +744,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndAddAcquire(ByteBufferHandle handle, Object obb, int index, $type$ delta) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndAdd$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -757,7 +757,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndAddRelease(ByteBufferHandle handle, Object obb, int index, $type$ delta) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndAdd$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -785,7 +785,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseOr(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseOr$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -798,7 +798,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseOrRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseOr$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -811,7 +811,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseOrAcquire(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseOr$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -837,7 +837,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseAnd(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseAnd$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -850,7 +850,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseAndRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseAnd$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -863,7 +863,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseAndAcquire(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseAnd$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -890,7 +890,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseXor(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseXor$RawType$(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -903,7 +903,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseXorRelease(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseXor$RawType$Release(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
@ -916,7 +916,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
|||
|
||||
@ForceInline
|
||||
static $type$ getAndBitwiseXorAcquire(ByteBufferHandle handle, Object obb, int index, $type$ value) {
|
||||
ByteBuffer bb = (ByteBuffer) obb;
|
||||
ByteBuffer bb = (ByteBuffer) Objects.requireNonNull(obb);
|
||||
if (handle.be == BE) {
|
||||
return UNSAFE.getAndBitwiseXor$RawType$Acquire(
|
||||
UNSAFE.getObject(bb, BYTE_BUFFER_HB),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2018, 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
|
||||
|
@ -26,11 +26,11 @@ package java.net;
|
|||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import sun.net.ResourceManager;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import sun.net.ResourceManager;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
|
@ -115,6 +115,7 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||
fd = new FileDescriptor();
|
||||
try {
|
||||
datagramSocketCreate();
|
||||
SocketCleanable.register(fd);
|
||||
} catch (SocketException ioe) {
|
||||
ResourceManager.afterUdpClose();
|
||||
fd = null;
|
||||
|
@ -265,6 +266,7 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||
*/
|
||||
protected void close() {
|
||||
if (fd != null) {
|
||||
SocketCleanable.unregister(fd);
|
||||
datagramSocketClose();
|
||||
ResourceManager.afterUdpClose();
|
||||
fd = null;
|
||||
|
@ -275,11 +277,6 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||
return (fd == null) ? true : false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void finalize() {
|
||||
close();
|
||||
}
|
||||
|
||||
/**
|
||||
* set a value - since we only support (setting) binary options
|
||||
* here, o must be a Boolean
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2018, 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
|
||||
|
@ -25,17 +25,18 @@
|
|||
|
||||
package java.net;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileDescriptor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import sun.net.ConnectionResetException;
|
||||
import sun.net.NetHooks;
|
||||
import sun.net.ResourceManager;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Default Socket Implementation. This implementation does
|
||||
|
@ -136,6 +137,7 @@ abstract class AbstractPlainSocketImpl extends SocketImpl
|
|||
fd = new FileDescriptor();
|
||||
try {
|
||||
socketCreate(false);
|
||||
SocketCleanable.register(fd);
|
||||
} catch (IOException ioe) {
|
||||
ResourceManager.afterUdpClose();
|
||||
fd = null;
|
||||
|
@ -144,6 +146,7 @@ abstract class AbstractPlainSocketImpl extends SocketImpl
|
|||
} else {
|
||||
fd = new FileDescriptor();
|
||||
socketCreate(true);
|
||||
SocketCleanable.register(fd);
|
||||
}
|
||||
if (socket != null)
|
||||
socket.setCreated();
|
||||
|
@ -643,14 +646,6 @@ abstract class AbstractPlainSocketImpl extends SocketImpl
|
|||
socketSendUrgentData (data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up if the user forgets to close it.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void finalize() throws IOException {
|
||||
close();
|
||||
}
|
||||
|
||||
/*
|
||||
* "Acquires" and returns the FileDescriptor for this impl
|
||||
*
|
||||
|
@ -748,6 +743,7 @@ abstract class AbstractPlainSocketImpl extends SocketImpl
|
|||
* Close the socket (and release the file descriptor).
|
||||
*/
|
||||
protected void socketClose() throws IOException {
|
||||
SocketCleanable.unregister(fd);
|
||||
socketClose0(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2018, 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
|
||||
|
@ -549,6 +549,7 @@ class ServerSocket implements java.io.Closeable {
|
|||
si.address = new InetAddress();
|
||||
si.fd = new FileDescriptor();
|
||||
getImpl().accept(si);
|
||||
SocketCleanable.register(si.fd); // raw fd has been set
|
||||
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
|
|
107
src/java.base/share/classes/java/net/SocketCleanable.java
Normal file
107
src/java.base/share/classes/java/net/SocketCleanable.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 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
|
||||
* questions.
|
||||
*/
|
||||
package java.net;
|
||||
|
||||
import jdk.internal.misc.JavaIOFileDescriptorAccess;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.ref.CleanerFactory;
|
||||
import jdk.internal.ref.PhantomCleanable;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.ref.Cleaner;
|
||||
|
||||
|
||||
/**
|
||||
* Cleanup for a socket/datagramsocket FileDescriptor when it becomes phantom reachable.
|
||||
* Create a cleanup if the raw fd != -1. Windows closes sockets using the fd.
|
||||
* Subclassed from {@code PhantomCleanable} so that {@code clear} can be
|
||||
* called to disable the cleanup when the socket fd is closed by any means
|
||||
* other than calling {@link FileDescriptor#close}.
|
||||
* Otherwise, it would incorrectly close the handle or fd after it has been reused.
|
||||
*/
|
||||
final class SocketCleanable extends PhantomCleanable<Object> {
|
||||
|
||||
// Access to FileDescriptor internals
|
||||
private static final JavaIOFileDescriptorAccess fdAccess =
|
||||
SharedSecrets.getJavaIOFileDescriptorAccess();
|
||||
|
||||
// Native function to call NET_SocketClose(fd)
|
||||
private static native void cleanupClose0(int fd) throws IOException;
|
||||
|
||||
// The raw fd to close
|
||||
private final int fd;
|
||||
|
||||
/**
|
||||
* Register a socket specific Cleanable with the FileDescriptor
|
||||
* if the FileDescriptor is non-null and the raw fd is != -1.
|
||||
*
|
||||
* @param fdo the FileDescriptor; may be null
|
||||
*/
|
||||
static void register(FileDescriptor fdo) {
|
||||
if (fdo != null) {
|
||||
int fd = fdAccess.get(fdo);
|
||||
if (fd != -1) {
|
||||
fdAccess.registerCleanup(fdo,
|
||||
new SocketCleanable(fdo, CleanerFactory.cleaner(), fd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a Cleanable from the FileDescriptor.
|
||||
* @param fdo the FileDescriptor; may be null
|
||||
*/
|
||||
static void unregister(FileDescriptor fdo) {
|
||||
if (fdo != null) {
|
||||
fdAccess.unregisterCleanup(fdo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a phantom cleanable reference.
|
||||
*
|
||||
* @param obj the object to monitor
|
||||
* @param cleaner the cleaner
|
||||
* @param fd file descriptor to close
|
||||
*/
|
||||
private SocketCleanable(Object obj, Cleaner cleaner, int fd) {
|
||||
super(obj, cleaner);
|
||||
this.fd = fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the native handle or fd.
|
||||
*/
|
||||
@Override
|
||||
protected void performCleanup() {
|
||||
try {
|
||||
cleanupClose0(fd);
|
||||
} catch (IOException ioe) {
|
||||
throw new UncheckedIOException("close", ioe);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2018, 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
|
||||
|
@ -1802,11 +1802,11 @@ public class KeyStore {
|
|||
|
||||
// Load the keystore data
|
||||
if (keystore != null) {
|
||||
dataStream.reset(); // prepare the stream for loading
|
||||
if (hasPassword) {
|
||||
dataStream.reset(); // prepare the stream for loading
|
||||
keystore.load(dataStream, password);
|
||||
} else {
|
||||
keystore.load(param);
|
||||
keystore.keyStoreSpi.engineLoad(dataStream, param);
|
||||
}
|
||||
return keystore;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2018, 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
|
||||
|
@ -395,6 +395,12 @@ public abstract class KeyStoreSpi {
|
|||
public void engineLoad(KeyStore.LoadStoreParameter param)
|
||||
throws IOException, NoSuchAlgorithmException,
|
||||
CertificateException {
|
||||
engineLoad(null, param);
|
||||
}
|
||||
|
||||
void engineLoad(InputStream stream, KeyStore.LoadStoreParameter param)
|
||||
throws IOException, NoSuchAlgorithmException,
|
||||
CertificateException {
|
||||
|
||||
if (param == null) {
|
||||
engineLoad((InputStream)null, (char[])null);
|
||||
|
@ -425,7 +431,7 @@ public abstract class KeyStoreSpi {
|
|||
throw new NoSuchAlgorithmException("ProtectionParameter must"
|
||||
+ " be PasswordProtection or CallbackHandlerProtection");
|
||||
}
|
||||
engineLoad(null, password);
|
||||
engineLoad(stream, password);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -610,7 +610,7 @@ public final class Instant
|
|||
* <p>
|
||||
* The epoch second count is a simple incrementing count of seconds where
|
||||
* second 0 is 1970-01-01T00:00:00Z.
|
||||
* The nanosecond part of the day is returned by {@link #getNano}.
|
||||
* The nanosecond part is returned by {@link #getNano}.
|
||||
*
|
||||
* @return the seconds from the epoch of 1970-01-01T00:00:00Z
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2018, 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
|
||||
|
@ -411,7 +411,7 @@ class ZoneName {
|
|||
"Pacific/Wake", "Wake", "Pacific/Wake",
|
||||
"Pacific/Pago_Pago", "Samoa", "Pacific/Apia",
|
||||
"America/Moncton", "Atlantic", "America/Halifax",
|
||||
"Africa/Sao_Tome", "GMT", "Atlantic/Reykjavik",
|
||||
"Africa/Sao_Tome", "Africa_Western", "Africa/Lagos",
|
||||
"America/Glace_Bay", "Atlantic", "America/Halifax",
|
||||
"Asia/Jakarta", "Indonesia_Western", "Asia/Jakarta",
|
||||
"Africa/Asmera", "Africa_Eastern", "Africa/Nairobi",
|
||||
|
@ -494,7 +494,6 @@ class ZoneName {
|
|||
"America/Kralendijk", "Atlantic", "America/Halifax",
|
||||
};
|
||||
private static final String[] mzoneMap = new String[] {
|
||||
"GMT", "ST", "Africa/Sao_Tome",
|
||||
"GMT", "ML", "Africa/Bamako",
|
||||
"GMT", "IE", "Europe/Dublin",
|
||||
"GMT", "SN", "Africa/Dakar",
|
||||
|
@ -509,6 +508,7 @@ class ZoneName {
|
|||
"GMT", "GB", "Europe/London",
|
||||
"GMT", "LR", "Africa/Monrovia",
|
||||
"GMT", "TG", "Africa/Lome",
|
||||
"Africa_Western", "ST", "Africa/Sao_Tome",
|
||||
"Africa_Western", "CF", "Africa/Bangui",
|
||||
"Africa_Western", "NE", "Africa/Niamey",
|
||||
"Africa_Western", "CM", "Africa/Douala",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue