Skip to content

Commit 9629286

Browse files
committed
8309303: jdk/internal/misc/VM/RuntimeArguments test ignores jdk/internal/vm/options
Backport-of: 679a6d89358eb36c596e3ffa9a86869402c9beb9
1 parent 43e37bb commit 9629286

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

test/jdk/jdk/internal/misc/VM/RuntimeArguments.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,12 @@
3030
* @run testng RuntimeArguments
3131
*/
3232

33+
import java.io.IOException;
34+
import java.io.InputStream;
35+
import java.io.UncheckedIOException;
36+
import java.lang.module.ModuleFinder;
37+
import java.lang.module.ModuleReader;
38+
import java.lang.module.ModuleReference;
3339
import java.util.Arrays;
3440
import java.util.List;
3541
import java.util.stream.Stream;
@@ -41,6 +47,30 @@
4147

4248
public class RuntimeArguments {
4349
static final String TEST_CLASSES = System.getProperty("test.classes");
50+
static final List<String> VM_OPTIONS = getInitialOptions();
51+
52+
/*
53+
* Read jdk/internal/vm/options resource from the runtime image.
54+
* If present, the runtime image was created with jlink --add-options and
55+
* the java launcher launches the application as if
56+
* $ java @options <app>
57+
* The VM options listed in the jdk/internal/vm/options resource file
58+
* are passed to the VM.
59+
*/
60+
static List<String> getInitialOptions() {
61+
ModuleReference mref = ModuleFinder.ofSystem().find("java.base").orElseThrow();
62+
try (ModuleReader reader = mref.open()) {
63+
InputStream in = reader.open("jdk/internal/vm/options").orElse(null);
64+
if (in != null) {
65+
// support the simplest form for now: whitespace-separated
66+
return List.of(new String(in.readAllBytes()).split("\s"));
67+
} else {
68+
return List.of();
69+
}
70+
} catch (IOException e) {
71+
throw new UncheckedIOException(e);
72+
}
73+
}
4474

4575
@DataProvider(name = "options")
4676
public Object[][] options() {
@@ -83,13 +113,15 @@ public static void main(String... expected) {
83113
@Test(dataProvider = "options")
84114
public void test(List<String> args, List<String> expected) throws Exception {
85115
// launch a test program
86-
// $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected>
87-
116+
// $ java <args> -classpath <cpath> RuntimeArguments <vm_options> <expected>
88117
Stream<String> options = Stream.concat(args.stream(),
89118
Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments"));
90119

91120
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
92-
Stream.concat(options, expected.stream())
121+
// The runtime image may be created with jlink --add-options
122+
// The initial VM options will be included in the result
123+
// returned by VM.getRuntimeArguments()
124+
Stream.concat(options, Stream.concat(VM_OPTIONS.stream(), expected.stream()))
93125
.toArray(String[]::new)
94126
);
95127
ProcessTools.executeProcess(pb).shouldHaveExitValue(0);

0 commit comments

Comments
 (0)