changeset 19020:0c9a906bada4

More clean-up/comments
author alanb
date Wed, 08 Feb 2017 13:44:36 +0000
parents ae537b2d3427
children 15bacfdf9078
files src/java.base/share/classes/java/lang/module/Configuration.java src/java.base/share/classes/java/lang/module/ModuleDescriptor.java src/java.base/share/classes/java/lang/reflect/AccessibleObject.java src/java.base/share/classes/jdk/internal/module/Builder.java src/java.base/share/classes/sun/launcher/LauncherHelper.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java
diffstat 6 files changed, 65 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/module/Configuration.java	Wed Feb 08 11:27:16 2017 +0000
+++ b/src/java.base/share/classes/java/lang/module/Configuration.java	Wed Feb 08 13:44:36 2017 +0000
@@ -319,8 +319,8 @@
      * </ul>
      *
      * @implNote In the implementation then observability of modules may depend
-     * on referential integrity checks that ensure that different builds of
-     * tightly coupled modules cannot be combined in the same configuration.
+     * on referential integrity checks that ensure different builds of tightly
+     * coupled modules are not combined in the same configuration.
      *
      * @param  before
      *         The <em>before</em> module finder to find modules
--- a/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java	Wed Feb 08 11:27:16 2017 +0000
+++ b/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java	Wed Feb 08 13:44:36 2017 +0000
@@ -32,18 +32,17 @@
 import java.nio.ByteBuffer;
 import java.nio.file.Path;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
-import java.util.TreeSet;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -439,11 +438,12 @@
          * are compared (see {@link ModuleDescriptor#compareTo
          * ModuleDescriptor.compareTo}). Where the package names are equal and
          * the set of modifiers are equal then the set of target modules are
-         * compared. This is done by sorting the sets, iterating over both sets
-         * in ascending order, and comparing the corresponding elements
-         * lexicographically. Where the sets differ in size, and the larger set
-         * contains all elements of the smaller set, then the larger set is
-         * considered to succeed the smaller set. </p>
+         * compared. This is done by sorting the names of the target modules
+         * in ascending order, and according to their natural ordering, and then
+         * comparing the corresponding elements lexicographically. Where the
+         * sets differ in size, and the larger set contains all elements of the
+         * smaller set, then the larger set is considered to succeed the smaller
+         * set. </p>
          *
          * @param  that
          *         The module export to compare
@@ -650,11 +650,12 @@
          * are compared (see {@link ModuleDescriptor#compareTo
          * ModuleDescriptor.compareTo}). Where the package names are equal and
          * the set of modifiers are equal then the set of target modules are
-         * compared. This is done by sorting the sets, iterating over both sets
-         * in ascending order, and comparing the corresponding elements
-         * lexicographically. Where the sets differ in size, and the larger set
-         * contains all elements of the smaller set, then the larger set is
-         * considered to succeed the smaller set. </p>
+         * compared. This is done by sorting the names of the target modules
+         * in ascending order, and according to their natural ordering, and then
+         * comparing the corresponding elements lexicographically. Where the
+         * sets differ in size, and the larger set contains all elements of the
+         * smaller set, then the larger set is considered to succeed the smaller
+         * set. </p>
          *
          * @param  that
          *         The module opens to compare
@@ -1326,7 +1327,8 @@
     }
 
     /**
-     * <p> Returns the set of module dependences. </p>
+     * <p> Returns the set of {@code Requires} objects representing the module
+     * dependences. </p>
      *
      * <p> The set includes a dependency on "{@code java.base}" when this
      * module is not named "{@code java.base}". If this module is an automatic
@@ -1340,7 +1342,8 @@
     }
 
     /**
-     * <p> Returns the set of exported packages. </p>
+     * <p> Returns the set of {@code Exports} objects representing the exported
+     * packages. </p>
      *
      * <p> If this module is an automatic module then the set of exports
      * is empty. </p>
@@ -1352,7 +1355,8 @@
     }
 
     /**
-     * <p> Returns the set of open packages. </p>
+     * <p> Returns the set of {@code Opens} objects representing the open
+     * packages. </p>
      *
      * <p> If this module is an open module or an automatic module then the
      * set of open packages is empty. </p>
@@ -1377,7 +1381,8 @@
     }
 
     /**
-     * <p> Returns the set of services that the module provides. </p>
+     * <p> Returns the set of {@code Provides} objects representing the
+     * services that the module provides. </p>
      *
      * @return The possibly-empty unmodifiable set of the services that this
      *         module provides
@@ -2659,24 +2664,14 @@
     /**
      * Compares two sets of {@code Comparable} objects.
      */
