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