提交 51b76b36 编写于 作者: A alanb

6726309: Compiler warnings in nio code

Reviewed-by: sherman, iris
上级 ef0b0d2b
......@@ -82,7 +82,7 @@ public abstract class AbstractSelector
this.provider = provider;
}
private final Set cancelledKeys = new HashSet();
private final Set<SelectionKey> cancelledKeys = new HashSet<SelectionKey>();
void cancel(SelectionKey k) { // package-private
synchronized (cancelledKeys) {
......
......@@ -303,7 +303,7 @@ public abstract class Charset$Coder$ {
#if[encoder]
private WeakReference cachedDecoder = null;
private WeakReference<CharsetDecoder> cachedDecoder = null;
/**
* Tells whether or not the given byte array is a legal replacement value
......@@ -322,13 +322,13 @@ public abstract class Charset$Coder$ {
* is a legal replacement value for this encoder
*/
public boolean isLegalReplacement(byte[] repl) {
WeakReference wr = cachedDecoder;
WeakReference<CharsetDecoder> wr = cachedDecoder;
CharsetDecoder dec = null;
if ((wr == null) || ((dec = (CharsetDecoder)wr.get()) == null)) {
if ((wr == null) || ((dec = wr.get()) == null)) {
dec = charset().newDecoder();
dec.onMalformedInput(CodingErrorAction.REPORT);
dec.onUnmappableCharacter(CodingErrorAction.REPORT);
cachedDecoder = new WeakReference(dec);
cachedDecoder = new WeakReference<CharsetDecoder>(dec);
} else {
dec.reset();
}
......
......@@ -379,7 +379,7 @@ public abstract class Charset
}
// Thread-local gate to prevent recursive provider lookups
private static ThreadLocal gate = new ThreadLocal();
private static ThreadLocal<ThreadLocal> gate = new ThreadLocal<ThreadLocal>();
private static Charset lookupViaProviders(final String charsetName) {
......@@ -539,9 +539,9 @@ public abstract class Charset
// Fold charsets from the given iterator into the given map, ignoring
// charsets whose names already have entries in the map.
//
private static void put(Iterator i, Map m) {
private static void put(Iterator<Charset> i, Map<String,Charset> m) {
while (i.hasNext()) {
Charset cs = (Charset)i.next();
Charset cs = i.next();
if (!m.containsKey(cs.name()))
m.put(cs.name(), cs);
}
......@@ -623,7 +623,7 @@ public abstract class Charset
private final String name; // tickles a bug in oldjavac
private final String[] aliases; // tickles a bug in oldjavac
private Set aliasSet = null;
private Set<String> aliasSet = null;
/**
* Initializes a new charset with the given canonical name and alias
......@@ -665,7 +665,7 @@ public abstract class Charset
if (aliasSet != null)
return aliasSet;
int n = aliases.length;
HashSet hs = new HashSet(n);
HashSet<String> hs = new HashSet<String>(n);
for (int i = 0; i < n; i++)
hs.add(aliases[i]);
aliasSet = Collections.unmodifiableSet(hs);
......
......@@ -194,7 +194,7 @@ public class CoderResult {
private static abstract class Cache {
private Map cache = null;
private Map<Integer,WeakReference<CoderResult>> cache = null;
protected abstract CoderResult create(int len);
......@@ -202,16 +202,16 @@ public class CoderResult {
if (len <= 0)
throw new IllegalArgumentException("Non-positive length");
Integer k = new Integer(len);
WeakReference w;
WeakReference<CoderResult> w;
CoderResult e = null;
if (cache == null) {
cache = new HashMap();
} else if ((w = (WeakReference)cache.get(k)) != null) {
e = (CoderResult)w.get();
cache = new HashMap<Integer,WeakReference<CoderResult>>();
} else if ((w = cache.get(k)) != null) {
e = w.get();
}
if (e == null) {
e = create(len);
cache.put(k, new WeakReference(e));
cache.put(k, new WeakReference<CoderResult>(e));
}
return e;
}
......
......@@ -42,19 +42,19 @@ abstract class SelectorImpl
{
// The set of keys with data ready for an operation
protected Set selectedKeys;
protected Set<SelectionKey> selectedKeys;
// The set of keys registered with this Selector
protected HashSet keys;
protected HashSet<SelectionKey> keys;
// Public views of the key sets
private Set publicKeys; // Immutable
private Set publicSelectedKeys; // Removal allowed, but not addition
private Set<SelectionKey> publicKeys; // Immutable
private Set<SelectionKey> publicSelectedKeys; // Removal allowed, but not addition
protected SelectorImpl(SelectorProvider sp) {
super(sp);
keys = new HashSet();
selectedKeys = new HashSet();
keys = new HashSet<SelectionKey>();
selectedKeys = new HashSet<SelectionKey>();
if (Util.atBugLevel("1.4")) {
publicKeys = keys;
publicSelectedKeys = selectedKeys;
......@@ -64,13 +64,13 @@ abstract class SelectorImpl
}
}
public Set keys() {
public Set<SelectionKey> keys() {
if (!isOpen() && !Util.atBugLevel("1.4"))
throw new ClosedSelectorException();
return publicKeys;
}
public Set selectedKeys() {
public Set<SelectionKey> selectedKeys() {
if (!isOpen() && !Util.atBugLevel("1.4"))
throw new ClosedSelectorException();
return publicSelectedKeys;
......
......@@ -51,9 +51,13 @@ class Util {
// Per-thread soft cache of the last temporary direct buffer
private static ThreadLocal<SoftReference<ByteBuffer>>[] bufferPool;
@SuppressWarnings("unchecked")
static ThreadLocal<SoftReference<ByteBuffer>>[] createThreadLocalBufferPool() {
return new ThreadLocal[TEMP_BUF_POOL_SIZE];
}
static {
bufferPool = (ThreadLocal<SoftReference<ByteBuffer>>[])
new ThreadLocal[TEMP_BUF_POOL_SIZE];
bufferPool = createThreadLocalBufferPool();
for (int i=0; i<TEMP_BUF_POOL_SIZE; i++)
bufferPool[i] = new ThreadLocal<SoftReference<ByteBuffer>>();
}
......
......@@ -116,7 +116,7 @@ Java_java_nio_Bits_copyFromShortArray(JNIEnv *env, jobject this, jobject src,
jshort *srcShort, *dstShort, *endShort;
jshort tmpShort;
dstShort = (jshort *)dstAddr;
dstShort = (jshort *)jlong_to_ptr(dstAddr);
while (length > 0) {
/* do not change this if-else statement, see WARNING above */
......@@ -151,7 +151,7 @@ Java_java_nio_Bits_copyToShortArray(JNIEnv *env, jobject this, jlong srcAddr,
jshort *srcShort, *dstShort, *endShort;
jshort tmpShort;
srcShort = (jshort *)srcAddr;
srcShort = (jshort *)jlong_to_ptr(srcAddr);
while (length > 0) {
/* do not change this if-else statement, see WARNING above */
......@@ -186,7 +186,7 @@ Java_java_nio_Bits_copyFromIntArray(JNIEnv *env, jobject this, jobject src,
jint *srcInt, *dstInt, *endInt;
jint tmpInt;
dstInt = (jint *)dstAddr;
dstInt = (jint *)jlong_to_ptr(dstAddr);
while (length > 0) {
/* do not change this code, see WARNING above */
......@@ -221,7 +221,7 @@ Java_java_nio_Bits_copyToIntArray(JNIEnv *env, jobject this, jlong srcAddr,
jint *srcInt, *dstInt, *endInt;
jint tmpInt;
srcInt = (jint *)srcAddr;
srcInt = (jint *)jlong_to_ptr(srcAddr);
while (length > 0) {
/* do not change this code, see WARNING above */
......@@ -256,7 +256,7 @@ Java_java_nio_Bits_copyFromLongArray(JNIEnv *env, jobject this, jobject src,
jlong *srcLong, *dstLong, *endLong;
jlong tmpLong;
dstLong = (jlong *)dstAddr;
dstLong = (jlong *)jlong_to_ptr(dstAddr);
while (length > 0) {
/* do not change this code, see WARNING above */
......@@ -291,7 +291,7 @@ Java_java_nio_Bits_copyToLongArray(JNIEnv *env, jobject this, jlong srcAddr,
jlong *srcLong, *dstLong, *endLong;
jlong tmpLong;
srcLong = (jlong *)srcAddr;
srcLong = (jlong *)jlong_to_ptr(srcAddr);
while (length > 0) {
/* do not change this code, see WARNING above */
......
......@@ -50,7 +50,7 @@ class DevPollSelectorImpl
private int totalChannels;
// Maps from file descriptors to keys
private HashMap fdToKey;
private Map<Integer,SelectionKeyImpl> fdToKey;
// True if this Selector has been closed
private boolean closed = false;
......@@ -71,7 +71,7 @@ class DevPollSelectorImpl
fd1 = fdes[1];
pollWrapper = new DevPollArrayWrapper();
pollWrapper.initInterrupt(fd0, fd1);
fdToKey = new HashMap();
fdToKey = new HashMap<Integer,SelectionKeyImpl>();
totalChannels = 1;
}
......@@ -110,8 +110,7 @@ class DevPollSelectorImpl
int numKeysUpdated = 0;
for (int i=0; i<entries; i++) {
int nextFD = pollWrapper.getDescriptor(i);
SelectionKeyImpl ski = (SelectionKeyImpl) fdToKey.get(
new Integer(nextFD));
SelectionKeyImpl ski = fdToKey.get(Integer.valueOf(nextFD));
// ski is null in the case of an interrupt
if (ski != null) {
int rOps = pollWrapper.getReventOps(i);
......@@ -169,7 +168,7 @@ class DevPollSelectorImpl
protected void implRegister(SelectionKeyImpl ski) {
int fd = IOUtil.fdVal(ski.channel.getFD());
fdToKey.put(new Integer(fd), ski);
fdToKey.put(Integer.valueOf(fd), ski);
totalChannels++;
keys.add(ski);
}
......@@ -178,7 +177,7 @@ class DevPollSelectorImpl
int i = ski.getIndex();
assert (i >= 0);
int fd = ski.channel.getFDVal();
fdToKey.remove(new Integer(fd));
fdToKey.remove(Integer.valueOf(fd));
pollWrapper.release(fd);
totalChannels--;
ski.setIndex(-1);
......
......@@ -48,7 +48,7 @@ class EPollSelectorImpl
EPollArrayWrapper pollWrapper;
// Maps from file descriptors to keys
private HashMap fdToKey;
private Map<Integer,SelectionKeyImpl> fdToKey;
// True if this Selector has been closed
private boolean closed = false;
......@@ -69,7 +69,7 @@ class EPollSelectorImpl
fd1 = fdes[1];
pollWrapper = new EPollArrayWrapper();
pollWrapper.initInterrupt(fd0, fd1);
fdToKey = new HashMap();
fdToKey = new HashMap<Integer,SelectionKeyImpl>();
}
protected int doSelect(long timeout)
......@@ -107,8 +107,7 @@ class EPollSelectorImpl
int numKeysUpdated = 0;
for (int i=0; i<entries; i++) {
int nextFD = pollWrapper.getDescriptor(i);
SelectionKeyImpl ski = (SelectionKeyImpl) fdToKey.get(
new Integer(nextFD));
SelectionKeyImpl ski = fdToKey.get(Integer.valueOf(nextFD));
// ski is null in the case of an interrupt
if (ski != null) {
int rOps = pollWrapper.getEventOps(i);
......@@ -164,7 +163,7 @@ class EPollSelectorImpl
protected void implRegister(SelectionKeyImpl ski) {
int fd = IOUtil.fdVal(ski.channel.getFD());
fdToKey.put(new Integer(fd), ski);
fdToKey.put(Integer.valueOf(fd), ski);
pollWrapper.add(fd);
keys.add(ski);
}
......@@ -172,7 +171,7 @@ class EPollSelectorImpl
protected void implDereg(SelectionKeyImpl ski) throws IOException {
assert (ski.getIndex() >= 0);
int fd = ski.channel.getFDVal();
fdToKey.remove(new Integer(fd));
fdToKey.remove(Integer.valueOf(fd));
pollWrapper.release(fd);
ski.setIndex(-1);
keys.remove(ski);
......
......@@ -43,7 +43,11 @@ Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj,
int result = 0;
int i = 0;
void *a = (void *) jlong_to_ptr(address);
char * vec = (char *)malloc(numPages * sizeof(char));
#ifdef __linux__
unsigned char *vec = (unsigned char *)malloc(numPages * sizeof(char));
#else
char *vec = (char *)malloc(numPages * sizeof(char));
#endif
if (vec == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
......
......@@ -123,7 +123,7 @@ Java_sun_nio_ch_DatagramChannelImpl_receive0(JNIEnv *env, jobject this,
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
SOCKADDR sa;
int sa_len = SOCKADDR_LEN;
socklen_t sa_len = SOCKADDR_LEN;
jboolean retry = JNI_FALSE;
jint n = 0;
jobject senderAddr;
......
......@@ -88,7 +88,8 @@ Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd)
{
int sotype, arglen=sizeof(sotype);
int sotype;
socklen_t arglen=sizeof(sotype);
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) {
if (sotype == SOCK_STREAM)
return sun_nio_ch_InheritedChannel_SOCK_STREAM;
......
......@@ -138,7 +138,7 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo)
{
SOCKADDR sa;
int sa_len = SOCKADDR_LEN;
socklen_t sa_len = SOCKADDR_LEN;
if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
handleSocketError(env, errno);
return -1;
......@@ -150,7 +150,7 @@ JNIEXPORT jobject JNICALL
Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo)
{
SOCKADDR sa;
int sa_len = SOCKADDR_LEN;
socklen_t sa_len = SOCKADDR_LEN;
int port;
if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
handleSocketError(env, errno);
......
......@@ -81,12 +81,12 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this,
jint ssfd = (*env)->GetIntField(env, ssfdo, fd_fdID);
jint newfd;
struct sockaddr *sa;
int sa_len;
int alloc_len;
jobject remote_ia = 0;
jobject isa;
jint remote_port;
NET_AllocSockaddr(&sa, &sa_len);
NET_AllocSockaddr(&sa, &alloc_len);
/*
* accept connection but ignore ECONNABORTED indicating that
......@@ -94,6 +94,7 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this,
* accept() was called.
*/
for (;;) {
socklen_t sa_len = alloc_len;
newfd = accept(ssfd, sa, &sa_len);
if (newfd >= 0) {
break;
......
......@@ -55,7 +55,7 @@ Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this,
jboolean ready)
{
int error = 0;
int n = sizeof(int);
socklen_t n = sizeof(int);
jint fd = fdval(env, fdo);
int result = 0;
struct pollfd poller;
......
......@@ -67,7 +67,7 @@ class PipeImpl
}
private class Initializer
implements PrivilegedExceptionAction
implements PrivilegedExceptionAction<Void>
{
private final SelectorProvider sp;
......@@ -76,7 +76,7 @@ class PipeImpl
this.sp = sp;
}
public Object run() throws IOException {
public Void run() throws IOException {
ServerSocketChannel ssc = null;
SocketChannel sc1 = null;
SocketChannel sc2 = null;
......
......@@ -72,7 +72,7 @@ final class WindowsSelectorImpl extends SelectorImpl {
private int threadsCount = 0;
// A list of helper threads for select.
private final List threads = new ArrayList();
private final List<Thread> threads = new ArrayList<Thread>();
//Pipe used as a wakeup object.
private final Pipe wakeupPipe;
......@@ -82,6 +82,7 @@ final class WindowsSelectorImpl extends SelectorImpl {
// Maps file descriptors to their indices in pollArray
private final static class FdMap extends HashMap<Integer, MapEntry> {
static final long serialVersionUID = 0L;
private MapEntry get(int desc) {
return get(new Integer(desc));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册