< prev index next >

src/java.base/share/classes/jdk/internal/module/SystemModuleFinders.java

Print this page

 37 import java.nio.ByteBuffer;
 38 import java.nio.file.Files;
 39 import java.nio.file.Path;
 40 import java.util.ArrayDeque;
 41 import java.util.Collections;
 42 import java.util.Deque;
 43 import java.util.HashMap;
 44 import java.util.HashSet;
 45 import java.util.Iterator;
 46 import java.util.Map;
 47 import java.util.Objects;
 48 import java.util.Optional;
 49 import java.util.Set;
 50 import java.util.Spliterator;
 51 import java.util.function.Consumer;
 52 import java.util.function.Supplier;
 53 import java.util.stream.Stream;
 54 import java.util.stream.StreamSupport;
 55 
 56 import jdk.internal.jimage.ImageReader;
 57 import jdk.internal.jimage.ImageReaderFactory;
 58 import jdk.internal.access.JavaNetUriAccess;
 59 import jdk.internal.access.SharedSecrets;
 60 import jdk.internal.util.StaticProperty;
 61 import jdk.internal.module.ModuleHashes.HashSupplier;
 62 
 63 /**
 64  * The factory for SystemModules objects and for creating ModuleFinder objects
 65  * that find modules in the runtime image.
 66  *
 67  * This class supports initializing the module system when the runtime is an
 68  * images build, an exploded build, or an images build with java.base patched
 69  * by an exploded java.base. It also supports a testing mode that re-parses
 70  * the module-info.class resources in the run-time image.
 71  */
 72 
 73 public final class SystemModuleFinders {
 74     private static final JavaNetUriAccess JNUA = SharedSecrets.getJavaNetUriAccess();
 75 
 76     private static final boolean USE_FAST_PATH;
 77     static {

375      */
376     static HashSupplier hashSupplier(Map<String, byte[]> nameToHash, String name) {
377         byte[] hash = nameToHash.get(name);
378         if (hash != null) {
379             // avoid lambda here
380             return new HashSupplier() {
381                 @Override
382                 public byte[] generate(String algorithm) {
383                     return hash;
384                 }
385             };
386         } else {
387             return null;
388         }
389     }
390 
391     /**
392      * Holder class for the ImageReader.
393      */
394     private static class SystemImage {
395         static final ImageReader READER = ImageReaderFactory.getImageReader();
396         static ImageReader reader() {
397             return READER;
398         }
399     }
400 
401     /**
402      * A ModuleReader for reading resources from a module linked into the
403      * run-time image.
404      */
405     private static class SystemModuleReader implements ModuleReader {
406         private final String module;
407         private volatile boolean closed;
408 
409         SystemModuleReader(String module) {
410             this.module = module;
411         }
412 
413         /**
414          * Returns {@code true} if the given resource exists, {@code false}
415          * if not found.

 37 import java.nio.ByteBuffer;
 38 import java.nio.file.Files;
 39 import java.nio.file.Path;
 40 import java.util.ArrayDeque;
 41 import java.util.Collections;
 42 import java.util.Deque;
 43 import java.util.HashMap;
 44 import java.util.HashSet;
 45 import java.util.Iterator;
 46 import java.util.Map;
 47 import java.util.Objects;
 48 import java.util.Optional;
 49 import java.util.Set;
 50 import java.util.Spliterator;
 51 import java.util.function.Consumer;
 52 import java.util.function.Supplier;
 53 import java.util.stream.Stream;
 54 import java.util.stream.StreamSupport;
 55 
 56 import jdk.internal.jimage.ImageReader;
 57 import jdk.internal.jimage.SystemImageReader;
 58 import jdk.internal.access.JavaNetUriAccess;
 59 import jdk.internal.access.SharedSecrets;
 60 import jdk.internal.util.StaticProperty;
 61 import jdk.internal.module.ModuleHashes.HashSupplier;
 62 
 63 /**
 64  * The factory for SystemModules objects and for creating ModuleFinder objects
 65  * that find modules in the runtime image.
 66  *
 67  * This class supports initializing the module system when the runtime is an
 68  * images build, an exploded build, or an images build with java.base patched
 69  * by an exploded java.base. It also supports a testing mode that re-parses
 70  * the module-info.class resources in the run-time image.
 71  */
 72 
 73 public final class SystemModuleFinders {
 74     private static final JavaNetUriAccess JNUA = SharedSecrets.getJavaNetUriAccess();
 75 
 76     private static final boolean USE_FAST_PATH;
 77     static {

375      */
376     static HashSupplier hashSupplier(Map<String, byte[]> nameToHash, String name) {
377         byte[] hash = nameToHash.get(name);
378         if (hash != null) {
379             // avoid lambda here
380             return new HashSupplier() {
381                 @Override
382                 public byte[] generate(String algorithm) {
383                     return hash;
384                 }
385             };
386         } else {
387             return null;
388         }
389     }
390 
391     /**
392      * Holder class for the ImageReader.
393      */
394     private static class SystemImage {
395         static final ImageReader READER = SystemImageReader.get();
396         static ImageReader reader() {
397             return READER;
398         }
399     }
400 
401     /**
402      * A ModuleReader for reading resources from a module linked into the
403      * run-time image.
404      */
405     private static class SystemModuleReader implements ModuleReader {
406         private final String module;
407         private volatile boolean closed;
408 
409         SystemModuleReader(String module) {
410             this.module = module;
411         }
412 
413         /**
414          * Returns {@code true} if the given resource exists, {@code false}
415          * if not found.
< prev index next >