8256167: Convert JDK use of Reference::get to Reference::refersTo

Reviewed-by: sspitsyn, shade, dfuchs, alanb, kbarrett
This commit is contained in:
Mandy Chung 2020-12-06 00:08:22 +00:00
parent 78be334c38
commit 972bc3b408
12 changed files with 49 additions and 53 deletions

View file

@ -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);
}
}