--- old/src/hotspot/share/memory/filemap.cpp 2019-03-27 11:33:19.346006320 -0700 +++ new/src/hotspot/share/memory/filemap.cpp 2019-03-27 11:33:19.174000180 -0700 @@ -24,6 +24,7 @@ #include "precompiled.hpp" #include "jvm.h" +#include "classfile/classFileStream.hpp" #include "classfile/classLoader.inline.hpp" #include "classfile/classLoaderData.inline.hpp" #include "classfile/classLoaderExt.hpp" @@ -1502,7 +1503,12 @@ const char* const class_name = name->as_C_string(); const char* const file_name = ClassLoader::file_name_for_class_name(class_name, name->utf8_length()); - return cpe->open_stream_for_loader(file_name, ClassLoaderData::class_loader_data(class_loader()), THREAD); + ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader()); + ClassFileStream* cfs = cpe->open_stream_for_loader(file_name, loader_data, THREAD); + assert(cfs != NULL, "must be able to read the classfile data of shared classes for built-in loaders."); + log_debug(cds, jvmti)("classfile data for %s [%d: %s] = %d bytes", class_name, path_index, + cfs->source(), cfs->length()); + return cfs; } #endif --- old/test/hotspot/jtreg/TEST.groups 2019-03-27 11:33:19.886025598 -0700 +++ new/test/hotspot/jtreg/TEST.groups 2019-03-27 11:33:19.738020314 -0700 @@ -321,6 +321,21 @@ runtime/appcds/ \ -:tier1_runtime_appcds +# This group should be executed with "jtreg -vmoptions:-Dtest.cds.run.with.jfr=true ..." +# to test interaction between AppCDS and JFR. It also has the side effect of +# testing JVMTI ClassFileLoadHook. +# +# The excluded tests disallow the jdk.jfr module, which is required to +# run with JFR. +hotspot_appcds_with_jfr = \ + runtime/appcds/ \ + -runtime/appcds/cacheObject/ArchivedModuleCompareTest.java \ + -runtime/appcds/jigsaw/classpathtests/BootAppendTests.java \ + -runtime/appcds/jigsaw/classpathtests/ClassPathTests.java \ + -runtime/appcds/jigsaw/classpathtests/EmptyClassInBootClassPath.java \ + -runtime/appcds/jigsaw/JigsawOptionsCombo.java \ + -runtime/appcds/jigsaw/modulepath/MainModuleOnly.java + tier1_serviceability = \ serviceability/dcmd/compiler \ -serviceability/dcmd/compiler/CompilerQueueTest.java \ --- old/test/hotspot/jtreg/runtime/appcds/TestCommon.java 2019-03-27 11:33:20.434045160 -0700 +++ new/test/hotspot/jtreg/runtime/appcds/TestCommon.java 2019-03-27 11:33:20.282039734 -0700 @@ -145,6 +145,15 @@ return executeAndLog(pb, "dump"); } + // This allows you to run the AppCDS tests with JFR enabled at runtime (though not at + // dump time, as that's uncommon for typical AppCDS users). + // + // To run in this special mode, specify the following in your jtreg command-line + // -vmoptions:-Dtest.cds.run.with.jfr=true + // + // Some AppCDS tests are not compatible with this mode. See the group + // hotspot_appcds_with_jfr in ../../TEST.ROOT for details. + private static final boolean RUN_WITH_JFR = Boolean.getBoolean("test.cds.run.with.jfr"); // Execute JVM using AppCDS archive with specified AppCDSOptions public static OutputAnalyzer runWithArchive(AppCDSOptions opts) @@ -166,6 +175,22 @@ for (String s : opts.suffix) cmd.add(s); + if (RUN_WITH_JFR) { + boolean usesJFR = false; + for (String s : cmd) { + if (s.startsWith("-XX:StartFlightRecording=") || s.startsWith("-XX:FlightRecorderOptions")) { + System.out.println("JFR option might have been specified. Don't interfere: " + s); + usesJFR = true; + break; + } + } + if (!usesJFR) { + System.out.println("JFR option not specified. Enabling JFR ..."); + cmd.add(0, "-XX:StartFlightRecording=dumponexit=true"); + System.out.println(cmd); + } + } + String[] cmdLine = cmd.toArray(new String[cmd.size()]); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); return executeAndLog(pb, "exec"); --- old/test/hotspot/jtreg/runtime/appcds/customLoader/HelloCustom.java 2019-03-27 11:33:20.950063581 -0700 +++ new/test/hotspot/jtreg/runtime/appcds/customLoader/HelloCustom.java 2019-03-27 11:33:20.798058155 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2019, 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 @@ -28,8 +28,6 @@ * @requires vm.cds * @requires vm.cds.custom.loaders * @library /test/lib /test/hotspot/jtreg/runtime/appcds - * @modules java.base/jdk.internal.misc - * java.management * @compile test-classes/Hello.java test-classes/CustomLoadee.java * @build sun.hotspot.WhiteBox * @run driver ClassFileInstaller -jar hello.jar Hello @@ -43,6 +41,9 @@ public class HelloCustom { public static void main(String[] args) throws Exception { + run(); + } + public static void run(String... extra_runtime_args) throws Exception { String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar"); String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; @@ -62,11 +63,12 @@ use_whitebox_jar); output = TestCommon.exec(appJar, - // command-line arguments ... - use_whitebox_jar, - "-XX:+UnlockDiagnosticVMOptions", - "-XX:+WhiteBoxAPI", - "Hello", customJarPath); + TestCommon.concat(extra_runtime_args, + // command-line arguments ... + use_whitebox_jar, + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+WhiteBoxAPI", + "Hello", customJarPath)); TestCommon.checkExec(output); } } --- old/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/ModulePathAndCP.java 2019-03-27 11:33:21.482082573 -0700 +++ new/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/ModulePathAndCP.java 2019-03-27 11:33:21.330077147 -0700 @@ -93,6 +93,10 @@ } public static void main(String... args) throws Exception { + run(); + } + + public static void run(String... extra_runtime_args) throws Exception { // compile the modules and create the modular jar files buildTestModule(); String appClasses[] = {MAIN_CLASS, APP_CLASS}; @@ -104,6 +108,7 @@ "-m", MAIN_MODULE); TestCommon.checkDump(output); String prefix[] = {"-Djava.class.path=", "-Xlog:class+load=trace"}; + prefix = TestCommon.concat(prefix, extra_runtime_args); // run with the archive with the --module-path the same as the one during // dump time. The classes should be loaded from the archive. --- /dev/null 2019-02-25 13:26:02.045529497 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/customLoader/HelloCustom_JFR.java 2019-03-27 11:33:21.870096424 -0700 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019, 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. + * + */ + +/* + * @test + * @summary Same as HelloCustom, but add -XX:StartFlightRecording=dumponexit=true to the runtime + * options. This makes sure that the shared classes are compatible with both + * JFR and JVMTI ClassFileLoadHook. + * @requires vm.hasJFR + * @requires vm.cds + * @requires vm.cds.custom.loaders + * @library /test/lib /test/hotspot/jtreg/runtime/appcds + * @compile test-classes/Hello.java test-classes/CustomLoadee.java + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller -jar hello.jar Hello + * @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee + * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox + * @run driver HelloCustom_JFR + */ + +import jdk.test.lib.process.OutputAnalyzer; +import sun.hotspot.WhiteBox; + +public class HelloCustom_JFR { + public static void main(String[] args) throws Exception { + HelloCustom.run("-XX:StartFlightRecording=dumponexit=true", "-Xlog:cds+jvmti=debug"); + } +} + --- /dev/null 2019-02-25 13:26:02.045529497 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/ModulePathAndCP_JFR.java 2019-03-27 11:33:22.538120271 -0700 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019, 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. + * + */ + +/** + * @test + * @requires vm.hasJFR & vm.cds + * @library /test/lib /test/hotspot/jtreg/runtime/appcds + * @modules jdk.compiler + * jdk.jartool/sun.tools.jar + * jdk.jlink + * @run driver ModulePathAndCP_JFR + * @summary Same as ModulePathAndCP, but add -XX:StartFlightRecording=dumponexit=true to the runtime + * options. This makes sure that the shared classes are compatible with both + * JFR and JVMTI ClassFileLoadHook. + */ + +public class ModulePathAndCP_JFR { + public static void main(String... args) throws Exception { + ModulePathAndCP.run("-XX:StartFlightRecording=dumponexit=true", "-Xlog:cds+jvmti=debug"); + } +} +