mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8256167: Convert JDK use of Reference::get
to Reference::refersTo
Reviewed-by: sspitsyn, shade, dfuchs, alanb, kbarrett
This commit is contained in:
parent
78be334c38
commit
972bc3b408
12 changed files with 49 additions and 53 deletions
|
@ -2044,9 +2044,9 @@ public class Thread implements Runnable {
|
|||
return true;
|
||||
|
||||
if (obj instanceof WeakClassKey) {
|
||||
Object referent = get();
|
||||
Class<?> referent = get();
|
||||
return (referent != null) &&
|
||||
(referent == ((WeakClassKey) obj).get());
|
||||
(((WeakClassKey) obj).refersTo(referent));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,7 +26,7 @@
|
|||
package java.lang;
|
||||
import jdk.internal.misc.TerminatingThreadLocal;
|
||||
|
||||
import java.lang.ref.*;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -433,7 +433,7 @@ public class ThreadLocal<T> {
|
|||
private Entry getEntry(ThreadLocal<?> key) {
|
||||
int i = key.threadLocalHashCode & (table.length - 1);
|
||||
Entry e = table[i];
|
||||
if (e != null && e.get() == key)
|
||||
if (e != null && e.refersTo(key))
|
||||
return e;
|
||||
else
|
||||
return getEntryAfterMiss(key, i, e);
|
||||
|
@ -453,10 +453,9 @@ public class ThreadLocal<T> {
|
|||
int len = tab.length;
|
||||
|
||||
while (e != null) {
|
||||
ThreadLocal<?> k = e.get();
|
||||
if (k == key)
|
||||
if (e.refersTo(key))
|
||||
return e;
|
||||
if (k == null)
|
||||
if (e.refersTo(null))
|
||||
expungeStaleEntry(i);
|
||||
else
|
||||
i = nextIndex(i, len);
|
||||
|
@ -485,14 +484,12 @@ public class ThreadLocal<T> {
|
|||
for (Entry e = tab[i];
|
||||
e != null;
|
||||
e = tab[i = nextIndex(i, len)]) {
|
||||
ThreadLocal<?> k = e.get();
|
||||
|
||||
if (k == key) {
|
||||
if (e.refersTo(key)) {
|
||||
e.value = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (k == null) {
|
||||
if (e.refersTo(null)) {
|
||||
replaceStaleEntry(key, value, i);
|
||||
return;
|
||||
}
|
||||
|
@ -514,7 +511,7 @@ public class ThreadLocal<T> {
|
|||
for (Entry e = tab[i];
|
||||
e != null;
|
||||
e = tab[i = nextIndex(i, len)]) {
|
||||
if (e.get() == key) {
|
||||
if (e.refersTo(key)) {
|
||||
e.clear();
|
||||
expungeStaleEntry(i);
|
||||
return;
|
||||
|
@ -551,7 +548,7 @@ public class ThreadLocal<T> {
|
|||
for (int i = prevIndex(staleSlot, len);
|
||||
(e = tab[i]) != null;
|
||||
i = prevIndex(i, len))
|
||||
if (e.get() == null)
|
||||
if (e.refersTo(null))
|
||||
slotToExpunge = i;
|
||||
|
||||
// Find either the key or trailing null slot of run, whichever
|
||||
|
@ -559,14 +556,12 @@ public class ThreadLocal<T> {
|
|||
for (int i = nextIndex(staleSlot, len);
|
||||
(e = tab[i]) != null;
|
||||
i = nextIndex(i, len)) {
|
||||
ThreadLocal<?> k = e.get();
|
||||
|
||||
// If we find key, then we need to swap it
|
||||
// with the stale entry to maintain hash table order.
|
||||
// The newly stale slot, or any other stale slot
|
||||
// encountered above it, can then be sent to expungeStaleEntry
|
||||
// to remove or rehash all of the other entries in run.
|
||||
if (k == key) {
|
||||
if (e.refersTo(key)) {
|
||||
e.value = value;
|
||||
|
||||
tab[i] = tab[staleSlot];
|
||||
|
@ -582,7 +577,7 @@ public class ThreadLocal<T> {
|
|||
// If we didn't find stale entry on backward scan, the
|
||||
// first stale entry seen while scanning for key is the
|
||||
// first still present in the run.
|
||||
if (k == null && slotToExpunge == staleSlot)
|
||||
if (e.refersTo(null) && slotToExpunge == staleSlot)
|
||||
slotToExpunge = i;
|
||||
}
|
||||
|
||||
|
@ -673,7 +668,7 @@ public class ThreadLocal<T> {
|
|||
do {
|
||||
i = nextIndex(i, len);
|
||||
Entry e = tab[i];
|
||||
if (e != null && e.get() == null) {
|
||||
if (e != null && e.refersTo(null)) {
|
||||
n = len;
|
||||
removed = true;
|
||||
i = expungeStaleEntry(i);
|
||||
|
@ -733,7 +728,7 @@ public class ThreadLocal<T> {
|
|||
int len = tab.length;
|
||||
for (int j = 0; j < len; j++) {
|
||||
Entry e = tab[j];
|
||||
if (e != null && e.get() == null)
|
||||
if (e != null && e.refersTo(null))
|
||||
expungeStaleEntry(j);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2020, 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
|
||||
|
@ -402,9 +402,8 @@ class DirectMethodHandle extends MethodHandle {
|
|||
if (ref == null) {
|
||||
return true; // the final state
|
||||
}
|
||||
Thread clinitThread = ref.get();
|
||||
// Somebody may still be running defc.<clinit>.
|
||||
if (clinitThread == Thread.currentThread()) {
|
||||
if (ref.refersTo(Thread.currentThread())) {
|
||||
// If anybody is running defc.<clinit>, it is this thread.
|
||||
if (UNSAFE.shouldBeInitialized(defc))
|
||||
// Yes, we are running it; keep the barrier for now.
|
||||
|
|
|
@ -337,7 +337,7 @@ public abstract class Reference<T> {
|
|||
*
|
||||
* @return The object to which this reference refers, or
|
||||
* {@code null} if this reference object has been cleared
|
||||
* @see refersTo
|
||||
* @see #refersTo
|
||||
*/
|
||||
@IntrinsicCandidate
|
||||
public T get() {
|
||||
|
|
|
@ -642,7 +642,7 @@ public class AccessibleObject implements AnnotatedElement {
|
|||
}
|
||||
|
||||
boolean isCacheFor(Class<?> caller, Class<?> refc) {
|
||||
return callerRef.get() == caller && targetRef.get() == refc;
|
||||
return callerRef.refersTo(caller) && targetRef.refersTo(refc);
|
||||
}
|
||||
|
||||
static Object protectedMemberCallerCache(Class<?> caller, Class<?> refc) {
|
||||
|
@ -674,7 +674,7 @@ public class AccessibleObject implements AnnotatedElement {
|
|||
if (cache instanceof WeakReference) {
|
||||
@SuppressWarnings("unchecked")
|
||||
WeakReference<Class<?>> ref = (WeakReference<Class<?>>) cache;
|
||||
return ref.get() == caller;
|
||||
return ref.refersTo(caller);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue