mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
Merge
This commit is contained in:
commit
845f7823de
1200 changed files with 35255 additions and 79887 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 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
|
||||
|
@ -136,7 +136,7 @@ abstract class AsynchronousFileChannelImpl
|
|||
if (fileLockTable == null) {
|
||||
synchronized (this) {
|
||||
if (fileLockTable == null) {
|
||||
fileLockTable = FileLockTable.newSharedFileLockTable(this, fdObj);
|
||||
fileLockTable = new FileLockTable(this, fdObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 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
|
||||
|
@ -27,11 +27,32 @@ package sun.nio.ch;
|
|||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.PortUnreachableException;
|
||||
import java.net.ProtocolFamily;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketOption;
|
||||
import java.net.StandardProtocolFamily;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.channels.spi.*;
|
||||
import java.util.*;
|
||||
import java.nio.channels.AlreadyBoundException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import java.nio.channels.MembershipKey;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.UnsupportedAddressTypeException;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import sun.net.ResourceManager;
|
||||
import sun.net.ext.ExtendedSocketOptions;
|
||||
|
||||
|
@ -49,9 +70,6 @@ class DatagramChannelImpl
|
|||
|
||||
// Our file descriptor
|
||||
private final FileDescriptor fd;
|
||||
|
||||
// fd value needed for dev/poll. This value will remain valid
|
||||
// even after the value in the file descriptor object has been set to -1
|
||||
private final int fdVal;
|
||||
|
||||
// The protocol family of the socket
|
||||
|
@ -67,10 +85,10 @@ class DatagramChannelImpl
|
|||
private int cachedSenderPort;
|
||||
|
||||
// Lock held by current reading or connecting thread
|
||||
private final Object readLock = new Object();
|
||||
private final ReentrantLock readLock = new ReentrantLock();
|
||||
|
||||
// Lock held by current writing or connecting thread
|
||||
private final Object writeLock = new Object();
|
||||
private final ReentrantLock writeLock = new ReentrantLock();
|
||||
|
||||
// Lock held by any thread that modifies the state fields declared below
|
||||
// DO NOT invoke a blocking I/O operation while holding this lock!
|
||||
|
@ -103,7 +121,6 @@ class DatagramChannelImpl
|
|||
|
||||
// -- End of fields protected by stateLock
|
||||
|
||||
|
||||
public DatagramChannelImpl(SelectorProvider sp)
|
||||
throws IOException
|
||||
{
|
||||
|
@ -138,16 +155,27 @@ class DatagramChannelImpl
|
|||
throw new UnsupportedOperationException("IPv6 not available");
|
||||
}
|
||||
}
|
||||
this.family = family;
|
||||
this.fd = Net.socket(family, false);
|
||||
this.fdVal = IOUtil.fdVal(fd);
|
||||
this.state = ST_UNCONNECTED;
|
||||
|
||||
ResourceManager.beforeUdpCreate();
|
||||
try {
|
||||
this.family = family;
|
||||
this.fd = Net.socket(family, false);
|
||||
this.fdVal = IOUtil.fdVal(fd);
|
||||
this.state = ST_UNCONNECTED;
|
||||
} catch (IOException ioe) {
|
||||
ResourceManager.afterUdpClose();
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
|
||||
public DatagramChannelImpl(SelectorProvider sp, FileDescriptor fd)
|
||||
throws IOException
|
||||
{
|
||||
super(sp);
|
||||
|
||||
// increment UDP count to match decrement when closing
|
||||
ResourceManager.beforeUdpCreate();
|
||||
|
||||
this.family = Net.isIPv6Available() ?
|
||||
StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
|
||||
this.fd = fd;
|
||||
|
@ -328,7 +356,8 @@ class DatagramChannelImpl
|
|||
public SocketAddress receive(ByteBuffer dst) throws IOException {
|
||||
if (dst.isReadOnly())
|
||||
throw new IllegalArgumentException("Read-only buffer");
|
||||
synchronized (readLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
ensureOpen();
|
||||
// Socket was not bound before attempting receive
|
||||
if (localAddress() == null)
|
||||
|
@ -348,6 +377,8 @@ class DatagramChannelImpl
|
|||
if (n == IOStatus.UNAVAILABLE)
|
||||
return null;
|
||||
} else {
|
||||
// Cannot receive into user's buffer when running with a
|
||||
// security manager and not connected
|
||||
bb = Util.getTemporaryDirectBuffer(dst.remaining());
|
||||
for (;;) {
|
||||
do {
|
||||
|
@ -379,6 +410,8 @@ class DatagramChannelImpl
|
|||
end((n > 0) || (n == IOStatus.UNAVAILABLE));
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,7 +458,8 @@ class DatagramChannelImpl
|
|||
if (src == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
synchronized (writeLock) {
|
||||
writeLock.lock();
|
||||
try {
|
||||
ensureOpen();
|
||||
InetSocketAddress isa = Net.checkAddress(target);
|
||||
InetAddress ia = isa.getAddress();
|
||||
|
@ -474,6 +508,8 @@ class DatagramChannelImpl
|
|||
end((n > 0) || (n == IOStatus.UNAVAILABLE));
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -534,7 +570,8 @@ class DatagramChannelImpl
|
|||
public int read(ByteBuffer buf) throws IOException {
|
||||
if (buf == null)
|
||||
throw new NullPointerException();
|
||||
synchronized (readLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
ensureOpen();
|
||||
if (!isConnected())
|
||||
|
@ -555,6 +592,8 @@ class DatagramChannelImpl
|
|||
end((n > 0) || (n == IOStatus.UNAVAILABLE));
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -563,7 +602,8 @@ class DatagramChannelImpl
|
|||
{
|
||||
if ((offset < 0) || (length < 0) || (offset > dsts.length - length))
|
||||
throw new IndexOutOfBoundsException();
|
||||
synchronized (readLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
ensureOpen();
|
||||
if (!isConnected())
|
||||
|
@ -584,13 +624,16 @@ class DatagramChannelImpl
|
|||
end((n > 0) || (n == IOStatus.UNAVAILABLE));
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int write(ByteBuffer buf) throws IOException {
|
||||
if (buf == null)
|
||||
throw new NullPointerException();
|
||||
synchronized (writeLock) {
|
||||
writeLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
ensureOpen();
|
||||
if (!isConnected())
|
||||
|
@ -611,6 +654,8 @@ class DatagramChannelImpl
|
|||
end((n > 0) || (n == IOStatus.UNAVAILABLE));
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -619,7 +664,8 @@ class DatagramChannelImpl
|
|||
{
|
||||
if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
|
||||
throw new IndexOutOfBoundsException();
|
||||
synchronized (writeLock) {
|
||||
writeLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
ensureOpen();
|
||||
if (!isConnected())
|
||||
|
@ -640,6 +686,8 @@ class DatagramChannelImpl
|
|||
end((n > 0) || (n == IOStatus.UNAVAILABLE));
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -661,8 +709,10 @@ class DatagramChannelImpl
|
|||
|
||||
@Override
|
||||
public DatagramChannel bind(SocketAddress local) throws IOException {
|
||||
synchronized (readLock) {
|
||||
synchronized (writeLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
writeLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
ensureOpen();
|
||||
if (localAddress != null)
|
||||
|
@ -692,7 +742,11 @@ class DatagramChannelImpl
|
|||
Net.bind(family, fd, isa.getAddress(), isa.getPort());
|
||||
localAddress = Net.localAddress(fd);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -714,8 +768,10 @@ class DatagramChannelImpl
|
|||
|
||||
@Override
|
||||
public DatagramChannel connect(SocketAddress sa) throws IOException {
|
||||
synchronized(readLock) {
|
||||
synchronized(writeLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
writeLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
ensureOpenAndUnconnected();
|
||||
InetSocketAddress isa = Net.checkAddress(sa);
|
||||
|
@ -741,10 +797,9 @@ class DatagramChannelImpl
|
|||
localAddress = Net.localAddress(fd);
|
||||
|
||||
// flush any packets already received.
|
||||
boolean blocking = false;
|
||||
synchronized (blockingLock()) {
|
||||
boolean blocking = isBlocking();
|
||||
try {
|
||||
blocking = isBlocking();
|
||||
ByteBuffer tmpBuf = ByteBuffer.allocate(100);
|
||||
if (blocking) {
|
||||
configureBlocking(false);
|
||||
|
@ -759,14 +814,20 @@ class DatagramChannelImpl
|
|||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatagramChannel disconnect() throws IOException {
|
||||
synchronized(readLock) {
|
||||
synchronized(writeLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
writeLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
if (!isConnected() || !isOpen())
|
||||
return this;
|
||||
|
@ -783,7 +844,11 @@ class DatagramChannelImpl
|
|||
// refresh local address
|
||||
localAddress = Net.localAddress(fd);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1087,7 +1152,8 @@ class DatagramChannelImpl
|
|||
int poll(int events, long timeout) throws IOException {
|
||||
assert Thread.holdsLock(blockingLock()) && !isBlocking();
|
||||
|
||||
synchronized (readLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
int n = 0;
|
||||
try {
|
||||
begin();
|
||||
|
@ -1102,6 +1168,8 @@ class DatagramChannelImpl
|
|||
end(n > 0);
|
||||
}
|
||||
return n;
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 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,10 +25,22 @@
|
|||
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.DatagramSocketImpl;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketOption;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
|
||||
|
||||
// Make a datagram-socket channel look like a datagram socket.
|
||||
|
@ -178,7 +190,6 @@ public class DatagramSocketAdaptor
|
|||
|
||||
dc.configureBlocking(false);
|
||||
try {
|
||||
int n;
|
||||
SocketAddress sender;
|
||||
if ((sender = dc.receive(bb)) != null)
|
||||
return sender;
|
||||
|
@ -188,19 +199,18 @@ public class DatagramSocketAdaptor
|
|||
throw new ClosedChannelException();
|
||||
long st = System.currentTimeMillis();
|
||||
int result = dc.poll(Net.POLLIN, to);
|
||||
if (result > 0 &&
|
||||
((result & Net.POLLIN) != 0)) {
|
||||
if (result > 0 && ((result & Net.POLLIN) != 0)) {
|
||||
if ((sender = dc.receive(bb)) != null)
|
||||
return sender;
|
||||
}
|
||||
to -= System.currentTimeMillis() - st;
|
||||
if (to <= 0)
|
||||
throw new SocketTimeoutException();
|
||||
|
||||
}
|
||||
} finally {
|
||||
if (dc.isOpen())
|
||||
try {
|
||||
dc.configureBlocking(true);
|
||||
} catch (ClosedChannelException e) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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
|
||||
|
@ -1083,49 +1083,19 @@ public class FileChannelImpl
|
|||
|
||||
// -- Locks --
|
||||
|
||||
|
||||
|
||||
// keeps track of locks on this file
|
||||
private volatile FileLockTable fileLockTable;
|
||||
|
||||
// indicates if file locks are maintained system-wide (as per spec)
|
||||
private static boolean isSharedFileLockTable;
|
||||
|
||||
// indicates if the disableSystemWideOverlappingFileLockCheck property
|
||||
// has been checked
|
||||
private static volatile boolean propertyChecked;
|
||||
|
||||
// The lock list in J2SE 1.4/5.0 was local to each FileChannel instance so
|
||||
// the overlap check wasn't system wide when there were multiple channels to
|
||||
// the same file. This property is used to get 1.4/5.0 behavior if desired.
|
||||
private static boolean isSharedFileLockTable() {
|
||||
if (!propertyChecked) {
|
||||
synchronized (FileChannelImpl.class) {
|
||||
if (!propertyChecked) {
|
||||
String value = GetPropertyAction.privilegedGetProperty(
|
||||
"sun.nio.ch.disableSystemWideOverlappingFileLockCheck");
|
||||
isSharedFileLockTable = ((value == null) || value.equals("false"));
|
||||
propertyChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isSharedFileLockTable;
|
||||
}
|
||||
|
||||
private FileLockTable fileLockTable() throws IOException {
|
||||
if (fileLockTable == null) {
|
||||
synchronized (this) {
|
||||
if (fileLockTable == null) {
|
||||
if (isSharedFileLockTable()) {
|
||||
int ti = threads.add();
|
||||
try {
|
||||
ensureOpen();
|
||||
fileLockTable = FileLockTable.newSharedFileLockTable(this, fd);
|
||||
} finally {
|
||||
threads.remove(ti);
|
||||
}
|
||||
} else {
|
||||
fileLockTable = new SimpleFileLockTable();
|
||||
int ti = threads.add();
|
||||
try {
|
||||
ensureOpen();
|
||||
fileLockTable = new FileLockTable(this, fd);
|
||||
} finally {
|
||||
threads.remove(ti);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1229,59 +1199,6 @@ public class FileChannelImpl
|
|||
fileLockTable.remove(fli);
|
||||
}
|
||||
|
||||
// -- File lock support --
|
||||
|
||||
/**
|
||||
* A simple file lock table that maintains a list of FileLocks obtained by a
|
||||
* FileChannel. Use to get 1.4/5.0 behaviour.
|
||||
*/
|
||||
private static class SimpleFileLockTable extends FileLockTable {
|
||||
// synchronize on list for access
|
||||
private final List<FileLock> lockList = new ArrayList<FileLock>(2);
|
||||
|
||||
public SimpleFileLockTable() {
|
||||
}
|
||||
|
||||
private void checkList(long position, long size)
|
||||
throws OverlappingFileLockException
|
||||
{
|
||||
assert Thread.holdsLock(lockList);
|
||||
for (FileLock fl: lockList) {
|
||||
if (fl.overlaps(position, size)) {
|
||||
throw new OverlappingFileLockException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void add(FileLock fl) throws OverlappingFileLockException {
|
||||
synchronized (lockList) {
|
||||
checkList(fl.position(), fl.size());
|
||||
lockList.add(fl);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(FileLock fl) {
|
||||
synchronized (lockList) {
|
||||
lockList.remove(fl);
|
||||
}
|
||||
}
|
||||
|
||||
public List<FileLock> removeAll() {
|
||||
synchronized(lockList) {
|
||||
List<FileLock> result = new ArrayList<FileLock>(lockList);
|
||||
lockList.clear();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void replace(FileLock fl1, FileLock fl2) {
|
||||
synchronized (lockList) {
|
||||
lockList.remove(fl1);
|
||||
lockList.add(fl2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -- Native methods --
|
||||
|
||||
// Creates a new mapping
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 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,64 +25,27 @@
|
|||
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.nio.channels.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.lang.ref.*;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
|
||||
abstract class FileLockTable {
|
||||
protected FileLockTable() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a file lock table for a channel that is connected to
|
||||
* the a system-wide map of all file locks for the Java virtual machine.
|
||||
*/
|
||||
public static FileLockTable newSharedFileLockTable(Channel channel,
|
||||
FileDescriptor fd)
|
||||
throws IOException
|
||||
{
|
||||
return new SharedFileLockTable(channel, fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file lock to the table.
|
||||
*
|
||||
* @throws OverlappingFileLockException if the file lock overlaps
|
||||
* with an existing file lock in the table
|
||||
*/
|
||||
public abstract void add(FileLock fl) throws OverlappingFileLockException;
|
||||
|
||||
/**
|
||||
* Remove an existing file lock from the table.
|
||||
*/
|
||||
public abstract void remove(FileLock fl);
|
||||
|
||||
/**
|
||||
* Removes all file locks from the table.
|
||||
*
|
||||
* @return The list of file locks removed
|
||||
*/
|
||||
public abstract List<FileLock> removeAll();
|
||||
|
||||
/**
|
||||
* Replaces an existing file lock in the table.
|
||||
*/
|
||||
public abstract void replace(FileLock fl1, FileLock fl2);
|
||||
}
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.channels.Channel;
|
||||
import java.nio.channels.FileLock;
|
||||
import java.nio.channels.OverlappingFileLockException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* A file lock table that is over a system-wide map of all file locks.
|
||||
*/
|
||||
class SharedFileLockTable extends FileLockTable {
|
||||
|
||||
class FileLockTable {
|
||||
/**
|
||||
* A weak reference to a FileLock.
|
||||
* <p>
|
||||
* SharedFileLockTable uses a list of file lock references to avoid keeping the
|
||||
* FileLockTable uses a list of file lock references to avoid keeping the
|
||||
* FileLock (and FileChannel) alive.
|
||||
*/
|
||||
private static class FileLockReference extends WeakReference<FileLock> {
|
||||
|
@ -115,13 +78,20 @@ class SharedFileLockTable extends FileLockTable {
|
|||
// File key for the file that this channel is connected to
|
||||
private final FileKey fileKey;
|
||||
|
||||
SharedFileLockTable(Channel channel, FileDescriptor fd) throws IOException {
|
||||
// Locks obtained for this channel
|
||||
private final Set<FileLock> locks;
|
||||
|
||||
/**
|
||||
* Creates a file lock table for a channel that is connected to the
|
||||
* system-wide map of all file locks for the Java virtual machine.
|
||||
*/
|
||||
FileLockTable(Channel channel, FileDescriptor fd) throws IOException {
|
||||
this.channel = channel;
|
||||
this.fileKey = FileKey.create(fd);
|
||||
this.locks = new HashSet<FileLock>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(FileLock fl) throws OverlappingFileLockException {
|
||||
void add(FileLock fl) throws OverlappingFileLockException {
|
||||
List<FileLockReference> list = lockMap.get(fileKey);
|
||||
|
||||
for (;;) {
|
||||
|
@ -135,6 +105,7 @@ class SharedFileLockTable extends FileLockTable {
|
|||
if (prev == null) {
|
||||
// we successfully created the key so we add the file lock
|
||||
list.add(new FileLockReference(fl, queue, fileKey));
|
||||
locks.add(fl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -151,6 +122,7 @@ class SharedFileLockTable extends FileLockTable {
|
|||
if (list == current) {
|
||||
checkList(list, fl.position(), fl.size());
|
||||
list.add(new FileLockReference(fl, queue, fileKey));
|
||||
locks.add(fl);
|
||||
break;
|
||||
}
|
||||
list = current;
|
||||
|
@ -170,8 +142,7 @@ class SharedFileLockTable extends FileLockTable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(FileLock fl) {
|
||||
void remove(FileLock fl) {
|
||||
assert fl != null;
|
||||
|
||||
// the lock must exist so the list of locks must be present
|
||||
|
@ -187,6 +158,7 @@ class SharedFileLockTable extends FileLockTable {
|
|||
assert (lock != null) && (lock.acquiredBy() == channel);
|
||||
ref.clear();
|
||||
list.remove(index);
|
||||
locks.remove(fl);
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
|
@ -194,8 +166,7 @@ class SharedFileLockTable extends FileLockTable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileLock> removeAll() {
|
||||
List<FileLock> removeAll() {
|
||||
List<FileLock> result = new ArrayList<FileLock>();
|
||||
List<FileLockReference> list = lockMap.get(fileKey);
|
||||
if (list != null) {
|
||||
|
@ -220,13 +191,14 @@ class SharedFileLockTable extends FileLockTable {
|
|||
|
||||
// once the lock list is empty we remove it from the map
|
||||
removeKeyIfEmpty(fileKey, list);
|
||||
|
||||
locks.clear();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(FileLock fromLock, FileLock toLock) {
|
||||
void replace(FileLock fromLock, FileLock toLock) {
|
||||
// the lock must exist so there must be a list
|
||||
List<FileLockReference> list = lockMap.get(fileKey);
|
||||
assert list != null;
|
||||
|
@ -238,6 +210,8 @@ class SharedFileLockTable extends FileLockTable {
|
|||
if (lock == fromLock) {
|
||||
ref.clear();
|
||||
list.set(index, new FileLockReference(toLock, queue, fileKey));
|
||||
locks.remove(fromLock);
|
||||
locks.add(toLock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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
|
||||
|
@ -78,7 +78,7 @@ public class IOUtil {
|
|||
src.position(pos);
|
||||
|
||||
int n = writeFromNativeBuffer(fd, bb, position,
|
||||
directIO, alignment, nd);
|
||||
directIO, alignment, nd);
|
||||
if (n > 0) {
|
||||
// now update src
|
||||
src.position(pos + n);
|
||||
|
@ -161,8 +161,7 @@ public class IOUtil {
|
|||
if (!(buf instanceof DirectBuffer)) {
|
||||
ByteBuffer shadow;
|
||||
if (directIO)
|
||||
shadow = Util.getTemporaryAlignedDirectBuffer(rem,
|
||||
alignment);
|
||||
shadow = Util.getTemporaryAlignedDirectBuffer(rem, alignment);
|
||||
else
|
||||
shadow = Util.getTemporaryDirectBuffer(rem);
|
||||
shadow.put(buf);
|
||||
|
@ -241,8 +240,7 @@ public class IOUtil {
|
|||
int rem = dst.remaining();
|
||||
if (directIO) {
|
||||
Util.checkRemainingBufferSizeAligned(rem, alignment);
|
||||
bb = Util.getTemporaryAlignedDirectBuffer(rem,
|
||||
alignment);
|
||||
bb = Util.getTemporaryAlignedDirectBuffer(rem, alignment);
|
||||
} else {
|
||||
bb = Util.getTemporaryDirectBuffer(rem);
|
||||
}
|
||||
|
@ -277,8 +275,7 @@ public class IOUtil {
|
|||
return 0;
|
||||
int n = 0;
|
||||
if (position != -1) {
|
||||
n = nd.pread(fd, ((DirectBuffer)bb).address() + pos,
|
||||
rem, position);
|
||||
n = nd.pread(fd, ((DirectBuffer)bb).address() + pos, rem, position);
|
||||
} else {
|
||||
n = nd.read(fd, ((DirectBuffer)bb).address() + pos, rem);
|
||||
}
|
||||
|
@ -332,8 +329,7 @@ public class IOUtil {
|
|||
if (!(buf instanceof DirectBuffer)) {
|
||||
ByteBuffer shadow;
|
||||
if (directIO) {
|
||||
shadow = Util.getTemporaryAlignedDirectBuffer(rem,
|
||||
alignment);
|
||||
shadow = Util.getTemporaryAlignedDirectBuffer(rem, alignment);
|
||||
} else {
|
||||
shadow = Util.getTemporaryDirectBuffer(rem);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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,9 +25,20 @@
|
|||
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.channels.*;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
import java.nio.channels.NotYetBoundException;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
|
||||
// Make a server-socket channel look like a server socket.
|
||||
|
@ -37,7 +48,7 @@ import java.nio.channels.*;
|
|||
// class.
|
||||
//
|
||||
|
||||
public class ServerSocketAdaptor // package-private
|
||||
class ServerSocketAdaptor // package-private
|
||||
extends ServerSocket
|
||||
{
|
||||
|
||||
|
@ -96,13 +107,18 @@ public class ServerSocketAdaptor // package-private
|
|||
try {
|
||||
if (!ssc.isBound())
|
||||
throw new NotYetBoundException();
|
||||
|
||||
if (timeout == 0) {
|
||||
// for compatibility reasons: accept connection if available
|
||||
// when configured non-blocking
|
||||
SocketChannel sc = ssc.accept();
|
||||
if (sc == null && !ssc.isBlocking())
|
||||
throw new IllegalBlockingModeException();
|
||||
return sc.socket();
|
||||
}
|
||||
|
||||
if (!ssc.isBlocking())
|
||||
throw new IllegalBlockingModeException();
|
||||
ssc.configureBlocking(false);
|
||||
try {
|
||||
SocketChannel sc;
|
||||
|
@ -121,10 +137,10 @@ public class ServerSocketAdaptor // package-private
|
|||
throw new SocketTimeoutException();
|
||||
}
|
||||
} finally {
|
||||
if (ssc.isOpen())
|
||||
try {
|
||||
ssc.configureBlocking(true);
|
||||
} catch (ClosedChannelException e) { }
|
||||
}
|
||||
|
||||
} catch (Exception x) {
|
||||
Net.translateException(x);
|
||||
assert false;
|
||||
|
@ -178,8 +194,7 @@ public class ServerSocketAdaptor // package-private
|
|||
if (!isBound())
|
||||
return "ServerSocket[unbound]";
|
||||
return "ServerSocket[addr=" + getInetAddress() +
|
||||
// ",port=" + getPort() +
|
||||
",localport=" + getLocalPort() + "]";
|
||||
",localport=" + getLocalPort() + "]";
|
||||
}
|
||||
|
||||
public void setReceiveBufferSize(int size) throws SocketException {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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
|
||||
|
@ -27,10 +27,25 @@ package sun.nio.ch;
|
|||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.channels.spi.*;
|
||||
import java.util.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ProtocolFamily;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketOption;
|
||||
import java.net.StandardProtocolFamily;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.nio.channels.AlreadyBoundException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.NotYetBoundException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import sun.net.NetHooks;
|
||||
|
||||
/**
|
||||
|
@ -47,16 +62,13 @@ class ServerSocketChannelImpl
|
|||
|
||||
// Our file descriptor
|
||||
private final FileDescriptor fd;
|
||||
|
||||
// fd value needed for dev/poll. This value will remain valid
|
||||
// even after the value in the file descriptor object has been set to -1
|
||||
private int fdVal;
|
||||
private final int fdVal;
|
||||
|
||||
// ID of native thread currently blocked in this channel, for signalling
|
||||
private volatile long thread;
|
||||
|
||||
// Lock held by thread currently blocked in this channel
|
||||
private final Object lock = new Object();
|
||||
private final ReentrantLock acceptLock = new ReentrantLock();
|
||||
|
||||
// Lock held by any thread that modifies the state fields declared below
|
||||
// DO NOT invoke a blocking I/O operation while holding this lock!
|
||||
|
@ -77,7 +89,7 @@ class ServerSocketChannelImpl
|
|||
private boolean isReuseAddress;
|
||||
|
||||
// Our socket adaptor, if any
|
||||
ServerSocket socket;
|
||||
private ServerSocket socket;
|
||||
|
||||
// -- End of fields protected by stateLock
|
||||
|
||||
|
@ -211,7 +223,8 @@ class ServerSocketChannelImpl
|
|||
|
||||
@Override
|
||||
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
|
||||
synchronized (lock) {
|
||||
acceptLock.lock();
|
||||
try {
|
||||
if (!isOpen())
|
||||
throw new ClosedChannelException();
|
||||
if (isBound())
|
||||
|
@ -227,12 +240,15 @@ class ServerSocketChannelImpl
|
|||
synchronized (stateLock) {
|
||||
localAddress = Net.localAddress(fd);
|
||||
}
|
||||
} finally {
|
||||
acceptLock.unlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SocketChannel accept() throws IOException {
|
||||
synchronized (lock) {
|
||||
acceptLock.lock();
|
||||
try {
|
||||
if (!isOpen())
|
||||
throw new ClosedChannelException();
|
||||
if (!isBound())
|
||||
|
@ -278,6 +294,8 @@ class ServerSocketChannelImpl
|
|||
}
|
||||
return sc;
|
||||
|
||||
} finally {
|
||||
acceptLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +371,8 @@ class ServerSocketChannelImpl
|
|||
int poll(int events, long timeout) throws IOException {
|
||||
assert Thread.holdsLock(blockingLock()) && !isBlocking();
|
||||
|
||||
synchronized (lock) {
|
||||
acceptLock.lock();
|
||||
try {
|
||||
int n = 0;
|
||||
try {
|
||||
begin();
|
||||
|
@ -368,6 +387,8 @@ class ServerSocketChannelImpl
|
|||
end(n > 0);
|
||||
}
|
||||
return n;
|
||||
} finally {
|
||||
acceptLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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,10 +25,23 @@
|
|||
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketImpl;
|
||||
import java.net.SocketOption;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -45,7 +58,7 @@ import java.util.concurrent.TimeUnit;
|
|||
// java.net.Socket so as to simplify tracking future changes to that class.
|
||||
//
|
||||
|
||||
public class SocketAdaptor
|
||||
class SocketAdaptor
|
||||
extends Socket
|
||||
{
|
||||
|
||||
|
@ -89,7 +102,6 @@ public class SocketAdaptor
|
|||
throw new IllegalBlockingModeException();
|
||||
|
||||
try {
|
||||
|
||||
if (timeout == 0) {
|
||||
sc.connect(remote);
|
||||
return;
|
||||
|
@ -119,8 +131,9 @@ public class SocketAdaptor
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
if (sc.isOpen())
|
||||
try {
|
||||
sc.configureBlocking(true);
|
||||
} catch (ClosedChannelException e) { }
|
||||
}
|
||||
|
||||
} catch (Exception x) {
|
||||
|
@ -188,10 +201,11 @@ public class SocketAdaptor
|
|||
synchronized (sc.blockingLock()) {
|
||||
if (!sc.isBlocking())
|
||||
throw new IllegalBlockingModeException();
|
||||
|
||||
if (timeout == 0)
|
||||
return sc.read(bb);
|
||||
sc.configureBlocking(false);
|
||||
|
||||
sc.configureBlocking(false);
|
||||
try {
|
||||
int n;
|
||||
if ((n = sc.read(bb)) != 0)
|
||||
|
@ -213,10 +227,10 @@ public class SocketAdaptor
|
|||
throw new SocketTimeoutException();
|
||||
}
|
||||
} finally {
|
||||
if (sc.isOpen())
|
||||
try {
|
||||
sc.configureBlocking(true);
|
||||
} catch (ClosedChannelException e) { }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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
|
||||
|
@ -27,11 +27,30 @@ package sun.nio.ch;
|
|||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ProtocolFamily;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketOption;
|
||||
import java.net.StandardProtocolFamily;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.channels.spi.*;
|
||||
import java.util.*;
|
||||
import java.nio.channels.AlreadyBoundException;
|
||||
import java.nio.channels.AlreadyConnectedException;
|
||||
import java.nio.channels.AsynchronousCloseException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.ConnectionPendingException;
|
||||
import java.nio.channels.NoConnectionPendingException;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import sun.net.NetHooks;
|
||||
import sun.net.ext.ExtendedSocketOptions;
|
||||
|
||||
|
@ -49,9 +68,6 @@ class SocketChannelImpl
|
|||
|
||||
// Our file descriptor object
|
||||
private final FileDescriptor fd;
|
||||
|
||||
// fd value needed for dev/poll. This value will remain valid
|
||||
// even after the value in the file descriptor object has been set to -1
|
||||
private final int fdVal;
|
||||
|
||||
// IDs of native threads doing reads and writes, for signalling
|
||||
|
@ -59,10 +75,10 @@ class SocketChannelImpl
|
|||
private volatile long writerThread;
|
||||
|
||||
// Lock held by current reading or connecting thread
|
||||
private final Object readLock = new Object();
|
||||
private final ReentrantLock readLock = new ReentrantLock();
|
||||
|
||||
// Lock held by current writing or connecting thread
|
||||
private final Object writeLock = new Object();
|
||||
private final ReentrantLock writeLock = new ReentrantLock();
|
||||
|
||||
// Lock held by any thread that modifies the state fields declared below
|
||||
// DO NOT invoke a blocking I/O operation while holding this lock!
|
||||
|
@ -89,7 +105,6 @@ class SocketChannelImpl
|
|||
// Input/Output open
|
||||
private boolean isInputOpen = true;
|
||||
private boolean isOutputOpen = true;
|
||||
private boolean readyToConnect = false;
|
||||
|
||||
// Socket adaptor, created on demand
|
||||
private Socket socket;
|
||||
|
@ -298,7 +313,8 @@ class SocketChannelImpl
|
|||
if (buf == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
synchronized (readLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
if (!ensureReadOpen())
|
||||
return -1;
|
||||
int n = 0;
|
||||
|
@ -418,6 +434,8 @@ class SocketChannelImpl
|
|||
assert IOStatus.check(n);
|
||||
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,7 +444,8 @@ class SocketChannelImpl
|
|||
{
|
||||
if ((offset < 0) || (length < 0) || (offset > dsts.length - length))
|
||||
throw new IndexOutOfBoundsException();
|
||||
synchronized (readLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
if (!ensureReadOpen())
|
||||
return -1;
|
||||
long n = 0;
|
||||
|
@ -453,13 +472,16 @@ class SocketChannelImpl
|
|||
}
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int write(ByteBuffer buf) throws IOException {
|
||||
if (buf == null)
|
||||
throw new NullPointerException();
|
||||
synchronized (writeLock) {
|
||||
writeLock.lock();
|
||||
try {
|
||||
ensureWriteOpen();
|
||||
int n = 0;
|
||||
try {
|
||||
|
@ -484,6 +506,8 @@ class SocketChannelImpl
|
|||
}
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -492,7 +516,8 @@ class SocketChannelImpl
|
|||
{
|
||||
if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
|
||||
throw new IndexOutOfBoundsException();
|
||||
synchronized (writeLock) {
|
||||
writeLock.lock();
|
||||
try {
|
||||
ensureWriteOpen();
|
||||
long n = 0;
|
||||
try {
|
||||
|
@ -517,12 +542,15 @@ class SocketChannelImpl
|
|||
}
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// package-private
|
||||
int sendOutOfBandData(byte b) throws IOException {
|
||||
synchronized (writeLock) {
|
||||
writeLock.lock();
|
||||
try {
|
||||
ensureWriteOpen();
|
||||
int n = 0;
|
||||
try {
|
||||
|
@ -547,6 +575,8 @@ class SocketChannelImpl
|
|||
}
|
||||
assert IOStatus.check(n);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -568,8 +598,10 @@ class SocketChannelImpl
|
|||
|
||||
@Override
|
||||
public SocketChannel bind(SocketAddress local) throws IOException {
|
||||
synchronized (readLock) {
|
||||
synchronized (writeLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
writeLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
if (!isOpen())
|
||||
throw new ClosedChannelException();
|
||||
|
@ -587,7 +619,11 @@ class SocketChannelImpl
|
|||
Net.bind(fd, isa.getAddress(), isa.getPort());
|
||||
localAddress = Net.localAddress(fd);
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -616,14 +652,16 @@ class SocketChannelImpl
|
|||
}
|
||||
|
||||
public boolean connect(SocketAddress sa) throws IOException {
|
||||
synchronized (readLock) {
|
||||
synchronized (writeLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
writeLock.lock();
|
||||
try {
|
||||
ensureOpenAndUnconnected();
|
||||
InetSocketAddress isa = Net.checkAddress(sa);
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null)
|
||||
sm.checkConnect(isa.getAddress().getHostAddress(),
|
||||
isa.getPort());
|
||||
isa.getPort());
|
||||
synchronized (blockingLock()) {
|
||||
int n = 0;
|
||||
try {
|
||||
|
@ -636,8 +674,8 @@ class SocketChannelImpl
|
|||
// notify hook only if unbound
|
||||
if (localAddress == null) {
|
||||
NetHooks.beforeTcpConnect(fd,
|
||||
isa.getAddress(),
|
||||
isa.getPort());
|
||||
isa.getAddress(),
|
||||
isa.getPort());
|
||||
}
|
||||
readerThread = NativeThread.current();
|
||||
}
|
||||
|
@ -646,10 +684,9 @@ class SocketChannelImpl
|
|||
if (ia.isAnyLocalAddress())
|
||||
ia = InetAddress.getLocalHost();
|
||||
n = Net.connect(fd,
|
||||
ia,
|
||||
isa.getPort());
|
||||
if ( (n == IOStatus.INTERRUPTED)
|
||||
&& isOpen())
|
||||
ia,
|
||||
isa.getPort());
|
||||
if ((n == IOStatus.INTERRUPTED) && isOpen())
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
@ -686,13 +723,19 @@ class SocketChannelImpl
|
|||
}
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean finishConnect() throws IOException {
|
||||
synchronized (readLock) {
|
||||
synchronized (writeLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
writeLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
if (!isOpen())
|
||||
throw new ClosedChannelException();
|
||||
|
@ -714,24 +757,20 @@ class SocketChannelImpl
|
|||
}
|
||||
if (!isBlocking()) {
|
||||
for (;;) {
|
||||
n = checkConnect(fd, false,
|
||||
readyToConnect);
|
||||
if ( (n == IOStatus.INTERRUPTED)
|
||||
&& isOpen())
|
||||
n = checkConnect(fd, false);
|
||||
if ((n == IOStatus.INTERRUPTED) && isOpen())
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
for (;;) {
|
||||
n = checkConnect(fd, true,
|
||||
readyToConnect);
|
||||
n = checkConnect(fd, true);
|
||||
if (n == 0) {
|
||||
// Loop in case of
|
||||
// spurious notifications
|
||||
continue;
|
||||
}
|
||||
if ( (n == IOStatus.INTERRUPTED)
|
||||
&& isOpen())
|
||||
if ((n == IOStatus.INTERRUPTED) && isOpen())
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
@ -769,7 +808,11 @@ class SocketChannelImpl
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -903,9 +946,6 @@ class SocketChannelImpl
|
|||
if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
|
||||
newOps = intOps;
|
||||
sk.nioReadyOps(newOps);
|
||||
// No need to poll again in checkConnect,
|
||||
// the error will be detected there
|
||||
readyToConnect = true;
|
||||
return (newOps & ~oldOps) != 0;
|
||||
}
|
||||
|
||||
|
@ -918,7 +958,6 @@ class SocketChannelImpl
|
|||
((intOps & SelectionKey.OP_CONNECT) != 0) &&
|
||||
((state == ST_UNCONNECTED) || (state == ST_PENDING))) {
|
||||
newOps |= SelectionKey.OP_CONNECT;
|
||||
readyToConnect = true;
|
||||
}
|
||||
|
||||
if (((ops & Net.POLLOUT) != 0) &&
|
||||
|
@ -942,7 +981,8 @@ class SocketChannelImpl
|
|||
int poll(int events, long timeout) throws IOException {
|
||||
assert Thread.holdsLock(blockingLock()) && !isBlocking();
|
||||
|
||||
synchronized (readLock) {
|
||||
readLock.lock();
|
||||
try {
|
||||
int n = 0;
|
||||
try {
|
||||
begin();
|
||||
|
@ -957,6 +997,8 @@ class SocketChannelImpl
|
|||
end(n > 0);
|
||||
}
|
||||
return n;
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1024,8 +1066,7 @@ class SocketChannelImpl
|
|||
|
||||
// -- Native methods --
|
||||
|
||||
private static native int checkConnect(FileDescriptor fd,
|
||||
boolean block, boolean ready)
|
||||
private static native int checkConnect(FileDescriptor fd, boolean block)
|
||||
throws IOException;
|
||||
|
||||
private static native int sendOutOfBandData(FileDescriptor fd, byte data)
|
||||
|
|
|
@ -236,10 +236,8 @@ public class DoubleByte {
|
|||
int b2 = src[sp++] & 0xff;
|
||||
if (b2 < b2Min || b2 > b2Max ||
|
||||
(c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
|
||||
if (b2c[b1] == B2C_UNMAPPABLE || // isNotLeadingByte
|
||||
b2c[b2] != B2C_UNMAPPABLE || // isLeadingByte
|
||||
decodeSingle(b2) != UNMAPPABLE_DECODING) {
|
||||
sp--;
|
||||
if (crMalformedOrUnmappable(b1, b2).length() == 1) {
|
||||
sp--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -472,6 +470,13 @@ public class DoubleByte {
|
|||
b2cSB_UNMAPPABLE = new char[0x100];
|
||||
Arrays.fill(b2cSB_UNMAPPABLE, UNMAPPABLE_DECODING);
|
||||
}
|
||||
|
||||
// always returns unmappableForLenth(2) for doublebyte_only
|
||||
@Override
|
||||
protected CoderResult crMalformedOrUnmappable(int b1, int b2) {
|
||||
return CoderResult.unmappableForLength(2);
|
||||
}
|
||||
|
||||
public Decoder_DBCSONLY(Charset cs, char[][] b2c, char[] b2cSB, int b2Min, int b2Max,
|
||||
boolean isASCIICompatible) {
|
||||
super(cs, 0.5f, 1.0f, b2c, b2cSB_UNMAPPABLE, b2Min, b2Max, isASCIICompatible);
|
||||
|
|
|
@ -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
|
||||
|
@ -580,8 +580,8 @@ public class PolicyFile extends java.security.Policy {
|
|||
k.add(policy);
|
||||
return k;
|
||||
});
|
||||
Object[] source = {policy, pe.getLocalizedMessage()};
|
||||
System.err.println(LocalizedMessage.getMessage
|
||||
Object[] source = {policy, pe.getNonlocalizedMessage()};
|
||||
System.err.println(LocalizedMessage.getNonlocalized
|
||||
(POLICY + ".error.parsing.policy.message", source));
|
||||
if (debug != null) {
|
||||
pe.printStackTrace();
|
||||
|
@ -808,14 +808,14 @@ public class PolicyFile extends java.security.Policy {
|
|||
Object[] source = {pe.permission,
|
||||
ite.getTargetException().toString()};
|
||||
System.err.println(
|
||||
LocalizedMessage.getMessage(
|
||||
LocalizedMessage.getNonlocalized(
|
||||
POLICY + ".error.adding.Permission.perm.message",
|
||||
source));
|
||||
} catch (Exception e) {
|
||||
Object[] source = {pe.permission,
|
||||
e.toString()};
|
||||
System.err.println(
|
||||
LocalizedMessage.getMessage(
|
||||
LocalizedMessage.getNonlocalized(
|
||||
POLICY + ".error.adding.Permission.perm.message",
|
||||
source));
|
||||
}
|
||||
|
@ -826,7 +826,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
} catch (Exception e) {
|
||||
Object[] source = {e.toString()};
|
||||
System.err.println(
|
||||
LocalizedMessage.getMessage(
|
||||
LocalizedMessage.getNonlocalized(
|
||||
POLICY + ".error.adding.Entry.message",
|
||||
source));
|
||||
}
|
||||
|
@ -1803,7 +1803,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
if (colonIndex == -1) {
|
||||
Object[] source = {pe.name};
|
||||
throw new Exception(
|
||||
LocalizedMessage.getMessage(
|
||||
LocalizedMessage.getNonlocalized(
|
||||
"alias.name.not.provided.pe.name.",
|
||||
source));
|
||||
}
|
||||
|
@ -1811,7 +1811,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
if ((suffix = getDN(suffix, keystore)) == null) {
|
||||
Object[] source = {value.substring(colonIndex+1)};
|
||||
throw new Exception(
|
||||
LocalizedMessage.getMessage(
|
||||
LocalizedMessage.getNonlocalized(
|
||||
"unable.to.perform.substitution.on.alias.suffix",
|
||||
source));
|
||||
}
|
||||
|
@ -1821,7 +1821,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
} else {
|
||||
Object[] source = {prefix};
|
||||
throw new Exception(
|
||||
LocalizedMessage.getMessage(
|
||||
LocalizedMessage.getNonlocalized(
|
||||
"substitution.value.prefix.unsupported",
|
||||
source));
|
||||
}
|
||||
|
@ -2037,7 +2037,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
super(type);
|
||||
if (type == null) {
|
||||
throw new NullPointerException
|
||||
(LocalizedMessage.getMessage("type.can.t.be.null"));
|
||||
(LocalizedMessage.getNonlocalized("type.can.t.be.null"));
|
||||
}
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
|
|
|
@ -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
|
||||
|
@ -205,8 +205,8 @@ public class PolicyParser {
|
|||
if (!domainEntries.containsKey(domainName)) {
|
||||
domainEntries.put(domainName, de);
|
||||
} else {
|
||||
LocalizedMessage localizedMsg =
|
||||
new LocalizedMessage("duplicate.keystore.domain.name");
|
||||
LocalizedMessage localizedMsg = new LocalizedMessage(
|
||||
"duplicate.keystore.domain.name");
|
||||
Object[] source = {domainName};
|
||||
String msg = "duplicate keystore domain name: " +
|
||||
domainName;
|
||||
|
@ -220,7 +220,7 @@ public class PolicyParser {
|
|||
}
|
||||
|
||||
if (keyStoreUrlString == null && storePassURL != null) {
|
||||
throw new ParsingException(LocalizedMessage.getMessage
|
||||
throw new ParsingException(LocalizedMessage.getNonlocalized
|
||||
("keystorePasswordURL.can.not.be.specified.without.also.specifying.keystore"));
|
||||
}
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ public class PolicyParser {
|
|||
keyStoreType = match("quoted string");
|
||||
} else {
|
||||
throw new ParsingException(st.lineno(),
|
||||
LocalizedMessage.getMessage("expected.keystore.type"));
|
||||
LocalizedMessage.getNonlocalized("expected.keystore.type"));
|
||||
}
|
||||
|
||||
// parse keystore provider
|
||||
|
@ -375,7 +375,7 @@ public class PolicyParser {
|
|||
keyStoreProvider = match("quoted string");
|
||||
} else {
|
||||
throw new ParsingException(st.lineno(),
|
||||
LocalizedMessage.getMessage("expected.keystore.provider"));
|
||||
LocalizedMessage.getNonlocalized("expected.keystore.provider"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ public class PolicyParser {
|
|||
if (e.codeBase != null)
|
||||
throw new ParsingException(
|
||||
st.lineno(),
|
||||
LocalizedMessage.getMessage
|
||||
LocalizedMessage.getNonlocalized
|
||||
("multiple.Codebase.expressions"));
|
||||
e.codeBase = match("quoted string");
|
||||
peekAndMatch(",");
|
||||
|
@ -433,7 +433,7 @@ public class PolicyParser {
|
|||
if (e.signedBy != null)
|
||||
throw new ParsingException(
|
||||
st.lineno(),
|
||||
LocalizedMessage.getMessage
|
||||
LocalizedMessage.getNonlocalized
|
||||
("multiple.SignedBy.expressions"));
|
||||
e.signedBy = match("quoted string");
|
||||
|
||||
|
@ -452,7 +452,7 @@ public class PolicyParser {
|
|||
if (actr <= cctr)
|
||||
throw new ParsingException(
|
||||
st.lineno(),
|
||||
LocalizedMessage.getMessage
|
||||
LocalizedMessage.getNonlocalized
|
||||
("SignedBy.has.empty.alias"));
|
||||
|
||||
peekAndMatch(",");
|
||||
|
@ -495,7 +495,7 @@ public class PolicyParser {
|
|||
}
|
||||
throw new ParsingException
|
||||
(st.lineno(),
|
||||
LocalizedMessage.getMessage
|
||||
LocalizedMessage.getNonlocalized
|
||||
("can.not.specify.Principal.with.a.wildcard.class.without.a.wildcard.name"));
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ public class PolicyParser {
|
|||
|
||||
} else {
|
||||
throw new ParsingException(st.lineno(),
|
||||
LocalizedMessage.getMessage
|
||||
LocalizedMessage.getNonlocalized
|
||||
("expected.codeBase.or.SignedBy.or.Principal"));
|
||||
}
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ public class PolicyParser {
|
|||
} else {
|
||||
throw new
|
||||
ParsingException(st.lineno(),
|
||||
LocalizedMessage.getMessage
|
||||
LocalizedMessage.getNonlocalized
|
||||
("expected.permission.entry"));
|
||||
}
|
||||
}
|
||||
|
@ -733,7 +733,7 @@ public class PolicyParser {
|
|||
switch (lookahead) {
|
||||
case StreamTokenizer.TT_NUMBER:
|
||||
throw new ParsingException(st.lineno(), expect,
|
||||
LocalizedMessage.getMessage("number.") +
|
||||
LocalizedMessage.getNonlocalized("number.") +
|
||||
String.valueOf(st.nval));
|
||||
case StreamTokenizer.TT_EOF:
|
||||
LocalizedMessage localizedMsg = new LocalizedMessage
|
||||
|
@ -826,10 +826,10 @@ public class PolicyParser {
|
|||
switch (lookahead) {
|
||||
case StreamTokenizer.TT_NUMBER:
|
||||
throw new ParsingException(st.lineno(), ";",
|
||||
LocalizedMessage.getMessage("number.") +
|
||||
LocalizedMessage.getNonlocalized("number.") +
|
||||
String.valueOf(st.nval));
|
||||
case StreamTokenizer.TT_EOF:
|
||||
throw new ParsingException(LocalizedMessage.getMessage
|
||||
throw new ParsingException(LocalizedMessage.getNonlocalized
|
||||
("expected.read.end.of.file."));
|
||||
default:
|
||||
lookahead = st.nextToken();
|
||||
|
@ -987,7 +987,7 @@ public class PolicyParser {
|
|||
*/
|
||||
public PrincipalEntry(String principalClass, String principalName) {
|
||||
if (principalClass == null || principalName == null)
|
||||
throw new NullPointerException(LocalizedMessage.getMessage
|
||||
throw new NullPointerException(LocalizedMessage.getNonlocalized
|
||||
("null.principalClass.or.principalName"));
|
||||
this.principalClass = principalClass;
|
||||
this.principalName = principalName;
|
||||
|
@ -1339,8 +1339,6 @@ public class PolicyParser {
|
|||
|
||||
public ParsingException(int line, String msg) {
|
||||
super("line " + line + ": " + msg);
|
||||
// don't call form.format unless getLocalizedMessage is called
|
||||
// to avoid unnecessary permission checks
|
||||
localizedMsg = new LocalizedMessage("line.number.msg");
|
||||
source = new Object[] {line, msg};
|
||||
}
|
||||
|
@ -1348,16 +1346,14 @@ public class PolicyParser {
|
|||
public ParsingException(int line, String expect, String actual) {
|
||||
super("line " + line + ": expected [" + expect +
|
||||
"], found [" + actual + "]");
|
||||
// don't call form.format unless getLocalizedMessage is called
|
||||
// to avoid unnecessary permission checks
|
||||
localizedMsg = new LocalizedMessage
|
||||
("line.number.expected.expect.found.actual.");
|
||||
source = new Object[] {line, expect, actual};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return i18nMessage != null ? i18nMessage : localizedMsg.format(source);
|
||||
public String getNonlocalizedMessage() {
|
||||
return i18nMessage != null ? i18nMessage :
|
||||
localizedMsg.formatNonlocalized(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -523,9 +523,11 @@ public final class Main {
|
|||
|
||||
if (c != null) {
|
||||
command = c;
|
||||
} else if (collator.compare(flags, "-help") == 0 ||
|
||||
collator.compare(flags, "-h") == 0 ||
|
||||
collator.compare(flags, "-?") == 0) {
|
||||
} else if (collator.compare(flags, "--help") == 0 ||
|
||||
collator.compare(flags, "-h") == 0 ||
|
||||
collator.compare(flags, "-?") == 0 ||
|
||||
// -help: legacy.
|
||||
collator.compare(flags, "-help") == 0) {
|
||||
help = true;
|
||||
} else if (collator.compare(flags, "-conf") == 0) {
|
||||
i++;
|
||||
|
@ -4608,6 +4610,8 @@ public final class Main {
|
|||
System.err.printf(" %-20s%s\n", c, rb.getString(c.description));
|
||||
}
|
||||
System.err.println();
|
||||
System.err.println(rb.getString(
|
||||
"Use.keytool.help.for.all.available.commands"));
|
||||
System.err.println(rb.getString(
|
||||
"Use.keytool.command.name.help.for.usage.of.command.name"));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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
|
||||
|
@ -45,12 +45,12 @@ public class Resources extends java.util.ListResourceBundle {
|
|||
{"option.1.set.twice", "The %s option is specified multiple times. All except the last one will be ignored."},
|
||||
{"multiple.commands.1.2", "Only one command is allowed: both %1$s and %2$s were specified."},
|
||||
{"Use.keytool.help.for.all.available.commands",
|
||||
"Use \"keytool -help\" for all available commands"},
|
||||
"Use \"keytool -?, -h, or --help\" for this help message"},
|
||||
{"Key.and.Certificate.Management.Tool",
|
||||
"Key and Certificate Management Tool"},
|
||||
{"Commands.", "Commands:"},
|
||||
{"Use.keytool.command.name.help.for.usage.of.command.name",
|
||||
"Use \"keytool -command_name -help\" for usage of command_name.\n" +
|
||||
"Use \"keytool -command_name --help\" for usage of command_name.\n" +
|
||||
"Use the -conf <url> option to specify a pre-configured options file."},
|
||||
// keytool: help: commands
|
||||
{"Generates.a.certificate.request",
|
||||
|
@ -462,7 +462,7 @@ public class Resources extends java.util.ListResourceBundle {
|
|||
{"with.weak", "%s (weak)"},
|
||||
{"key.bit", "%1$d-bit %2$s key"},
|
||||
{"key.bit.weak", "%1$d-bit %2$s key (weak)"},
|
||||
{"unknown.size.1", "unknown size %s key"},
|
||||
{"unknown.size.1", "%s key of unknown size"},
|
||||
{".PATTERN.printX509Cert.with.weak",
|
||||
"Owner: {0}\nIssuer: {1}\nSerial number: {2}\nValid from: {3} until: {4}\nCertificate fingerprints:\n\t SHA1: {5}\n\t SHA256: {6}\nSignature algorithm name: {7}\nSubject Public Key Algorithm: {8}\nVersion: {9}"},
|
||||
{"PKCS.10.with.weak",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 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
|
||||
|
@ -42,7 +42,7 @@ package sun.security.util;
|
|||
|
||||
public class LocalizedMessage {
|
||||
|
||||
private static final Resources resources = new Resources();
|
||||
private static final Resources RESOURCES = new Resources();
|
||||
|
||||
private final String key;
|
||||
|
||||
|
@ -59,16 +59,28 @@ public class LocalizedMessage {
|
|||
|
||||
/**
|
||||
* Return a localized string corresponding to the key stored in this
|
||||
* object, formatted with the provided arguments. When the VM is booted,
|
||||
* this method will obtain the correct localized message and format it
|
||||
* using java.text.MessageFormat. Otherwise, a non-localized string is
|
||||
* returned, and the formatting is performed by simplified formatting code.
|
||||
* object, formatted with the provided arguments. This method should only
|
||||
* be called when the VM is booted and all resources needed to obtain
|
||||
* and format the localized message are loaded (or can be loaded).
|
||||
*
|
||||
* @param arguments The arguments that should be placed in the message
|
||||
* @return A formatted message string
|
||||
*/
|
||||
public String format(Object... arguments) {
|
||||
return getMessage(key, arguments);
|
||||
public String formatLocalized(Object... arguments) {
|
||||
return getLocalized(key, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-localized string corresponding to the key stored in this
|
||||
* object, formatted with the provided arguments. All strings are obtained
|
||||
* from sun.security.util.Resources, and the formatting only supports
|
||||
* simple positional argument replacement (e.g. {1}).
|
||||
*
|
||||
* @param arguments The arguments that should be placed in the message
|
||||
* @return A formatted message string
|
||||
*/
|
||||
public String formatNonlocalized(Object... arguments) {
|
||||
return getNonlocalized(key, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,10 +93,10 @@ public class LocalizedMessage {
|
|||
* @param arguments The arguments that should be placed in the message
|
||||
* @return A formatted message string
|
||||
*/
|
||||
public static String getMessageUnbooted(String key,
|
||||
Object... arguments) {
|
||||
public static String getNonlocalized(String key,
|
||||
Object... arguments) {
|
||||
|
||||
String value = resources.getString(key);
|
||||
String value = RESOURCES.getString(key);
|
||||
if (arguments == null || arguments.length == 0) {
|
||||
return value;
|
||||
}
|
||||
|
@ -110,8 +122,7 @@ public class LocalizedMessage {
|
|||
try {
|
||||
int index = Integer.parseInt(indexStr);
|
||||
sb.append(arguments[index]);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
// argument index is not an integer
|
||||
throw new RuntimeException("not an integer: " + indexStr);
|
||||
}
|
||||
|
@ -123,29 +134,22 @@ public class LocalizedMessage {
|
|||
|
||||
/**
|
||||
* Return a localized string corresponding to the provided key, and
|
||||
* formatted with the provided arguments. When the VM is booted, this
|
||||
* method will obtain the correct localized message and format it using
|
||||
* java.text.MessageFormat. Otherwise, a non-localized string is returned,
|
||||
* and the formatting is performed by simplified formatting code.
|
||||
* formatted with the provided arguments. This method should only be
|
||||
* called when the VM is booted and all resources needed to obtain
|
||||
* and format the localized message are loaded (or can be loaded).
|
||||
*
|
||||
* @param key The key of the desired string in the security resource bundle
|
||||
* @param arguments The arguments that should be placed in the message
|
||||
* @return A formatted message string
|
||||
*/
|
||||
public static String getMessage(String key,
|
||||
Object... arguments) {
|
||||
public static String getLocalized(String key, Object... arguments) {
|
||||
|
||||
if (jdk.internal.misc.VM.isBooted()) {
|
||||
// Localization and formatting resources are available
|
||||
String value = ResourcesMgr.getString(key);
|
||||
if (arguments == null) {
|
||||
return value;
|
||||
}
|
||||
java.text.MessageFormat form = new java.text.MessageFormat(value);
|
||||
return form.format(arguments);
|
||||
} else {
|
||||
return getMessageUnbooted(key, arguments);
|
||||
String value = ResourcesMgr.getString(key);
|
||||
if (arguments == null) {
|
||||
return value;
|
||||
}
|
||||
java.text.MessageFormat form = new java.text.MessageFormat(value);
|
||||
return form.format(arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 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
|
||||
|
@ -31,8 +31,8 @@
|
|||
*/
|
||||
|
||||
package sun.util.locale;
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public final class BaseLocale {
|
||||
|
@ -48,26 +48,28 @@ public final class BaseLocale {
|
|||
|
||||
private volatile int hash;
|
||||
|
||||
// This method must be called only when creating the Locale.* constants.
|
||||
private BaseLocale(String language, String region) {
|
||||
this.language = language;
|
||||
this.script = "";
|
||||
this.region = region;
|
||||
this.variant = "";
|
||||
}
|
||||
|
||||
private BaseLocale(String language, String script, String region, String variant) {
|
||||
this.language = (language != null) ? LocaleUtils.toLowerString(language).intern() : "";
|
||||
this.script = (script != null) ? LocaleUtils.toTitleString(script).intern() : "";
|
||||
this.region = (region != null) ? LocaleUtils.toUpperString(region).intern() : "";
|
||||
this.variant = (variant != null) ? variant.intern() : "";
|
||||
// This method must be called with normalize = false only when creating the
|
||||
// Locale.* constants and non-normalized BaseLocale$Keys used for lookup.
|
||||
private BaseLocale(String language, String script, String region, String variant,
|
||||
boolean normalize) {
|
||||
if (normalize) {
|
||||
this.language = LocaleUtils.toLowerString(language).intern();
|
||||
this.script = LocaleUtils.toTitleString(script).intern();
|
||||
this.region = LocaleUtils.toUpperString(region).intern();
|
||||
this.variant = variant.intern();
|
||||
} else {
|
||||
this.language = language;
|
||||
this.script = script;
|
||||
this.region = region;
|
||||
this.variant = variant;
|
||||
}
|
||||
}
|
||||
|
||||
// Called for creating the Locale.* constants. No argument
|
||||
// validation is performed.
|
||||
public static BaseLocale createInstance(String language, String region) {
|
||||
BaseLocale base = new BaseLocale(language, region);
|
||||
CACHE.put(new Key(language, region), base);
|
||||
BaseLocale base = new BaseLocale(language, "", region, "", false);
|
||||
CACHE.put(new Key(base), base);
|
||||
return base;
|
||||
}
|
||||
|
||||
|
@ -84,7 +86,7 @@ public final class BaseLocale {
|
|||
}
|
||||
}
|
||||
|
||||
Key key = new Key(language, script, region, variant);
|
||||
Key key = new Key(language, script, region, variant, false);
|
||||
BaseLocale baseLocale = CACHE.get(key);
|
||||
return baseLocale;
|
||||
}
|
||||
|
@ -123,16 +125,16 @@ public final class BaseLocale {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
if (language.length() > 0) {
|
||||
if (!language.isEmpty()) {
|
||||
sj.add("language=" + language);
|
||||
}
|
||||
if (script.length() > 0) {
|
||||
if (!script.isEmpty()) {
|
||||
sj.add("script=" + script);
|
||||
}
|
||||
if (region.length() > 0) {
|
||||
if (!region.isEmpty()) {
|
||||
sj.add("region=" + region);
|
||||
}
|
||||
if (variant.length() > 0) {
|
||||
if (!variant.isEmpty()) {
|
||||
sj.add("variant=" + variant);
|
||||
}
|
||||
return sj.toString();
|
||||
|
@ -155,10 +157,17 @@ public final class BaseLocale {
|
|||
}
|
||||
|
||||
private static final class Key {
|
||||
private final SoftReference<String> lang;
|
||||
private final SoftReference<String> scrt;
|
||||
private final SoftReference<String> regn;
|
||||
private final SoftReference<String> vart;
|
||||
/**
|
||||
* Keep a SoftReference to the Key data if normalized (actually used
|
||||
* as a cache key) and not initialized via the constant creation path.
|
||||
*
|
||||
* This allows us to avoid creating SoftReferences on lookup Keys
|
||||
* (which are short-lived) and for Locales created via
|
||||
* Locale#createConstant.
|
||||
*/
|
||||
private final SoftReference<BaseLocale> holderRef;
|
||||
private final BaseLocale holder;
|
||||
|
||||
private final boolean normalized;
|
||||
private final int hash;
|
||||
|
||||
|
@ -166,15 +175,16 @@ public final class BaseLocale {
|
|||
* Creates a Key. language and region must be normalized
|
||||
* (intern'ed in the proper case).
|
||||
*/
|
||||
private Key(String language, String region) {
|
||||
assert language.intern() == language
|
||||
&& region.intern() == region;
|
||||
|
||||
lang = new SoftReference<>(language);
|
||||
scrt = new SoftReference<>("");
|
||||
regn = new SoftReference<>(region);
|
||||
vart = new SoftReference<>("");
|
||||
private Key(BaseLocale locale) {
|
||||
this.holder = locale;
|
||||
this.holderRef = null;
|
||||
this.normalized = true;
|
||||
String language = locale.getLanguage();
|
||||
String region = locale.getRegion();
|
||||
assert LocaleUtils.toLowerString(language).intern() == language
|
||||
&& LocaleUtils.toUpperString(region).intern() == region
|
||||
&& locale.getVariant() == ""
|
||||
&& locale.getScript() == "";
|
||||
|
||||
int h = language.hashCode();
|
||||
if (region != "") {
|
||||
|
@ -186,51 +196,64 @@ public final class BaseLocale {
|
|||
hash = h;
|
||||
}
|
||||
|
||||
public Key(String language, String script, String region, String variant) {
|
||||
this(language, script, region, variant, false);
|
||||
private Key(String language, String script, String region,
|
||||
String variant, boolean normalize) {
|
||||
if (language == null) {
|
||||
language = "";
|
||||
}
|
||||
if (script == null) {
|
||||
script = "";
|
||||
}
|
||||
if (region == null) {
|
||||
region = "";
|
||||
}
|
||||
if (variant == null) {
|
||||
variant = "";
|
||||
}
|
||||
|
||||
BaseLocale locale = new BaseLocale(language, script, region, variant, normalize);
|
||||
this.normalized = normalize;
|
||||
if (normalized) {
|
||||
this.holderRef = new SoftReference<>(locale);
|
||||
this.holder = null;
|
||||
} else {
|
||||
this.holderRef = null;
|
||||
this.holder = locale;
|
||||
}
|
||||
this.hash = hashCode(locale);
|
||||
}
|
||||
|
||||
private Key(String language, String script, String region,
|
||||
String variant, boolean normalized) {
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
private int hashCode(BaseLocale locale) {
|
||||
int h = 0;
|
||||
if (language != null) {
|
||||
lang = new SoftReference<>(language);
|
||||
int len = language.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + LocaleUtils.toLower(language.charAt(i));
|
||||
}
|
||||
} else {
|
||||
lang = new SoftReference<>("");
|
||||
String lang = locale.getLanguage();
|
||||
int len = lang.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + LocaleUtils.toLower(lang.charAt(i));
|
||||
}
|
||||
if (script != null) {
|
||||
scrt = new SoftReference<>(script);
|
||||
int len = script.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + LocaleUtils.toLower(script.charAt(i));
|
||||
}
|
||||
} else {
|
||||
scrt = new SoftReference<>("");
|
||||
String scrt = locale.getScript();
|
||||
len = scrt.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + LocaleUtils.toLower(scrt.charAt(i));
|
||||
}
|
||||
if (region != null) {
|
||||
regn = new SoftReference<>(region);
|
||||
int len = region.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + LocaleUtils.toLower(region.charAt(i));
|
||||
}
|
||||
} else {
|
||||
regn = new SoftReference<>("");
|
||||
String regn = locale.getRegion();
|
||||
len = regn.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + LocaleUtils.toLower(regn.charAt(i));
|
||||
}
|
||||
if (variant != null) {
|
||||
vart = new SoftReference<>(variant);
|
||||
int len = variant.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + variant.charAt(i);
|
||||
}
|
||||
} else {
|
||||
vart = new SoftReference<>("");
|
||||
String vart = locale.getVariant();
|
||||
len = vart.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
h = 31*h + vart.charAt(i);
|
||||
}
|
||||
hash = h;
|
||||
this.normalized = normalized;
|
||||
return h;
|
||||
}
|
||||
|
||||
private BaseLocale getBaseLocale() {
|
||||
return (holder == null) ? holderRef.get() : holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,46 +261,31 @@ public final class BaseLocale {
|
|||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj instanceof Key && this.hash == ((Key)obj).hash) {
|
||||
String tl = this.lang.get();
|
||||
String ol = ((Key)obj).lang.get();
|
||||
if (tl != null && ol != null &&
|
||||
LocaleUtils.caseIgnoreMatch(ol, tl)) {
|
||||
String ts = this.scrt.get();
|
||||
String os = ((Key)obj).scrt.get();
|
||||
if (ts != null && os != null &&
|
||||
LocaleUtils.caseIgnoreMatch(os, ts)) {
|
||||
String tr = this.regn.get();
|
||||
String or = ((Key)obj).regn.get();
|
||||
if (tr != null && or != null &&
|
||||
LocaleUtils.caseIgnoreMatch(or, tr)) {
|
||||
String tv = this.vart.get();
|
||||
String ov = ((Key)obj).vart.get();
|
||||
return (ov != null && ov.equals(tv));
|
||||
}
|
||||
}
|
||||
BaseLocale other = ((Key) obj).getBaseLocale();
|
||||
BaseLocale locale = this.getBaseLocale();
|
||||
if (other != null && locale != null
|
||||
&& LocaleUtils.caseIgnoreMatch(other.getLanguage(), locale.getLanguage())
|
||||
&& LocaleUtils.caseIgnoreMatch(other.getScript(), locale.getScript())
|
||||
&& LocaleUtils.caseIgnoreMatch(other.getRegion(), locale.getRegion())
|
||||
// variant is case sensitive in JDK!
|
||||
&& other.getVariant().equals(locale.getVariant())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static Key normalize(Key key) {
|
||||
if (key.normalized) {
|
||||
return key;
|
||||
}
|
||||
|
||||
String lang = LocaleUtils.toLowerString(key.lang.get()).intern();
|
||||
String scrt = LocaleUtils.toTitleString(key.scrt.get()).intern();
|
||||
String regn = LocaleUtils.toUpperString(key.regn.get()).intern();
|
||||
String vart = key.vart.get().intern(); // preserve upper/lower cases
|
||||
|
||||
return new Key(lang, scrt, regn, vart, true);
|
||||
// Only normalized keys may be softly referencing the data holder
|
||||
assert (key.holder != null && key.holderRef == null);
|
||||
BaseLocale locale = key.holder;
|
||||
return new Key(locale.getLanguage(), locale.getScript(),
|
||||
locale.getRegion(), locale.getVariant(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,18 +296,12 @@ public final class BaseLocale {
|
|||
|
||||
@Override
|
||||
protected Key normalizeKey(Key key) {
|
||||
assert key.lang.get() != null &&
|
||||
key.scrt.get() != null &&
|
||||
key.regn.get() != null &&
|
||||
key.vart.get() != null;
|
||||
|
||||
return Key.normalize(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseLocale createObject(Key key) {
|
||||
return new BaseLocale(key.lang.get(), key.scrt.get(),
|
||||
key.regn.get(), key.vart.get());
|
||||
return Key.normalize(key).getBaseLocale();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 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
|
||||
|
@ -37,8 +37,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public abstract class LocaleObjectCache<K, V> {
|
||||
private ConcurrentMap<K, CacheEntry<K, V>> map;
|
||||
private ReferenceQueue<V> queue = new ReferenceQueue<>();
|
||||
private final ConcurrentMap<K, CacheEntry<K, V>> map;
|
||||
private final ReferenceQueue<V> queue = new ReferenceQueue<>();
|
||||
|
||||
public LocaleObjectCache() {
|
||||
this(16, 0.75f, 16);
|
||||
|
@ -57,17 +57,14 @@ public abstract class LocaleObjectCache<K, V> {
|
|||
value = entry.get();
|
||||
}
|
||||
if (value == null) {
|
||||
V newVal = createObject(key);
|
||||
// make sure key is normalized *after* the object creation
|
||||
// so that newVal is assured to be created from a valid key.
|
||||
key = normalizeKey(key);
|
||||
V newVal = createObject(key);
|
||||
if (key == null || newVal == null) {
|
||||
// subclass must return non-null key/value object
|
||||
return null;
|
||||
}
|
||||
|
||||
CacheEntry<K, V> newEntry = new CacheEntry<>(key, newVal, queue);
|
||||
|
||||
entry = map.putIfAbsent(key, newEntry);
|
||||
if (entry == null) {
|
||||
value = newVal;
|
||||
|
@ -92,7 +89,7 @@ public abstract class LocaleObjectCache<K, V> {
|
|||
private void cleanStaleEntries() {
|
||||
CacheEntry<K, V> entry;
|
||||
while ((entry = (CacheEntry<K, V>)queue.poll()) != null) {
|
||||
map.remove(entry.getKey());
|
||||
map.remove(entry.getKey(), entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue