aboutsummaryrefslogtreecommitdiff
path: root/src/java.base/share/classes/java/lang/ThreadLocal.java
diff options
context:
space:
mode:
authorMandy Chung <mchung@openjdk.org>2020-12-06 00:08:22 +0000
committerMandy Chung <mchung@openjdk.org>2020-12-06 00:08:22 +0000
commit972bc3b408251b0566f1f488382e66b8cee3c8dd (patch)
tree64b6b42b6df389763c3860c7d6d40c8b32e887f2 /src/java.base/share/classes/java/lang/ThreadLocal.java
parent78be334c3817a1b5840922a9bf1339a40dcc5185 (diff)
downloadopenjdk-972bc3b408251b0566f1f488382e66b8cee3c8dd.tar.gz
openjdk-972bc3b408251b0566f1f488382e66b8cee3c8dd.zip
8256167: Convert JDK use of `Reference::get` to `Reference::refersTo`
Reviewed-by: sspitsyn, shade, dfuchs, alanb, kbarrett
Diffstat (limited to 'src/java.base/share/classes/java/lang/ThreadLocal.java')
-rw-r--r--src/java.base/share/classes/java/lang/ThreadLocal.java31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/java.base/share/classes/java/lang/ThreadLocal.java b/src/java.base/share/classes/java/lang/ThreadLocal.java
index 35529d4a142..ae696768395 100644
--- a/src/java.base/share/classes/java/lang/ThreadLocal.java
+++ b/src/java.base/share/classes/java/lang/ThreadLocal.java
@@ -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);
}
}