You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I couldn't find any information on this, but would it be hard to allow reproducible builds with substrate?
If that could be an option from early on that would be amazing.
Reacted by John Lenz, James D. Marble, Santiago M. Mola, Douglas Roark, Alexander Cramb, iseki, Stephan Schroevers, Reilly Brogan, Stig, Glavo and 1 more
Random identifiers isn't inherently a problem if you use a fixed seed (these ids in hotspot don't need to be cryptographically random I presume). So, potentially fixing the random seeds and using a single thread might get most of the way there? One also needs to be careful of things like hashmaps which are used to write out some mappings, as they will be randomly ordered.
Due to the dependency on HotSpot, implementing this feature will not be trivial. Luckily, we already have an ongoing project related to profile-guided optimizations that removes some non-determinism in images.
This is a good feature request. We will have to prioritize it and schedule together with other requests. If you need reproducible images for a concrete project, and this is a blocker, we can increase our priority on this issue.
I'm I reading the message right here, that building JVMCI or Graal or GraalVM suite in parallel mode might not be trivial using the mx build tool, if not please let me know, so I can discuss this separately?
@vjovanov@thomaswue I just wanted to check in and see if there has been any progress on this. We would love to start using this for our releases in peergos and this is the last remaining issue.
One main issue to support this feature is that the values ending up in the image heap might be based on unpredictable input. There could be for example a hash map with elements relying on System#identityHashCode, which is based on random values. Or some static initializer storing a derivative value of System#currentTimeMillis.
One way to solve it would be to output some human readable intermediate file describing the results of the closed world analysis including the reachable methods as well as the image heap objects. This file could then be used to generate the exact same binary multiple times.
Hi @thomaswue , thank you very much for the update. I think the fundamental success criteria is a reproducible way to get the binary from something a human can derive from the source easily. I'm not sure if that would be true of such an intermediate format, especially the heap dump?
If the sources of non determinism are within the user's code, then that's their responsibility so we are only concerned about sources within graalvm itself.
The identity hashcode is based on the address in memory. So making all execution single threaded, and maybe disabling the GC should give deterministic addresses within a process. e.g. running a hello world that prints new Object().hashCode() gives the same value each run.
If something in the JVM is being initialized with the time then I'd be happy to supply the time as a parameter. Literally making the time constant may break some things.. So we could make subsequent calls increase the time by a fixed amount if necessary.
Hi @vjovanov (or @thomaswue), was there any progress on this feature?
Is there a way, in the current release, to reproduce native-image builds? (With GraalVM 20.2, a simple "hello-world.java" still outputs distinct binaries on every single build).
There has not been much progress on this feature. I am currently looking for a candidate to handle this issue. It will not be an easy task to make this work.
Reacted by Manuel Gustavo Saraiva, Dr Ian Preston and iseki
Hi @vjovanov, thank you very much for your quick update.
Since this has been open for quite a while, do you have a target date or release version for this feature?
We have bit-for-bit reproducible Native Image builds working for two SGX enclave images, and we would like to bring this upstream. @vjovanov wrote in 2020 that you were looking for someone to take this on; we would like to. Before we open more PRs, we want to check whether reproducible builds are still a goal, and which direction you would accept.
Why we need it
We build SGX enclaves with Native Image (Apache Teaclave Java TEE SDK, SGX_TEE mode). An enclave is identified by its measurement (MRENCLAVE), a hash over its pages, and a single differing byte changes it. For remote attestation, a third party must be able to rebuild the enclave from source and arrive at the same measurement, so the image has to be bit-identical.
What we have
Base: oracle/graal graal-25.4.4.1.1 with labs-openjdk jdk-25.0.4.1.1+1 (jvmci-25.4-b23), Linux x86_64. The images are stripped shared libraries without debug info, PGO or layered images. All builds ran on one host, in the same container image and build directory, with a fixed command line and a pinned -H:ImageBuildID. We re-checked every root cause listed below against current master.
Every build identical. A small hello-world enclave and a larger test enclave that uses BouncyCastle: 84 of 84 builds from our reproducibility package matched the reference image of their enclave (MRENCLAVE, shared library and unsigned enclave). That includes 32 builds run 16 at a time on 16 CPUs and 9 builds pinned to a single CPU. On SGX hardware, the hello-world enclave reported exactly the measurement the build computed.
Rebuilt from the README alone. A separate run that had only a copy of the package and its README reproduced both measurements, on the same machine. A second machine is the next step.
Where we started. On stock GraalVM, every build gave a different enclave; one pair of hello-world builds differed in about 10 million byte positions, mostly shifted code and heap.
What it takes, and why
As @thomaswue pointed out above, one main issue is the image heap: it can hold values derived from identity hashes or the clock. And, as Vojin noted, analysis and class initialization run in parallel. Native Image snapshots the heap of a live, multi-threaded HotSpot builder, so all of this ends up in the image. We kept that design and made each of these inputs deterministic. Building images without snapshotting a live JVM heap would mean redesigning the builder.
What did not work, so you do not have to try it: a single-threaded builder, even with deterministically seeded HotSpot hash generators (the per-thread hash streams still diverge after several thousand draws); recording the hashes of one build and replaying them (millions of entries, tied to that one build). Rehashing the image heap at snapshot time is not enough either, because identity hashes already leak into ordinary fields and are constant-folded into code (for example MathContext.hashCode).
Deterministic order (about 20 PRs' worth). Places where the builder iterates over a ConcurrentHashMap or another unordered collection, or fills a structure from parallel threads, and that order reaches the image: the CGlobalData layout, reflection metadata, image-heap maps such as the class registries and run-time options, the module layer and service catalog, method profiles, static fields, and a few more. Most fixes are small and sort by a stable key; build time did not change measurably for our images, but we have not measured large applications. A few change an order the JDK leaves unspecified but users can observe (getDeclaredMethods, ServiceLoader across modules). We think they can still be unconditional, and we would point these out in each PR.
Build environment (a handful). The build time (Clock, resources, ZoneInfoFile), which would follow SOURCE_DATE_EPOCH; the image heap MAGIC, today a random number, which can come from the image build ID; and builder thread state that reaches the image (ids of build-time threads, ThreadLocal counters).
Identity hashes (the design question). The image heap stores the builder's identity hash of every object. Maps and sets in the image heap whose keys use identity hashes (classes, enum constants, plain objects) have already placed their entries by those hashes, and some hashes are folded into code, so the image cannot simply assign new ones. The hash has to be deterministic when it is first assigned, and HotSpot assigns it the first time any code in the builder asks for it, often before the image-heap scanner sees the object.
On the builder side we use the existing JVMCI method makeIdentityHashCode(requestedValue) (as layered images do) to give scanned objects a content-derived hash. No new JVMCI API is needed for that.
For objects that HotSpot hashes first, we patched HotSpot: about 640 added lines behind 12 experimental flags, giving content-derived identity hashes for strings, class mirrors (including hidden, proxy and array classes), enum constants and the instances of an allow-listed set of classes.
The allow-list is per image (14 classes for hello-world, 45 for the test enclave), generated from about 4 recording builds. It is the part we least consider product quality.
This is clearly not how it should look upstream, and it is where we most need your guidance.
Open problems we would file as issues. Type ids depend on which unreachable types the builder happens to create; StringConcat and type-switch hidden classes keep HotSpot addresses in their names; the java.util.logging tree depends on builder GC timing; under CPU contention, the order of @CLibrary libraries and the ids of build-time threads change. Libraries whose static initializers run in parallel during analysis can add their own races; we had to fix one for BouncyCastle in our SDK.
About half of our GraalVM change units would not go upstream as written: most of them are the builder side of our identity-hash policy, partly hard-coded for specific JDK classes, which would need a proper design. The rest are diagnostics and pinned values we used to find the causes.
A possible shape upstream
Groups 1 and 2 as regular PRs, one root cause each, unconditional, in small batches.
Group 4, and the parts of group 3 that change run-time values, behind an option such as --reproducible, which leaves today's behavior untouched when it is not set.
A CI check that builds the same image twice in separate builder JVMs (with different thread counts) and compares code, metadata, .data and the image heap with identity-hash fields masked; with JVM support, the whole image.
Not covered yet: layered images, platforms other than Linux x86_64, compact object headers, and the run-time effect of content-derived hashes, which give distinct but equal objects the same identity hash.
Questions
Are reproducible builds still a goal for Native Image?
Are you fine with the ordering fixes (group 2) being unconditional?
How would you like the identity-hash problem solved? We know that JVM changes would have to go through OpenJDK. The minimal capability we need is for the builder to control the identity hash of objects it cannot reach first (strings, class mirrors, enum constants). Is there internal work, for example for layered images, that we should align with, or do you see a way to avoid JVM changes?
In what order and size would you like the PRs?
We are happy to share a reproducer and the list of candidate PRs with the evidence for each.
Activity
vjovanov commentedon Jan 30, 2018
By reproducible, do you mean binaries from same jars with the same flags should always be the same? If yes, here is the list of reasons they are not:
One thing I tried is to build with
-H:NumberOfThreads=1without a build server. This did not help even for the hello world image.What is the use-case for reproducible builds?
ianopolous commentedon Jan 30, 2018
The use case is for safe distribution of binaries. Having a verifiable build (the same compiler version and config => binary identical output) means you can prove that the given binary was built from a given version of the source. This is the reason the entire debian project has mostly moved to reproducible builds. https://wiki.debian.org/ReproducibleBuilds
More on the general motivation can be read here: https://reproducible-builds.org/
Random identifiers isn't inherently a problem if you use a fixed seed (these ids in hotspot don't need to be cryptographically random I presume). So, potentially fixing the random seeds and using a single thread might get most of the way there? One also needs to be careful of things like hashmaps which are used to write out some mappings, as they will be randomly ordered.
vjovanov commentedon Jan 30, 2018
Due to the dependency on HotSpot, implementing this feature will not be trivial. Luckily, we already have an ongoing project related to profile-guided optimizations that removes some non-determinism in images.
This is a good feature request. We will have to prioritize it and schedule together with other requests. If you need reproducible images for a concrete project, and this is a blocker, we can increase our priority on this issue.
neomatrix369 commentedon Jun 23, 2018
I'm I reading the message right here, that building JVMCI or Graal or GraalVM suite in parallel mode might not be trivial using the
mxbuild tool, if not please let me know, so I can discuss this separately?concavelenz commentedon Jan 11, 2019
Just want to note this is also important for us for Closure Compiler.
ianopolous commentedon Sep 12, 2019
@vjovanov @thomaswue I just wanted to check in and see if there has been any progress on this. We would love to start using this for our releases in peergos and this is the last remaining issue.
thomaswue commentedon Sep 14, 2019
One main issue to support this feature is that the values ending up in the image heap might be based on unpredictable input. There could be for example a hash map with elements relying on System#identityHashCode, which is based on random values. Or some static initializer storing a derivative value of System#currentTimeMillis.
One way to solve it would be to output some human readable intermediate file describing the results of the closed world analysis including the reachable methods as well as the image heap objects. This file could then be used to generate the exact same binary multiple times.
Would this address your use cases?
ianopolous commentedon Sep 16, 2019
Hi @thomaswue , thank you very much for the update. I think the fundamental success criteria is a reproducible way to get the binary from something a human can derive from the source easily. I'm not sure if that would be true of such an intermediate format, especially the heap dump?
If the sources of non determinism are within the user's code, then that's their responsibility so we are only concerned about sources within graalvm itself.
The identity hashcode is based on the address in memory. So making all execution single threaded, and maybe disabling the GC should give deterministic addresses within a process. e.g. running a hello world that prints new Object().hashCode() gives the same value each run.
If something in the JVM is being initialized with the time then I'd be happy to supply the time as a parameter. Literally making the time constant may break some things.. So we could make subsequent calls increase the time by a fixed amount if necessary.
manuelgustavor3 commentedon Oct 12, 2020
Hi @vjovanov (or @thomaswue), was there any progress on this feature?
Is there a way, in the current release, to reproduce native-image builds? (With GraalVM 20.2, a simple "hello-world.java" still outputs distinct binaries on every single build).
vjovanov commentedon Oct 12, 2020
There has not been much progress on this feature. I am currently looking for a candidate to handle this issue. It will not be an easy task to make this work.
manuelgustavor3 commentedon Oct 12, 2020
Hi @vjovanov, thank you very much for your quick update.
Since this has been open for quite a while, do you have a target date or release version for this feature?
[-][substrate-vm] Feature request: reproducible builds[/-][+]Reproducible builds for GraalVM Native Image[/+]MarkusBernhardt commentedon Nov 8, 2026
We have bit-for-bit reproducible Native Image builds working for two SGX enclave images, and we would like to bring this upstream. @vjovanov wrote in 2020 that you were looking for someone to take this on; we would like to. Before we open more PRs, we want to check whether reproducible builds are still a goal, and which direction you would accept.
Why we need it
We build SGX enclaves with Native Image (Apache Teaclave Java TEE SDK,
SGX_TEEmode). An enclave is identified by its measurement (MRENCLAVE), a hash over its pages, and a single differing byte changes it. For remote attestation, a third party must be able to rebuild the enclave from source and arrive at the same measurement, so the image has to be bit-identical.What we have
Base: oracle/graal
graal-25.4.4.1.1with labs-openjdkjdk-25.0.4.1.1+1(jvmci-25.4-b23), Linux x86_64. The images are stripped shared libraries without debug info, PGO or layered images. All builds ran on one host, in the same container image and build directory, with a fixed command line and a pinned-H:ImageBuildID. We re-checked every root cause listed below against current master.What it takes, and why
As @thomaswue pointed out above, one main issue is the image heap: it can hold values derived from identity hashes or the clock. And, as Vojin noted, analysis and class initialization run in parallel. Native Image snapshots the heap of a live, multi-threaded HotSpot builder, so all of this ends up in the image. We kept that design and made each of these inputs deterministic. Building images without snapshotting a live JVM heap would mean redesigning the builder.
What did not work, so you do not have to try it: a single-threaded builder, even with deterministically seeded HotSpot hash generators (the per-thread hash streams still diverge after several thousand draws); recording the hashes of one build and replaying them (millions of entries, tied to that one build). Rehashing the image heap at snapshot time is not enough either, because identity hashes already leak into ordinary fields and are constant-folded into code (for example
MathContext.hashCode).The work falls into five groups:
Bugs worth fixing anyway (about 10). They break Java or GraalVM contracts, or make the analysis result depend on task scheduling. We opened three of them as drafts last week (OCA signed): [svm] Run the class initializer simulation before folding IsStaticFinalFieldInitializedNode #14922 (class-initializer simulation race), [svm] Forward QUERIED-to-ACCESSED upgrades of annotation methods to annotation proxy methods #14912 and [svm] Check for hiding reflection members only after the registration is published #14913 (reflection registration). Others: an
equals/hashCodecontract violation inOptionOrigin, image-heap lists tracked by content in hash sets (lost updates, shown by tests), and the vtable builder mutating its own slot records.Deterministic order (about 20 PRs' worth). Places where the builder iterates over a
ConcurrentHashMapor another unordered collection, or fills a structure from parallel threads, and that order reaches the image: the CGlobalData layout, reflection metadata, image-heap maps such as the class registries and run-time options, the module layer and service catalog, method profiles, static fields, and a few more. Most fixes are small and sort by a stable key; build time did not change measurably for our images, but we have not measured large applications. A few change an order the JDK leaves unspecified but users can observe (getDeclaredMethods,ServiceLoaderacross modules). We think they can still be unconditional, and we would point these out in each PR.Build environment (a handful). The build time (
Clock, resources,ZoneInfoFile), which would followSOURCE_DATE_EPOCH; the image heapMAGIC, today a random number, which can come from the image build ID; and builder thread state that reaches the image (ids of build-time threads,ThreadLocalcounters).Identity hashes (the design question). The image heap stores the builder's identity hash of every object. Maps and sets in the image heap whose keys use identity hashes (classes, enum constants, plain objects) have already placed their entries by those hashes, and some hashes are folded into code, so the image cannot simply assign new ones. The hash has to be deterministic when it is first assigned, and HotSpot assigns it the first time any code in the builder asks for it, often before the image-heap scanner sees the object.
makeIdentityHashCode(requestedValue)(as layered images do) to give scanned objects a content-derived hash. No new JVMCI API is needed for that.This is clearly not how it should look upstream, and it is where we most need your guidance.
Open problems we would file as issues. Type ids depend on which unreachable types the builder happens to create; StringConcat and type-switch hidden classes keep HotSpot addresses in their names; the
java.util.loggingtree depends on builder GC timing; under CPU contention, the order of@CLibrarylibraries and the ids of build-time threads change. Libraries whose static initializers run in parallel during analysis can add their own races; we had to fix one for BouncyCastle in our SDK.About half of our GraalVM change units would not go upstream as written: most of them are the builder side of our identity-hash policy, partly hard-coded for specific JDK classes, which would need a proper design. The rest are diagnostics and pinned values we used to find the causes.
A possible shape upstream
--reproducible, which leaves today's behavior untouched when it is not set..dataand the image heap with identity-hash fields masked; with JVM support, the whole image.Not covered yet: layered images, platforms other than Linux x86_64, compact object headers, and the run-time effect of content-derived hashes, which give distinct but equal objects the same identity hash.
Questions
We are happy to share a reproducer and the list of candidate PRs with the evidence for each.
Drafted with help from Claude Code.
MarkusBernhardt commentedon Nov 24, 2026
Am I correct to estimate that reproducible builds are not a priority anymore for GraalVM?