Path: blob/master/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java
41159 views
/*1* Copyright (c) 2015, 2018, 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*/2425package jdk.internal.loader;2627import java.lang.module.Configuration;28import java.lang.module.ResolvedModule;29import java.util.HashMap;30import java.util.List;31import java.util.Map;32import java.util.stream.Stream;3334/**35* A pool of class loaders.36*37* @see ModuleLayer#defineModulesWithManyLoaders38*/3940public final class LoaderPool {4142// maps module names to class loaders43private final Map<String, Loader> loaders;444546/**47* Creates a pool of class loaders. Each module in the given configuration48* is mapped to its own class loader in the pool. The class loader is49* created with the given parent class loader as its parent.50*/51public LoaderPool(Configuration cf,52List<ModuleLayer> parentLayers,53ClassLoader parentLoader)54{55Map<String, Loader> loaders = new HashMap<>();56for (ResolvedModule resolvedModule : cf.modules()) {57Loader loader = new Loader(resolvedModule, this, parentLoader);58String mn = resolvedModule.name();59loaders.put(mn, loader);60}61this.loaders = loaders;6263// complete the initialization64loaders.values().forEach(l -> l.initRemotePackageMap(cf, parentLayers));65}666768/**69* Returns the class loader for the named module70*/71public Loader loaderFor(String name) {72Loader loader = loaders.get(name);73assert loader != null;74return loader;75}7677/**78* Returns a stream of the loaders in this pool.79*/80public Stream<Loader> loaders() {81return loaders.values().stream();82}8384}858687