< prev index next >

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

Print this page


2697             }
2698         }
2699         return map;
2700     }
2701 
2702     // the storage for ClassLoaderValue(s) associated with this ClassLoader
2703     private volatile ConcurrentHashMap<?, ?> classLoaderValueMap;
2704 
2705     /**
2706      * Attempts to atomically set a volatile field in this object. Returns
2707      * {@code true} if not beaten by another thread. Avoids the use of
2708      * AtomicReferenceFieldUpdater in this class.
2709      */
2710     private boolean trySetObjectField(String name, Object obj) {
2711         Unsafe unsafe = Unsafe.getUnsafe();
2712         Class<?> k = ClassLoader.class;
2713         long offset;
2714         offset = unsafe.objectFieldOffset(k, name);
2715         return unsafe.compareAndSetReference(this, offset, null, obj);
2716     }











2717 }
2718 
2719 /*
2720  * A utility class that will enumerate over an array of enumerations.
2721  */
2722 final class CompoundEnumeration<E> implements Enumeration<E> {
2723     private final Enumeration<E>[] enums;
2724     private int index;
2725 
2726     public CompoundEnumeration(Enumeration<E>[] enums) {
2727         this.enums = enums;
2728     }
2729 
2730     private boolean next() {
2731         while (index < enums.length) {
2732             if (enums[index] != null && enums[index].hasMoreElements()) {
2733                 return true;
2734             }
2735             index++;
2736         }


2697             }
2698         }
2699         return map;
2700     }
2701 
2702     // the storage for ClassLoaderValue(s) associated with this ClassLoader
2703     private volatile ConcurrentHashMap<?, ?> classLoaderValueMap;
2704 
2705     /**
2706      * Attempts to atomically set a volatile field in this object. Returns
2707      * {@code true} if not beaten by another thread. Avoids the use of
2708      * AtomicReferenceFieldUpdater in this class.
2709      */
2710     private boolean trySetObjectField(String name, Object obj) {
2711         Unsafe unsafe = Unsafe.getUnsafe();
2712         Class<?> k = ClassLoader.class;
2713         long offset;
2714         offset = unsafe.objectFieldOffset(k, name);
2715         return unsafe.compareAndSetReference(this, offset, null, obj);
2716     }
2717 
2718     /**
2719      * Called by the VM, during -Xshare:dump
2720      */
2721     private void resetArchivedStates() {
2722         parallelLockMap.clear();
2723         packages.clear();
2724         package2certs.clear();
2725         classes.clear();
2726         classLoaderValueMap = null;
2727     }
2728 }
2729 
2730 /*
2731  * A utility class that will enumerate over an array of enumerations.
2732  */
2733 final class CompoundEnumeration<E> implements Enumeration<E> {
2734     private final Enumeration<E>[] enums;
2735     private int index;
2736 
2737     public CompoundEnumeration(Enumeration<E>[] enums) {
2738         this.enums = enums;
2739     }
2740 
2741     private boolean next() {
2742         while (index < enums.length) {
2743             if (enums[index] != null && enums[index].hasMoreElements()) {
2744                 return true;
2745             }
2746             index++;
2747         }
< prev index next >