RFR: 8276764: Enable deterministic file content ordering for Jar and Jmod

Andrew Leonard aleonard at openjdk.java.net
Thu Nov 18 09:13:38 UTC 2021


On Wed, 17 Nov 2021 21:44:29 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> Both jar and jmod utilise java.io file operations whose methods define no ordering of the return file lists, and in fact rely on OS query file ordering, which can differ by underlying OS architecture.
>> This PR adds sort processing to the creation of such jar's and jmod's to enable a deterministic content ordering.
>> 
>> Signed-off-by: Andrew Leonard <anleonar at redhat.com>
>
> src/jdk.jartool/share/classes/sun/tools/jar/Main.java line 131:
> 
>> 129:     // There's also a files array per version
>> 130:     // Use a LinkedHashMap to keep original insertion ordering
>> 131:     Map<Integer,String[]> filesMap = new LinkedHashMap<>();
> 
> The entries of `filesMap` is sorted by the version.   Is the value of each entry already sorted?  Does that matter?   It's unclear to me since `expand` is called for each entry's value:
> 
> 
>     private void expand() throws IOException {
>         for (int version : filesMap.keySet()) {
>             String[] files = filesMap.get(version);
>             expand(null, files, pathsMap.get(version), version);
>         }
>     }

@mlchung the way I looked at this was the filesMap is a HashMap, so the filesMap.keySet() iteration order is not defined (or necessarily deterministic), the expanded order of the file sets for each version could be ver1, ver2, ver3 or ver3, ver2, ver1... the next time you run it with the same parameters.
LinkedHashMap will ensure the iterated order is as inserted (or as specified in the jar args list..)

Although you say "filesMap is sorted by version", I don't see where that is done?

-------------

PR: https://git.openjdk.java.net/jdk/pull/6395


More information about the compiler-dev mailing list