mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +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
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 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
|
||||
|
@ -1755,7 +1755,7 @@ public abstract class ResourceBundle {
|
|||
// Otherwise, remove the cached one since we can't keep
|
||||
// the same bundles having different parents.
|
||||
BundleReference bundleRef = cacheList.get(cacheKey);
|
||||
if (bundleRef != null && bundleRef.get() == bundle) {
|
||||
if (bundleRef != null && bundleRef.refersTo(bundle)) {
|
||||
cacheList.remove(cacheKey, bundleRef);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
|
@ -27,7 +27,6 @@ package java.util;
|
|||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
|
@ -283,8 +282,14 @@ public class WeakHashMap<K,V>
|
|||
* Checks for equality of non-null reference x and possibly-null y. By
|
||||
* default uses Object.equals.
|
||||
*/
|
||||
private static boolean eq(Object x, Object y) {
|
||||
return x == y || x.equals(y);
|
||||
private boolean matchesKey(Entry<K,V> e, Object key) {
|
||||
// check if the given entry refers to the given key without
|
||||
// keeping a strong reference to the entry's referent
|
||||
if (e.refersTo(key)) return true;
|
||||
|
||||
// then check for equality if the referent is not cleared
|
||||
Object k = e.get();
|
||||
return k != null && key.equals(k);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -399,7 +404,7 @@ public class WeakHashMap<K,V>
|
|||
int index = indexFor(h, tab.length);
|
||||
Entry<K,V> e = tab[index];
|
||||
while (e != null) {
|
||||
if (e.hash == h && eq(k, e.get()))
|
||||
if (e.hash == h && matchesKey(e, k))
|
||||
return e.value;
|
||||
e = e.next;
|
||||
}
|
||||
|
@ -428,7 +433,7 @@ public class WeakHashMap<K,V>
|
|||
Entry<K,V>[] tab = getTable();
|
||||
int index = indexFor(h, tab.length);
|
||||
Entry<K,V> e = tab[index];
|
||||
while (e != null && !(e.hash == h && eq(k, e.get())))
|
||||
while (e != null && !(e.hash == h && matchesKey(e, k)))
|
||||
e = e.next;
|
||||
return e;
|
||||
}
|
||||
|
@ -452,7 +457,7 @@ public class WeakHashMap<K,V>
|
|||
int i = indexFor(h, tab.length);
|
||||
|
||||
for (Entry<K,V> e = tab[i]; e != null; e = e.next) {
|
||||
if (h == e.hash && eq(k, e.get())) {
|
||||
if (h == e.hash && matchesKey(e, k)) {
|
||||
V oldValue = e.value;
|
||||
if (value != oldValue)
|
||||
e.value = value;
|
||||
|
@ -515,8 +520,7 @@ public class WeakHashMap<K,V>
|
|||
src[j] = null;
|
||||
while (e != null) {
|
||||
Entry<K,V> next = e.next;
|
||||
Object key = e.get();
|
||||
if (key == null) {
|
||||
if (e.refersTo(null)) {
|
||||
e.next = null; // Help GC
|
||||
e.value = null; // " "
|
||||
size--;
|
||||
|
@ -597,7 +601,7 @@ public class WeakHashMap<K,V>
|
|||
|
||||
while (e != null) {
|
||||
Entry<K,V> next = e.next;
|
||||
if (h == e.hash && eq(k, e.get())) {
|
||||
if (h == e.hash && matchesKey(e, k)) {
|
||||
modCount++;
|
||||
size--;
|
||||
if (prev == e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue