Skip to content

Commit

Permalink
Backport 679a6d8
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Jun 13, 2023
1 parent ea4ab65 commit 00e804e
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions test/jdk/jdk/internal/misc/VM/RuntimeArguments.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,12 @@
* @run testng RuntimeArguments
*/

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
Expand All @@ -41,6 +47,30 @@

public class RuntimeArguments {
static final String TEST_CLASSES = System.getProperty("test.classes");
static final List<String> VM_OPTIONS = getInitialOptions();

/*
* Read jdk/internal/vm/options resource from the runtime image.
* If present, the runtime image was created with jlink --add-options and
* the java launcher launches the application as if
* $ java @options <app>
* The VM options listed in the jdk/internal/vm/options resource file
* are passed to the VM.
*/
static List<String> getInitialOptions() {
ModuleReference mref = ModuleFinder.ofSystem().find("java.base").orElseThrow();
try (ModuleReader reader = mref.open()) {
InputStream in = reader.open("jdk/internal/vm/options").orElse(null);
if (in != null) {
// support the simplest form for now: whitespace-separated
return List.of(new String(in.readAllBytes()).split("\s"));
} else {
return List.of();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@DataProvider(name = "options")
public Object[][] options() {
Expand Down Expand Up @@ -83,13 +113,15 @@ public static void main(String... expected) {
@Test(dataProvider = "options")
public void test(List<String> args, List<String> expected) throws Exception {
// launch a test program
// $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected>

// $ java <args> -classpath <cpath> RuntimeArguments <vm_options> <expected>
Stream<String> options = Stream.concat(args.stream(),
Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments"));

ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Stream.concat(options, expected.stream())
// The runtime image may be created with jlink --add-options
// The initial VM options will be included in the result
// returned by VM.getRuntimeArguments()
Stream.concat(options, Stream.concat(VM_OPTIONS.stream(), expected.stream()))
.toArray(String[]::new)
);
ProcessTools.executeProcess(pb).shouldHaveExitValue(0);
Expand Down

0 comments on commit 00e804e

Please sign in to comment.