Path: blob/master/src/java.base/share/classes/jdk/internal/module/ArchivedModuleGraph.java
41159 views
/*1* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package jdk.internal.module;2526import java.util.function.Function;27import java.lang.module.Configuration;28import java.lang.module.ModuleFinder;29import jdk.internal.misc.CDS;3031/**32* Used by ModuleBootstrap for archiving the configuration for the boot layer,33* and the system module finder.34*/35class ArchivedModuleGraph {36private static ArchivedModuleGraph archivedModuleGraph;3738private final boolean hasSplitPackages;39private final boolean hasIncubatorModules;40private final ModuleFinder finder;41private final Configuration configuration;42private final Function<String, ClassLoader> classLoaderFunction;4344private ArchivedModuleGraph(boolean hasSplitPackages,45boolean hasIncubatorModules,46ModuleFinder finder,47Configuration configuration,48Function<String, ClassLoader> classLoaderFunction) {49this.hasSplitPackages = hasSplitPackages;50this.hasIncubatorModules = hasIncubatorModules;51this.finder = finder;52this.configuration = configuration;53this.classLoaderFunction = classLoaderFunction;54}5556ModuleFinder finder() {57return finder;58}5960Configuration configuration() {61return configuration;62}6364Function<String, ClassLoader> classLoaderFunction() {65return classLoaderFunction;66}6768boolean hasSplitPackages() {69return hasSplitPackages;70}7172boolean hasIncubatorModules() {73return hasIncubatorModules;74}7576/**77* Returns the ArchivedModuleGraph for the given initial module.78*/79static ArchivedModuleGraph get(String mainModule) {80ArchivedModuleGraph graph = archivedModuleGraph;81// We only allow the unnamed module (default) case for now82if (mainModule == null) {83return graph;84} else {85return null;86}87}8889/**90* Archive the module graph for the given initial module.91*/92static void archive(boolean hasSplitPackages,93boolean hasIncubatorModules,94ModuleFinder finder,95Configuration configuration,96Function<String, ClassLoader> classLoaderFunction) {97archivedModuleGraph = new ArchivedModuleGraph(hasSplitPackages,98hasIncubatorModules,99finder,100configuration,101classLoaderFunction);102}103104static {105CDS.initializeFromArchive(ArchivedModuleGraph.class);106}107}108109110