166 // maps a module name to a module reference
167 private final Map<String, ModuleReference> nameToModule;
168
169 // maps a module reference to a module reader
170 private final Map<ModuleReference, ModuleReader> moduleToReader;
171
172 // cache of resource name -> list of URLs.
173 // used only for resources that are not in module packages
174 private volatile SoftReference<Map<String, List<URL>>> resourceCache;
175
176 /**
177 * Create a new instance.
178 */
179 BuiltinClassLoader(String name, BuiltinClassLoader parent, URLClassPath ucp) {
180 // ensure getParent() returns null when the parent is the boot loader
181 super(name, parent == null || parent == ClassLoaders.bootLoader() ? null : parent);
182
183 this.parent = parent;
184 this.ucp = ucp;
185
186 this.nameToModule = new ConcurrentHashMap<>();
187 this.moduleToReader = new ConcurrentHashMap<>();
188 }
189
190 /**
191 * Returns {@code true} if there is a class path associated with this
192 * class loader.
193 */
194 boolean hasClassPath() {
195 return ucp != null;
196 }
197
198 /**
199 * Register a module this class loader. This has the effect of making the
200 * types in the module visible.
201 */
202 public void loadModule(ModuleReference mref) {
203 String mn = mref.descriptor().name();
204 if (nameToModule.putIfAbsent(mn, mref) != null) {
205 throw new InternalError(mn + " already defined to this loader");
206 }
|
166 // maps a module name to a module reference
167 private final Map<String, ModuleReference> nameToModule;
168
169 // maps a module reference to a module reader
170 private final Map<ModuleReference, ModuleReader> moduleToReader;
171
172 // cache of resource name -> list of URLs.
173 // used only for resources that are not in module packages
174 private volatile SoftReference<Map<String, List<URL>>> resourceCache;
175
176 /**
177 * Create a new instance.
178 */
179 BuiltinClassLoader(String name, BuiltinClassLoader parent, URLClassPath ucp) {
180 // ensure getParent() returns null when the parent is the boot loader
181 super(name, parent == null || parent == ClassLoaders.bootLoader() ? null : parent);
182
183 this.parent = parent;
184 this.ucp = ucp;
185
186 this.nameToModule = new ConcurrentHashMap<>(32);
187 this.moduleToReader = new ConcurrentHashMap<>();
188 }
189
190 /**
191 * Returns {@code true} if there is a class path associated with this
192 * class loader.
193 */
194 boolean hasClassPath() {
195 return ucp != null;
196 }
197
198 /**
199 * Register a module this class loader. This has the effect of making the
200 * types in the module visible.
201 */
202 public void loadModule(ModuleReference mref) {
203 String mn = mref.descriptor().name();
204 if (nameToModule.putIfAbsent(mn, mref) != null) {
205 throw new InternalError(mn + " already defined to this loader");
206 }
|