jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
author alanb
Wed, 22 Mar 2017 16:26:27 +0000
changeset 44359 c6761862ca0b
parent 43813 ab5cb6ace73b
child 44364 9cc9dc782213
permissions -rw-r--r--
8174823: Module system implementation refresh (3/2017) Reviewed-by: chegar, mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, sundararajan.athijegannathan@oracle.com, peter.levart@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43713
alanb
parents: 43712
diff changeset
     2
 * Copyright (c) 2014, 2017, 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.module;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.File;
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    29
import java.io.PrintStream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.lang.module.Configuration;
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    31
import java.lang.module.ModuleDescriptor;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    32
import java.lang.module.ModuleFinder;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.lang.module.ModuleReference;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.lang.module.ResolvedModule;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.lang.reflect.Layer;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
    36
import java.lang.reflect.LayerInstantiationException;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.lang.reflect.Module;
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    38
import java.net.URI;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.nio.file.Paths;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    41
import java.util.ArrayList;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.HashSet;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    45
import java.util.List;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.Optional;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import java.util.function.Function;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import jdk.internal.loader.BootLoader;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import jdk.internal.loader.BuiltinClassLoader;
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    53
import jdk.internal.misc.SharedSecrets;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import jdk.internal.perf.PerfCounter;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
 * Initializes/boots the module system.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
 * The {@link #boot() boot} method is called early in the startup to initialize
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
 * the module system. In summary, the boot method creates a Configuration by
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
 * resolving a set of module names specified via the launcher (or equivalent)
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
    62
 * -m and --add-modules options. The modules are located on a module path that
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
    63
 * is constructed from the upgrade module path, system modules, and application
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    64
 * module path. The Configuration is instantiated as the boot Layer with each
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    65
 * module in the the configuration defined to one of the built-in class loaders.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
public final class ModuleBootstrap {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    private ModuleBootstrap() { }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    private static final String JAVA_BASE = "java.base";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    73
    private static final String JAVA_SE = "java.se";
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    74
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    75
    // the token for "all default modules"
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    76
    private static final String ALL_DEFAULT = "ALL-DEFAULT";
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    77
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    // the token for "all unnamed modules"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    private static final String ALL_UNNAMED = "ALL-UNNAMED";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    // the token for "all system modules"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    private static final String ALL_SYSTEM = "ALL-SYSTEM";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    // the token for "all modules on the module path"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    87
    // The ModulePatcher for the initial configuration
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    88
    private static final ModulePatcher patcher = initModulePatcher();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    89
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    // ModuleFinder for the initial configuration
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    private static ModuleFinder initialFinder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    94
     * Returns the ModulePatcher for the initial configuration.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    95
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    96
    public static ModulePatcher patcher() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    97
        return patcher;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    98
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    99
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   100
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
     * Returns the ModuleFinder for the initial configuration
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    public static ModuleFinder finder() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        assert initialFinder != null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        return initialFinder;
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
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
     * Initialize the module system, returning the boot Layer.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
     * @see java.lang.System#initPhase2()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    public static Layer boot() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        long t0 = System.nanoTime();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   117
        // system modules (may be patched)
43813
ab5cb6ace73b 8175079: Lazy initialization of ImageReader breaks rmid
redestad
parents: 43713
diff changeset
   118
        ModuleFinder systemModules = ModuleFinder.ofSystem();
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   119
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   120
        PerfCounters.systemModulesTime.addElapsedTimeFrom(t0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   122
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   123
        long t1 = System.nanoTime();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   124
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   125
        // Once we have the system modules then we define the base module to
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   126
        // the VM. We do this here so that java.base is defined as early as
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        // possible and also that resources in the base module can be located
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        // for error messages that may happen from here on.
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   129
        ModuleReference base = systemModules.find(JAVA_BASE).orElse(null);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   130
        if (base == null)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
            throw new InternalError(JAVA_BASE + " not found");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   132
        URI baseUri = base.location().orElse(null);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   133
        if (baseUri == null)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   134
            throw new InternalError(JAVA_BASE + " does not have a location");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        BootLoader.loadModule(base);
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   136
        Modules.defineModule(null, base.descriptor(), baseUri);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   138
        PerfCounters.defineBaseTime.addElapsedTimeFrom(t1);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   139
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   140
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   141
        long t2 = System.nanoTime();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   143
        // --upgrade-module-path option specified to launcher
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        ModuleFinder upgradeModulePath
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   145
            = createModulePathFinder("jdk.module.upgrade.path");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   146
        if (upgradeModulePath != null)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   147
            systemModules = ModuleFinder.compose(upgradeModulePath, systemModules);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   149
        // --module-path option specified to the launcher
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        ModuleFinder appModulePath = createModulePathFinder("jdk.module.path");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   152
        // The module finder: [--upgrade-module-path] system [--module-path]
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   153
        ModuleFinder finder = systemModules;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        if (appModulePath != null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            finder = ModuleFinder.compose(finder, appModulePath);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   157
        // The root modules to resolve
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   158
        Set<String> roots = new HashSet<>();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   159
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   160
        // launcher -m option to specify the main/initial module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        String mainModule = System.getProperty("jdk.module.main");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   162
        if (mainModule != null)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   163
            roots.add(mainModule);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   165
        // additional module(s) specified by --add-modules
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   166
        boolean addAllDefaultModules = false;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        boolean addAllSystemModules = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        boolean addAllApplicationModules = false;
41114
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   169
        for (String mod: getExtraAddModules()) {
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   170
            switch (mod) {
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   171
                case ALL_DEFAULT:
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   172
                    addAllDefaultModules = true;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   173
                    break;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   174
                case ALL_SYSTEM:
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   175
                    addAllSystemModules = true;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   176
                    break;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   177
                case ALL_MODULE_PATH:
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   178
                    addAllApplicationModules = true;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   179
                    break;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   180
                default :
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   181
                    roots.add(mod);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   185
        // --limit-modules
41114
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   186
        String propValue = getAndRemoveProperty("jdk.module.limitmods");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        if (propValue != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            Set<String> mods = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
            for (String mod: propValue.split(",")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                mods.add(mod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
            finder = limitFinder(finder, mods, roots);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   195
        // If there is no initial module specified then assume that the initial
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   196
        // module is the unnamed module of the application class loader. This
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   197
        // is implemented by resolving "java.se" and all (non-java.*) modules
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   198
        // that export an API. If "java.se" is not observable then all java.*
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   199
        // modules are resolved. Modules that have the DO_NOT_RESOLVE_BY_DEFAULT
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   200
        // bit set in their ModuleResolution attribute flags are excluded from
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   201
        // the default set of roots.
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   202
        if (mainModule == null || addAllDefaultModules) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   203
            boolean hasJava = false;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   204
            if (systemModules.find(JAVA_SE).isPresent()) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   205
                // java.se is a system module
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   206
                if (finder == systemModules || finder.find(JAVA_SE).isPresent()) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   207
                    // java.se is observable
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   208
                    hasJava = true;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   209
                    roots.add(JAVA_SE);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
            }
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   212
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   213
            for (ModuleReference mref : systemModules.findAll()) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   214
                String mn = mref.descriptor().name();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   215
                if (hasJava && mn.startsWith("java."))
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   216
                    continue;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   217
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   218
                if (ModuleResolution.doNotResolveByDefault(mref))
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   219
                    continue;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   220
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   221
                // add as root if observable and exports at least one package
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   222
                if ((finder == systemModules || finder.find(mn).isPresent())) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   223
                    ModuleDescriptor descriptor = mref.descriptor();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   224
                    for (ModuleDescriptor.Exports e : descriptor.exports()) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   225
                        if (!e.isQualified()) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   226
                            roots.add(mn);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   227
                            break;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   228
                        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   229
                    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   230
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   234
        // If `--add-modules ALL-SYSTEM` is specified then all observable system
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   235
        // modules will be resolved.
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   236
        if (addAllSystemModules) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   237
            ModuleFinder f = finder;  // observable modules
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   238
            systemModules.findAll()
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   239
                .stream()
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   240
                .filter(mref -> !ModuleResolution.doNotResolveByDefault(mref))
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   241
                .map(ModuleReference::descriptor)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   242
                .map(ModuleDescriptor::name)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   243
                .filter(mn -> f.find(mn).isPresent())  // observable
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   244
                .forEach(mn -> roots.add(mn));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   245
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   246
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   247
        // If `--add-modules ALL-MODULE-PATH` is specified then all observable
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   248
        // modules on the application module path will be resolved.
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   249
        if (appModulePath != null && addAllApplicationModules) {
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   250
            ModuleFinder f = finder;  // observable modules
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   251
            appModulePath.findAll()
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   252
                .stream()
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   253
                .map(ModuleReference::descriptor)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   254
                .map(ModuleDescriptor::name)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   255
                .filter(mn -> f.find(mn).isPresent())  // observable
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   256
                .forEach(mn -> roots.add(mn));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   257
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   258
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   259
        PerfCounters.optionsAndRootsTime.addElapsedTimeFrom(t2);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   260
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   261
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   262
        long t3 = System.nanoTime();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   263
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   264
        // determine if post resolution checks are needed
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   265
        boolean needPostResolutionChecks = true;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   266
        if (baseUri.getScheme().equals("jrt")   // toLowerCase not needed here
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   267
                && (upgradeModulePath == null)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   268
                && (appModulePath == null)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   269
                && (patcher.isEmpty())) {
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   270
            needPostResolutionChecks = false;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   271
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   272
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   273
        PrintStream traceOutput = null;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   274
        if (Boolean.getBoolean("jdk.launcher.traceResolver"))
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   275
            traceOutput = System.out;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        // run the resolver to create the configuration
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   278
        Configuration cf = SharedSecrets.getJavaLangModuleAccess()
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   279
                .resolveAndBind(finder,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   280
                                roots,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   281
                                needPostResolutionChecks,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   282
                                traceOutput);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        // time to create configuration
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   285
        PerfCounters.resolveTime.addElapsedTimeFrom(t3);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   286
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   287
        // check module names and incubating status
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   288
        checkModuleNamesAndStatus(cf);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        // mapping of modules to class loaders
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        Function<String, ClassLoader> clf = ModuleLoaderMap.mappingFunction(cf);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        // check that all modules to be mapped to the boot loader will be
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   294
        // loaded from the runtime image
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   295
        if (needPostResolutionChecks) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
            for (ResolvedModule resolvedModule : cf.modules()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                ModuleReference mref = resolvedModule.reference();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
                String name = mref.descriptor().name();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                ClassLoader cl = clf.apply(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   300
                if (cl == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   302
                    if (upgradeModulePath != null
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
                            && upgradeModulePath.find(name).isPresent())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
                        fail(name + ": cannot be loaded from upgrade module path");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   306
                    if (!systemModules.find(name).isPresent())
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
                        fail(name + ": cannot be loaded from application module path");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
            }
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   310
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   311
            // check if module specified in --patch-module is present
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   312
            for (String mn: patcher.patchedModules()) {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   313
                if (!cf.findModule(mn).isPresent()) {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   314
                    warnUnknownModule(PATCH_MODULE, mn);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   315
                }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   316
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
42770
d363e7c3584a 8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents: 42704
diff changeset
   319
        // if needed check that there are no split packages in the set of
d363e7c3584a 8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents: 42704
diff changeset
   320
        // resolved modules for the boot layer
d363e7c3584a 8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents: 42704
diff changeset
   321
        if (SystemModules.hasSplitPackages() || needPostResolutionChecks) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   322
            Map<String, String> packageToModule = new HashMap<>();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   323
            for (ResolvedModule resolvedModule : cf.modules()) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   324
                ModuleDescriptor descriptor =
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   325
                    resolvedModule.reference().descriptor();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   326
                String name = descriptor.name();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   327
                for (String p : descriptor.packages()) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   328
                    String other = packageToModule.putIfAbsent(p, name);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   329
                    if (other != null) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   330
                        String msg = "Package " + p + " in both module "
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   331
                                     + name + " and module " + other;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   332
                        throw new LayerInstantiationException(msg);
42770
d363e7c3584a 8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents: 42704
diff changeset
   333
                    }
d363e7c3584a 8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents: 42704
diff changeset
   334
                }
d363e7c3584a 8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents: 42704
diff changeset
   335
            }
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   336
        }
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   337
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   338
        long t4 = System.nanoTime();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        // define modules to VM/runtime
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        Layer bootLayer = Layer.empty().defineModules(cf, clf);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   343
        PerfCounters.layerCreateTime.addElapsedTimeFrom(t4);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   345
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   346
        long t5 = System.nanoTime();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
        // define the module to its class loader, except java.base
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
        for (ResolvedModule resolvedModule : cf.modules()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
            ModuleReference mref = resolvedModule.reference();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
            String name = mref.descriptor().name();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
            ClassLoader cl = clf.apply(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
            if (cl == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                if (!name.equals(JAVA_BASE)) BootLoader.loadModule(mref);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                ((BuiltinClassLoader)cl).loadModule(mref);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   360
        PerfCounters.loadModulesTime.addElapsedTimeFrom(t5);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   361
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   363
        // --add-reads, --add-exports/--add-opens
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
        addExtraReads(bootLayer);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   365
        addExtraExportsAndOpens(bootLayer);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        // total time to initialize
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
        PerfCounters.bootstrapTime.addElapsedTimeFrom(t0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
        // remember the ModuleFinder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
        initialFinder = finder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
        return bootLayer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
     * Returns a ModuleFinder that limits observability to the given root
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378
     * modules, their transitive dependences, plus a set of other modules.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
    private static ModuleFinder limitFinder(ModuleFinder finder,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                                            Set<String> roots,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                                            Set<String> otherMods)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   383
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   384
        // resolve all root modules
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   385
        Configuration cf = Configuration.empty().resolve(finder,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   386
                                                         ModuleFinder.of(),
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   387
                                                         roots);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   388
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   389
        // module name -> reference
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   390
        Map<String, ModuleReference> map = new HashMap<>();
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   391
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   392
        // root modules and their transitive dependences
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   393
        cf.modules().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
            .map(ResolvedModule::reference)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   395
            .forEach(mref -> map.put(mref.descriptor().name(), mref));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   396
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   397
        // additional modules
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   398
        otherMods.stream()
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   399
            .map(finder::find)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   400
            .flatMap(Optional::stream)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   401
            .forEach(mref -> map.putIfAbsent(mref.descriptor().name(), mref));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   402
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
        // set of modules that are observable
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
        Set<ModuleReference> mrefs = new HashSet<>(map.values());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   406
        return new ModuleFinder() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   407
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   408
            public Optional<ModuleReference> find(String name) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   409
                return Optional.ofNullable(map.get(name));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   410
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   411
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   412
            public Set<ModuleReference> findAll() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   413
                return mrefs;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   414
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   415
        };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   416
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   417
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   418
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   419
     * Creates a finder from the module path that is the value of the given
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   420
     * system property and optionally patched by --patch-module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   421
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   422
    private static ModuleFinder createModulePathFinder(String prop) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   423
        String s = System.getProperty(prop);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   424
        if (s == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   425
            return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   426
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   427
            String[] dirs = s.split(File.pathSeparator);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   428
            Path[] paths = new Path[dirs.length];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   429
            int i = 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   430
            for (String dir: dirs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                paths[i++] = Paths.get(dir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   432
            }
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   433
            return ModulePath.of(patcher, paths);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   434
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   435
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   436
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   437
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   438
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   439
     * Initialize the module patcher for the initial configuration passed on the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   440
     * value of the --patch-module options.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   441
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   442
    private static ModulePatcher initModulePatcher() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   443
        Map<String, List<String>> map = decode("jdk.module.patch.",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   444
                                               File.pathSeparator,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   445
                                               false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   446
        return new ModulePatcher(map);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   447
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   448
41114
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   449
    /**
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   450
     * Returns the set of module names specified via --add-modules options
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   451
     * on the command line
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   452
     */
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   453
    private static Set<String> getExtraAddModules() {
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   454
        String prefix = "jdk.module.addmods.";
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   455
        int index = 0;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   456
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   457
        // the system property is removed after decoding
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   458
        String value = getAndRemoveProperty(prefix + index);
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   459
        if (value == null) {
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   460
            return Collections.emptySet();
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   461
        }
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   462
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   463
        Set<String> modules = new HashSet<>();
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   464
        while (value != null) {
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   465
            for (String s : value.split(",")) {
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   466
                if (s.length() > 0) modules.add(s);
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   467
            }
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   468
            index++;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   469
            value = getAndRemoveProperty(prefix + index);
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   470
        }
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   471
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   472
        return modules;
f83e9aebbab4 8165634: Support multiple --add-modules options on the command line
hseigel
parents: 40261
diff changeset
   473
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
    /**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   476
     * Process the --add-reads options to add any additional read edges that
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   477
     * are specified on the command-line.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   479
    private static void addExtraReads(Layer bootLayer) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   480
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   481
        // decode the command line options
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   482
        Map<String, List<String>> map = decode("jdk.module.addreads.");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   483
        if (map.isEmpty())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   484
            return;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   485
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   486
        for (Map.Entry<String, List<String>> e : map.entrySet()) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   487
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   488
            // the key is $MODULE
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   489
            String mn = e.getKey();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   490
            Optional<Module> om = bootLayer.findModule(mn);
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   491
            if (!om.isPresent()) {
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   492
                warnUnknownModule(ADD_READS, mn);
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   493
                continue;
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   494
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   495
            Module m = om.get();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   496
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   497
            // the value is the set of other modules (by name)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   498
            for (String name : e.getValue()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   499
                if (ALL_UNNAMED.equals(name)) {
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   500
                    Modules.addReadsAllUnnamed(m);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   501
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   502
                    om = bootLayer.findModule(name);
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   503
                    if (om.isPresent()) {
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   504
                        Modules.addReads(m, om.get());
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   505
                    } else {
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   506
                        warnUnknownModule(ADD_READS, name);
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   507
                    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   508
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   509
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   510
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   511
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   512
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   513
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   514
     * Process the --add-exports and --add-opens options to export/open
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   515
     * additional packages specified on the command-line.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   516
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   517
    private static void addExtraExportsAndOpens(Layer bootLayer) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   518
        IllegalAccessLogger.Builder builder = new IllegalAccessLogger.Builder();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   519
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   520
        // --add-exports
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   521
        String prefix = "jdk.module.addexports.";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   522
        Map<String, List<String>> extraExports = decode(prefix);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   523
        if (!extraExports.isEmpty()) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   524
            addExtraExportsOrOpens(bootLayer, extraExports, false, builder);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   525
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   526
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   527
        // --add-opens
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   528
        prefix = "jdk.module.addopens.";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   529
        Map<String, List<String>> extraOpens = decode(prefix);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   530
        if (!extraOpens.isEmpty()) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   531
            addExtraExportsOrOpens(bootLayer, extraOpens, true, builder);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   532
        }
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42774
diff changeset
   533
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   534
        // --permit-illegal-access
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   535
        if (getAndRemoveProperty("jdk.module.permitIllegalAccess") != null) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   536
            warn("--permit-illegal-access will be removed in the next major release");
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   537
            bootLayer.modules().stream().forEach(m -> {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   538
                m.getDescriptor()
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   539
                 .packages()
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   540
                 .stream()
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   541
                 .filter(pn -> !m.isOpen(pn))
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   542
                 .forEach(pn -> {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   543
                     builder.logAccessToOpenPackage(m, pn, "--permit-illegal-access");
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   544
                     Modules.addOpensToAllUnnamed(m, pn);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   545
                 });
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   546
            });
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   547
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   548
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   549
        IllegalAccessLogger.setIllegalAccessLogger(builder.build());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   550
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   551
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   552
    private static void addExtraExportsOrOpens(Layer bootLayer,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   553
                                               Map<String, List<String>> map,
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   554
                                               boolean opens,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   555
                                               IllegalAccessLogger.Builder builder)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   556
    {
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   557
        String option = opens ? ADD_OPENS : ADD_EXPORTS;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   558
        for (Map.Entry<String, List<String>> e : map.entrySet()) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   559
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   560
            // the key is $MODULE/$PACKAGE
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   561
            String key = e.getKey();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   562
            String[] s = key.split("/");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   563
            if (s.length != 2)
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   564
                fail(unableToParse(option, "<module>/<package>", key));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   565
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   566
            String mn = s[0];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   567
            String pn = s[1];
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   568
            if (mn.isEmpty() || pn.isEmpty())
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   569
                fail(unableToParse(option, "<module>/<package>", key));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   570
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   571
            // The exporting module is in the boot layer
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   572
            Module m;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   573
            Optional<Module> om = bootLayer.findModule(mn);
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   574
            if (!om.isPresent()) {
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   575
                warnUnknownModule(option, mn);
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   576
                continue;
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   577
            }
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   578
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   579
            m = om.get();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   580
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   581
            if (!m.getDescriptor().packages().contains(pn)) {
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   582
                warn("package " + pn + " not in " + mn);
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   583
                continue;
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   584
            }
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   585
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   586
            // the value is the set of modules to export to (by name)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   587
            for (String name : e.getValue()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   588
                boolean allUnnamed = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   589
                Module other = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   590
                if (ALL_UNNAMED.equals(name)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   591
                    allUnnamed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   592
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   593
                    om = bootLayer.findModule(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   594
                    if (om.isPresent()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   595
                        other = om.get();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   596
                    } else {
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   597
                        warnUnknownModule(option, name);
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   598
                        continue;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   599
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   600
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   601
                if (allUnnamed) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   602
                    if (opens) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   603
                        builder.logAccessToOpenPackage(m, pn, option);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   604
                        Modules.addOpensToAllUnnamed(m, pn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   605
                    } else {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   606
                        builder.logAccessToExportedPackage(m, pn, option);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   607
                        Modules.addExportsToAllUnnamed(m, pn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   608
                    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   609
                } else {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   610
                    if (opens) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   611
                        Modules.addOpens(m, pn, other);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   612
                    } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   613
                        Modules.addExports(m, pn, other);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   614
                    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   615
                }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   616
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   617
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   618
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   619
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   620
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   621
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   622
     * Decodes the values of --add-reads, -add-exports, --add-opens or
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   623
     * --patch-modules options that are encoded in system properties.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   624
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   625
     * @param prefix the system property prefix
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   626
     * @praam regex the regex for splitting the RHS of the option value
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   627
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   628
    private static Map<String, List<String>> decode(String prefix,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   629
                                                    String regex,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   630
                                                    boolean allowDuplicates) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   631
        int index = 0;
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   632
        // the system property is removed after decoding
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   633
        String value = getAndRemoveProperty(prefix + index);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   634
        if (value == null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   635
            return Collections.emptyMap();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   636
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   637
        Map<String, List<String>> map = new HashMap<>();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   638
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   639
        while (value != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   640
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   641
            int pos = value.indexOf('=');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   642
            if (pos == -1)
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   643
                fail(unableToParse(option(prefix), "<module>=<value>", value));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   644
            if (pos == 0)
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   645
                fail(unableToParse(option(prefix), "<module>=<value>", value));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   646
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   647
            // key is <module> or <module>/<package>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   648
            String key = value.substring(0, pos);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
            String rhs = value.substring(pos+1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   651
            if (rhs.isEmpty())
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   652
                fail(unableToParse(option(prefix), "<module>=<value>", value));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   653
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   654
            // value is <module>(,<module>)* or <file>(<pathsep><file>)*
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   655
            if (!allowDuplicates && map.containsKey(key))
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   656
                fail(key + " specified more than once to " + option(prefix));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   657
            List<String> values = map.computeIfAbsent(key, k -> new ArrayList<>());
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   658
            int ntargets = 0;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   659
            for (String s : rhs.split(regex)) {
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   660
                if (s.length() > 0) {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   661
                    values.add(s);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   662
                    ntargets++;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   663
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   664
            }
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   665
            if (ntargets == 0)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   666
                fail("Target must be specified: " + option(prefix) + " " + value);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   667
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   668
            index++;
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   669
            value = getAndRemoveProperty(prefix + index);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   670
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   671
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   672
        return map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   673
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   674
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   675
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   676
     * Decodes the values of --add-reads, -add-exports or --add-opens
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   677
     * which use the "," to separate the RHS of the option value.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   678
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   679
    private static Map<String, List<String>> decode(String prefix) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   680
        return decode(prefix, ",", true);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   681
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   682
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   683
    /**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   684
     * Gets and remove the named system property
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   685
     */
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   686
    private static String getAndRemoveProperty(String key) {
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   687
        return (String)System.getProperties().remove(key);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
   688
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   689
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   690
    /**
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   691
     * Checks the names and resolution bit of each module in the configuration,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   692
     * emitting warnings if needed.
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   693
     */
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   694
    private static void checkModuleNamesAndStatus(Configuration cf) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   695
        String incubating = null;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   696
        for (ResolvedModule rm : cf.modules()) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   697
            ModuleReference mref = rm.reference();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   698
            String mn = mref.descriptor().name();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   699
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   700
            // emit warning if the WARN_INCUBATING module resolution bit set
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   701
            if (ModuleResolution.hasIncubatingWarning(mref)) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   702
                if (incubating == null) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   703
                    incubating = mn;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   704
                } else {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   705
                    incubating += ", " + mn;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   706
                }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   707
            }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   708
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   709
        if (incubating != null)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   710
            warn("Using incubator modules: " + incubating);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   711
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   712
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   713
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   714
     * Throws a RuntimeException with the given message
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   715
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   716
    static void fail(String m) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   717
        throw new RuntimeException(m);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   718
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   719
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   720
    static void warn(String m) {
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   721
        System.err.println("WARNING: " + m);
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   722
    }
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 41114
diff changeset
   723
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   724
    static void warnUnknownModule(String option, String mn) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
   725
        warn("Unknown module: " + mn + " specified to " + option);
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   726
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   727
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   728
    static String unableToParse(String option, String text, String value) {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   729
        return "Unable to parse " +  option + " " + text + ": " + value;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   730
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   731
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   732
    private static final String ADD_MODULES  = "--add-modules";
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   733
    private static final String ADD_EXPORTS  = "--add-exports";
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   734
    private static final String ADD_OPENS    = "--add-opens";
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   735
    private static final String ADD_READS    = "--add-reads";
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   736
    private static final String PATCH_MODULE = "--patch-module";
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   737
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   738
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   739
    /*
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   740
     * Returns the command-line option name corresponds to the specified
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   741
     * system property prefix.
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   742
     */
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   743
    static String option(String prefix) {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   744
        switch (prefix) {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   745
            case "jdk.module.addexports.":
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   746
                return ADD_EXPORTS;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   747
            case "jdk.module.addopens.":
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   748
                return ADD_OPENS;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   749
            case "jdk.module.addreads.":
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   750
                return ADD_READS;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   751
            case "jdk.module.patch.":
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   752
                return PATCH_MODULE;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   753
            case "jdk.module.addmods.":
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   754
                return ADD_MODULES;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   755
            default:
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   756
                throw new IllegalArgumentException(prefix);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   757
        }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   758
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents: 42770
diff changeset
   759
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   760
    static class PerfCounters {
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   761
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   762
        static PerfCounter systemModulesTime
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   763
            = PerfCounter.newPerfCounter("jdk.module.bootstrap.systemModulesTime");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   764
        static PerfCounter defineBaseTime
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   765
            = PerfCounter.newPerfCounter("jdk.module.bootstrap.defineBaseTime");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   766
        static PerfCounter optionsAndRootsTime
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   767
            = PerfCounter.newPerfCounter("jdk.module.bootstrap.optionsAndRootsTime");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   768
        static PerfCounter resolveTime
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   769
            = PerfCounter.newPerfCounter("jdk.module.bootstrap.resolveTime");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   770
        static PerfCounter layerCreateTime
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   771
            = PerfCounter.newPerfCounter("jdk.module.bootstrap.layerCreateTime");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   772
        static PerfCounter loadModulesTime
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   773
            = PerfCounter.newPerfCounter("jdk.module.bootstrap.loadModulesTime");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   774
        static PerfCounter bootstrapTime
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   775
            = PerfCounter.newPerfCounter("jdk.module.bootstrap.totalTime");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   776
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   777
}