Consider the following command: jlink --add-modules java.management.rmi,jdk.httpserver --output image
Running it repeatedly with identical inputs does not always produce the same `lib/modules` file. The only differing resource is `java.base/jdk/internal/module/SystemModules$all.class` (or `SystemModules$default.class`), generated by `SystemModulesPlugin`. The bytecode of `moduleReads()` differs only in the order in which the deduplicated sets are created and the local-variable slots in which they are stored. The problem occurs near the beginning of `SystemModulesPlugin.SystemModulesClassGenerator.generate(...)`, where duplicate map values are identified and assigned to local-variable slots in a nondeterministic order. Later in the same method, however, the map entries are emitted deterministically using a `TreeMap`. The proposed change uses the same `TreeMap` for value deduplication and local-variable-slot assignment, making the generated bytecode deterministic. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - 8392531: jlink produces a different lib/modules on every run Changes: https://git.openjdk.org/jdk/pull/32948/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32948&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8392531 Stats: 86 lines in 2 files changed: 80 ins; 0 del; 6 mod Patch: https://git.openjdk.org/jdk/pull/32948.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/32948/head:pull/32948 PR: https://git.openjdk.org/jdk/pull/32948
