Skip to content

Commit 679a6d8

Browse files
author
Mandy Chung
committedJun 9, 2023
8309303: jdk/internal/misc/VM/RuntimeArguments test ignores jdk/internal/vm/options
Reviewed-by: dnsimon, alanb
1 parent 6cd370e commit 679a6d8

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed
 

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

+36-4
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);

5 commit comments

Comments
 (5)

openjdk-notifier[bot] commented on Jun 9, 2023

@openjdk-notifier[bot]

mlchung commented on Jun 13, 2023

@mlchung
Member

/backport jdk21

openjdk[bot] commented on Jun 13, 2023

@openjdk[bot]

@mlchung the backport was successfully created on the branch mlchung-backport-679a6d89 in my personal fork of openjdk/jdk21. To create a pull request with this backport targeting openjdk/jdk21:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 679a6d89 from the openjdk/jdk repository.

The commit being backported was authored by Mandy Chung on 9 Jun 2023 and was reviewed by Doug Simon and Alan Bateman.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21:

$ git fetch https://github.com/openjdk-bots/jdk21.git mlchung-backport-679a6d89:mlchung-backport-679a6d89
$ git checkout mlchung-backport-679a6d89
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21.git mlchung-backport-679a6d89

GoeLin commented on Oct 7, 2024

@GoeLin
Member

/backport jdk17u-dev

openjdk[bot] commented on Oct 7, 2024

@openjdk[bot]

@GoeLin the backport was successfully created on the branch backport-GoeLin-679a6d89-master in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 679a6d89 from the openjdk/jdk repository.

The commit being backported was authored by Mandy Chung on 9 Jun 2023 and was reviewed by Doug Simon and Alan Bateman.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-679a6d89-master:backport-GoeLin-679a6d89-master
$ git checkout backport-GoeLin-679a6d89-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-679a6d89-master
Please sign in to comment.