提交 8f7132bc 编写于 作者: D darcy

8021429: Fix lint warnings in java.lang.ref

Reviewed-by: lancea, mduigou, alanb
上级 dac7033a
/* /*
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,13 +25,12 @@ ...@@ -25,13 +25,12 @@
package java.lang.ref; package java.lang.ref;
/**
/* Final references, used to implement finalization */ * Final references, used to implement finalization
*/
class FinalReference<T> extends Reference<T> { class FinalReference<T> extends Reference<T> {
public FinalReference(T referent, ReferenceQueue<? super T> q) { public FinalReference(T referent, ReferenceQueue<? super T> q) {
super(referent, q); super(referent, q);
} }
} }
/* /*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,16 +29,16 @@ import java.security.PrivilegedAction; ...@@ -29,16 +29,16 @@ import java.security.PrivilegedAction;
import java.security.AccessController; import java.security.AccessController;
final class Finalizer extends FinalReference { /* Package-private; must be in final class Finalizer extends FinalReference<Object> { /* Package-private; must be in
same package as the Reference same package as the Reference
class */ class */
/* A native method that invokes an arbitrary object's finalize method is /* A native method that invokes an arbitrary object's finalize method is
required since the finalize method is protected required since the finalize method is protected
*/ */
static native void invokeFinalizeMethod(Object o) throws Throwable; static native void invokeFinalizeMethod(Object o) throws Throwable;
private static ReferenceQueue queue = new ReferenceQueue(); private static ReferenceQueue<Object> queue = new ReferenceQueue<>();
private static Finalizer unfinalized = null; private static Finalizer unfinalized = null;
private static final Object lock = new Object(); private static final Object lock = new Object();
......
...@@ -96,6 +96,7 @@ public abstract class Reference<T> { ...@@ -96,6 +96,7 @@ public abstract class Reference<T> {
* Enqueued: next reference in queue (or this if last) * Enqueued: next reference in queue (or this if last)
* Inactive: this * Inactive: this
*/ */
@SuppressWarnings("rawtypes")
Reference next; Reference next;
/* When active: next element in a discovered reference list maintained by GC (or this if last) /* When active: next element in a discovered reference list maintained by GC (or this if last)
...@@ -119,7 +120,7 @@ public abstract class Reference<T> { ...@@ -119,7 +120,7 @@ public abstract class Reference<T> {
* them. This list is protected by the above lock object. The * them. This list is protected by the above lock object. The
* list uses the discovered field to link its elements. * list uses the discovered field to link its elements.
*/ */
private static Reference pending = null; private static Reference<Object> pending = null;
/* High-priority thread to enqueue pending References /* High-priority thread to enqueue pending References
*/ */
...@@ -131,7 +132,7 @@ public abstract class Reference<T> { ...@@ -131,7 +132,7 @@ public abstract class Reference<T> {
public void run() { public void run() {
for (;;) { for (;;) {
Reference r; Reference<Object> r;
synchronized (lock) { synchronized (lock) {
if (pending != null) { if (pending != null) {
r = pending; r = pending;
...@@ -166,7 +167,7 @@ public abstract class Reference<T> { ...@@ -166,7 +167,7 @@ public abstract class Reference<T> {
continue; continue;
} }
ReferenceQueue q = r.queue; ReferenceQueue<Object> q = r.queue;
if (q != ReferenceQueue.NULL) q.enqueue(r); if (q != ReferenceQueue.NULL) q.enqueue(r);
} }
} }
......
/* /*
* Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -40,14 +40,14 @@ public class ReferenceQueue<T> { ...@@ -40,14 +40,14 @@ public class ReferenceQueue<T> {
*/ */
public ReferenceQueue() { } public ReferenceQueue() { }
private static class Null extends ReferenceQueue { private static class Null<S> extends ReferenceQueue<S> {
boolean enqueue(Reference r) { boolean enqueue(Reference<? extends S> r) {
return false; return false;
} }
} }
static ReferenceQueue NULL = new Null(); static ReferenceQueue<Object> NULL = new Null<>();
static ReferenceQueue ENQUEUED = new Null(); static ReferenceQueue<Object> ENQUEUED = new Null<>();
static private class Lock { }; static private class Lock { };
private Lock lock = new Lock(); private Lock lock = new Lock();
...@@ -58,7 +58,7 @@ public class ReferenceQueue<T> { ...@@ -58,7 +58,7 @@ public class ReferenceQueue<T> {
synchronized (lock) { synchronized (lock) {
// Check that since getting the lock this reference hasn't already been // Check that since getting the lock this reference hasn't already been
// enqueued (and even then removed) // enqueued (and even then removed)
ReferenceQueue queue = r.queue; ReferenceQueue<?> queue = r.queue;
if ((queue == NULL) || (queue == ENQUEUED)) { if ((queue == NULL) || (queue == ENQUEUED)) {
return false; return false;
} }
...@@ -75,10 +75,13 @@ public class ReferenceQueue<T> { ...@@ -75,10 +75,13 @@ public class ReferenceQueue<T> {
} }
} }
@SuppressWarnings("unchecked")
private Reference<? extends T> reallyPoll() { /* Must hold lock */ private Reference<? extends T> reallyPoll() { /* Must hold lock */
Reference<? extends T> r = head; Reference<? extends T> r = head;
if (r != null) { if (r != null) {
head = (r.next == r) ? null : r.next; head = (r.next == r) ?
null :
r.next; // Unchecked due to the next field having a raw type in Reference
r.queue = NULL; r.queue = NULL;
r.next = r; r.next = r;
queueLength--; queueLength--;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册