test/hotspot/jtreg/runtime/SharedArchiveFile/BootAppendTests.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
open Cdiff test/hotspot/jtreg/runtime/SharedArchiveFile/BootAppendTests.java
test/hotspot/jtreg/runtime/SharedArchiveFile/BootAppendTests.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2016, 2017, 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.
--- 1,7 ----
/*
! * Copyright (c) 2016, 2018, 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.
*** 25,39 ****
* @test
* @requires vm.cds & !vm.graal.enabled
* @summary Testing -Xbootclasspath/a support for CDS
* @requires vm.cds
* @library /test/lib
! * @modules java.base/jdk.internal.misc
* java.management
* jdk.internal.jvmstat/sun.jvmstat.monitor
* @compile javax/sound/sampled/MyClass.jasm
! * @compile org/omg/CORBA/Context.jasm
* @compile nonjdk/myPackage/MyClass.java
* @build LoadClass
* @run main/othervm BootAppendTests
*/
--- 25,40 ----
* @test
* @requires vm.cds & !vm.graal.enabled
* @summary Testing -Xbootclasspath/a support for CDS
* @requires vm.cds
* @library /test/lib
! * @modules java.compiler
! * java.base/jdk.internal.misc
* java.management
* jdk.internal.jvmstat/sun.jvmstat.monitor
* @compile javax/sound/sampled/MyClass.jasm
! * @compile javax/annotation/processing/FilerException.jasm
* @compile nonjdk/myPackage/MyClass.java
* @build LoadClass
* @run main/othervm BootAppendTests
*/
*** 51,61 ****
import jdk.test.lib.process.OutputAnalyzer;
public class BootAppendTests {
private static final String APP_CLASS = "LoadClass";
private static final String BOOT_APPEND_MODULE_CLASS = "javax/sound/sampled/MyClass";
! private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS = "org/omg/CORBA/Context";
private static final String BOOT_APPEND_CLASS = "nonjdk/myPackage/MyClass";
private static final String BOOT_APPEND_MODULE_CLASS_NAME =
BOOT_APPEND_MODULE_CLASS.replace('/', '.');
private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME =
BOOT_APPEND_DUPLICATE_MODULE_CLASS.replace('/', '.');
--- 52,63 ----
import jdk.test.lib.process.OutputAnalyzer;
public class BootAppendTests {
private static final String APP_CLASS = "LoadClass";
private static final String BOOT_APPEND_MODULE_CLASS = "javax/sound/sampled/MyClass";
! private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS =
! "javax/annotation/processing/FilerException";
private static final String BOOT_APPEND_CLASS = "nonjdk/myPackage/MyClass";
private static final String BOOT_APPEND_MODULE_CLASS_NAME =
BOOT_APPEND_MODULE_CLASS.replace('/', '.');
private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME =
BOOT_APPEND_DUPLICATE_MODULE_CLASS.replace('/', '.');
*** 139,271 ****
// Test #2: If a class on -Xbootclasspath/a has the same fully qualified
// name as a class defined in boot modules, the class is not loaded
// from -Xbootclasspath/a. Verify the behavior is the same at runtime
// when CDS is enabled.
//
! // The org.omg.CORBA.Context is a boot module class. The class on
! // the -Xbootclasspath/a path that has the same fully-qualified name
! // should not be loaded at runtime when CDS is enabled.
! // The one from the boot modules should be loaded instead.
public static void testBootAppendDuplicateModuleClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
! .addPrefix("--add-modules", "java.corba", "-showversion",
"-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
! CDSTestUtils.checkExec(out, opts, "[class,load] org.omg.CORBA.Context source: jrt:/java.corba");
}
}
// Test #3: If a class on -Xbootclasspath/a is from a package defined in boot modules,
// the class can be loaded from -Xbootclasspath/a when the module is excluded
// using --limit-modules. Verify the behavior is the same at runtime when CDS
// is enabled.
//
! // The java.desktop module is excluded using --limit-modules at runtime,
! // javax.sound.sampled.MyClass is archived from -Xbootclasspath/a. It can be
! // loaded from the archive at runtime.
public static void testBootAppendExcludedModuleClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-showversion",
"--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_MODULE_CLASS_NAME);
!
! OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
! CDSTestUtils.checkExec(out, opts, "[class,load] javax.sound.sampled.MyClass");
!
! // When CDS is enabled, the shared class should be loaded from the archive.
if (mode.equals("on")) {
! CDSTestUtils.checkExec(out, opts, "[class,load] javax.sound.sampled.MyClass source: shared objects file");
}
}
}
// Test #4: If a class on -Xbootclasspath/a has the same fully qualified
// name as a class defined in boot modules, the class is loaded
// from -Xbootclasspath/a when the boot module is excluded using
// --limit-modules. Verify the behavior is the same at runtime
// when CDS is enabled.
//
! // The org.omg.CORBA.Context is a boot module class. The class
! // on -Xbootclasspath/a that has the same fully-qualified name
! // as org.omg.CORBA.Context can be loaded at runtime when
! // java.corba is excluded.
public static void testBootAppendDuplicateExcludedModuleClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-showversion",
"--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
! OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
! CDSTestUtils.checkExec(out, opts, "[class,load] org.omg.CORBA.Context");
! if (!CDSTestUtils.isUnableToMap(out)) {
! if (mode.equals("off")) {
! out.shouldMatch(".*\\[class,load\\] org.omg.CORBA.Context source:.*bootAppend.jar");
} else {
! CDSTestUtils.checkExec(out, opts, "[class,load] org.omg.CORBA.Context source: shared objects file");
! }
}
}
}
// Test #5: If a class on -Xbootclasspath/a is not from named modules,
// the class can be loaded at runtime. Verify the behavior is
// the same at runtime when CDS is enabled.
//
// The nonjdk.myPackage is not defined in named modules. The
! // archived nonjdk.myPackage.MyClass from -Xbootclasspath/a
! // can be loaded at runtime when CDS is enabled.
public static void testBootAppendClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-showversion",
"--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_CLASS_NAME);
! OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
! CDSTestUtils.checkExec(out, opts, "[class,load] nonjdk.myPackage.MyClass");
!
! // If CDS is enabled, the nonjdk.myPackage.MyClass should be loaded
! // from the shared archive.
if (mode.equals("on")) {
! CDSTestUtils.checkExec(out, opts,
! "[class,load] nonjdk.myPackage.MyClass source: shared objects file");
}
}
}
// Test #6: This is similar to Test #5. During runtime, an extra dir
// is appended to the bootclasspath. It should not invalidate
! // the shared archive.
public static void testBootAppendExtraDir() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar + File.pathSeparator + appJar,
"-showversion", "--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_CLASS_NAME);
! OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
! CDSTestUtils.checkExec(out, opts, "[class,load] nonjdk.myPackage.MyClass");
!
! // If CDS is enabled, the nonjdk.myPackage.MyClass should be loaded
! // from the shared archive.
if (mode.equals("on")) {
! CDSTestUtils.checkExec(out, opts,
! "[class,load] nonjdk.myPackage.MyClass source: shared objects file");
}
}
}
}
--- 141,294 ----
// Test #2: If a class on -Xbootclasspath/a has the same fully qualified
// name as a class defined in boot modules, the class is not loaded
// from -Xbootclasspath/a. Verify the behavior is the same at runtime
// when CDS is enabled.
//
! // The javax/annotation/processing/FilerException is a platform module
! // class. The class on the -Xbootclasspath/a path that has the same
! // fully-qualified name should not be loaded at runtime when CDS is enabled.
! // The one from the platform modules should be loaded instead.
public static void testBootAppendDuplicateModuleClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
! .addPrefix("-showversion",
"-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
! CDSTestUtils.checkExec(out, opts, "[class,load] javax.annotation.processing.FilerException source: jrt:/java.compiler");
}
}
// Test #3: If a class on -Xbootclasspath/a is from a package defined in boot modules,
// the class can be loaded from -Xbootclasspath/a when the module is excluded
// using --limit-modules. Verify the behavior is the same at runtime when CDS
// is enabled.
//
! // The java.desktop module is excluded using --limit-modules at runtime
! // CDS will be disabled with the --limit-modules option during runtime.
! // javax.sound.sampled.MyClass will be loaded from the jar at runtime.
public static void testBootAppendExcludedModuleClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-showversion",
"--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_MODULE_CLASS_NAME);
! CDSTestUtils.Result res = CDSTestUtils.run(opts);
! String MATCH_PATTERN =
! ".class.load. javax.sound.sampled.MyClass source:.*bootAppend.jar*";
if (mode.equals("on")) {
! res.assertSilentlyDisabledCDS(out -> {
! out.shouldHaveExitValue(0)
! .shouldMatch(MATCH_PATTERN);
! });
! } else {
! res.assertNormalExit(out -> {
! out.shouldMatch(MATCH_PATTERN);
! });
}
}
}
// Test #4: If a class on -Xbootclasspath/a has the same fully qualified
// name as a class defined in boot modules, the class is loaded
// from -Xbootclasspath/a when the boot module is excluded using
// --limit-modules. Verify the behavior is the same at runtime
// when CDS is enabled.
//
! // The javax.annotation.processing.FilerException is a platform module class.
! // The class on -Xbootclasspath/a that has the same fully-qualified name
! // as javax.annotation.processing.FilerException can be loaded at runtime when
! // java.compiler is excluded.
! // CDS is disabled during runtime if the --limit-modules option is
! // specified.
public static void testBootAppendDuplicateExcludedModuleClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-showversion",
"--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
! CDSTestUtils.Result res = CDSTestUtils.run(opts);
! String MATCH_PATTERN =
! ".class.load. javax.annotation.processing.FilerException source:.*bootAppend.jar*";
! if (mode.equals("on")) {
! res.assertSilentlyDisabledCDS(out -> {
! out.shouldHaveExitValue(0)
! .shouldMatch(MATCH_PATTERN);
! });
} else {
! res.assertNormalExit(out -> {
! out.shouldMatch(MATCH_PATTERN);
! });
}
}
}
// Test #5: If a class on -Xbootclasspath/a is not from named modules,
// the class can be loaded at runtime. Verify the behavior is
// the same at runtime when CDS is enabled.
//
// The nonjdk.myPackage is not defined in named modules. The
! // nonjdk.myPackage.MyClass will be loaded from the jar in
! // -Xbootclasspath/a since CDS will be disabled with the
! // --limit-modules option.
public static void testBootAppendClass() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-showversion",
"--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_CLASS_NAME);
! CDSTestUtils.Result res = CDSTestUtils.run(opts);
! String MATCH_PATTERN =
! ".class.load. nonjdk.myPackage.MyClass source:.*bootAppend.jar*";
if (mode.equals("on")) {
! res.assertSilentlyDisabledCDS(out -> {
! out.shouldHaveExitValue(0)
! .shouldMatch(MATCH_PATTERN);
! });
! } else {
! res.assertNormalExit(out -> {
! out.shouldMatch(MATCH_PATTERN);
! });
}
}
}
// Test #6: This is similar to Test #5. During runtime, an extra dir
// is appended to the bootclasspath. It should not invalidate
! // the shared archive. However, CDS will be disabled with the
! // --limit-modules in the command line.
public static void testBootAppendExtraDir() throws Exception {
for (String mode : modes) {
CDSOptions opts = (new CDSOptions())
.setXShareMode(mode).setUseVersion(false)
.addPrefix("-Xbootclasspath/a:" + bootAppendJar + File.pathSeparator + appJar,
"-showversion", "--limit-modules=java.base", "-cp", appJar)
.addSuffix("-Xlog:class+load=info",
APP_CLASS, BOOT_APPEND_CLASS_NAME);
! CDSTestUtils.Result res = CDSTestUtils.run(opts);
! String MATCH_PATTERN =
! ".class.load. nonjdk.myPackage.MyClass source:.*bootAppend.jar*";
if (mode.equals("on")) {
! res.assertSilentlyDisabledCDS(out -> {
! out.shouldHaveExitValue(0)
! .shouldMatch(MATCH_PATTERN);
! });
! } else {
! res.assertNormalExit(out -> {
! out.shouldMatch(MATCH_PATTERN);
! });
}
}
}
}
test/hotspot/jtreg/runtime/SharedArchiveFile/BootAppendTests.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File