|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
30 | 30 | * @run testng RuntimeArguments
|
31 | 31 | */
|
32 | 32 |
|
| 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; |
33 | 39 | import java.util.Arrays;
|
34 | 40 | import java.util.List;
|
35 | 41 | import java.util.stream.Stream;
|
|
41 | 47 |
|
42 | 48 | public class RuntimeArguments {
|
43 | 49 | 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 | + } |
44 | 74 |
|
45 | 75 | @DataProvider(name = "options")
|
46 | 76 | public Object[][] options() {
|
@@ -83,13 +113,15 @@ public static void main(String... expected) {
|
83 | 113 | @Test(dataProvider = "options")
|
84 | 114 | public void test(List<String> args, List<String> expected) throws Exception {
|
85 | 115 | // launch a test program
|
86 |
| - // $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected> |
87 |
| - |
| 116 | + // $ java <args> -classpath <cpath> RuntimeArguments <vm_options> <expected> |
88 | 117 | Stream<String> options = Stream.concat(args.stream(),
|
89 | 118 | Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments"));
|
90 | 119 |
|
91 | 120 | 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())) |
93 | 125 | .toArray(String[]::new)
|
94 | 126 | );
|
95 | 127 | ProcessTools.executeProcess(pb).shouldHaveExitValue(0);
|
|
5 commit comments
openjdk-notifier[bot] commentedon Jun 9, 2023
Review
Issues
mlchung commentedon Jun 13, 2023
/backport jdk21
openjdk[bot] commentedon Jun 13, 2023
@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:
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:
GoeLin commentedon Oct 7, 2024
/backport jdk17u-dev
openjdk[bot] commentedon Oct 7, 2024
@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:
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: