src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
author mchung
Wed, 06 Feb 2019 10:53:13 -0800
changeset 53660 929f0c7e019b
parent 53018 8bf9268df0e2
permissions -rw-r--r--
8218419: Can't get annotations that are present on packages in -Xbootclasspath/a Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
53660
929f0c7e019b 8218419: Can't get annotations that are present on packages in -Xbootclasspath/a
mchung
parents: 53018
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package jdk.internal.loader;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.net.URL;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.nio.file.InvalidPathException;
49285
4d2e3f5abb48 8194746: (fs) Add equivalents of Paths.get to Path interface
bpb
parents: 48994
diff changeset
    31
import java.nio.file.Path;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.security.CodeSource;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.security.PermissionCollection;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.jar.Manifest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 49285
diff changeset
    36
import jdk.internal.access.JavaLangAccess;
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 49285
diff changeset
    37
import jdk.internal.access.SharedSecrets;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.internal.misc.VM;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 * Creates and provides access to the built-in platform and application class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 * loaders. It also creates the class loader that is used to locate resources
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * in modules defined to the boot class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
public class ClassLoaders {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    private ClassLoaders() { }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    // the built-in class loaders
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final BootClassLoader BOOT_LOADER;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private static final PlatformClassLoader PLATFORM_LOADER;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private static final AppClassLoader APP_LOADER;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
48994
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    57
    // Creates the built-in class loaders.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    static {
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 44750
diff changeset
    59
        // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute
48994
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    60
        String append = VM.getSavedProperty("jdk.boot.class.path.append");
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    61
        BOOT_LOADER =
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 52427
diff changeset
    62
            new BootClassLoader((append != null && !append.isEmpty())
48994
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    63
                ? new URLClassPath(append, true)
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    64
                : null);
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    65
        PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
48994
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    67
        // A class path is required when no initial module is specified.
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    68
        // In this case the class path defaults to "", meaning the current
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    69
        // working directory.  When an initial module is specified, on the
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    70
        // contrary, we drop this historic interpretation of the empty
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    71
        // string and instead treat it as unspecified.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        String cp = System.getProperty("java.class.path");
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 52427
diff changeset
    73
        if (cp == null || cp.isEmpty()) {
48994
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    74
            String initialModuleName = System.getProperty("jdk.module.main");
817e39d3a9e0 8198480: Improve ClassLoaders static init block
martin
parents: 47216
diff changeset
    75
            cp = (initialModuleName == null) ? "" : null;
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 44750
diff changeset
    76
        }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 44750
diff changeset
    77
        URLClassPath ucp = new URLClassPath(cp, false);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
     * Returns the class loader that is used to find resources in modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
     * defined to the boot class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
     * @apiNote This method is not public, it should instead be used via
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
     * the BootLoader class that provides a restricted API to this class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
     * loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    static BuiltinClassLoader bootLoader() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        return BOOT_LOADER;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
     * Returns the platform class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
    public static ClassLoader platformClassLoader() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        return PLATFORM_LOADER;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
     * Returns the application class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    public static ClassLoader appClassLoader() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        return APP_LOADER;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
     * The class loader that is used to find resources in modules defined to
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
     * the boot class loader. It is not used for class loading.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
    private static class BootClassLoader extends BuiltinClassLoader {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        BootClassLoader(URLClassPath bcp) {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 41814
diff changeset
   113
            super(null, null, bcp);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        @Override
53660
929f0c7e019b 8218419: Can't get annotations that are present on packages in -Xbootclasspath/a
mchung
parents: 53018
diff changeset
   117
        protected Class<?> loadClassOrNull(String cn, boolean resolve) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            return JLA.findBootstrapClassOrNull(this, cn);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
    };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
     * The platform class loader, a unique type to make it easier to distinguish
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
     * from the application class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    private static class PlatformClassLoader extends BuiltinClassLoader {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        static {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
            if (!ClassLoader.registerAsParallelCapable())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                throw new InternalError();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        PlatformClassLoader(BootClassLoader parent) {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 41814
diff changeset
   133
            super("platform", parent, null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
         * Called by the VM to support define package for AppCDS.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
         * Shared classes are returned in ClassLoader::findLoadedClass
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
         * that bypass the defineClass call.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        private Package definePackage(String pn, Module module) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            return JLA.definePackage(this, pn, module);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
     * The application class loader that is a {@code BuiltinClassLoader} with
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
     * customizations to be compatible with long standing behavior.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    private static class AppClassLoader extends BuiltinClassLoader {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        static {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            if (!ClassLoader.registerAsParallelCapable())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                throw new InternalError();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        final URLClassPath ucp;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        AppClassLoader(PlatformClassLoader parent, URLClassPath ucp) {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 41814
diff changeset
   160
            super("app", parent, ucp);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
            this.ucp = ucp;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        protected Class<?> loadClass(String cn, boolean resolve)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
            throws ClassNotFoundException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
            // for compatibility reasons, say where restricted package list has
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            // been updated to list API packages in the unnamed module.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            SecurityManager sm = System.getSecurityManager();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            if (sm != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                int i = cn.lastIndexOf('.');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                if (i != -1) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                    sm.checkPackageAccess(cn.substring(0, i));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
            return super.loadClass(cn, resolve);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        protected PermissionCollection getPermissions(CodeSource cs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            PermissionCollection perms = super.getPermissions(cs);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            perms.add(new RuntimePermission("exitVM"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            return perms;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
         * Called by the VM to support dynamic additions to the class path
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
         * @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        void appendToClassPathForInstrumentation(String path) {
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 44750
diff changeset
   194
            ucp.addFile(path);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
         * Called by the VM to support define package for AppCDS
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
         * Shared classes are returned in ClassLoader::findLoadedClass
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
         * that bypass the defineClass call.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        private Package definePackage(String pn, Module module) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
            return JLA.definePackage(this, pn, module);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
         * Called by the VM to support define package for AppCDS
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        protected Package defineOrCheckPackage(String pn, Manifest man, URL url) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
            return super.defineOrCheckPackage(pn, man, url);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
    /**
38793
7dba4e68157d 8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL.
jiangli
parents: 38326
diff changeset
   216
     * Attempts to convert the given string to a file URL.
7dba4e68157d 8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL.
jiangli
parents: 38326
diff changeset
   217
     *
7dba4e68157d 8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL.
jiangli
parents: 38326
diff changeset
   218
     * @apiNote This is called by the VM
38326
9e4be8e12bac 8156989: Trailing empty element in classpath ignored
alanb
parents: 36674
diff changeset
   219
     */
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 44750
diff changeset
   220
    @Deprecated
38793
7dba4e68157d 8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL.
jiangli
parents: 38326
diff changeset
   221
    private static URL toFileURL(String s) {
38326
9e4be8e12bac 8156989: Trailing empty element in classpath ignored
alanb
parents: 36674
diff changeset
   222
        try {
44750
662ff2218c05 8178726: Can't load classes from classpath if it is a UNC share
simonis
parents: 44545
diff changeset
   223
            // Use an intermediate File object to construct a URI/URL without
662ff2218c05 8178726: Can't load classes from classpath if it is a UNC share
simonis
parents: 44545
diff changeset
   224
            // authority component as URLClassPath can't handle URLs with a UNC
662ff2218c05 8178726: Can't load classes from classpath if it is a UNC share
simonis
parents: 44545
diff changeset
   225
            // server name in the authority component.
49285
4d2e3f5abb48 8194746: (fs) Add equivalents of Paths.get to Path interface
bpb
parents: 48994
diff changeset
   226
            return Path.of(s).toRealPath().toFile().toURI().toURL();
38326
9e4be8e12bac 8156989: Trailing empty element in classpath ignored
alanb
parents: 36674
diff changeset
   227
        } catch (InvalidPathException | IOException ignore) {
9e4be8e12bac 8156989: Trailing empty element in classpath ignored
alanb
parents: 36674
diff changeset
   228
            // malformed path string or class path element does not exist
38793
7dba4e68157d 8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL.
jiangli
parents: 38326
diff changeset
   229
            return null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
}