diff -r 8c2680d7f686 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java Tue Dec 27 09:44:54 2016 +0100 +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java Mon Jan 02 13:32:38 2017 +0100 @@ -33,8 +33,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -118,7 +118,9 @@ // generate the byte code to create ModuleDescriptors // skip parsing module-info.class and skip name check - in.moduleView().modules().forEach(module -> { + in.moduleView().modules() + .sorted((m1, m2) -> m1.name().compareTo(m2.name())) + .forEach(module -> { ResourcePoolEntry data = module.findEntry("module-info.class").orElseThrow( // automatic module not supported yet @@ -149,17 +151,19 @@ // Generate the new class ClassWriter cwriter = generator.getClassWriter(); - in.entries().forEach(data -> { - if (data.path().endsWith("module-info.class")) - return; - if (generator.isOverriddenClass(data.path())) { - byte[] bytes = cwriter.toByteArray(); - ResourcePoolEntry ndata = data.copyWithContent(bytes); - out.add(ndata); - } else { - out.add(data); - } - }); + in.entries() + .sorted((m1, m2) -> m1.moduleName().compareTo(m2.moduleName())) + .forEach(data -> { + if (data.path().endsWith("module-info.class")) + return; + if (generator.isOverriddenClass(data.path())) { + byte[] bytes = cwriter.toByteArray(); + ResourcePoolEntry ndata = data.copyWithContent(bytes); + out.add(ndata); + } else { + out.add(data); + } + }); return out.build(); } @@ -341,7 +345,7 @@ /* * static initializer initializing the static fields * - * static Map map = new HashMap<>(); + * static Map map = new LinkedHashMap<>(); */ private void clinit(int numModules, int numPackages, boolean hasSplitPackages) { @@ -429,7 +433,7 @@ */ public ClassWriter getClassWriter() { int numModules = moduleInfos.size(); - Set allPackages = new HashSet<>(); + Set allPackages = new LinkedHashSet<>(); int packageCount = 0; for (ModuleInfo minfo : moduleInfos) { allPackages.addAll(minfo.packages); @@ -767,7 +771,7 @@ * or * Builder.newExports(Set ms, String pn) * - * Set targets = new HashSet<>(); + * Set targets = new LinkedHashSet<>(); * targets.add(t); * : * : @@ -820,7 +824,7 @@ * or * Builder.newOpens(Set ms, String pn) * - * Set targets = new HashSet<>(); + * Set targets = new LinkedHashSet<>(); * targets.add(t); * : * : @@ -881,7 +885,7 @@ /* * Invoke Builder.newProvides(String service, Set providers) * - * Set providers = new HashSet<>(); + * Set providers = new LinkedHashSet<>(); * providers.add(impl); * : * : @@ -1034,22 +1038,22 @@ class DedupSetBuilder { // map Set to a specialized builder to allow them to be // deduplicated as they are requested - final Map, SetBuilder> stringSets = new HashMap<>(); + final Map, SetBuilder> stringSets = new LinkedHashMap<>(); // map Set to a specialized builder to allow them to be // deduplicated as they are requested final Map, EnumSetBuilder> - requiresModifiersSets = new HashMap<>(); + requiresModifiersSets = new LinkedHashMap<>(); // map Set to a specialized builder to allow them to be // deduplicated as they are requested final Map, EnumSetBuilder> - exportsModifiersSets = new HashMap<>(); + exportsModifiersSets = new LinkedHashMap<>(); // map Set to a specialized builder to allow them to be // deduplicated as they are requested final Map, EnumSetBuilder> - opensModifiersSets = new HashMap<>(); + opensModifiersSets = new LinkedHashMap<>(); private final int stringSetVar; private final int enumSetVar;