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