From 679a6d89358eb36c596e3ffa9a86869402c9beb9 Mon Sep 17 00:00:00 2001 From: Mandy Chung Date: Fri, 9 Jun 2023 16:44:56 +0000 Subject: [PATCH] 8309303: jdk/internal/misc/VM/RuntimeArguments test ignores jdk/internal/vm/options Reviewed-by: dnsimon, alanb --- .../internal/misc/VM/RuntimeArguments.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/test/jdk/jdk/internal/misc/VM/RuntimeArguments.java b/test/jdk/jdk/internal/misc/VM/RuntimeArguments.java index bcf3eda476d..90d3be1f7df 100644 --- a/test/jdk/jdk/internal/misc/VM/RuntimeArguments.java +++ b/test/jdk/jdk/internal/misc/VM/RuntimeArguments.java @@ -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 @@ -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; @@ -41,6 +47,30 @@ import static org.testng.Assert.*; public class RuntimeArguments { static final String TEST_CLASSES = System.getProperty("test.classes"); + static final List 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 + * The VM options listed in the jdk/internal/vm/options resource file + * are passed to the VM. + */ + static List 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() { @@ -83,13 +113,15 @@ public class RuntimeArguments { @Test(dataProvider = "options") public void test(List args, List expected) throws Exception { // launch a test program - // $ java -classpath RuntimeArguments - + // $ java -classpath RuntimeArguments Stream 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);