< prev index next >

src/java.base/share/classes/java/lang/ClassLoader.java

Print this page




2985                 // beaten by someone else
2986                 map = classLoaderValueMap;
2987             }
2988         }
2989         return map;
2990     }
2991 
2992     // the storage for ClassLoaderValue(s) associated with this ClassLoader
2993     private volatile ConcurrentHashMap<?, ?> classLoaderValueMap;
2994 
2995     /**
2996      * Attempts to atomically set a volatile field in this object. Returns
2997      * {@code true} if not beaten by another thread. Avoids the use of
2998      * AtomicReferenceFieldUpdater in this class.
2999      */
3000     private boolean trySetObjectField(String name, Object obj) {
3001         Unsafe unsafe = Unsafe.getUnsafe();
3002         Class<?> k = ClassLoader.class;
3003         long offset;
3004         offset = unsafe.objectFieldOffset(k, name);
3005         return unsafe.compareAndSetObject(this, offset, null, obj);
3006     }
3007 }
3008 
3009 /*
3010  * A utility class that will enumerate over an array of enumerations.
3011  */
3012 final class CompoundEnumeration<E> implements Enumeration<E> {
3013     private final Enumeration<E>[] enums;
3014     private int index;
3015 
3016     public CompoundEnumeration(Enumeration<E>[] enums) {
3017         this.enums = enums;
3018     }
3019 
3020     private boolean next() {
3021         while (index < enums.length) {
3022             if (enums[index] != null && enums[index].hasMoreElements()) {
3023                 return true;
3024             }
3025             index++;


2985                 // beaten by someone else
2986                 map = classLoaderValueMap;
2987             }
2988         }
2989         return map;
2990     }
2991 
2992     // the storage for ClassLoaderValue(s) associated with this ClassLoader
2993     private volatile ConcurrentHashMap<?, ?> classLoaderValueMap;
2994 
2995     /**
2996      * Attempts to atomically set a volatile field in this object. Returns
2997      * {@code true} if not beaten by another thread. Avoids the use of
2998      * AtomicReferenceFieldUpdater in this class.
2999      */
3000     private boolean trySetObjectField(String name, Object obj) {
3001         Unsafe unsafe = Unsafe.getUnsafe();
3002         Class<?> k = ClassLoader.class;
3003         long offset;
3004         offset = unsafe.objectFieldOffset(k, name);
3005         return unsafe.compareAndSetReference(this, offset, null, obj);
3006     }
3007 }
3008 
3009 /*
3010  * A utility class that will enumerate over an array of enumerations.
3011  */
3012 final class CompoundEnumeration<E> implements Enumeration<E> {
3013     private final Enumeration<E>[] enums;
3014     private int index;
3015 
3016     public CompoundEnumeration(Enumeration<E>[] enums) {
3017         this.enums = enums;
3018     }
3019 
3020     private boolean next() {
3021         while (index < enums.length) {
3022             if (enums[index] != null && enums[index].hasMoreElements()) {
3023                 return true;
3024             }
3025             index++;
< prev index next >