Skip to content

Commit 6ef1b72

Browse files
Tudor-Stefan Magirescuolpaw
authored andcommitted
[GR-65623] Implement layer compatibility check for class and module-path entries.
PullRequest: graal/21629
2 parents 8eef57c + 9185afd commit 6ef1b72

File tree

10 files changed

+382
-70
lines changed

10 files changed

+382
-70
lines changed

compiler/ci/ci_common/benchmark-suites.libsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@
9191

9292
barista_template(suite_version=null, suite_name="barista", max_jdk_version=null, cmd_app_prefix=["hwloc-bind --cpubind node:0.core:0-3.pu:0 --membind node:0"], non_prefix_barista_args=[]):: cc.compiler_benchmark + {
9393
suite:: suite_name,
94-
local barista_version = "v0.4.7",
94+
local barista_version = "v0.4.8",
9595
local suite_version_args = if suite_version != null then ["--bench-suite-version=" + suite_version] else [],
9696
local prefix_barista_arg = if std.length(cmd_app_prefix) > 0 then [std.format("--cmd-app-prefix=%s", std.join(" ", cmd_app_prefix))] else [],
9797
local all_barista_args = prefix_barista_arg + non_prefix_barista_args,
9898
local barista_args_with_separator = if std.length(all_barista_args) > 0 then ["--"] + all_barista_args else [],
9999
downloads+: {
100100
"WRK": { "name": "wrk", "version": "a211dd5", platformspecific: true},
101101
"WRK2": { "name": "wrk2", "version": "2.1", platformspecific: true},
102-
"BARISTA_BENCHMARKS": { "name": "barista", "version": "0.4.7"}
102+
"BARISTA_BENCHMARKS": { "name": "barista", "version": "0.4.8"}
103103
},
104104
packages+: {
105105
maven: "==3.8.6",

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/util/Digest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ public static String digest(byte[] bytes, int offset, int length) {
102102
* new byte array.
103103
*/
104104
public static byte[] digestAsByteArray(byte[] bytes, int offset, int length) {
105-
LongLong hash = MurmurHash3_x64_128(bytes, offset, length, HASH_SEED);
105+
return longLongToByteArray(MurmurHash3_x64_128(bytes, offset, length, HASH_SEED));
106+
}
106107

108+
private static byte[] longLongToByteArray(LongLong hash) {
107109
byte[] array = new byte[DIGEST_SIZE];
108110
encodeBase62(hash.l1, array, 0);
109111
encodeBase62(hash.l2, array, BASE62_DIGITS_PER_LONG);
@@ -281,4 +283,20 @@ private static long fmix64(long input) {
281283

282284
return k;
283285
}
286+
287+
public static final class DigestBuilder {
288+
private LongLong digest;
289+
290+
public DigestBuilder() {
291+
digest = new LongLong(0L, 0L);
292+
}
293+
294+
public void update(byte[] input) {
295+
digest = MurmurHash3_x64_128(input, 0, input.length, digest.l1 ^ digest.l2);
296+
}
297+
298+
public byte[] digest() {
299+
return longLongToByteArray(digest);
300+
}
301+
}
284302
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/imagelayer/NativeImageLayers.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Args = [email protected]
115115
The `layer-create.args` file-path is relative to the directory that contains the `native-image.properties` file and might look like this:
116116
```
117117
base-layer.nil
118+
# ignore this classpath/modulepath entry during layer compatibility checks
119+
digest-ignore
118120
module=java.base
119121
# micronaut and dependencies
120122
package=io.micronaut.*
@@ -129,6 +131,13 @@ package=org.reactivestreams.*
129131
Each line corresponds to one entry in the list of comma-separated entries that can usually be found in a regular `--layer-create` argument.
130132
Lines starting with `#` are ignored and can therefore be used to provide comments in such an option argument file.
131133

134+
Note the use of the `digest-ignore` suboption in the `layer-create.args` example file above.
135+
This suboption _only takes effect_ when the `--layer-create` option is specified _within a file_, and is ignored if provided via the command line.
136+
When defining `--layer-create` in a file, always include this suboption (see [compatibility rules](#compatibility-rules)).
137+
138+
Avoid placing other class or resource files in the same classpath/modulepath entry as the file(s) defining `--layer-create`.
139+
These files would be excluded from compatibility checks, potentially leading to subtle, difficult-to-debug issues.
140+
132141
### Option `--layer-use` consumes a shared layer, and can extend it or create a final executable:
133142

134143
```
@@ -195,16 +204,31 @@ native-image --module-path target/AwesomeLib-1.0-SNAPSHOT.jar --shared
195204

196205
### Compatibility rules
197206

198-
Currently, layer build compatibility checking is very limited and is only performed for the image builder arguments.
207+
Layer build compatibility checks are performed to ensure the consistency of _image builder arguments_ and _classpath/modulepath entries_.
208+
These will be covered in the following subsections.
209+
210+
#### Image builder arguments compatibility
211+
199212
The list below gives a few examples of checks that are already implemented.
200213

201214
- Module system options `--add-exports`, `--add-opens`, `--add-reads` that were passed in the previous image build also need to be passed in the current image build.
202215
Note that additional module system options not found in the previous image build are allowed to be used in the current image build.
203216
- Builder options of the form `-H:NeverInline=<pattern>` follow the same logic as the module system options above.
204217
- If debug option `-g` was passed in the previous image build it must also be passed in the current image build at the same position.
205218
- Other options like `-H:EntryPointNamePrefix=...`, `-H:APIFunctionPrefix=...`, ... follow the same logic as the `-g` option.
219+
- Environment variables provided using `-E` to the previous image build must be passed to the current image build, with their values remaining unchanged. Additional environment variables may be supplied to the current build if needed.
220+
221+
#### Classpath & modulepath compatibility
222+
223+
The classpath/modulepath entries used in the previous image layer build must also be included in the current image layer build.
224+
These entries must retain the same content. If any of the shared entries are modified (.e.g, updated jar files), the previous image layer must be rebuilt with the updated versions.
225+
226+
For example, assume the previous layer build used the classpath: `/path/to/foo.jar:/path/to/bar.jar`.
227+
Then the current layer build must include both `/path/to/foo.jar` and `/path/to/bar.jar`, possibly alongside additional entries: `path/to/foo.jar:/path/to/bar.jar:/path/to/extra.jar`.
228+
Additionally, the contents of `foo.jar` and `bar.jar` should remain unchanged between the two builds.
206229

207-
The number of checks is subject to change and will be further improved in the future.
230+
**Exception**: Classpath or modulepath entries that include a `native-image.properties` file specifying the `--layer-create` option with the `digest-ignore` suboption are exempt from this rule.
231+
These entries should be _excluded_ from subsequent layer builds.
208232

209233
### Limitations
210234

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.net.URL;
3030
import java.net.URLConnection;
3131
import java.nio.ByteBuffer;
32+
import java.nio.file.FileSystem;
3233
import java.nio.file.Path;
3334
import java.util.Arrays;
3435
import java.util.HashMap;
@@ -181,6 +182,13 @@ protected URLConnection openConnection(URL url) throws IOException {
181182
final class Target_jdk_internal_jrtfs_JrtFileSystemProvider_JRTDisabled {
182183
}
183184

185+
@TargetClass(className = "jdk.internal.jrtfs.JrtFileSystemProvider", onlyWith = JRTEnabled.class)
186+
final class Target_jdk_internal_jrtfs_JrtFileSystemProvider_BuildTime {
187+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)//
188+
@Alias//
189+
volatile FileSystem theFileSystem;
190+
}
191+
184192
// endregion Disable jimage/jrtfs
185193

186194
@TargetClass(className = "jdk.internal.jimage.BasicImageReader")

0 commit comments

Comments
 (0)