Path: blob/master/jcl/src/java.base/share/classes/java/lang/ClassLoader.java
12513 views
/*[INCLUDE-IF Sidecar18-SE]*/1/*******************************************************************************2* Copyright (c) 1998, 2022 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/22package java.lang;2324import java.io.*;25import java.security.CodeSource;26import java.security.ProtectionDomain;2728/*[IF !Sidecar19-SE]29import com.ibm.oti.vm.AbstractClassLoader;30/*[ENDIF]*/31import com.ibm.oti.vm.VM;3233import java.net.URL;34import java.util.Enumeration;35import java.util.HashMap;36import java.util.Hashtable;37import java.util.LinkedList;38import java.util.Map;39import java.util.NoSuchElementException;40import java.util.Queue;41import java.util.Vector;42import java.util.Collections;43import java.util.WeakHashMap;44import java.lang.ref.ReferenceQueue;45import java.lang.ref.WeakReference;46import java.lang.reflect.*;47import java.security.cert.Certificate;48import sun.security.util.SecurityConstants;4950/*[IF JAVA_SPEC_VERSION >= 11]*/51import java.lang.reflect.Modifier;52import java.util.Spliterator;53import java.util.Spliterators;54import java.util.stream.Stream;55import java.util.stream.StreamSupport;56import jdk.internal.module.ServicesCatalog;57import java.util.concurrent.ConcurrentHashMap;58import jdk.internal.reflect.CallerSensitive;59import jdk.internal.loader.ClassLoaders;60import jdk.internal.loader.BootLoader;61/*[ELSE]62import sun.reflect.CallerSensitive;63/*[ENDIF]*/6465/*[IF JAVA_SPEC_VERSION >= 15]*/66import jdk.internal.loader.NativeLibraries;67import jdk.internal.loader.NativeLibrary;68/*[ENDIF] JAVA_SPEC_VERSION >= 15 */6970/*[IF JAVA_SPEC_VERSION >= 18]*/71import jdk.internal.reflect.CallerSensitiveAdapter;72/*[ENDIF] JAVA_SPEC_VERSION >= 18 */7374/**75* ClassLoaders are used to dynamically load, link and install76* classes into a running image.77*78* @version initial79*/80public abstract class ClassLoader {81private static CodeSource defaultCodeSource = new CodeSource(null, (Certificate[])null);828384/**85* This is the bootstrap ClassLoader86*/87static ClassLoader bootstrapClassLoader;88/*[IF Sidecar19-SE]*/89private ServicesCatalog servicesCatalog;90private final Module unnamedModule;91private final String classLoaderName;92private final static String DELEGATING_CL = "jdk.internal.reflect.DelegatingClassLoader"; //$NON-NLS-1$93/*[ELSE]94private final static String DELEGATING_CL = "sun.reflect.DelegatingClassLoader"; //$NON-NLS-1$95/*[ENDIF]*/96private boolean isDelegatingCL = false;9798/*99* This is the application ClassLoader100*/101private static ClassLoader applicationClassLoader;102private static boolean initSystemClassLoader;103private final static boolean isAssertOptionFound = foundJavaAssertOption();104105private long vmRef;106ClassLoader parent;107108/*[PR CMVC 130382] Optimize checking ClassLoader assertion status */109private static boolean checkAssertionOptions;110/*[PR CMVC 94437] fix deadlocks */111/*[PR 122459] LIR646 - Remove use of generic object for synchronization */112private static final class AssertionLock { AssertionLock() {} }113private final Object assertionLock = new AssertionLock();114private boolean defaultAssertionStatus;115private Map<String, Boolean> packageAssertionStatus;116private Map<String, Boolean> classAssertionStatus;117/*[IF Sidecar19-SE]*/118private final Hashtable<String, NamedPackage> packages = new Hashtable<>();119private volatile ConcurrentHashMap<?, ?> classLoaderValueMap;120/*[ELSE]121private final Hashtable<String, Package> packages = new Hashtable<>();122/*[ENDIF] Sidecar19-SE*/123/*[PR CMVC 94437] fix deadlocks */124/*[PR 122459] LIR646 - Remove use of generic object for synchronization */125private static final class LazyInitLock { LazyInitLock() {} }126private final Object lazyInitLock = new LazyInitLock();127private volatile Hashtable<Class<?>, Object[]> classSigners; // initialized if needed128private volatile Hashtable<String, Certificate[]> packageSigners;129private static Certificate[] emptyCertificates = new Certificate[0];130private volatile ProtectionDomain defaultProtectionDomain;131132// store parallel capable classloader classes133private static Map<Class<?>, Object> parallelCapableCollection;134// store class binary name based lock135private volatile Hashtable<String, ClassNameLockRef> classNameBasedLock;136// for performance purpose, only check once if registered as parallel capable137// assume customer classloader follow Java specification requirement138// in which registerAsParallelCapable shall be invoked during initialization139private boolean isParallelCapable;140private static final class ClassNameBasedLock { ClassNameBasedLock() {} }141private static final Package[] EMPTY_PACKAGE_ARRAY = new Package[0];142143// Cache instances of java.lang.invoke.MethodType generated from method descriptor strings144private Map<String, java.lang.invoke.MethodType> methodTypeFromMethodDescriptorStringCache;145146private static boolean allowArraySyntax;147/*[IF Sidecar19-SE]*/148private static boolean lazyClassLoaderInit = true;149/*[ELSE]150private static boolean lazyClassLoaderInit = false;151/*[ENDIF]*/152private static boolean specialLoaderInited = false;153private static InternalAnonymousClassLoader internalAnonClassLoader;154/*[IF JAVA_SPEC_VERSION >= 15]*/155private NativeLibraries nativelibs = null;156/*[ENDIF] JAVA_SPEC_VERSION >= 15 */157private static native void initAnonClassLoader(InternalAnonymousClassLoader anonClassLoader);158159/*[PR JAZZ 73143]: ClassLoader incorrectly discards class loading locks*/160static final class ClassNameLockRef extends WeakReference<Object> implements Runnable {161private static final ReferenceQueue<Object> queue = new ReferenceQueue<>();162private final String key;163private final Hashtable<?, ?> classNameLockHT;164public ClassNameLockRef(Object referent, String keyValue, Hashtable<?, ?> classNameLockHTValue) {165super(referent, queue);166key = keyValue;167classNameLockHT = classNameLockHTValue;168}169@Override170public void run() {171synchronized(classNameLockHT) {172if (classNameLockHT.get(key) == this) {173classNameLockHT.remove(key);174}175}176}177}178179static final void initializeClassLoaders() {180if (null != bootstrapClassLoader) {181return;182}183parallelCapableCollection = Collections.synchronizedMap(new WeakHashMap<>());184185allowArraySyntax = "true".equalsIgnoreCase( //$NON-NLS-1$186System.internalGetProperties().getProperty("sun.lang.ClassLoader.allowArraySyntax")); //$NON-NLS-1$187188/*[PR CMVC 193184] reflect.cache must be enabled here, otherwise performance slow down is experienced */189String propValue = System.internalGetProperties().getProperty("reflect.cache"); //$NON-NLS-1$190if (propValue != null) propValue = propValue.toLowerCase();191/* Do not enable reflect cache if -Dreflect.cache=false is in commandline */192boolean reflectCacheEnabled = false;193boolean reflectCacheDebug = false;194if (!"false".equals(propValue)) { //$NON-NLS-1$195/*JAZZ 42080: Turning off reflection caching for cloud to reduce Object Leaks*/196reflectCacheEnabled = true;197if (propValue != null) {198int debugIndex = propValue.indexOf("debug"); //$NON-NLS-1$199if (debugIndex >= 0) {200/*[PR 125873] Improve reflection cache */201/* reflect.cache=boot is handled in completeInitialization() */202reflectCacheDebug = true;203}204}205}206207try {208/* CMVC 179008 - b143 needs ProtectionDomain initialized here */209Class.forName("java.security.ProtectionDomain"); //$NON-NLS-1$210} catch(ClassNotFoundException e) {211// ignore212}213214/*[IF JAVA_SPEC_VERSION >= 11]*/215// This static method call ensures jdk.internal.loader.ClassLoaders.BOOT_LOADER initialization first216jdk.internal.loader.ClassLoaders.platformClassLoader();217if (bootstrapClassLoader.servicesCatalog != null) {218throw new InternalError("bootstrapClassLoader.servicesCatalog is NOT null "); //$NON-NLS-1$219}220bootstrapClassLoader.servicesCatalog = BootLoader.getServicesCatalog();221if (bootstrapClassLoader.classLoaderValueMap != null) {222/*[IF JAVA_SPEC_VERSION < 17]*/223throw new InternalError("bootstrapClassLoader.classLoaderValueMap is NOT null "); //$NON-NLS-1$224/*[ENDIF] JAVA_SPEC_VERSION < 17 */225} else {226bootstrapClassLoader.classLoaderValueMap = BootLoader.getClassLoaderValueMap();227}228applicationClassLoader = ClassLoaders.appClassLoader();229/*[ELSE] JAVA_SPEC_VERSION >= 11 */230ClassLoader sysTemp = null;231// Proper initialization requires BootstrapLoader is the first loader instantiated232String systemLoaderString = System.internalGetProperties().getProperty("systemClassLoader"); //$NON-NLS-1$233if (null == systemLoaderString) {234sysTemp = com.ibm.oti.vm.BootstrapClassLoader.singleton();235} else {236try {237sysTemp = (ClassLoader)Class.forName(systemLoaderString, true, null).newInstance();238} catch (Throwable x) {239x.printStackTrace();240System.exit(1);241}242}243bootstrapClassLoader = sysTemp;244AbstractClassLoader.setBootstrapClassLoader(bootstrapClassLoader);245lazyClassLoaderInit = true;246applicationClassLoader = bootstrapClassLoader;247/*[ENDIF] JAVA_SPEC_VERSION >= 11 */248249/* [PR 78889] The creation of this classLoader requires lazy initialization. The internal classLoader struct250* is created in the initAnonClassLoader call. The "new InternalAnonymousClassLoader()" call must be251* done exactly after lazyClassLoaderInit is set and before the "java.lang.ClassLoader.lazyInitialization"252* is read in. This is the only way to guarantee that ClassLoader will be created with lazy initialization. */253internalAnonClassLoader = new InternalAnonymousClassLoader();254initAnonClassLoader(internalAnonClassLoader);255256String lazyValue = System.internalGetProperties().getProperty("java.lang.ClassLoader.lazyInitialization"); //$NON-NLS-1$257if (null != lazyValue) {258lazyValue = lazyValue.toLowerCase();259if ("false".equals(lazyValue)) { //$NON-NLS-1$260lazyClassLoaderInit = false;261}262}263264/*[IF Sidecar19-SE]*/265jdk.internal.misc.VM.initLevel(1);266/*267* Following code ensures that the field jdk.internal.reflect.langReflectAccess268* is initialized before any usage references. This is a workaround.269* More details are at https://github.com/eclipse-openj9/openj9/issues/3399#issuecomment-459004840.270*/271Modifier.isPublic(Modifier.PUBLIC);272/*[IF JAVA_SPEC_VERSION >= 10]*/273try {274/*[ENDIF] JAVA_SPEC_VERSION >= 10 */275System.bootLayer = jdk.internal.module.ModuleBootstrap.boot();276/*[IF JAVA_SPEC_VERSION >= 10]*/277} catch (Exception ex) {278System.out.println(ex);279Throwable t = ex.getCause();280while (t != null) {281System.out.println("Caused by: " + t); //$NON-NLS-1$282t = t.getCause();283}284System.exit(1);285}286/*[ENDIF] JAVA_SPEC_VERSION >= 10 */287jdk.internal.misc.VM.initLevel(2);288System.initSecurityManager(applicationClassLoader);289jdk.internal.misc.VM.initLevel(3);290/*[ELSE]*/291applicationClassLoader = sun.misc.Launcher.getLauncher().getClassLoader();292/*[ENDIF]*/293294/* Find the extension class loader */295ClassLoader tempLoader = applicationClassLoader;296while (null != tempLoader.parent) {297tempLoader = tempLoader.parent;298}299VMAccess.setExtClassLoader(tempLoader);300301/*[PR 125932] Reflect cache may be initialized by multiple Threads */302/*[PR JAZZ 107786] constructorParameterTypesField should be initialized regardless of reflectCacheEnabled or not */303Class.initCacheIds(reflectCacheEnabled, reflectCacheDebug);304}305306/**307* Constructs a new instance of this class with the system308* class loader as its parent.309*310* @exception SecurityException311* if a security manager exists and it does not312* allow the creation of new ClassLoaders.313*/314protected ClassLoader() {315this(checkSecurityPermission(), null, applicationClassLoader);316}317318/**319* This is a static helper method to perform security check earlier such that current ClassLoader object320* can't be resurrected when there is a SecurityException thrown.321*322* @return Void a unused reference passed to the Constructor323*/324private static Void checkSecurityPermission() {325@SuppressWarnings("removal")326SecurityManager security = System.getSecurityManager();327if (security != null) {328security.checkCreateClassLoader();329}330return null;331}332333/**334* Constructs a new instance of this class with the given335* class loader as its parent.336*337* @param parentLoader ClassLoader338* the ClassLoader to use as the new class339* loaders parent.340* @exception SecurityException341* if a security manager exists and it does not342* allow the creation of new ClassLoaders.343*/344protected ClassLoader(ClassLoader parentLoader) {345this(checkSecurityPermission(), null, parentLoader);346}347348/*[IF Sidecar19-SE]*/349/**350* Constructs a class loader with the specified name and the given351* class loader as its parent.352*353* @param classLoaderName name of this ClassLoader354* or null if not named.355* @param parentLoader ClassLoader356* the ClassLoader to use as the new class357* loaders parent.358* @exception IllegalArgumentException359* if the name of this class loader is empty.360* @exception SecurityException361* if a security manager exists and it does not362* allow the creation of new ClassLoaders.363*@since 9364*/365protected ClassLoader(String classLoaderName, ClassLoader parentLoader) {366this(checkSecurityPermission(), classLoaderName, parentLoader);367}368/*[ENDIF]*/369370private ClassLoader(Void staticMethodHolder, String classLoaderName, ClassLoader parentLoader) {371// This assumes that DelegatingClassLoader is constructed via ClassLoader(parentLoader)372isDelegatingCL = DELEGATING_CL.equals(this.getClass().getName());373374/*[IF JAVA_SPEC_VERSION > 8]*/375if ((classLoaderName != null) && classLoaderName.isEmpty()) {376/*[MSG "K0645", "The given class loader name can't be empty."]*/377throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0645")); //$NON-NLS-1$378}379/*[ENDIF] JAVA_SPEC_VERSION > 8 */380381if (parallelCapableCollection.containsKey(this.getClass())) {382isParallelCapable = true;383}384385// VM Critical: must set parent before calling initializeInternal()386parent = parentLoader;387/*[IF JAVA_SPEC_VERSION == 8]*/388specialLoaderInited = (bootstrapClassLoader != null);389/*[ENDIF] JAVA_SPEC_VERSION == 8 */390if (specialLoaderInited) {391if (!lazyClassLoaderInit) {392VM.initializeClassLoader(this, VM.J9_CLASSLOADER_TYPE_OTHERS, isParallelCapable);393}394/*[IF JAVA_SPEC_VERSION > 8]*/395unnamedModule = new Module(this);396/*[ENDIF] JAVA_SPEC_VERSION > 8 */397}398/*[IF JAVA_SPEC_VERSION > 8]*/399else {400if (bootstrapClassLoader == null) {401// BootstrapClassLoader.unnamedModule is set by JVM_SetBootLoaderUnnamedModule402unnamedModule = null;403bootstrapClassLoader = this;404VM.initializeClassLoader(bootstrapClassLoader, VM.J9_CLASSLOADER_TYPE_BOOT, false);405} else {406// Assuming the second classloader initialized is platform classloader407VM.initializeClassLoader(this, VM.J9_CLASSLOADER_TYPE_PLATFORM, false);408specialLoaderInited = true;409unnamedModule = new Module(this);410}411}412this.classLoaderName = classLoaderName;413/*[ENDIF] JAVA_SPEC_VERSION > 8 */414415/*[IF JAVA_SPEC_VERSION >= 19]*/416this.nativelibs = NativeLibraries.newInstance((this == bootstrapClassLoader) ? null : this);417/*[ELSEIF JAVA_SPEC_VERSION >= 17] */418this.nativelibs = NativeLibraries.jniNativeLibraries((this == bootstrapClassLoader) ? null : this);419/*[ENDIF] JAVA_SPEC_VERSION >= 19 */420421if (isAssertOptionFound) {422initializeClassLoaderAssertStatus();423}424}425426/**427* Constructs a new class from an array of bytes containing a428* class definition in class file format.429*430* @param classRep byte[]431* a memory image of a class file.432* @param offset int433* the offset into the classRep.434* @param length int435* the length of the class file.436*437* @return the newly defined Class438*439* @throws ClassFormatError when the bytes are invalid440*441* @deprecated Use defineClass(String, byte[], int, int)442*/443/*[IF Sidecar19-SE]*/444@Deprecated(forRemoval=false, since="1.1")445/*[ELSE]*/446@Deprecated447/*[ENDIF]*/448449protected final Class<?> defineClass (byte [] classRep, int offset, int length) throws ClassFormatError {450return defineClass ((String) null, classRep, offset, length);451}452453/**454* Constructs a new class from an array of bytes containing a455* class definition in class file format.456*457* @param className java.lang.String458* the name of the new class459* @param classRep byte[]460* a memory image of a class file461* @param offset int462* the offset into the classRep463* @param length int464* the length of the class file465*466* @return the newly defined Class467*468* @throws ClassFormatError when the bytes are invalid469*/470protected final Class<?> defineClass(String className, byte[] classRep, int offset, int length) throws ClassFormatError {471return defineClass(className, classRep, offset, length, null);472}473474private String checkClassName(String className) {475int index;476if((index = className.lastIndexOf('.')) >= 0) {477String packageName = className.substring(0, index);478/*[PR 94856]*/479if (className.startsWith("java.")) { //$NON-NLS-1$480/*[IF Sidecar19-SE]*/481/*[PR RTC 115588: java.* classes can be loaded by the platform class loader]*/482ClassLoader platformCL = ClassLoaders.platformClassLoader();483if (!(this == platformCL || this.isAncestorOf(platformCL))) {484/*[ENDIF]*/485/*[MSG "K01d2", "{1} - protected system package '{0}'"]*/486throw new SecurityException(com.ibm.oti.util.Msg.getString("K01d2", packageName, className)); //$NON-NLS-1$487/*[IF Sidecar19-SE]*/488}489/*[ENDIF]*/490}491return packageName;492}493return ""; //$NON-NLS-1$494}495496/**497* Constructs a new class from an array of bytes containing a498* class definition in class file format and assigns the new499* class to the specified protection domain.500*501* @param className java.lang.String502* the name of the new class.503* @param classRep byte[]504* a memory image of a class file.505* @param offset int506* the offset into the classRep.507* @param length int508* the length of the class file.509* @param protectionDomain ProtectionDomain510* the protection domain this class should511* belong to.512*513* @return the newly defined Class514*515* @throws ClassFormatError when the bytes are invalid516*/517protected final Class<?> defineClass (518final String className,519final byte[] classRep,520final int offset,521final int length,522ProtectionDomain protectionDomain)523throws java.lang.ClassFormatError524{525return defineClassInternal(className, classRep, offset, length, protectionDomain, false /* allowNullProtectionDomain */);526}527528final Class<?> defineClassInternal(529final String className,530final byte[] classRep,531final int offset,532final int length,533ProtectionDomain protectionDomain,534boolean allowNullProtectionDomain)535throws java.lang.ClassFormatError536{537Certificate[] certs = null;538if (protectionDomain != null) {539final CodeSource cs = protectionDomain.getCodeSource();540if (cs != null) certs = cs.getCertificates();541}542if (className != null) {543/*[PR 95417]*/544String packageName = checkClassName(className);545if ((protectionDomain == null) && allowNullProtectionDomain) {546/*547* Skip checkPackageSigners(), in this condition, the caller of this method is548* java.lang.Access.defineClass() and invoked by trusted system code hence549* there is no need to check its ProtectionDomain and associated code source certificates.550*/551} else {552/*[PR 93858]*/553checkPackageSigners(packageName, className, certs);554}555}556557/*[PR 123387] bogus parameters to defineClass() should produce ArrayIndexOutOfBoundsException */558if (offset < 0 || length < 0 || offset > classRep.length || length > classRep.length - offset) {559throw new ArrayIndexOutOfBoundsException();560}561562if ((protectionDomain == null) && !allowNullProtectionDomain) {563protectionDomain = getDefaultProtectionDomain();564}565566final ProtectionDomain pd = protectionDomain;567/*[PR CMVC 92062] disallow extending restricted packages */568/*[PR CMVC 110183] checkPackageAccess() (accessClassInPackage permission) denied when granted access */569/*[PR CVMC 124584] checkPackageAccess(), not defineClassImpl(), should use ProtectionDomain */570Class<?> answer = defineClassImpl(className, classRep, offset, length, pd);571572if (certs != null) {573setSigners(answer, certs);574}575576boolean isVerbose = isVerboseImpl();577URL url = null;578if (isVerbose) {579if (pd != null) {580CodeSource cs = pd.getCodeSource();581if (cs != null) {582url = cs.getLocation();583}584}585}586/*[IF Sidecar19-SE]*/587addPackageToList(answer);588/*[ENDIF] Sidecar19-SE */589590/*[PR CMVC 89001] Verbose output when loading non-bootstrap classes */591if (isVerbose) {592/*[PR CMVC 99348] Do not log to System.err */593String location = (url != null) ? url.toString() : "<unknown>"; //$NON-NLS-1$594com.ibm.oti.vm.VM.dumpString("class load: " + answer.getName() + " from: " + location + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$595}596return answer;597}598599/*[IF JAVA_SPEC_VERSION >= 15]*/600601private final native Class<?> defineClassImpl1(Class<?> hostClass, String className, byte[] classRep, ProtectionDomain protectionDomain, boolean init, int flags, Object classData);602final Class<?> defineClassInternal(603Class<?> hostClass,604String className,605byte[] classRep,606ProtectionDomain protectionDomain,607boolean init,608int flags,609Object classData)610throws java.lang.ClassFormatError611{612Class<?> answer = defineClassImpl1(hostClass, className, classRep, protectionDomain, init, flags, classData);613return answer;614}615/*[ENDIF] JAVA_SPEC_VERSION >= 15 */616617/*[IF Sidecar19-SE]*/618/**619* This class is a function that maps a package name to a newly created620* {@code NamedPackage} object for use below in updating the {@code packages} map.621*/622private static final class NamedPackageProvider implements java.util.function.Function<String, NamedPackage> {623624private final Class<?> newClass;625626NamedPackageProvider(Class<?> newClass) {627super();628this.newClass = newClass;629}630631@Override632public NamedPackage apply(String pkgName) {633return new NamedPackage(pkgName, newClass.getModule());634}635636}637638/**639* Add a class's package name to this classloader's list of packages, if not already present.640* @param newClass641*/642void addPackageToList(Class<?> newClass) {643synchronized (packages) {644packages.computeIfAbsent(newClass.getPackageName(), new NamedPackageProvider(newClass));645}646}647/*[ENDIF] Sidecar19-SE */648649/*[PR CMVC 89001] Verbose output when loading non-bootstrap classes */650private native boolean isVerboseImpl();651652private static native boolean foundJavaAssertOption();653654private void checkPackageSigners(final String packageName, String className, final Certificate[] classCerts) {655Certificate[] packageCerts = null;656synchronized(lazyInitLock) {657if (packageSigners != null) {658packageCerts = packageSigners.get(packageName);659} else {660packageSigners = new Hashtable<>();661}662}663if (packageCerts == null) {664if (classCerts == null) {665packageSigners.put(packageName, emptyCertificates);666} else {667packageSigners.put(packageName, classCerts);668669}670} else {671if ((classCerts == null && packageCerts.length == 0) || classCerts == packageCerts)672return;673if (classCerts != null && classCerts.length == packageCerts.length) {674boolean foundMatch = true;675test: for (int i=0; i<classCerts.length; i++) {676if (classCerts[i] == packageCerts[i]) continue;677if (classCerts[i].equals(packageCerts[i])) continue;678for (int j=0; j<packageCerts.length; j++) {679if (j == i) continue;680if (classCerts[i] == packageCerts[j]) continue test;681if (classCerts[i].equals(packageCerts[j])) continue test;682}683foundMatch = false;684break;685}686if (foundMatch) return;687}688/*[MSG "K01d1", "Signers of '{0}' do not match signers of other classes in package"]*/689throw new SecurityException(com.ibm.oti.util.Msg.getString("K01d1", className)); //$NON-NLS-1$690}691}692693/**694* Gets the current default protection domain. If there isn't695* one, it attempts to construct one based on the currently696* in place security policy.697* <p>698* If the default protection domain can not be determined,699* answers null.700* <p>701*702* @return ProtectionDomain or null703* the default protection domain.704*/705private final ProtectionDomain getDefaultProtectionDomain () {706if (isParallelCapable) {707if (defaultProtectionDomain == null) {708synchronized(lazyInitLock) {709return getDefaultProtectionDomainHelper();710}711}712return defaultProtectionDomain;713} else {714// no need for synchronisation when not parallel capable715return getDefaultProtectionDomainHelper();716}717}718719private final ProtectionDomain getDefaultProtectionDomainHelper() {720if (defaultProtectionDomain == null) {721/*[PR 115587] Default 1.4 behavior is to create dynamic ProtectionDomains */722defaultProtectionDomain = new ProtectionDomain(defaultCodeSource, null, this, null);723}724return defaultProtectionDomain;725}726727/*728* VM level support for constructing a new class. Should not729* be called by subclasses.730*/731private final native Class<?> defineClassImpl(String className, byte [] classRep, int offset, int length, Object protectionDomain);732733734/**735* Overridden by subclasses, by default throws ClassNotFoundException.736* This method is called by loadClass() after the parent ClassLoader737* has failed to find a loaded class of the same name.738*739* @return java.lang.Class740* the class or null.741* @param className String742* the name of the class to search for.743* @exception ClassNotFoundException744* always, unless overridden.745*/746protected Class<?> findClass (String className) throws ClassNotFoundException {747throw new ClassNotFoundException();748}749750/*[IF Sidecar19-SE]*/751/**752* Overridden by subclasses that support the loading from modules.753* When the moduleName is null, the default implementation invokes findClass(String),754* attempts to find the class and return it, or returns null in case of ClassNotFoundException.755* When the moduleName is not null, the default implementation returns null.756* This method is called by Class.forName(Module module, String name).757*758* @return java.lang.Class759* the class or null.760* @param moduleName761* the name of the module from which the class is to be loaded.762* @param className String763* the name of the class to search for.764765*/766protected Class<?> findClass(String moduleName, String className) {767Class<?> classFound = null;768if (moduleName == null) {769try {770classFound = findClass(className);771} catch (ClassNotFoundException e) {772// returns null if the class can't be found773}774}775return classFound;776}777/*[ENDIF] Sidecar19-SE */778779/**780* Attempts to find and return a class which has already781* been loaded by the virtual machine. Note that the class782* may not have been linked and the caller should call783* resolveClass() on the result if necessary.784*785* @return java.lang.Class786* the class or null.787* @param className String788* the name of the class to search for.789*/790protected final Class<?> findLoadedClass (String className) {791/*[PR CMVC 124675] allow findLoadedClass to find arrays if magic system property set */792if (!allowArraySyntax) {793if (className != null && className.length() > 0 && className.charAt(0) == '[') {794return null;795}796}797return findLoadedClassImpl(className);798}799800private native Class<?> findLoadedClassImpl(String className);801802/**803* Attempts to load a class using the system class loader.804* Note that the class has already been linked.805*806* @return java.lang.Class807* the class which was loaded.808* @param className String809* the name of the class to search for.810* @exception ClassNotFoundException811* if the class can not be found.812*/813protected final Class<?> findSystemClass (String className) throws ClassNotFoundException {814return applicationClassLoader.loadClass(className);815}816817/**818* Returns the specified ClassLoader's parent.819*820* @return java.lang.ClassLoader821* the class or null.822* @exception SecurityException823* if a security manager exists and it does not824* allow the parent loader to be retrieved.825*/826@CallerSensitive827public final ClassLoader getParent() {828@SuppressWarnings("removal")829SecurityManager security = System.getSecurityManager();830if (security != null) {831ClassLoader callersClassLoader = callerClassLoader();832/*[PR JAZZ103 76960] permission check is needed against the parent instead of this classloader */833if (needsClassLoaderPermissionCheck(callersClassLoader, parent)) {834security.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);835}836}837return parent;838}839840/**841* Answers an URL which can be used to access the resource842* described by resName, using the class loader's resource lookup843* algorithm. The default behavior is just to return null.844*845* @return URL846* the location of the resource.847* @param resName String848* the name of the resource to find.849*850* @see Class#getResource851*/852public URL getResource (String resName) {853URL result = null;854if (null == parent) {855/*[IF Sidecar19-SE]*/856result = BootLoader.findResource(resName);857/*[ELSE]858result = bootstrapClassLoader.findResource(resName);859/*[ENDIF]*/860} else {861result = parent.getResource(resName);862}863if (null == result) {864result = findResource(resName);865}866return result;867}868869/*870* A sequence of two or more enumerations.871*/872private static final class CompoundEnumeration<T> implements Enumeration<T> {873874private final Queue<Enumeration<T>> queue;875876CompoundEnumeration(Enumeration<T> first, Enumeration<T> second) {877super();878if (first instanceof CompoundEnumeration<?>) {879queue = ((CompoundEnumeration<T>) first).queue;880} else {881queue = new LinkedList<>();882queue.add(first);883}884queue.add(second);885}886887void append(Enumeration<T> element) {888queue.add(element);889}890891@Override892public boolean hasMoreElements() {893for (;;) {894Enumeration<T> head = queue.peek();895896if (head == null) {897return false;898}899900if (head.hasMoreElements()) {901return true;902}903904queue.remove();905}906}907908@Override909public T nextElement() {910for (;;) {911Enumeration<T> head = queue.peek();912913if (head == null) {914throw new NoSuchElementException();915}916917if (head.hasMoreElements()) {918return head.nextElement();919}920921queue.remove();922}923}924}925926/**927* Answers an Enumeration of URL which can be used to access the resources928* described by resName, using the class loader's resource lookup929* algorithm.930*931* @param resName String932* the name of the resource to find.933934* @return Enumeration935* the locations of the resources.936*937* @throws IOException when an error occurs938*/939public Enumeration<URL> getResources(String resName) throws IOException {940Enumeration<URL> resources = null;941942/*[PR CMVC 198371] ClassLoader.getResources doesn't get override or Overridden get */943if (parent != null) {944resources = parent.getResources(resName);945} else if (this != bootstrapClassLoader) {946resources =947/*[IF Sidecar19-SE]*/948BootLoader.findResources(resName);949/*[ELSE]950bootstrapClassLoader.getResources(resName);951/*[ENDIF]*/952}953954Enumeration<URL> localResources = findResources(resName);955956if (localResources != null && !localResources.hasMoreElements()) {957localResources = null;958}959960if (resources == null) {961resources = localResources;962if (resources == null) {963resources = Collections.emptyEnumeration();964}965} else if (localResources != null) {966if (resources instanceof CompoundEnumeration<?>) {967((CompoundEnumeration<URL>) resources).append(localResources);968} else {969resources = new CompoundEnumeration<>(resources, localResources);970}971}972973return resources;974}975976/**977* Answers a stream on a resource found by looking up978* resName using the class loader's resource lookup979* algorithm. The default behavior is just to return null.980*981* @return InputStream982* a stream on the resource or null.983* @param resName String984* the name of the resource to find.985*986* @see Class#getResourceAsStream987*/988public InputStream getResourceAsStream (String resName) {989URL url = getResource(resName);990try {991if (url != null) return url.openStream();992} catch (IOException e) {993// ignore994}995return null;996}997998static void completeInitialization() {999/*[PR JAZZ 57622: Support -Dreflect.cache=boot option] -Dreflect.cache=boot causes deadlock (Details: CMVC 120695). Loading Void class explicitly will prevent possible deadlock during caching reflect classes/methods. */1000@SuppressWarnings("unused")1001Class<?> voidClass = Void.TYPE;10021003/*[PR CMVC 193137] -Dreflect.cache=boot throws NPE. Caching reflect objects for bootstrap callers should be enabled late to avoid bootstrap problems. */1004/* Process reflect.cache=boot, other options are processed earlier in initializeClassLoaders() */1005String propValue = System.internalGetProperties().getProperty("reflect.cache"); //$NON-NLS-1$1006if (propValue != null) propValue = propValue.toLowerCase();1007/* Do not enable reflect cache if -Dreflect.cache=false is in commandline */1008boolean reflectCacheAppOnly = true;1009if (!"false".equals(propValue)) { //$NON-NLS-1$1010reflectCacheAppOnly = false;10111012if (propValue != null) {1013/*[PR 125873] Improve reflection cache */1014int bootIndex = propValue.indexOf("boot"); //$NON-NLS-1$1015if (bootIndex >= 0) {1016reflectCacheAppOnly = false;1017} else {1018int appIndex = propValue.indexOf("app"); //$NON-NLS-1$1019if (appIndex >= 0) {1020reflectCacheAppOnly = true;1021}1022}1023}1024}1025Class.setReflectCacheAppOnly(reflectCacheAppOnly);10261027initSystemClassLoader = true;1028}10291030/*[IF Sidecar18-SE-OpenJ9|Sidecar19-SE]*/1031//Returns incoming class's classloader without going through security checking1032static ClassLoader getClassLoader(Class<?> clz) {1033if (null != clz) {1034return clz.getClassLoader0();1035} else {1036return null;1037}1038}1039/*[ENDIF]*/10401041/*[IF Sidecar19-SE]*/1042/**1043* Return the Platform classloader.1044*1045* If a security manager exists and it does not1046* allow access a SecurityException will be thrown.1047*1048* @return the platformClassLoader1049* @throws SecurityException if access to the platform classloader is denied1050*/1051@CallerSensitive1052public static ClassLoader getPlatformClassLoader() {1053@SuppressWarnings("removal")1054SecurityManager security = System.getSecurityManager();1055ClassLoader platformClassLoader = ClassLoaders.platformClassLoader();1056if (security != null) {1057ClassLoader callersClassLoader = callerClassLoader();1058if (needsClassLoaderPermissionCheck(callersClassLoader, platformClassLoader)) {1059security.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);1060}1061}1062return platformClassLoader;1063}10641065// Loads a class in a module defined to this classloader1066// This method returns null if the class can't be found1067// Not delegate to the parent classloader1068final Class<?> loadLocalClass(java.lang.String name) {1069Class<?> localClass = null;1070try {1071localClass = loadClassHelper(name, false, false, null);1072} catch (ClassNotFoundException e) {1073// returns null if the class can't be found1074}1075return localClass;1076}10771078/**1079* Get the name given when creating the ClassLoader instance, or null if none was provided.1080* @return name of the class loader or null1081* @since 91082*/1083public String getName() {1084return classLoaderName;1085}1086/*[ENDIF] Sidecar19-SE */10871088/**1089* Convenience operation to obtain a reference to the system class loader.1090* The system class loader is the parent of any new <code>ClassLoader</code>1091* objects created in the course of an application and will normally be the1092* same <code>ClassLoader</code> as that used to launch an application.1093*1094* @return java.lang.ClassLoader the system classLoader.1095* @exception SecurityException1096* if a security manager exists and it does not permit the1097* caller to access the system class loader.1098*/1099@CallerSensitive1100public static ClassLoader getSystemClassLoader () {1101/*[PR CMVC 99755] Implement -Djava.system.class.loader option */1102if (initSystemClassLoader) {1103Class<?> classLoaderClass = ClassLoader.class;1104synchronized(classLoaderClass) {1105if (initSystemClassLoader) {1106initSystemClassLoader = false;11071108String userLoader = System.internalGetProperties().getProperty("java.system.class.loader"); //$NON-NLS-1$1109if (userLoader != null) {1110try {1111Class<?> loaderClass = Class.forName(userLoader, true, applicationClassLoader);1112Constructor<?> constructor = loaderClass.getConstructor(new Class<?>[]{classLoaderClass});1113applicationClassLoader = (ClassLoader)constructor.newInstance(new Object[]{applicationClassLoader});1114/*[PR JAZZ103 87642] Setting -Djava.system.class.loader on the command line doesn't update VMAccess.setExtClassLoader() */1115/* Find the extension class loader */1116ClassLoader tempLoader = applicationClassLoader;1117while (tempLoader.parent != null) {1118tempLoader = tempLoader.parent;1119}1120VMAccess.setExtClassLoader(tempLoader);1121} catch (Throwable e) {1122if (e instanceof InvocationTargetException) {1123throw new Error(e.getCause());1124} else {1125throw new Error(e);1126}1127}1128}1129}1130}1131}11321133ClassLoader sysLoader = applicationClassLoader;1134@SuppressWarnings("removal")1135SecurityManager security = System.getSecurityManager();1136if (security != null) {1137ClassLoader callersClassLoader = callerClassLoader();1138if (needsClassLoaderPermissionCheck(callersClassLoader, sysLoader)) {1139security.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);1140}1141}11421143return sysLoader;1144}11451146/**1147* Answers an URL specifying a resource which can be found by1148* looking up resName using the system class loader's resource1149* lookup algorithm.1150*1151* @return URL1152* a URL specifying a system resource or null.1153* @param resName String1154* the name of the resource to find.1155*1156* @see Class#getResource1157*/1158public static URL getSystemResource(String resName) {1159return getSystemClassLoader().getResource(resName);1160}11611162/**1163* Answers an Enumeration of URL containing all resources which can be1164* found by looking up resName using the system class loader's resource1165* lookup algorithm.1166*1167* @param resName String1168* the name of the resource to find.1169*1170* @return Enumeration1171* an Enumeration of URL containing the system resources1172*1173* @throws IOException when an error occurs1174*/1175public static Enumeration<URL> getSystemResources(String resName) throws IOException {1176return getSystemClassLoader().getResources(resName);1177}11781179/**1180* Answers a stream on a resource found by looking up1181* resName using the system class loader's resource lookup1182* algorithm. Basically, the contents of the java.class.path1183* are searched in order, looking for a path which matches1184* the specified resource.1185*1186* @return a stream on the resource or null.1187* @param resName the name of the resource to find.1188*1189* @see Class#getResourceAsStream1190*/1191public static InputStream getSystemResourceAsStream(String resName) {1192return getSystemClassLoader().getResourceAsStream(resName);1193}11941195/*[IF Sidecar19-SE]*/1196/**1197* Answers the unnamed Module of this class loader.1198*1199* @return the unnamed Module of this class loader1200*/1201public final Module getUnnamedModule()1202{1203return this.unnamedModule;1204}1205/*[ENDIF] Sidecar19-SE */12061207/**1208* Invoked by the Virtual Machine when resolving class references.1209* Equivalent to loadClass(className, false);1210*1211* @return java.lang.Class1212* the Class object.1213* @param className String1214* the name of the class to search for.1215* @exception ClassNotFoundException1216* If the class could not be found.1217*/1218public Class<?> loadClass (String className) throws ClassNotFoundException {1219/*[IF Sidecar19-SE]*/1220if ((bootstrapClassLoader == null) || (this == bootstrapClassLoader)) {1221Class<?> cls = VMAccess.findClassOrNull(className, bootstrapClassLoader);1222if (cls == null) {1223throw new ClassNotFoundException(className);1224}1225return cls;1226}1227/*[ENDIF] Sidecar19-SE */1228return loadClass(className, false);1229}12301231/**1232* Attempts to load the type <code>className</code> in the running VM,1233* optionally linking the type after a successful load.1234*1235* @return java.lang.Class1236* the Class object.1237* @param className String1238* the name of the class to search for.1239* @param resolveClass boolean1240* indicates if class should be resolved after loading.1241* @exception ClassNotFoundException1242* If the class could not be found.1243*/1244/*[PR CMVC 180958] SVT:HRT:deadlock following class library change to classloader */1245protected Class<?> loadClass(final String className, boolean resolveClass) throws ClassNotFoundException {1246return loadClassHelper(className, resolveClass, true1247/*[IF Sidecar19-SE]*/1248, null1249/*[ENDIF]*/1250);1251}12521253/*[IF Sidecar19-SE]*/1254/**1255* Invoked by package access methods such as java.lang.Package.getPackageInfo()1256* resolveClass flag is false, delegateToParent flag is false as well.1257*1258* @param module Module1259* the module to search for1260* @param className String1261* the name of the class to search for1262* @exception NullPointerException1263* if the given module is null1264* @return java.lang.Class1265* the Class object1266*/1267final Class<?> loadClass(Module module, String className) {1268Class<?> localClass = null;12691270if ((bootstrapClassLoader == null) || (this == bootstrapClassLoader)) {1271localClass = VMAccess.findClassOrNull(className, bootstrapClassLoader);1272} else {1273try {1274localClass = loadClassHelper(className, false, false, module);1275} catch (ClassNotFoundException e) {1276// returns null if the class can't be found1277}1278}1279return localClass;1280}1281/*[ENDIF]*/1282/**1283* Attempts to load the type <code>className</code> in the running VM,1284* optionally linking the type after a successful load.1285*1286* @param className String1287* the name of the class to search for.1288* @param resolveClass boolean1289* indicates if class should be resolved after loading.1290* @param delegateToParent boolean1291* indicate if the parent classloader should be delegated for class loading1292* @param module1293* the module from which the class is to be loaded.1294* @exception ClassNotFoundException1295* If the class could not be found.1296* @return java.lang.Class1297* the Class object.1298*/1299Class<?> loadClassHelper(final String className, boolean resolveClass, boolean delegateToParent1300/*[IF Sidecar19-SE]*/1301, Module module1302/*[ENDIF]*/1303) throws ClassNotFoundException {1304Object lock = isParallelCapable ? getClassLoadingLock(className) : this;13051306synchronized (lock) {1307// Ask the VM to look in its cache.1308Class<?> loadedClass = findLoadedClass(className);1309// search in parent if not found1310if (loadedClass == null) {1311if (delegateToParent) {1312try {1313if (parent == null) {1314/*[PR 95894]*/1315if (isDelegatingCL) {1316loadedClass = bootstrapClassLoader.findLoadedClass(className);1317}1318if (loadedClass == null) {1319loadedClass = bootstrapClassLoader.loadClass(className);1320}1321} else {1322if (isDelegatingCL) {1323loadedClass = parent.findLoadedClass(className);1324}1325if (loadedClass == null) {1326loadedClass = parent.loadClass(className, resolveClass);1327}1328}1329} catch (ClassNotFoundException e) {1330// don't do anything. Catching this exception is the normal protocol for1331// parent classloaders telling use they couldn't find a class.1332}1333}13341335// not findLoadedClass or by parent.loadClass, try locally1336if (loadedClass == null) {1337/*[IF Sidecar19-SE]*/1338if (module == null) {1339/*[ENDIF]*/1340loadedClass = findClass(className);1341/*[IF Sidecar19-SE]*/1342}1343else {1344loadedClass = findClass(module.getName(), className);1345}1346/*[ENDIF]*/1347}1348}13491350/*[IF Sidecar19-SE]*/1351if (module != null && loadedClass != null) {1352Module moduleLoadedClass = loadedClass.getModule();1353if (module != moduleLoadedClass) {1354return null;1355}1356}1357/*[ENDIF]*/13581359// resolve if required1360if (resolveClass) resolveClass(loadedClass);1361return loadedClass;1362}1363}13641365/**1366* Attempts to register the ClassLoader as being capable of1367* parallel class loading. This requires that all superclasses must1368* also be parallel capable.1369*1370* @return True if the ClassLoader successfully registers as1371* parallel capable, false otherwise.1372*1373* @see java.lang.ClassLoader1374*/1375@CallerSensitive1376protected static boolean registerAsParallelCapable() {1377final Class<?> callerCls = System.getCallerClass();13781379/*[IF JAVA_SPEC_VERSION >= 18]*/1380return registerAsParallelCapable(callerCls);1381/*[ELSE] JAVA_SPEC_VERSION >= 181382if (parallelCapableCollection.containsKey(callerCls)) {1383return true;1384}13851386Class<?> superCls = callerCls.getSuperclass();13871388if (superCls == ClassLoader.class || parallelCapableCollection.containsKey(superCls)) {1389parallelCapableCollection.put(callerCls, null);1390return true;1391}13921393return false;1394/*[ENDIF] JAVA_SPEC_VERSION >= 18 */1395}13961397/*[IF JAVA_SPEC_VERSION >= 18]*/1398@CallerSensitiveAdapter1399private static boolean registerAsParallelCapable(Class<?> callerCls) {1400if (parallelCapableCollection.containsKey(callerCls)) {1401return true;1402}14031404Class<?> superCls = callerCls.getSuperclass();14051406if (superCls == ClassLoader.class || parallelCapableCollection.containsKey(superCls)) {1407parallelCapableCollection.put(callerCls, null);1408return true;1409}14101411return false;1412}1413/*[ENDIF] JAVA_SPEC_VERSION >= 18 */14141415/**1416* Answers the lock object for class loading in parallel.1417* If this ClassLoader object has been registered as parallel capable,1418* a dedicated object associated with this specified class name is returned.1419* Otherwise, current ClassLoader object is returned.1420*1421* @param className String1422* name of the to be loaded class1423*1424* @return the lock for class loading operations1425*1426* @exception NullPointerException1427* if registered as parallel capable and className is null1428*1429* @see java.lang.ClassLoader1430*1431*/1432protected Object getClassLoadingLock(final String className) {1433Object lock = this;1434if (isParallelCapable) {1435if (classNameBasedLock == null) {1436synchronized(lazyInitLock) {1437if (classNameBasedLock == null) {1438classNameBasedLock = new Hashtable<>();1439}1440}1441}1442synchronized(classNameBasedLock) {1443// get() does null pointer check1444ClassNameLockRef wf = classNameBasedLock.get(className);1445lock = (null != wf) ? wf.get() : null;1446if (lock == null) {1447lock = new ClassNameBasedLock();1448classNameBasedLock.put(className, new ClassNameLockRef(lock, className, classNameBasedLock));1449}1450}1451}1452return lock;1453}145414551456/**1457* Forces a class to be linked (initialized). If the class has1458* already been linked this operation has no effect.1459*1460* @param clazz Class1461* the Class to link.1462* @exception NullPointerException1463* if clazz is null.1464*1465* @see Class#getResource1466*/1467protected final void resolveClass(Class<?> clazz) {1468if (clazz == null)1469throw new NullPointerException();1470}14711472/**1473* Forces the parent of a classloader instance to be newParent1474*1475* @param newParent ClassLoader1476* the ClassLoader to make the parent.1477*/1478private void setParent(ClassLoader newParent) {1479parent = newParent;1480}14811482/**1483* Answers true if the receiver is a system class loader.1484* <p>1485* Note that this method has package visibility only. It is1486* defined here to avoid the security manager check in1487* getSystemClassLoader, which would be required to implement1488* this method anywhere else.1489*1490* @return boolean1491* true if the receiver is a system class loader1492*1493* @see Class#getClassLoaderImpl()1494*/1495final boolean isASystemClassLoader() {1496/*[IF]14971FDVFL7: J9JCL:ALL - isASystemClassLoader should check starting at appClassLoader.1498/*[ENDIF]*/1499if (this == bootstrapClassLoader) return true;1500ClassLoader cl = applicationClassLoader;1501while (cl != null) {1502if (this == cl) return true;1503cl = cl.parent;1504}1505return false;1506}15071508/**1509* Answers true if the receiver is ancestor of another class loader.1510* <p>1511* Note that this method has package visibility only. It is1512* defined here to avoid the security manager check in1513* getParent, which would be required to implement1514* this method anywhere else.1515*1516* @param child ClassLoader, a child candidate1517*1518* @return boolean1519* true if the receiver is ancestor of the parameter1520*/1521final boolean isAncestorOf (ClassLoader child) {1522if (child == null) return false;1523if (this == bootstrapClassLoader) return true;1524ClassLoader cl = child.parent;1525while (cl != null) {1526if (this == cl) return true;1527cl = cl.parent;1528}1529return false;1530}153115321533/**1534* A class loader 'callerClassLoader' can access class loader 'requested' without permission check1535* if any of the following are true1536* (1) if class loader 'callerClassLoader' is same as class loader 'requested' or1537* (2) if 'callerClassLoader' is an ancestor of 'requested'.1538* (3) a 'callerClassLoader' in a system domain can access any class loader.1539*1540* @param callerClassLoader the calling ClassLoader1541* @param requested the ClassLoader being requested1542* @return boolean indicating if a security check is required1543*/1544static final boolean needsClassLoaderPermissionCheck(ClassLoader callerClassLoader, ClassLoader requested) {1545return callerClassLoader != null &&1546callerClassLoader != requested && !callerClassLoader.isAncestorOf(requested);1547}15481549/**1550* Answers an URL which can be used to access the resource1551* described by resName, using the class loader's resource lookup1552* algorithm. The default behavior is just to return null.1553* This should be implemented by a ClassLoader.1554*1555* @return URL1556* the location of the resource.1557* @param resName String1558* the name of the resource to find.1559*/1560protected URL findResource (String resName) {1561return null;1562}15631564/**1565* Answers an Enumeration of URL which can be used to access the resources1566* described by resName, using the class loader's resource lookup1567* algorithm. The default behavior is just to return an empty Enumeration.1568*1569* @param resName String1570* the name of the resource to find.1571* @return Enumeration1572* the locations of the resources.1573*1574* @throws IOException when an error occurs1575*/1576protected Enumeration<URL> findResources (String resName) throws IOException {1577return new Vector<URL>().elements();1578}15791580/**1581* Answers the absolute path of the file containing the library1582* associated with the given name, or null. If null is answered,1583* the system searches the directories specified by the system1584* property "java.library.path".1585*1586* @return String1587* the library file name or null.1588* @param libName String1589* the name of the library to find.1590*/1591protected String findLibrary(String libName) {1592return null;1593}15941595/**1596* Answers a package of given name defined by this ClassLoader.1597*1598* @param name The name of the package to find1599*1600* @return The package requested1601*/1602/*[IF Sidecar19-SE]*/1603public1604/*[ENDIF]*/1605final Package getDefinedPackage(String name) {1606/*[IF Sidecar19-SE]*/1607Package pkg = null;1608synchronized(packages) {1609NamedPackage np = packages.get(name);1610if (null != np) {1611if (np instanceof Package) {1612pkg = (Package)np;1613} else {1614pkg = NamedPackage.toPackage(np.packageName(), np.module());1615packages.put(name, pkg);1616}1617}1618}1619return pkg;1620/*[ELSE]*/1621return packages.get(name);1622/*[ENDIF] Sidecar19-SE*/1623}16241625/*[IF Sidecar19-SE]*/1626/**1627* Answers all the packages defined by this classloader.1628*1629* @return Array of Package objects or zero length array if no package is defined1630*/1631public final Package[] getDefinedPackages() {1632synchronized(packages) {1633if (packages.isEmpty()) {1634return EMPTY_PACKAGE_ARRAY;1635} else {1636return packages().toArray(Package[]::new);1637}1638}1639}1640/*[ENDIF] Sidecar19-SE*/1641/**1642* Attempt to locate the requested package. If no package information1643* can be located, null is returned.1644*1645* @param name The name of the package to find1646* @return The package requested, or null1647/*[IF Sidecar19-SE]1648*1649* @deprecated Use getDefinedPackage(String)1650/*[ENDIF]1651*/1652/*[IF Sidecar19-SE]*/1653@Deprecated(forRemoval=false, since="9")1654/*[ENDIF]*/1655protected Package getPackage(String name) {1656if (this == bootstrapClassLoader) {1657/*[IF Sidecar19-SE]*/1658return BootLoader.getDefinedPackage(name);1659/*[ELSE]*/1660return getDefinedPackage(name);1661/*[ENDIF]*/1662} else {1663Package p = getDefinedPackage(name);1664if (p == null) {1665ClassLoader parentLoader = this.parent;1666if (parentLoader == null) {1667parentLoader = bootstrapClassLoader;1668}1669p = parentLoader.getPackage(name);1670}1671return p;1672}1673}16741675private Package[] getPackagesHelper(1676/*[IF Sidecar19-SE]*/1677Hashtable<?, NamedPackage>1678/*[ELSE]1679Hashtable<?, Package>1680/*[ENDIF] Sidecar19-SE*/1681localPackages, Package[] ancestorsPackages) {1682int resultSize = localPackages.size();1683if (ancestorsPackages != null) {1684resultSize += ancestorsPackages.length;1685}1686Package[] result = new Package[resultSize];1687int i = 0;1688if (ancestorsPackages != null) {1689i = ancestorsPackages.length;1690System.arraycopy(ancestorsPackages, 0, result, 0, i);1691}16921693/*[IF Sidecar19-SE]*/1694Package[] pkgs = packages().toArray(Package[]::new);1695System.arraycopy(pkgs, 0, result, i, pkgs.length);1696/*[ELSE]1697Enumeration<Package> myPkgs = localPackages.elements();1698while (myPkgs.hasMoreElements()) {1699result[i++] = myPkgs.nextElement();1700}1701/*[ENDIF] Sidecar19-SE*/17021703return result;1704}17051706/**1707* Answers all the packages known to this class loader.1708*1709* @return All the packages known to this classloader1710*/1711protected Package[] getPackages() {1712/*[IF Sidecar19-SE]*/1713if (this == bootstrapClassLoader) {1714return BootLoader.packages().toArray(Package[]::new);1715}1716/*[ENDIF]*/17171718Package[] ancestorsPackages = null;1719if (parent == null) {1720/*[IF !Sidecar19-SE]*/1721if (this != bootstrapClassLoader) {1722/*[ENDIF]*/1723ancestorsPackages = bootstrapClassLoader.getPackages();1724/*[IF !Sidecar19-SE]*/1725}1726/*[ENDIF]*/1727} else {1728ancestorsPackages = parent.getPackages();1729}17301731/*[IF Sidecar19-SE]*/1732Hashtable<?, NamedPackage> localPackages = packages;1733/*[ELSE]1734Hashtable<?, Package> localPackages = packages;1735/*[ENDIF] Sidecar19-SE*/17361737boolean rtExceptionThrown = false;1738do {1739try {1740Package[] result;1741/*[IF Sidecar19-SE]*/1742if (rtExceptionThrown) {1743synchronized(packages) {1744result = getPackagesHelper(localPackages, ancestorsPackages);1745}1746} else {1747/*[ENDIF] Sidecar19-SE*/1748result = getPackagesHelper(localPackages, ancestorsPackages);1749/*[IF Sidecar19-SE]*/1750}1751/*[ENDIF] Sidecar19-SE*/1752return result;1753} catch(RuntimeException ex) {1754if (rtExceptionThrown) {1755throw ex;1756}1757rtExceptionThrown = true;1758/*[IF !Sidecar19-SE]*/1759localPackages = (Hashtable<?, Package>)packages.clone();1760/*[ENDIF] Sidecar19-SE*/1761}1762} while (true);1763}17641765/**1766* Define a new Package using the specified information.1767*1768* @param name The name of the package1769* @param specTitle The title of the specification for the Package1770* @param specVersion The version of the specification for the Package1771* @param specVendor The vendor of the specification for the Package1772* @param implTitle The implementation title of the Package1773* @param implVersion The implementation version of the Package1774* @param implVendor The specification vendor of the Package1775* @param sealBase The URL used to seal the Package, if null the Package is not sealed1776*1777* @return The Package created1778*1779* @exception IllegalArgumentException if the Package already exists1780*/1781protected Package definePackage(1782final String name, final String specTitle,1783final String specVersion, final String specVendor,1784final String implTitle, final String implVersion,1785final String implVendor, final URL sealBase)1786throws IllegalArgumentException1787{1788synchronized(packages) {1789/*[IF Sidecar19-SE]*/1790if (packages.containsKey(name)) {1791/*[ELSE]1792if (null != getPackage(name)) {1793/*[ENDIF]*/1794/*[MSG "K0053", "Package {0} already defined."]*/1795throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K0053", name)); //$NON-NLS-1$1796} else {1797Package newPackage = new Package(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase, this);1798packages.put(name, newPackage);1799return newPackage;1800}1801}1802}18031804/**1805* Gets the signers of a class.1806*1807* @param c The Class object1808* @return signers The signers for the class1809*/1810final Object[] getSigners(Class<?> c) {1811Hashtable<Class<?>, Object[]> localSigners = classSigners;1812if (localSigners == null) {1813synchronized (lazyInitLock) {1814localSigners = classSigners;1815if (localSigners == null) {1816return null;1817}1818}1819}1820Object[] result = localSigners.get(c);1821if (result != null) {1822result = result.clone();1823}1824return result;1825}18261827/**1828* Sets the signers of a class.1829*1830* @param c The Class object1831* @param signers The signers for the class1832*/18331834protected final void setSigners(final Class<?> c, final Object[] signers) {1835/*[PR CMVC 93861] setSigners() throws NullPointerException */1836if (c.getClassLoaderImpl() == this) {1837if (signers == null) {1838if (classSigners == null) {1839synchronized(lazyInitLock) {1840if (classSigners == null) {1841return;1842}1843}1844}1845classSigners.remove(c);1846} else {1847if (classSigners == null) {1848synchronized(lazyInitLock) {1849if (classSigners == null) {1850classSigners = new Hashtable<>();1851}1852}1853}1854classSigners.put(c, signers);1855}1856/*[PR 28064] Class.getSigner() method returns null */1857/*[PR CMVC 93861] setSigners() throws NullPointerException */1858} else c.getClassLoaderImpl().setSigners(c, signers);18591860}18611862@CallerSensitive1863static ClassLoader getCallerClassLoader() {1864ClassLoader loader = getStackClassLoader(2);1865if (loader == bootstrapClassLoader) return null;1866return loader;1867}18681869/**1870* Returns the ClassLoader of the method (including natives) at the1871* specified depth on the stack of the calling thread. Frames representing1872* the VM implementation of java.lang.reflect are not included in the list.1873*1874* Notes: <ul>1875* <li> This method operates on the defining classes of methods on stack.1876* NOT the classes of receivers. </li>1877*1878* <li> The item at depth zero is the caller of this method </li>1879* </ul>1880*1881* @param depth the stack depth of the requested ClassLoader1882* @return the ClassLoader at the specified depth1883*1884* @see com.ibm.oti.vm.VM#getStackClassLoader1885*/1886@CallerSensitive1887static final native ClassLoader getStackClassLoader(int depth);18881889/**1890* Returns the ClassLoader of the method that called the caller.1891* i.e. A.x() calls B.y() calls callerClassLoader(),1892* A's ClassLoader will be returned. Returns null for the1893* bootstrap ClassLoader.1894*1895* @return a ClassLoader or null for the bootstrap ClassLoader1896*/1897@CallerSensitive1898static ClassLoader callerClassLoader() {1899ClassLoader loader = getStackClassLoader(2);1900if (loader == bootstrapClassLoader) return null;1901return loader;1902}19031904/**1905* Loads and links the library specified by the argument.1906*1907* @param libName the name of the library to load1908* @param loader the classloader in which to load the library1909*1910* @exception UnsatisfiedLinkError1911* if the library could not be loaded1912* @exception SecurityException1913* if the library was not allowed to be loaded1914*/1915static void loadLibraryWithClassLoader(String libName, ClassLoader loader) {1916if (loader != null) {1917String realLibName = loader.findLibrary(libName);19181919if (realLibName != null) {1920loadLibraryWithPath(realLibName, loader, null);1921return;1922}1923}1924/*1925* [PR JAZZ 93728] Match behaviour of System.loadLibrary() in reference1926* implementation when system property java.library.path is set1927*/1928try {1929loadLibraryWithPath(libName, loader, System.internalGetProperties().getProperty("com.ibm.oti.vm.bootstrap.library.path")); //$NON-NLS-1$1930} catch (UnsatisfiedLinkError ule) {1931if (loader == null) {1932throw ule;1933} else {1934loadLibraryWithPath(libName, loader, System.internalGetProperties().getProperty("java.library.path")); //$NON-NLS-1$1935}1936}1937}19381939/**1940* Loads and links the library specified by the argument.1941* No security check is done.1942*1943* @param libName the name of the library to load1944* @param loader the classloader in which to load the library1945* @param libraryPath the library path to search, or null1946*1947* @exception UnsatisfiedLinkError1948* if the library could not be loaded1949*/1950static void loadLibraryWithPath(String libName, ClassLoader loader, String libraryPath) {1951/*[PR 137143] - failure to load library, need to strip leading '/' on Windows platforms, if present */1952if (File.separatorChar == '\\'){1953if (libName.startsWith("/") && com.ibm.oti.util.Util.startsWithDriveLetter(libName.substring(1))){ //$NON-NLS-1$1954libName = libName.substring(1);1955}1956}1957byte[] message = ClassLoader.loadLibraryWithPath(com.ibm.oti.util.Util.getBytes(libName), loader, libraryPath == null ? null : com.ibm.oti.util.Util.getBytes(libraryPath));19581959/* As Mac OS X used to be using lib<name>.jnilib Java native library format,1960* VM will attempt loading native library using the legacy library extension1961* on Mac OS X to support older applications1962*/1963if (System.internalGetProperties().getProperty("os.name").equals("Mac OS X")) { //$NON-NLS-1$ //$NON-NLS-2$1964if ((message != null) && (libraryPath != null)) {1965String legacyPath = libraryPath.replaceAll("/$", "") + "/lib" + libName + ".jnilib"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$19661967try {1968byte[] jnilibLoadMessage = ClassLoader.loadLibraryWithPath(com.ibm.oti.util.Util.getBytes(legacyPath), loader, null);1969if (jnilibLoadMessage == null) {1970message = null;1971}1972} catch (Exception e) { /* Ignore Exception */ }1973}1974}19751976if (message != null) {1977String error;1978try {1979error = com.ibm.oti.util.Util.convertFromUTF8(message, 0, message.length);1980} catch (java.io.IOException e) {1981error = com.ibm.oti.util.Util.toString(message);1982}1983/*[MSG "K0649", "{0} ({1})"]*/1984throw new UnsatisfiedLinkError(com.ibm.oti.util.Msg.getString("K0649", libName, error));//$NON-NLS-1$19851986}1987}19881989private static synchronized native byte[] loadLibraryWithPath(byte[] libName, ClassLoader loader, byte[] libraryPath);19901991static void loadLibrary(Class<?> caller, String name, boolean fullPath) {1992if (fullPath)1993loadLibraryWithPath(name, caller.getClassLoaderImpl(), null);1994else1995loadLibraryWithClassLoader(name, caller.getClassLoaderImpl());1996}19971998/*[IF JAVA_SPEC_VERSION >= 15]*/1999static void loadLibrary(Class<?> caller, File file) {2000ClassLoader loader = (caller == null) ? null : caller.getClassLoader();2001NativeLibraries nls = (loader == null) ? BootLoader.getNativeLibraries() : loader.nativelibs;2002NativeLibrary nl = nls.loadLibrary(caller, file);2003if (nl == null) {2004/*[MSG "K0647", "Can't load {0}"]*/2005throw new UnsatisfiedLinkError(com.ibm.oti.util.Msg.getString("K0647", file));//$NON-NLS-1$2006}2007}2008static void loadLibrary(Class<?> caller, String libName) {2009ClassLoader loader = (caller == null) ? null : caller.getClassLoader();2010if (loader == null) {2011NativeLibrary nl = BootLoader.getNativeLibraries().loadLibrary(caller, libName);2012if (nl == null) {2013/*[MSG "K0647", "Can't load {0}"]*/2014throw new UnsatisfiedLinkError(com.ibm.oti.util.Msg.getString("K0647", libName));//$NON-NLS-1$2015}2016} else {2017NativeLibraries nls = loader.nativelibs;2018String libfilename = loader.findLibrary(libName);2019if (libfilename != null) {2020File libfile = new File(libfilename);2021if (!libfile.isAbsolute()) {2022/*[MSG "K0648", "Not an absolute path: {0}"]*/2023throw new UnsatisfiedLinkError(com.ibm.oti.util.Msg.getString("K0648", libfilename));//$NON-NLS-1$2024}2025NativeLibrary nl = nls.loadLibrary(caller, libfile);2026if (nl == null) {2027/*[MSG "K0647", "Can't load {0}"]*/2028throw new UnsatisfiedLinkError(com.ibm.oti.util.Msg.getString("K0647", libfilename));//$NON-NLS-1$2029}2030} else {2031NativeLibrary nl = nls.loadLibrary(caller, libName);2032if (nl == null) {2033/*[MSG "K0647", "Can't load {0}"]*/2034throw new UnsatisfiedLinkError(com.ibm.oti.util.Msg.getString("K0647", libName));//$NON-NLS-1$2035}2036}2037}2038}20392040static long findNative(ClassLoader loader, String entryName) {2041NativeLibraries nativelib;2042if ((loader == null) || (loader == bootstrapClassLoader)) {2043nativelib = BootLoader.getNativeLibraries();2044} else {2045nativelib = loader.nativelibs;2046}2047return nativelib.find(entryName);2048}2049/*[ENDIF] JAVA_SPEC_VERSION >= 15 */20502051/**2052* Sets the assertion status of a class.2053*2054* @param cname Class name2055* @param enable Enable or disable assertion2056*2057* @since 1.42058*/2059public void setClassAssertionStatus(String cname, boolean enable) {2060setClassAssertionStatusImpl(cname, enable);2061}20622063private void setClassAssertionStatusImpl(String cname, boolean enable) {2064if (!isParallelCapable) {2065synchronized(this) {2066setClassAssertionStatusHelper(cname, enable);2067}2068} else {2069synchronized(assertionLock) {2070setClassAssertionStatusHelper(cname, enable);2071}2072}2073}20742075private void setClassAssertionStatusHelper(final String cname, final boolean enable) {2076if (classAssertionStatus == null ) {2077classAssertionStatus = new HashMap<>();2078}2079classAssertionStatus.put(cname, Boolean.valueOf(enable));2080}20812082/**2083* Sets the assertion status of a package.2084*2085* @param pname Package name2086* @param enable Enable or disable assertion2087*2088* @since 1.42089*/2090public void setPackageAssertionStatus(String pname, boolean enable) {2091setPackageAssertionStatusImpl(pname, enable);2092}20932094private void setPackageAssertionStatusImpl(String pname, boolean enable) {2095if (!isParallelCapable) {2096synchronized(this) {2097setPackageAssertionStatusHelper(pname, enable);2098}2099} else {2100synchronized(assertionLock) {2101setPackageAssertionStatusHelper(pname, enable);2102}2103}2104}21052106private void setPackageAssertionStatusHelper(final String pname, final boolean enable) {2107if (packageAssertionStatus == null ) {2108packageAssertionStatus = new HashMap<>();2109}2110packageAssertionStatus.put(pname, Boolean.valueOf(enable));21112112}21132114/**2115* Sets the default assertion status of a classloader2116*2117* @param enable Enable or disable assertion2118*2119* @since 1.42120*/2121public void setDefaultAssertionStatus(boolean enable){2122setDefaultAssertionStatusImpl(enable);2123}21242125private void setDefaultAssertionStatusImpl(boolean enable){2126if (!isParallelCapable) {2127synchronized(this) {2128defaultAssertionStatus = enable;2129}2130} else {2131synchronized(assertionLock) {2132defaultAssertionStatus = enable;2133}2134}2135}21362137/**2138* Clears the default, package and class assertion status of a classloader2139*2140* @since 1.42141*/2142public void clearAssertionStatus(){2143if (!isParallelCapable) {2144synchronized(this) {2145defaultAssertionStatus = false;2146classAssertionStatus = null;2147packageAssertionStatus = null;2148}2149} else {2150synchronized(assertionLock) {2151defaultAssertionStatus = false;2152classAssertionStatus = null;2153packageAssertionStatus = null;2154}2155}2156}21572158/**2159* Answers the assertion status of the named class2160*2161* Returns the assertion status of the class or nested class if it has2162* been set. Otherwise returns the assertion status of its package or2163* superpackage if that has been set. Otherwise returns the default assertion2164* status.2165* Returns 1 for enabled and 0 for disabled.2166*2167* @param cname String2168* the name of class.2169*2170* @return int2171* the assertion status.2172*2173* @since 1.42174*/2175boolean getClassAssertionStatus(String cname) {2176if (!isParallelCapable) {2177synchronized(this) {2178return getClassAssertionStatusHelper(cname);2179}2180} else {2181synchronized(assertionLock) {2182return getClassAssertionStatusHelper(cname);2183}2184}2185}2186private boolean getClassAssertionStatusHelper(String cname) {2187int dlrIndex = -1;21882189if (classAssertionStatus != null) {2190Boolean b = classAssertionStatus.get(cname);2191if (b != null) {2192return b.booleanValue();2193} else if ((dlrIndex = cname.indexOf('$'))>0) {2194b = classAssertionStatus.get(cname.substring(0, dlrIndex));2195if (b !=null)2196return b.booleanValue();2197}2198}2199/*[PR CMVC 80253] package assertion status not checked */2200if ((dlrIndex = cname.lastIndexOf('.'))>0) {2201return getPackageAssertionStatus(cname.substring(0, dlrIndex));2202}2203return getDefaultAssertionStatus();2204}220522062207/**2208* Answers the assertion status of the named package2209*2210* Returns the assertion status of the named package or superpackage if2211* that has been set. Otherwise returns the default assertion status.2212* Returns 1 for enabled and 0 for disabled.2213*2214* @param pname String2215* the name of package.2216*2217* @return int2218* the assertion status.2219*2220* @since 1.42221*/2222boolean getPackageAssertionStatus(String pname) {2223if (!isParallelCapable) {2224synchronized(this) {2225return getPackageAssertionStatusHelper(pname);2226}2227} else {2228synchronized(assertionLock) {2229return getPackageAssertionStatusHelper(pname);2230}2231}2232}2233private boolean getPackageAssertionStatusHelper(String pname) {2234int prdIndex = -1;22352236if (packageAssertionStatus != null) {2237Boolean b = packageAssertionStatus.get(pname);2238if (b != null) {2239return b.booleanValue();2240} else if ((prdIndex = pname.lastIndexOf('.'))>0) {2241return getPackageAssertionStatus(pname.substring(0, prdIndex));2242}2243}2244return getDefaultAssertionStatus();2245}22462247/**2248* Answers the default assertion status2249*2250* @return boolean2251* the default assertion status.2252*2253* @since 1.42254*/2255boolean getDefaultAssertionStatus() {2256if (!isParallelCapable) {2257synchronized(this) {2258return defaultAssertionStatus;2259}2260} else {2261synchronized(assertionLock) {2262return defaultAssertionStatus;2263}2264}2265}22662267/**2268* This sets the assertion status based on the commandline args to VM2269*2270* @since 1.42271*/2272private void initializeClassLoaderAssertStatus() {2273/*[PR CMVC 130382] Optimize checking ClassLoader assertion status */2274/*[IF Sidecar19-SE]*/2275boolean bootLoader = bootstrapClassLoader == this;2276/*[ELSE]2277boolean bootLoader = bootstrapClassLoader == null;2278/*[ENDIF]*/22792280if (!bootLoader && !checkAssertionOptions) {2281// if the bootLoader didn't find any assertion options, other2282// classloaders can skip the check for options2283return;2284}22852286boolean foundAssertionOptions = false;2287String [] vmargs = com.ibm.oti.vm.VM.getVMArgs();2288for (int i=0; i<vmargs.length; i++) {2289if (!vmargs[i].startsWith("-e") && !vmargs[i].startsWith("-d")) { //$NON-NLS-1$ //$NON-NLS-2$2290continue;2291}2292// splice around :2293int indexColon = vmargs[i].indexOf(':');2294String vmargOptions, vmargExtraInfo;2295if ( indexColon == -1 ) {2296vmargOptions = vmargs[i];2297vmargExtraInfo = null;2298} else {2299vmargOptions = vmargs[i].substring(0, indexColon);2300vmargExtraInfo = vmargs[i].substring(indexColon+1);2301}2302if ( vmargOptions.compareTo("-ea") == 0 //$NON-NLS-1$2303|| vmargOptions.compareTo("-enableassertions") == 0 //$NON-NLS-1$2304|| vmargOptions.compareTo("-da") == 0 //$NON-NLS-1$2305|| vmargOptions.compareTo("-disableassertions") == 0 //$NON-NLS-1$2306) {2307foundAssertionOptions = true;2308boolean def = vmargOptions.charAt(1) == 'e';2309if (vmargExtraInfo == null) {2310if (bootLoader) {2311continue;2312}2313setDefaultAssertionStatusImpl(def);2314} else {2315String str = vmargExtraInfo;2316int len = str.length();2317if ( len > 3 && str.charAt(len-1) == '.' &&2318str.charAt(len-2) == '.' && str.charAt(len-3) == '.') {2319str = str.substring(0,len-3);2320setPackageAssertionStatusImpl(str, def);2321} else {2322setClassAssertionStatusImpl(str, def);2323}2324}2325} else if ( vmargOptions.compareTo("-esa") == 0 //$NON-NLS-1$2326|| vmargOptions.compareTo("-enablesystemassertions") == 0 //$NON-NLS-1$2327|| vmargOptions.compareTo("-dsa") == 0 //$NON-NLS-1$2328|| vmargOptions.compareTo("-disablesystemassertions") == 0 //$NON-NLS-1$2329) {2330if (bootLoader) {2331boolean def = vmargOptions.charAt(1) == 'e';2332setDefaultAssertionStatusImpl(def);2333}2334}23352336}2337if (bootLoader && foundAssertionOptions) {2338// assertion options found, every classloader must check the options2339checkAssertionOptions = true;2340}2341}23422343/**2344* Constructs a new class from an array of bytes containing a2345* class definition in class file format and assigns the new2346* class to the specified protection domain.2347*2348* @param name java.lang.String2349* the name of the new class.2350* @param buffer2351* a memory image of a class file.2352* @param domain2353* the protection domain this class should2354* belong to.2355*2356* @return the newly defined Class2357*2358* @throws ClassFormatError when the bytes are invalid2359*2360* @since 1.52361*/2362protected final Class<?> defineClass(String name, java.nio.ByteBuffer buffer, ProtectionDomain domain) throws ClassFormatError {2363int position = buffer.position();2364int size = buffer.limit() - position;2365if (buffer.hasArray())2366return defineClass(name, buffer.array(), position, size, domain);23672368byte[] bytes = new byte[size];2369buffer.get(bytes);2370return defineClass(name, bytes, 0, size, domain);2371}23722373/**2374* Check if all the certs in one array are present in the other array2375* @param pcerts java.security.cert.Certificate[]2376* @param certs java.security.cert.Certificate[]2377* @return true when all the certs in one array are present in the other array2378* false otherwise2379*/2380private boolean compareCerts(java.security.cert.Certificate[] pcerts,2381java.security.cert.Certificate[] certs) {2382/*[PR CMVC 157478] compareCerts function missing in java.lang.ClassLoader class */2383if (pcerts == null) {2384pcerts = emptyCertificates;2385}2386if (certs == null) {2387certs = emptyCertificates;2388}2389if (pcerts == certs) {2390return true;2391} else if (pcerts.length != certs.length) {2392return false;2393}23942395boolean foundMatch = true;2396test: for(int i=0; i<pcerts.length; i++) {2397if (pcerts[i] == certs[i]) continue;2398if (pcerts[i].equals(certs[i])) continue;2399for(int j=0; j<certs.length; j++) {2400if (j == i) continue;2401if (pcerts[i] == certs[j]) continue test;2402if (pcerts[i].equals(certs[j])) continue test;2403}2404foundMatch = false;2405break;2406}2407return foundMatch;2408}24092410//prevent subclasses from becoming Cloneable2411@Override2412protected Object clone() throws CloneNotSupportedException {2413throw new CloneNotSupportedException();2414}24152416/**2417* Returns a {@code java.util.Map} from method descriptor string to the equivalent {@code MethodType} as generated by {@code MethodType.fromMethodDescriptorString}.2418* @return A {@code java.util.Map} from method descriptor string to the equivalent {@code MethodType}.2419*/2420Map<String, java.lang.invoke.MethodType> getMethodTypeCache() {2421if (null == methodTypeFromMethodDescriptorStringCache) {2422methodTypeFromMethodDescriptorStringCache = new java.util.concurrent.ConcurrentHashMap<>(16, 0.75f, 8);2423}2424return methodTypeFromMethodDescriptorStringCache;2425}24262427/*[IF Sidecar19-SE]*/2428ServicesCatalog createOrGetServicesCatalog() {2429if (null == this.servicesCatalog) {2430this.servicesCatalog = ServicesCatalog.create();2431}2432return this.servicesCatalog;2433}24342435ServicesCatalog getServicesCatalog() {2436return this.servicesCatalog;2437}24382439/*[ENDIF] Sidecar19-SE*/24402441/*[IF Sidecar19-SE]*/2442/**2443* Answers an URL which can be used to access the resource2444* described by resName, using the class loader's resource lookup2445* algorithm. By default, return null, unless moduleName is null,2446* in which case return findResource(resName).2447* This should be implemented by a ClassLoader.2448*2449* @return URL2450* the location of the resource.2451* @param moduleName String2452* the module name2453* @param resName String2454* the name of the resource to find.2455*2456* @throws IOException when an error occurs2457*/2458protected URL findResource(String moduleName, String resName) throws IOException {2459URL result = null;2460if (null == moduleName) {2461/* Handle the default case for subclasses which do not implement this method */2462result = findResource(resName);2463}2464return result;2465}24662467Package definePackage(String name, Module module) {2468Package pkg = null;2469if (name.isEmpty() && module.isNamed()) {2470throw new InternalError("Unnamed package in " + module); //$NON-NLS-1$2471}2472synchronized(packages) {2473NamedPackage np = packages.get(name);2474if ((null != np) && (np instanceof Package)) {2475pkg = (Package)np;2476} else {2477pkg = NamedPackage.toPackage(name, module);2478packages.put(name, pkg);2479}2480}24812482return pkg;2483}2484Stream<Package> packages() {2485return packages.values().stream().map(p->definePackage(p.packageName(), p.module()));2486}2487static ClassLoader getBuiltinAppClassLoader() {2488throw new Error("ClassLoader.getBuiltinAppClassLoader unimplemented"); //$NON-NLS-1$2489}2490static ClassLoader initSystemClassLoader() {2491throw new Error("ClassLoader.initSystemClassLoader unimplemented"); //$NON-NLS-1$2492}2493ConcurrentHashMap<?, ?> createOrGetClassLoaderValueMap() {2494if (null == classLoaderValueMap) {2495synchronized(lazyInitLock) {2496if (null == classLoaderValueMap) {2497classLoaderValueMap = new ConcurrentHashMap<>();2498}2499}2500}2501return classLoaderValueMap;2502}25032504/**2505* Answers a stream of URL which can be used to access the resources2506* described by name, using the class loader's resource lookup algorithm.2507*2508* @param name - the name of the resource to find25092510* @return a stream of the resources2511*2512* @throws NullPointerException when name is null2513*/2514public Stream<URL> resources(String name) {2515try {2516return StreamSupport.stream(Spliterators.spliteratorUnknownSize(getResources(name).asIterator(), Spliterator.NONNULL | Spliterator.IMMUTABLE), false);2517} catch (IOException e) {2518throw new UncheckedIOException(e);2519}2520}25212522/**2523* Indicating if this class loader is registered as parallel capable or not2524*2525* @return true if this is registered as parallel capable, otherwise false is returned2526*/2527public final boolean isRegisteredAsParallelCapable() {2528return isParallelCapable;2529}25302531/*[ENDIF] Sidecar19-SE*/2532}253325342535