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