Path: blob/master/src/java.base/share/classes/jdk/internal/loader/ArchivedClassLoaders.java
41159 views
/*1* Copyright (c) 2020, 2021, 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.loader;2526import java.util.Map;27import jdk.internal.misc.CDS;28import jdk.internal.module.ServicesCatalog;2930/**31* Used to archive the built-in class loaders, their services catalogs, and the32* package-to-module map used by the built-in class loaders.33*/34class ArchivedClassLoaders {35private static ArchivedClassLoaders archivedClassLoaders;3637private final ClassLoader bootLoader;38private final ClassLoader platformLoader;39private final ClassLoader appLoader;40private final ServicesCatalog[] servicesCatalogs;41private final Map<String, ?> packageToModule;4243private ArchivedClassLoaders() {44bootLoader = ClassLoaders.bootLoader();45platformLoader = ClassLoaders.platformClassLoader();46appLoader = ClassLoaders.appClassLoader();4748servicesCatalogs = new ServicesCatalog[3];49servicesCatalogs[0] = ServicesCatalog.getServicesCatalog(bootLoader);50servicesCatalogs[1] = ServicesCatalog.getServicesCatalog(platformLoader);51servicesCatalogs[2] = ServicesCatalog.getServicesCatalog(appLoader);5253packageToModule = BuiltinClassLoader.packageToModule();54}5556ClassLoader bootLoader() {57return bootLoader;58}5960ClassLoader platformLoader() {61return platformLoader;62}6364ClassLoader appLoader() {65return appLoader;66}6768ServicesCatalog servicesCatalog(ClassLoader loader) {69if (loader == bootLoader) {70return servicesCatalogs[0];71} else if (loader == platformLoader) {72return servicesCatalogs[1];73} else if (loader == appLoader) {74return servicesCatalogs[2];75} else {76throw new InternalError();77}78}7980Map<String, ?> packageToModule() {81return packageToModule;82}8384static void archive() {85archivedClassLoaders = new ArchivedClassLoaders();86}8788static ArchivedClassLoaders get() {89return archivedClassLoaders;90}9192static {93CDS.initializeFromArchive(ArchivedClassLoaders.class);94}95}969798