11/*
2- * Copyright (c) 1997, 2013 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1997, 2020 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2626package java .lang ;
2727import jdk .internal .misc .TerminatingThreadLocal ;
2828
29- import java .lang .ref .* ;
29+ import java .lang .ref .WeakReference ;
3030import java .util .Objects ;
3131import java .util .concurrent .atomic .AtomicInteger ;
3232import java .util .function .Supplier ;
@@ -433,7 +433,7 @@ private ThreadLocalMap(ThreadLocalMap parentMap) {
433433 private Entry getEntry (ThreadLocal <?> key ) {
434434 int i = key .threadLocalHashCode & (table .length - 1 );
435435 Entry e = table [i ];
436- if (e != null && e .get () == key )
436+ if (e != null && e .refersTo ( key ) )
437437 return e ;
438438 else
439439 return getEntryAfterMiss (key , i , e );
@@ -453,10 +453,9 @@ private Entry getEntryAfterMiss(ThreadLocal<?> key, int i, Entry e) {
453453 int len = tab .length ;
454454
455455 while (e != null ) {
456- ThreadLocal <?> k = e .get ();
457- if (k == key )
456+ if (e .refersTo (key ))
458457 return e ;
459- if (k == null )
458+ if (e . refersTo ( null ) )
460459 expungeStaleEntry (i );
461460 else
462461 i = nextIndex (i , len );
@@ -485,14 +484,12 @@ private void set(ThreadLocal<?> key, Object value) {
485484 for (Entry e = tab [i ];
486485 e != null ;
487486 e = tab [i = nextIndex (i , len )]) {
488- ThreadLocal <?> k = e .get ();
489-
490- if (k == key ) {
487+ if (e .refersTo (key )) {
491488 e .value = value ;
492489 return ;
493490 }
494491
495- if (k == null ) {
492+ if (e . refersTo ( null ) ) {
496493 replaceStaleEntry (key , value , i );
497494 return ;
498495 }
@@ -514,7 +511,7 @@ private void remove(ThreadLocal<?> key) {
514511 for (Entry e = tab [i ];
515512 e != null ;
516513 e = tab [i = nextIndex (i , len )]) {
517- if (e .get () == key ) {
514+ if (e .refersTo ( key ) ) {
518515 e .clear ();
519516 expungeStaleEntry (i );
520517 return ;
@@ -551,22 +548,20 @@ private void replaceStaleEntry(ThreadLocal<?> key, Object value,
551548 for (int i = prevIndex (staleSlot , len );
552549 (e = tab [i ]) != null ;
553550 i = prevIndex (i , len ))
554- if (e .get () == null )
551+ if (e .refersTo ( null ) )
555552 slotToExpunge = i ;
556553
557554 // Find either the key or trailing null slot of run, whichever
558555 // occurs first
559556 for (int i = nextIndex (staleSlot , len );
560557 (e = tab [i ]) != null ;
561558 i = nextIndex (i , len )) {
562- ThreadLocal <?> k = e .get ();
563-
564559 // If we find key, then we need to swap it
565560 // with the stale entry to maintain hash table order.
566561 // The newly stale slot, or any other stale slot
567562 // encountered above it, can then be sent to expungeStaleEntry
568563 // to remove or rehash all of the other entries in run.
569- if (k == key ) {
564+ if (e . refersTo ( key ) ) {
570565 e .value = value ;
571566
572567 tab [i ] = tab [staleSlot ];
@@ -582,7 +577,7 @@ private void replaceStaleEntry(ThreadLocal<?> key, Object value,
582577 // If we didn't find stale entry on backward scan, the
583578 // first stale entry seen while scanning for key is the
584579 // first still present in the run.
585- if (k == null && slotToExpunge == staleSlot )
580+ if (e . refersTo ( null ) && slotToExpunge == staleSlot )
586581 slotToExpunge = i ;
587582 }
588583
@@ -673,7 +668,7 @@ private boolean cleanSomeSlots(int i, int n) {
673668 do {
674669 i = nextIndex (i , len );
675670 Entry e = tab [i ];
676- if (e != null && e .get () == null ) {
671+ if (e != null && e .refersTo ( null ) ) {
677672 n = len ;
678673 removed = true ;
679674 i = expungeStaleEntry (i );
@@ -733,7 +728,7 @@ private void expungeStaleEntries() {
733728 int len = tab .length ;
734729 for (int j = 0 ; j < len ; j ++) {
735730 Entry e = tab [j ];
736- if (e != null && e .get () == null )
731+ if (e != null && e .refersTo ( null ) )
737732 expungeStaleEntry (j );
738733 }
739734 }
0 commit comments