Skip to content

Commit

Permalink
8315383: jlink SystemModulesPlugin incorrectly parses the options
Browse files Browse the repository at this point in the history
8311591: Add SystemModulesPlugin test case that splits module descriptors with new local variables defined by DedupSetBuilder

Reviewed-by: phh
Backport-of: ea5aa61c8cc5caa04f7c7eac9634df28011581dc
  • Loading branch information
Mandy Chung committed Sep 5, 2023
1 parent f1e8b19 commit b207ce7
Show file tree
Hide file tree
Showing 10 changed files with 402 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void configure(Map<String, String> config) {
if (split.length != 2) {
throw new IllegalArgumentException(getName() + ": " + arg);
}
if (split[0].equals("batch-size")) {
if (!split[0].equals("batch-size")) {
throw new IllegalArgumentException(getName() + ": " + arg);
}
this.moduleDescriptorsPerMethod = Integer.parseInt(split[1]);
Expand Down
111 changes: 111 additions & 0 deletions test/jdk/tools/jlink/JLinkDedupTestBatchSizeOne.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import jdk.test.lib.compiler.CompilerUtils;
import tests.JImageGenerator;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/*
* @test
* @summary Make sure that modules can be linked using jlink
* and deduplication works correctly when creating sub methods
* @bug 8311591
* @library /test/lib
* ../lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* jdk.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jlink.plugin
* jdk.jlink/jdk.tools.jmod
* jdk.jlink/jdk.tools.jimage
* jdk.compiler
* @build tests.* JLinkDedupTestBatchSizeOne jdk.test.lib.compiler.CompilerUtils
* @run main/othervm -Xmx1g -Xlog:init=debug -XX:+UnlockDiagnosticVMOptions -XX:+BytecodeVerificationLocal JLinkDedupTestBatchSizeOne
*/
public class JLinkDedupTestBatchSizeOne {

private static final String JAVA_HOME = System.getProperty("java.home");
private static final String TEST_SRC = System.getProperty("test.src");

private static final Path SRC_DIR = Paths.get(TEST_SRC, "dedup", "src");
private static final Path MODS_DIR = Paths.get("mods");

private static final String MODULE_PATH =
Paths.get(JAVA_HOME, "jmods").toString() +
File.pathSeparator + MODS_DIR.toString();

// the names of the modules in this test
private static String[] modules = new String[]{"m1", "m2", "m3", "m4"};

private static boolean hasJmods() {
if (!Files.exists(Paths.get(JAVA_HOME, "jmods"))) {
System.err.println("Test skipped. No jmods directory");
return false;
}
return true;
}

public static void compileAll() throws Throwable {
if (!hasJmods()) return;

for (String mn : modules) {
Path msrc = SRC_DIR.resolve(mn);
CompilerUtils.compile(msrc, MODS_DIR,
"--module-source-path", SRC_DIR.toString());
}
}

public static void main(String[] args) throws Throwable {
compileAll();
Path image = Paths.get("bug8311591");

JImageGenerator.getJLinkTask()
.modulePath(MODULE_PATH)
.output(image.resolve("out-jlink-dedup"))
.addMods("m1")
.addMods("m2")
.addMods("m3")
.addMods("m4")
.option("--system-modules=batch-size=1")
.call()
.assertSuccess();

Path binDir = image.resolve("out-jlink-dedup").resolve("bin").toAbsolutePath();
Path bin = binDir.resolve("java");

ProcessBuilder processBuilder = new ProcessBuilder(bin.toString(),
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+BytecodeVerificationLocal",
"-m", "m4/p4.Main");
processBuilder.inheritIO();
processBuilder.directory(binDir.toFile());
Process process = processBuilder.start();
int exitCode = process.waitFor();
if (exitCode != 0)
throw new AssertionError("JLinkDedupTest100Modules failed to launch");
}
}
36 changes: 36 additions & 0 deletions test/jdk/tools/jlink/dedup/src/m1/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import p1.AInterface;
import p3.ServiceInterface;

module m1 {
exports p1 to m4;

opens p1 to m4;

requires transitive java.desktop;
requires m3;

provides ServiceInterface with AInterface;
}
36 changes: 36 additions & 0 deletions test/jdk/tools/jlink/dedup/src/m1/p1/AInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package p1;
import p3.ServiceInterface;

public class AInterface implements ServiceInterface {

public String getString() {
return "A1_A2";
}

public String getServiceName() {
return "AService";
}
}
36 changes: 36 additions & 0 deletions test/jdk/tools/jlink/dedup/src/m2/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import p2.BInterface;
import p3.ServiceInterface;

module m2 {
exports p2 to m3,m4;

opens p2 to m4;

requires transitive java.desktop;
requires m3;

provides ServiceInterface with BInterface;
}
35 changes: 35 additions & 0 deletions test/jdk/tools/jlink/dedup/src/m2/p2/BInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package p2;
import p3.ServiceInterface;
public class BInterface implements ServiceInterface {

public String getString() {
return "B1_B2";
}

public String getServiceName() {
return "BService";
}
}
26 changes: 26 additions & 0 deletions test/jdk/tools/jlink/dedup/src/m3/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

module m3 {
exports p3;
}
30 changes: 30 additions & 0 deletions test/jdk/tools/jlink/dedup/src/m3/p3/ServiceInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package p3;
public interface ServiceInterface {

String getString();

String getServiceName();
}
30 changes: 30 additions & 0 deletions test/jdk/tools/jlink/dedup/src/m4/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import p3.ServiceInterface;

module m4 {
requires m3;
requires transitive java.desktop;
uses ServiceInterface;
}

1 comment on commit b207ce7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.