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