< prev index next >

src/java.base/share/classes/jdk/internal/loader/BootLoader.java

Print this page

  1 /*
  2  * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 53 public class BootLoader {
 54     private BootLoader() { }
 55 
 56     private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
 57 
 58     // The unnamed module for the boot loader
 59     private static final Module UNNAMED_MODULE;
 60     private static final String JAVA_HOME = StaticProperty.javaHome();
 61 
 62     static {
 63         JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
 64         UNNAMED_MODULE = jla.defineUnnamedModule(null);
 65         jla.addEnableNativeAccess(UNNAMED_MODULE);
 66         setBootLoaderUnnamedModule0(UNNAMED_MODULE);
 67     }
 68 
 69     // ClassLoaderValue map for the boot class loader
 70     private static final ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP
 71         = new ConcurrentHashMap<>();
 72 
 73     // native libraries loaded by the boot class loader
 74     private static final NativeLibraries NATIVE_LIBS
 75         = NativeLibraries.newInstance(null);




 76 
 77     /**
 78      * Returns the unnamed module for the boot loader.
 79      */
 80     public static Module getUnnamedModule() {
 81         return UNNAMED_MODULE;
 82     }
 83 
 84     /**
 85      * Returns the ServiceCatalog for modules defined to the boot class loader.
 86      */
 87     public static ServicesCatalog getServicesCatalog() {
 88         return ServicesCatalog.getServicesCatalog(ClassLoaders.bootLoader());
 89     }
 90 
 91     /**
 92      * Returns the ClassLoaderValue map for the boot class loader.
 93      */
 94     public static ConcurrentHashMap<?, ?> getClassLoaderValueMap() {
 95         return CLASS_LOADER_VALUE_MAP;
 96     }
 97 
 98     /**
 99      * Returns NativeLibraries for the boot class loader.
100      */
101     public static NativeLibraries getNativeLibraries() {
102         return NATIVE_LIBS;
103     }
104 
105     /**
106      * Returns {@code true} if there is a class path associated with the
107      * BootLoader.
108      */
109     public static boolean hasClassPath() {
110         return ClassLoaders.bootLoader().hasClassPath();
111     }
112 
113     /**
114      * Registers a module with this class loader so that its classes
115      * (and resources) become visible via this class loader.
116      */
117     public static void loadModule(ModuleReference mref) {
118         ClassLoaders.bootLoader().loadModule(mref);
119     }
120 
121     /**
122      * Loads the Class object with the given name defined to the boot loader.

  1 /*
  2  * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 53 public class BootLoader {
 54     private BootLoader() { }
 55 
 56     private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
 57 
 58     // The unnamed module for the boot loader
 59     private static final Module UNNAMED_MODULE;
 60     private static final String JAVA_HOME = StaticProperty.javaHome();
 61 
 62     static {
 63         JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
 64         UNNAMED_MODULE = jla.defineUnnamedModule(null);
 65         jla.addEnableNativeAccess(UNNAMED_MODULE);
 66         setBootLoaderUnnamedModule0(UNNAMED_MODULE);
 67     }
 68 
 69     // ClassLoaderValue map for the boot class loader
 70     private static final ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP
 71         = new ConcurrentHashMap<>();
 72 
 73     // Holder has the field(s) that need to be initialized during JVM bootstrap even if
 74     // the outer is aot-initialized.
 75     private static class Holder {
 76         // native libraries loaded by the boot class loader
 77         private static final NativeLibraries NATIVE_LIBS
 78             = NativeLibraries.newInstance(null);
 79     }
 80 
 81     /**
 82      * Returns the unnamed module for the boot loader.
 83      */
 84     public static Module getUnnamedModule() {
 85         return UNNAMED_MODULE;
 86     }
 87 
 88     /**
 89      * Returns the ServiceCatalog for modules defined to the boot class loader.
 90      */
 91     public static ServicesCatalog getServicesCatalog() {
 92         return ServicesCatalog.getServicesCatalog(ClassLoaders.bootLoader());
 93     }
 94 
 95     /**
 96      * Returns the ClassLoaderValue map for the boot class loader.
 97      */
 98     public static ConcurrentHashMap<?, ?> getClassLoaderValueMap() {
 99         return CLASS_LOADER_VALUE_MAP;
100     }
101 
102     /**
103      * Returns NativeLibraries for the boot class loader.
104      */
105     public static NativeLibraries getNativeLibraries() {
106         return Holder.NATIVE_LIBS;
107     }
108 
109     /**
110      * Returns {@code true} if there is a class path associated with the
111      * BootLoader.
112      */
113     public static boolean hasClassPath() {
114         return ClassLoaders.bootLoader().hasClassPath();
115     }
116 
117     /**
118      * Registers a module with this class loader so that its classes
119      * (and resources) become visible via this class loader.
120      */
121     public static void loadModule(ModuleReference mref) {
122         ClassLoaders.bootLoader().loadModule(mref);
123     }
124 
125     /**
126      * Loads the Class object with the given name defined to the boot loader.
< prev index next >