+    @SuppressWarnings("unchecked")
     private static <T extends Object & Comparable<? super T>>
     int compare(Set<T> s1, Set<T> s2) {
-        Iterator<T> iterator1 = new TreeSet<>(s1).iterator();
-        Iterator<T> iterator2 =  new TreeSet<>(s2).iterator();
-        while (iterator1.hasNext()) {
-            if (!iterator2.hasNext())
-                return 1; // s1 has more elements
-            T e1 = iterator1.next();
-            T e2 = iterator2.next();
-            int c = e1.compareTo(e2);
-            if (c != 0)
-                return c;
-        }
-        if (iterator2.hasNext()) {
-            return -1;  // s2 has more elements
-        } else {
-            return 0;
-        }
+        T[] a1 = (T[]) s1.toArray();
+        T[] a2 = (T[]) s2.toArray();
+        Arrays.sort(a1);
+        Arrays.sort(a2);
+        return Arrays.compare(a1, a2);
     }
 
     private static <E extends Enum<E>> long modsValue(Set<E> set) {
--- a/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java	Wed Feb 08 11:27:16 2017 +0000
+++ b/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java	Wed Feb 08 13:44:36 2017 +0000
@@ -62,7 +62,7 @@
  * object corresponds to a member in an exported or open package
  * (see {@link #setAccessible(boolean)}). </p>
  *
- * @jls 6.6
+ * @jls 6.6 Access Control
  * @since 1.2
  * @revised 9
  * @spec JPMS
--- a/src/java.base/share/classes/jdk/internal/module/Builder.java	Wed Feb 08 11:27:16 2017 +0000
+++ b/src/java.base/share/classes/jdk/internal/module/Builder.java	Wed Feb 08 13:44:36 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,6 @@
 import java.lang.module.ModuleDescriptor.Requires;
 import java.lang.module.ModuleDescriptor.Version;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -39,7 +38,7 @@
 import jdk.internal.misc.SharedSecrets;
 
 /**
- * This builder is optimized for reconstituting ModuleDescriptor
+ * This builder is optimized for reconstituting the {@code ModuleDescriptor}s
  * for system modules.  The validation should be done at jlink time.
  *
  * 1. skip name validation
@@ -137,8 +136,7 @@
     }
 
     final String name;
-    boolean open;
-    boolean synthetic;
+    boolean open, synthetic, mandated;
     Set<Requires> requires;
     Set<Exports> exports;
     Set<Opens> opens;
@@ -170,6 +168,11 @@
         return this;
     }
 
+    Builder mandated(boolean value) {
+        this.mandated = value;
+        return this;
+    }
+
     /**
      * Sets module exports.
      */
@@ -262,8 +265,6 @@
 
     /**
      * Sets the OS version.
-     *
-     * @throws IllegalStateException if already set
      */
     public Builder osVersion(String version) {
         this.osVersion = version;
@@ -271,24 +272,32 @@
     }
 
     /**
+     * Returns an immutable set of the module modifiers derived from the flags.
+     */
+    private Set<ModuleDescriptor.Modifier> modifiers() {
+        int n = 0;
+        if (open) n++;
+        if (synthetic) n++;
+        if (mandated) n++;
+        if (n == 0) {
+            return Collections.emptySet();
+        } else {
+            ModuleDescriptor.Modifier[] mods = new ModuleDescriptor.Modifier[n];
+            if (open) mods[--n] = ModuleDescriptor.Modifier.OPEN;
+            if (synthetic) mods[--n] = ModuleDescriptor.Modifier.SYNTHETIC;
+            if (mandated) mods[--n] = ModuleDescriptor.Modifier.MANDATED;
+            return Set.of(mods);
+        }
+    }
+
+    /**
      * Builds a {@code ModuleDescriptor} from the components.
      */
     public ModuleDescriptor build(int hashCode) {
         assert name != null;
-
-        Set<ModuleDescriptor.Modifier> modifiers;
-        if (open || synthetic) {
-            modifiers = new HashSet<>();
-            if (open) modifiers.add(ModuleDescriptor.Modifier.OPEN);
-            if (synthetic) modifiers.add(ModuleDescriptor.Modifier.SYNTHETIC);
-            modifiers = Collections.unmodifiableSet(modifiers);
-        } else {
-            modifiers = Collections.emptySet();
-        }
-
         return JLMA.newModuleDescriptor(name,
                                         version,
-                                        modifiers,
+                                        modifiers(),
                                         requires,
                                         exports,
                                         opens,
--- a/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Wed Feb 08 11:27:16 2017 +0000
+++ b/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Wed Feb 08 13:44:36 2017 +0000
@@ -956,6 +956,10 @@
                     ostream.print("open ");
                 if (md.isAutomatic())
                     ostream.print("automatic ");
+                if (md.modifiers().contains(ModuleDescriptor.Modifier.SYNTHETIC))
+                    ostream.print("synthetic ");
+                if (md.modifiers().contains(ModuleDescriptor.Modifier.MANDATED))
+                    ostream.print("mandated ");
                 ostream.println("module " + midAndLocation(md, mref.location()));
 
                 // unqualified exports (sorted by package)
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java	Wed Feb 08 11:27:16 2017 +0000
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java	Wed Feb 08 13:44:36 2017 +0000
@@ -774,6 +774,9 @@
                 if (md.modifiers().contains(ModuleDescriptor.Modifier.SYNTHETIC)) {
                     setModuleBit("synthetic", true);
                 }
+                if (md.modifiers().contains(ModuleDescriptor.Modifier.MANDATED)) {
+                    setModuleBit("mandated", true);
+                }
             }
 
             /*