On Fri, 18 Sep 2026 11:35:27 GMT, Dušan Bálek <[email protected]> wrote:

> 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).

This pull request has now been integrated.

Changeset: e7e908ef
Author:    Dušan Bálek <[email protected]>
URL:       
https://git.openjdk.org/jdk/commit/e7e908efbe6b2b0f8377f51bdc42c443ec8978be
Stats:     86 lines in 2 files changed: 80 ins; 0 del; 6 mod

8392531: jlink produces a different lib/modules on every run

Reviewed-by: alanb, sgehwolf

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

PR: https://git.openjdk.org/jdk/pull/32948

Reply via email to