--- old/src/java.base/share/classes/jdk/internal/module/Builder.java 2016-12-15 09:19:11.112004087 +0000 +++ new/src/java.base/share/classes/jdk/internal/module/Builder.java 2016-12-15 09:19:10.982995262 +0000 @@ -30,11 +30,8 @@ import java.lang.module.ModuleDescriptor.Provides; import java.lang.module.ModuleDescriptor.Requires; import java.lang.module.ModuleDescriptor.Version; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; import jdk.internal.misc.JavaLangModuleAccess; @@ -52,7 +49,7 @@ * SystemModules should contain modules for the boot layer. */ final class Builder { - private static final JavaLangModuleAccess jlma = + private static final JavaLangModuleAccess JLMA = SharedSecrets.getJavaLangModuleAccess(); // Static cache of the most recently seen Version to cheaply deduplicate @@ -60,13 +57,36 @@ static Version cachedVersion; /** - * Returns a {@link Requires} for a dependence on a module - * with the given (and possibly empty) set of modifiers. + * Returns a {@link Requires} for a dependence on a module with the given + * (and possibly empty) set of modifiers, and optionally the version + * recorded at compile time. + */ + public static Requires newRequires(Set mods, + String mn, + String compiledVersion) + { + Version version = null; + if (compiledVersion != null) { + // use the cached version if the same version string + Version ver = cachedVersion; + if (ver != null && compiledVersion.equals(ver.toString())) { + version = ver; + } else { + version = Version.parse(compiledVersion); + } + } + return JLMA.newRequires(mods, mn, version); + } + + /** + * Returns a {@link Requires} for a dependence on a module with the given + * (and possibly empty) set of modifiers, and optionally the version + * recorded at compile time. */ public static Requires newRequires(Set mods, String mn) { - return jlma.newRequires(mods, mn); + return newRequires(mods, mn, null); } /** @@ -77,7 +97,7 @@ public static Exports newExports(Set ms, String pn, Set targets) { - return jlma.newExports(ms, pn, targets); + return JLMA.newExports(ms, pn, targets); } /** @@ -85,7 +105,7 @@ * modifiers. */ public static Opens newOpens(Set ms, String pn) { - return jlma.newOpens(ms, pn); + return JLMA.newOpens(ms, pn); } /** @@ -96,7 +116,7 @@ public static Opens newOpens(Set ms, String pn, Set targets) { - return jlma.newOpens(ms, pn, targets); + return JLMA.newOpens(ms, pn, targets); } /** @@ -104,7 +124,7 @@ * of modifiers. */ public static Exports newExports(Set ms, String pn) { - return jlma.newExports(ms, pn); + return JLMA.newExports(ms, pn); } /** @@ -112,7 +132,7 @@ * implementation classes. */ public static Provides newProvides(String st, List pcs) { - return jlma.newProvides(st, pcs); + return JLMA.newProvides(st, pcs); } final String name; @@ -130,8 +150,6 @@ String osName; String osArch; String osVersion; - String algorithm; - Map hashes; Builder(String name) { this.name = name; @@ -275,34 +293,13 @@ } /** - * Sets the algorithm of the module hashes - */ - public Builder algorithm(String algorithm) { - this.algorithm = algorithm; - return this; - } - - /** - * Sets the module hash for the given module name - */ - public Builder moduleHash(String mn, byte[] hash) { - if (hashes == null) - hashes = new HashMap<>(); - - hashes.put(mn, hash); - return this; - } - - /** * Builds a {@code ModuleDescriptor} from the components. */ public ModuleDescriptor build(int hashCode) { assert name != null; - ModuleHashes moduleHashes = - hashes != null ? new ModuleHashes(algorithm, hashes) : null; - - return jlma.newModuleDescriptor(name, + return JLMA.newModuleDescriptor(name, + version, open, automatic, synthetic, @@ -311,13 +308,11 @@ opens, uses, provides, - version, + packages, mainClass, osName, osArch, osVersion, - packages, - moduleHashes, hashCode); } }