diff --git a/test/jdk/jfr/event/compiler/TestCodeSweeperConfig.java b/test/jdk/jfr/event/compiler/TestCodeSweeperConfig.java index 474f4353e7626093748da803e02183f3fafdfa03..7e0e17bdda8b97da38aa68951afbcf054b1f571e 100644 --- a/test/jdk/jfr/event/compiler/TestCodeSweeperConfig.java +++ b/test/jdk/jfr/event/compiler/TestCodeSweeperConfig.java @@ -38,8 +38,7 @@ import jdk.test.lib.jfr.Events; * @key jfr * * @library /lib / - * @run main/othervm -XX:+UseCodeCacheFlushing -XX:-SegmentedCodeCache jdk.jfr.event.compiler.TestCodeSweeperConfig - * @run main/othervm -XX:+UseCodeCacheFlushing -XX:+SegmentedCodeCache jdk.jfr.event.compiler.TestCodeSweeperConfig + * @run main/othervm -XX:+UseCodeCacheFlushing jdk.jfr.event.compiler.TestCodeSweeperConfig */ public class TestCodeSweeperConfig { diff --git a/test/jdk/jfr/event/compiler/TestCodeSweeperStats.java b/test/jdk/jfr/event/compiler/TestCodeSweeperStats.java deleted file mode 100644 index 922ee3fd7f7e47a88a8146f8bf50ae82c7fdb971..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/event/compiler/TestCodeSweeperStats.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.jfr.event.compiler; - -import java.io.File; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.file.Paths; -import java.util.List; - -import sun.hotspot.WhiteBox; -import jdk.jfr.Recording; -import jdk.jfr.consumer.RecordedEvent; -import jdk.test.lib.classloader.FilterClassLoader; -import jdk.test.lib.classloader.ParentLastURLClassLoader; -import jdk.test.lib.jfr.EventNames; -import jdk.test.lib.jfr.Events; -import jdk.test.lib.Utils; - -/** - * @test TestCodeSweeperStats - * @key jfr - * - * @library /lib / - * - * @build sun.hotspot.WhiteBox - * @run main ClassFileInstaller sun.hotspot.WhiteBox - * sun.hotspot.WhiteBox$WhiteBoxPermission - * @run main/othervm -Xbootclasspath/a:. - * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI - * -XX:CompileOnly=jdk.jfr.event.compiler.TestCodeSweeperStats::dummyMethod - * -XX:+SegmentedCodeCache jdk.jfr.event.compiler.TestCodeSweeperStats - * @run main/othervm -Xbootclasspath/a:. - * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI - * -XX:CompileOnly=jdk.jfr.event.compiler.TestCodeSweeperStats::dummyMethod - * -XX:-SegmentedCodeCache jdk.jfr.event.compiler.TestCodeSweeperStats - */ -public class TestCodeSweeperStats { - private static final String EVENT_NAME = EventNames.CodeSweeperStatistics; - private static final int WAIT_TIME = 10_000; - private static final String CLASS_METHOD_TO_COMPILE = "dummyMethod"; - private static final int METHODS_TO_COMPILE = Integer.getInteger("compile.methods.count", 10); - private static final int COMP_LEVEL_SIMPLE = 1; - private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4; - - public static void main(String[] args) throws Exception { - Recording recording = new Recording(); - recording.enable(EVENT_NAME).with("period", "endChunk"); - recording.start(); - compileAndSweep(); - recording.stop(); - - List events = Events.fromRecording(recording); - Events.hasEvents(events); - for (RecordedEvent event : events) { - Events.assertField(event, "sweepCount").atLeast(1); - Events.assertField(event, "methodReclaimedCount").equal(METHODS_TO_COMPILE); - Events.assertField(event, "totalSweepTime").atLeast(0L); - Events.assertField(event, "peakFractionTime").atLeast(0L); - Events.assertField(event, "peakSweepTime").atLeast(0L); - } - } - - private static void compileAndSweep() throws InterruptedException { - WhiteBox WB = WhiteBox.getWhiteBox(); - for (int i = 0; i < METHODS_TO_COMPILE; i++) { - System.out.println("compile " + i); - compileMethod(); - } - - WB.deoptimizeAll(); - System.out.println("All methods deoptimized"); - - // method will be sweeped out of code cache after 5 sweep cycles - for (int i = 0; i < 5; i++) { - WB.fullGC(); - WB.forceNMethodSweep(); - - } - // now wait for event(s) to be fired - Thread.sleep(WAIT_TIME); - } - - public void dummyMethod() { - System.out.println("Hello World!"); - } - - protected static void compileMethod() { - ClassLoader current = TestCodeSweeperStats.class.getClassLoader(); - String[] cpaths = System.getProperty("test.classes", ".").split(File.pathSeparator); - URL[] urls = new URL[cpaths.length]; - try { - for (int i = 0; i < cpaths.length; i++) { - urls[i] = Paths.get(cpaths[i]).toUri().toURL(); - } - } catch (MalformedURLException e) { - throw new Error(e); - } - - String currentClassName = TestCodeSweeperStats.class.getName(); - FilterClassLoader cl = new FilterClassLoader(new ParentLastURLClassLoader(urls, current), ClassLoader.getSystemClassLoader(), (name) -> currentClassName.equals(name)); - Class loadedClass = null; - String className = currentClassName; - try { - loadedClass = cl.loadClass(className); - } catch (ClassNotFoundException ex) { - throw new Error("Couldn't load class " + className, ex); - } - try { - Method mtd = loadedClass.getMethod(CLASS_METHOD_TO_COMPILE); - WhiteBox WB = WhiteBox.getWhiteBox(); - WB.testSetDontInlineMethod(mtd, true); - String directive = "[{ match: \"" + TestCodeSweeperStats.class.getName().replace('.', '/') - + "." + CLASS_METHOD_TO_COMPILE + "\", " + "BackgroundCompilation: false }]"; - WB.addCompilerDirective(directive); - if (!WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_FULL_OPTIMIZATION)) { - WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_SIMPLE); - } - Utils.waitForCondition(() -> WB.isMethodCompiled(mtd)); - } catch (NoSuchMethodException e) { - throw new Error("An exception while trying compile method " + e.getMessage(), e); - } - } -} diff --git a/test/jdk/jfr/event/compiler/TestCompilerCompile.java b/test/jdk/jfr/event/compiler/TestCompilerCompile.java index 4e6b5b9797522870ada1140583acb60533062666..c1aabc9eb628eb6fc3659b4de40f96df6e805eed 100644 --- a/test/jdk/jfr/event/compiler/TestCompilerCompile.java +++ b/test/jdk/jfr/event/compiler/TestCompilerCompile.java @@ -79,9 +79,6 @@ public class TestCompilerCompile { // compile dummyMethod() Method mtd = TestCompilerCompile.class.getDeclaredMethod(METHOD_NAME, new Class[0]); WhiteBox WB = WhiteBox.getWhiteBox(); - String directive = "[{ match: \"" + TestCompilerCompile.class.getName().replace('.', '/') - + "." + METHOD_NAME + "\", " + "BackgroundCompilation: false }]"; - WB.addCompilerDirective(directive); if (!WB.enqueueMethodForCompilation(mtd, 4 /* CompLevel_full_optimization */)) { WB.enqueueMethodForCompilation(mtd, 1 /* CompLevel_simple */); } diff --git a/test/jdk/jfr/event/compiler/TestCompilerPhase.java b/test/jdk/jfr/event/compiler/TestCompilerPhase.java index a08559d642520526c48546d3b44c4ba8b18c0d07..256a833793b97af575bb7e1240a7ebf087c8c26f 100644 --- a/test/jdk/jfr/event/compiler/TestCompilerPhase.java +++ b/test/jdk/jfr/event/compiler/TestCompilerPhase.java @@ -47,7 +47,7 @@ import sun.hotspot.WhiteBox; * @run main/othervm -Xbootclasspath/a:. * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI * -XX:CompileOnly=jdk.jfr.event.compiler.TestCompilerPhase::dummyMethod - * -XX:+SegmentedCodeCache -Xbootclasspath/a:. + * -Xbootclasspath/a:. * jdk.jfr.event.compiler.TestCompilerPhase */ public class TestCompilerPhase { @@ -64,9 +64,6 @@ public class TestCompilerPhase { // Provoke compilation Method mtd = TestCompilerPhase.class.getDeclaredMethod(METHOD_NAME, new Class[0]); WhiteBox WB = WhiteBox.getWhiteBox(); - String directive = "[{ match: \"" + TestCompilerPhase.class.getName().replace('.', '/') - + "." + METHOD_NAME + "\", " + "BackgroundCompilation: false }]"; - WB.addCompilerDirective(directive); if (!WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_FULL_OPTIMIZATION)) { WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_SIMPLE); } diff --git a/test/jdk/jfr/event/gc/collection/GCEventAll.java b/test/jdk/jfr/event/gc/collection/GCEventAll.java index c234dc1da8e08befaaeeefce99827b482af162b1..661dae028d9ab01e7a8e61df79bc1a37d88029f6 100644 --- a/test/jdk/jfr/event/gc/collection/GCEventAll.java +++ b/test/jdk/jfr/event/gc/collection/GCEventAll.java @@ -309,8 +309,9 @@ public class GCEventAll { if (event.getEventType().getName().contains("AllocationRequiringGC")) { // Unlike other events, these are sent *before* a GC. Asserts.assertLessThanOrEqual(event.getStartTime(), batchStartTime, "Timestamp in event after start event, should be sent before GC start"); - } else { - Asserts.assertGreaterThanOrEqual(event.getStartTime(), batchStartTime, "startTime in event before batch start event, should be sent after GC start"); + } else if (!event.getEventType().getName().contains("G1MMU")){ + // G1MMU event on JDK8 G1 can be out-of-order; don't check it here + Asserts.assertGreaterThanOrEqual(event.getStartTime(), batchStartTime, "startTime in event before batch start event, should be sent after GC start [" + event.getEventType().getName() + "]"); } Asserts.assertLessThanOrEqual(event.getEndTime(), batchEndTime, "endTime in event after batch end event, should be sent before GC end"); } diff --git a/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java b/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java index 51475b846bcd513c7da769f744cb8df81c1ef9be..21e1e68b71537e1f14d2fcb77bab8c636c123253 100644 --- a/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java +++ b/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java @@ -41,7 +41,7 @@ public class TestGCCauseWithG1ConcurrentMark { public static void main(String[] args) throws Exception { String testID = "G1ConcurrentMark"; String[] vmFlags = {"-XX:+UseG1GC", "-XX:+ExplicitGCInvokesConcurrent"}; - String[] gcNames = {GCHelper.gcG1New, GCHelper.gcG1Old, GCHelper.gcG1Full}; + String[] gcNames = {GCHelper.gcG1New, GCHelper.gcG1Old, GCHelper.gcG1Full, GCHelper.gcSerialOld}; String[] gcCauses = {"G1 Evacuation Pause", "Allocation Failure", "System.gc()"}; GCGarbageCollectionUtil.test(testID, vmFlags, gcNames, gcCauses); } diff --git a/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java b/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java index b4bd9cc4e0eaecb6a4a064659880cf79da170b83..93042ee18447e329b4384fa3d0d353c8ecd1cadd 100644 --- a/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java +++ b/test/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java @@ -41,7 +41,7 @@ public class TestGCCauseWithG1FullCollection { public static void main(String[] args) throws Exception { String testID = "G1FullCollection"; String[] vmFlags = {"-XX:+UseG1GC"}; - String[] gcNames = {GCHelper.gcG1New, GCHelper.gcG1Old, GCHelper.gcG1Full}; + String[] gcNames = {GCHelper.gcG1New, GCHelper.gcG1Old, GCHelper.gcG1Full, GCHelper.gcSerialOld}; String[] gcCauses = {"G1 Evacuation Pause", "Allocation Failure", "System.gc()"}; GCGarbageCollectionUtil.test(testID, vmFlags, gcNames, gcCauses); } diff --git a/test/jdk/jfr/event/gc/detailed/TestG1AIHOPEvent.java b/test/jdk/jfr/event/gc/detailed/TestG1AIHOPEvent.java deleted file mode 100644 index 8fca0f0ed4a6b30ab23049b05a4c2ff21e15a811..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/event/gc/detailed/TestG1AIHOPEvent.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2015, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.jfr.event.gc.detailed; - -import java.util.List; - -import jdk.jfr.Recording; -import jdk.jfr.consumer.RecordedEvent; -import jdk.test.lib.jfr.EventNames; -import jdk.test.lib.jfr.Events; - -/** - * @test - * @key jfr - * - * - * @library /lib / - * @run main/othervm -XX:NewSize=2m -XX:MaxNewSize=2m -Xmx32m -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -XX:+G1UseAdaptiveIHOP jdk.jfr.event.gc.detailed.TestG1AIHOPEvent - */ -public class TestG1AIHOPEvent { - - private final static String EVENT_NAME = EventNames.G1AdaptiveIHOP; - public static byte[] bytes; - - public static void main(String[] args) throws Exception { - - Recording recording = new Recording(); - - // activate the event we are interested in and start recording - recording.enable(EVENT_NAME); - recording.start(); - - // Setting NewSize and MaxNewSize will limit eden, so - // allocating 1024 5k byte arrays should trigger at - // least one Young GC. - for (int i = 0; i < 1024; i++) { - bytes = new byte[5 * 1024]; - } - recording.stop(); - - // Verify recording - List all = Events.fromRecording(recording); - Events.hasEvents(all); - - for (RecordedEvent e : all) { - Events.assertField(e, "gcId").above(0); - } - - recording.close(); - } -} diff --git a/test/jdk/jfr/event/gc/detailed/TestG1IHOPEvent.java b/test/jdk/jfr/event/gc/detailed/TestG1IHOPEvent.java deleted file mode 100644 index 4eeb9ac96aea7916120950f074862625e9bad3b6..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/event/gc/detailed/TestG1IHOPEvent.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2015, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.jfr.event.gc.detailed; - -import java.util.List; - -import jdk.jfr.Recording; -import jdk.jfr.consumer.RecordedEvent; -import jdk.test.lib.jfr.EventNames; -import jdk.test.lib.jfr.Events; - -/** - * @test - * @key jfr - * - * - * @library /lib / - * @run main/othervm -XX:NewSize=2m -XX:MaxNewSize=2m -Xmx32m -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -XX:-G1UseAdaptiveIHOP jdk.jfr.event.gc.detailed.TestG1IHOPEvent - * @run main/othervm -XX:NewSize=2m -XX:MaxNewSize=2m -Xmx32m -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -XX:+G1UseAdaptiveIHOP jdk.jfr.event.gc.detailed.TestG1IHOPEvent - */ -public class TestG1IHOPEvent { - - private final static String EVENT_NAME = EventNames.G1BasicIHOP; - public static byte[] bytes; - - public static void main(String[] args) throws Exception { - - Recording recording = new Recording(); - - // activate the event we are interested in and start recording - recording.enable(EVENT_NAME); - recording.start(); - - // Setting NewSize and MaxNewSize will limit eden, so - // allocating 1024 5k byte arrays should trigger at - // least one Young GC. - for (int i = 0; i < 1024; i++) { - bytes= new byte[5 * 1024]; - } - recording.stop(); - - // Verify recording - List all = Events.fromRecording(recording); - Events.hasEvents(all); - - for (RecordedEvent e : all) { - Events.assertField(e, "gcId").above(0); - } - - recording.close(); - - } -} diff --git a/test/jdk/jfr/event/gc/objectcount/TestObjectCountAfterGCEventWithG1FullCollection.java b/test/jdk/jfr/event/gc/objectcount/TestObjectCountAfterGCEventWithG1FullCollection.java index 4a7b060b300a0f8e8e5890f057facdd341777dd9..9eb036954783a8e50aa69469f9baba83b3e5c5d9 100644 --- a/test/jdk/jfr/event/gc/objectcount/TestObjectCountAfterGCEventWithG1FullCollection.java +++ b/test/jdk/jfr/event/gc/objectcount/TestObjectCountAfterGCEventWithG1FullCollection.java @@ -36,6 +36,6 @@ import jdk.test.lib.jfr.GCHelper; */ public class TestObjectCountAfterGCEventWithG1FullCollection { public static void main(String[] args) throws Exception { - ObjectCountAfterGCEvent.test(GCHelper.gcG1Full); + ObjectCountAfterGCEvent.test(GCHelper.gcSerialOld); } } diff --git a/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java b/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java index 03cb587a526e11065ee31166feddd3754f8e5be2..caa05cfa53284a1c4c49fcb10ca6c13f1bcd3976 100644 --- a/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java +++ b/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java @@ -76,8 +76,13 @@ public class TestLookForUntestedEvents { // NOTE: if the event is not covered, a bug should be open, and bug number // noted in the comments for this set. private static final Set knownNotCoveredEvents = new HashSet<>( - // DumpReason: JDK-8213918 - Arrays.asList("DumpReason") + Arrays.asList( + // DumpReason: JDK-8213918 + "DumpReason", + // No G1 IHOP in JDK 8 + "G1BasicIHOP", + "G1AdaptiveIHOP" + ) ); @@ -112,6 +117,7 @@ public class TestLookForUntestedEvents { // Account for hard-to-test, experimental and GC tested events eventsNotCoveredByTest.removeAll(hardToTestEvents); eventsNotCoveredByTest.removeAll(coveredGcEvents); + eventsNotCoveredByTest.removeAll(knownNotCoveredEvents); if (!eventsNotCoveredByTest.isEmpty()) { diff --git a/test/jdk/jfr/event/runtime/TestJavaMonitorInflateEvent.java b/test/jdk/jfr/event/runtime/TestJavaMonitorInflateEvent.java index d6004ce81256076e80bc60f7e43873b7dcf06be6..d98b4ce21c44500247809ea2ad87684e59d7c9db 100644 --- a/test/jdk/jfr/event/runtime/TestJavaMonitorInflateEvent.java +++ b/test/jdk/jfr/event/runtime/TestJavaMonitorInflateEvent.java @@ -102,7 +102,6 @@ public class TestJavaMonitorInflateEvent { continue; } Events.assertField(event, FIELD_ADDRESS).notEqual(0L); - Events.assertField(event, FIELD_CAUSE).notNull(); isAnyFound = true; break; } diff --git a/test/jdk/jfr/event/runtime/TestModuleEvents.java b/test/jdk/jfr/event/runtime/TestModuleEvents.java deleted file mode 100644 index 893e79975b7e05eafadd27e1659a2fb0aadd0041..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/event/runtime/TestModuleEvents.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.jfr.event.runtime; - -import static jdk.test.lib.Asserts.assertEquals; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import jdk.jfr.Recording; -import jdk.jfr.consumer.RecordedEvent; -import jdk.jfr.consumer.RecordedObject; -import jdk.test.lib.jfr.EventNames; -import jdk.test.lib.jfr.Events; - -/** - * @test - * @summary Tests the JFR events related to modules - * @key jfr - * - * - * @library /lib / - * @run main/othervm --limit-modules java.base,jdk.jfr jdk.jfr.event.runtime.TestModuleEvents - */ -public final class TestModuleEvents { - - private static final String MODULE_EXPORT_EVENT_NAME = EventNames.ModuleExport; - private static final String MODULE_REQUIRE_EVENT_NAME = EventNames.ModuleRequire; - private static final String UNNAMED = ""; - - public static void main(String[] args) throws Throwable { - verifyRequiredModules(); - verifyExportedModules(); - } - - private static void verifyRequiredModules() throws Throwable { - Recording recording = new Recording(); - recording.enable(MODULE_REQUIRE_EVENT_NAME); - - recording.start(); - recording.stop(); - - List events = Events.fromRecording(recording); - assertDependency(events, "jdk.jfr", "java.base"); // jdk.jfr requires java.base (by edfault) - assertDependency(events, "java.base", "jdk.jfr"); // java.base require jdk.jfr for JDK events, i.e. FileRead - - recording.close(); - } - - private static void assertDependency(List events, String source, String required) throws Exception { - for (RecordedEvent e : events) { - String sourceModule = e.getValue("source.name"); - if (source.equals(sourceModule)) { - RecordedObject module = e.getValue("requiredModule"); - if (module != null) { - if (required.equals(module.getValue("name"))) { - return; - } - } - } - } - throw new Exception("Could not find module dependency between " + source + " and requires modeule "+ required); - } - - private static void verifyExportedModules() throws Throwable { - Recording recording = new Recording(); - recording.enable(MODULE_EXPORT_EVENT_NAME); - recording.start(); - recording.stop(); - - Map edges = new HashMap<>(); - - List events = Events.fromRecording(recording); - events.stream().forEach((ev) -> { - String exportedPackage = getValue(ev.getValue("exportedPackage"), "name", UNNAMED); - String toModule = getValue(ev.getValue("targetModule"), "name", UNNAMED); - - edges.put(exportedPackage, toModule); - }); - - // We expect - // 1) jdk.jfr -> (because we use the package) - // 2) java.util -> (because we use the package) - // 3) jdk.jfr.events -> java.base (from the jfr design) - // 4) jdk.internal -> jdk.jfr (from the jfr design) - // Where 'a -> b' means "package 'a' exported to module 'b'" - assertEquals(edges.get("jdk/jfr"), UNNAMED); - assertEquals(edges.get("java/util"), UNNAMED); - assertEquals(edges.get("jdk/jfr/events"), "java.base"); - assertEquals(edges.get("jdk/internal"), "jdk.jfr"); - - recording.close(); - } - - // Helper function to get field from a RecordedObject - private static String getValue(RecordedObject ro, String field, String defVal) { - if (ro != null && ro.getValue(field) != null) { - return ro.getValue(field); - } else { - return defVal; - } - } -} diff --git a/test/jdk/jfr/jcmd/TestJcmdChangeLogLevel.java b/test/jdk/jfr/jcmd/TestJcmdChangeLogLevel.java deleted file mode 100644 index e9213b04e6eb4ca62be6a02540cfd21f429af968..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/jcmd/TestJcmdChangeLogLevel.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.jfr.jcmd; - - - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; - -import jdk.test.lib.dcmd.JcmdExecutor; -import jdk.test.lib.dcmd.PidJcmdExecutor; - -/** - * @test TestJcmdLogLevelChange - * @key jfr - * @summary Test changing log level - * - * - * @library /lib / - * - * @run main/othervm -Xlog:jfr=info jdk.jfr.jcmd.TestJcmdChangeLogLevel - */ -public class TestJcmdChangeLogLevel { - public static void main(String[] args) throws Exception { - final String fileName = "jfr_trace.txt"; - final String findWhat = "[info][jfr] Flight Recorder initialized"; - boolean passed = false; - - JcmdExecutor je = new PidJcmdExecutor(); - je.execute("VM.log output='file=" + fileName + "' what='jfr=info'"); - je.execute("JFR.start duration=1s"); - List lines; - - do { - try { - lines = Files.readAllLines(Paths.get(fileName)); - } catch (IOException e) { - throw new Error(e); - } - for (String l : lines) { - if (l.toString().contains(findWhat)) { - passed = true; - break; - } - } - if (lines.size() > 100) { - break; /* did not find it */ - } - } while(!passed); - - if (!passed) { - throw new Error("Not found " + findWhat + " in stream" + lines); - } - - System.out.println("PASSED"); - } -} diff --git a/test/jdk/jfr/jvm/TestJfrJavaBase.java b/test/jdk/jfr/jvm/TestJfrJavaBase.java deleted file mode 100644 index 96b4da615afde7f47653ca69df34e6b6e4453001..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/jvm/TestJfrJavaBase.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 - * @bug 8157032 - * @key jfr - * @summary verify that jfr can not be used when JVM is executed only with java.base - * - * @library /lib / - * - * @run driver jdk.jfr.jvm.TestJfrJavaBase - */ - -package jdk.jfr.jvm; - - -import jdk.test.lib.dcmd.PidJcmdExecutor; -import jdk.test.lib.process.OutputAnalyzer; -import jdk.test.lib.process.ProcessTools; - -public class TestJfrJavaBase { - - private static void checkOutput(OutputAnalyzer output) { - output.shouldContain("Module jdk.jfr not found."); - output.shouldContain("Flight Recorder can not be enabled."); - } - - public static void main(String[] args) throws Exception { - OutputAnalyzer output; - if (args.length == 0) { - output = ProcessTools.executeProcess(ProcessTools.createJavaProcessBuilder(false, - "-Dtest.jdk=" + System.getProperty("test.jdk"), - "--limit-modules", "java.base", "-cp", System.getProperty("java.class.path"), - TestJfrJavaBase.class.getName(), "runtest")); - output.shouldHaveExitValue(0); - } else { - output = ProcessTools.executeTestJava("-XX:StartFlightRecording=dumponexit=true", - "--limit-modules", "java.base", "-version"); - checkOutput(output); - output.shouldHaveExitValue(1); - - // Verify that JFR.start jcmd command reports an error when jdk.jfr module is not available - output = new PidJcmdExecutor().execute("JFR.start"); - checkOutput(output); - output.shouldHaveExitValue(0); - } - } -} diff --git a/test/jdk/jfr/jvm/TestLogOutput.java b/test/jdk/jfr/jvm/TestLogOutput.java deleted file mode 100644 index 95bb3bca1f6fd415a38d41e8cc43eb79fecb542f..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/jvm/TestLogOutput.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.jfr.jvm; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -/** - * @test TestLogOutput - * @key jfr - * @summary Sanity test jfr logging output - * - * @library /lib / - * @run main/othervm -Xlog:disable -Xlog:jfr*=trace:file=jfr_trace.txt -XX:StartFlightRecording=duration=1s,filename=recording.jfr jdk.jfr.jvm.TestLogOutput - */ -public class TestLogOutput { - public static void main(String[] args) throws Exception { - final String fileName = "jfr_trace.txt"; - final ListfindWhat = new ArrayList<>(); - findWhat.add("Starting a recording"); - findWhat.add("Flight Recorder initialized"); - boolean passed = false; - List matches = new ArrayList(findWhat); - - do { - List lines; - try { - lines = Files.readAllLines(Paths.get(fileName)); - } catch (IOException e) { - throw new Error(e); - } - for (String l : lines) { - for (String m : matches) { - if (l.toString().contains(m)) { - matches.remove(m); - break; - } - } - } - if (matches.size() < 1) { - passed = true; - break; - } - if (lines.size() > 100) { - break; /* did not find it */ - } - } while(!passed); - - if (!passed) { - throw new Error("Not found " + findWhat + " in stream"); - } - - System.out.println("PASSED"); - } -} diff --git a/test/lib/jdk/test/lib/jfr/GCHelper.java b/test/lib/jdk/test/lib/jfr/GCHelper.java index d8c275e3f4417216887a82121876d87702fb581d..4f2801262a6e57614b18ac4f2ab9e37401d41878 100644 --- a/test/lib/jdk/test/lib/jfr/GCHelper.java +++ b/test/lib/jdk/test/lib/jfr/GCHelper.java @@ -183,6 +183,7 @@ public class GCHelper { // List of expected collector overrides. "A.B" means that collector A may use collector B. collectorOverrides.add("G1Old.G1Full"); + collectorOverrides.add("G1Old.SerialOld"); collectorOverrides.add("ConcurrentMarkSweep.SerialOld"); collectorOverrides.add("SerialOld.PSMarkSweep"); diff --git a/test/lib/jfr/AppExecutorHelper.java b/test/lib/jfr/AppExecutorHelper.java deleted file mode 100644 index 239a0f7f9e351d2b8a51ea95b7c5c637cfffd76f..0000000000000000000000000000000000000000 --- a/test/lib/jfr/AppExecutorHelper.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import jdk.test.lib.process.OutputAnalyzer; -import jdk.test.lib.process.ProcessTools; - - -/** - * Helper class for running applications with enabled JFR recording - */ -public class AppExecutorHelper { - - /** - * Executes an application with enabled JFR and writes collected events - * to the given output file. - * Which events to track and other parameters are taken from the setting .jfc file. - * - * @param setting JFR settings file(optional) - * @param jfrFilename JFR resulting recording filename(optional) - * @param additionalVMFlags additional VM flags passed to the java(optional) - * @param className name of the class to execute - * @param classArguments arguments passed to the class(optional) - * @return output analyzer for executed application - */ - public static OutputAnalyzer executeAndRecord(String settings, String jfrFilename, String[] additionalVmFlags, - String className, String... classArguments) throws Exception { - List arguments = new ArrayList<>(); - String baseStartFlightRecording = "-XX:StartFlightRecording"; - String additionalStartFlightRecording = ""; - - if (additionalVmFlags != null) { - Collections.addAll(arguments, additionalVmFlags); - } - - if (settings != null & jfrFilename != null) { - additionalStartFlightRecording = String.format("=settings=%s,filename=%s", settings, jfrFilename); - } else if (settings != null) { - additionalStartFlightRecording = String.format("=settings=%s", settings); - } else if (jfrFilename != null) { - additionalStartFlightRecording = String.format("=filename=%s", jfrFilename); - } - arguments.add(baseStartFlightRecording + additionalStartFlightRecording); - - arguments.add(className); - if (classArguments.length > 0) { - Collections.addAll(arguments, classArguments); - } - - ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, arguments.toArray(new String[0])); - return ProcessTools.executeProcess(pb); - } -} diff --git a/test/lib/jfr/CommonHelper.java b/test/lib/jfr/CommonHelper.java deleted file mode 100644 index 10ae4dffaf8ce1ef4cf24d8ca733bc25f47f9584..0000000000000000000000000000000000000000 --- a/test/lib/jfr/CommonHelper.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import static jdk.test.lib.Asserts.assertEquals; -import static jdk.test.lib.Asserts.fail; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -import jdk.jfr.Recording; -import jdk.jfr.RecordingState; -import jdk.jfr.consumer.RecordedEvent; -import jdk.jfr.consumer.RecordingFile; -import jdk.test.lib.Asserts; -import jdk.test.lib.Utils; - - -/** - * Common helper class. - */ -public final class CommonHelper { - - private static RecordedEvent timeStampCounterEvent; - - public static void verifyException(VoidFunction f, String msg, Class expectedException) throws Throwable { - try { - f.run(); - } catch (Throwable t) { - if (expectedException.isAssignableFrom(t.getClass())) { - return; - } - t.printStackTrace(); - assertEquals(t.getClass(), expectedException, "Wrong exception class"); - } - fail("Missing Exception for: " + msg); - } - - public static Recording verifyExists(long recId, List recordings) { - for (Recording r : recordings) { - if (recId == r.getId()) { - return r; - } - } - Asserts.fail("Recording not found, id=" + recId); - return null; - } - - - public static void waitForRecordingState(Recording r, RecordingState expectedState) throws Exception { - while (r.getState() != expectedState) { - Thread.sleep(20); - } - } - - public static void verifyRecordingState(Recording r, RecordingState expectedState) throws Exception { - assertEquals(expectedState, r.getState(), "Wrong state"); - } - - public static boolean hasFastTimeEnabled() throws Exception { - return getTimeStampCounterEvent().getValue("fastTimeEnabled"); - } - - private synchronized static RecordedEvent getTimeStampCounterEvent() throws IOException, Exception { - if (timeStampCounterEvent == null) { - try (Recording r = new Recording()) { - r.enable(EventNames.CPUTimeStampCounter); - r.start(); - r.stop(); - Path p = Utils.createTempFile("timestamo", ".jfr"); - r.dump(p); - List events = RecordingFile.readAllEvents(p); - Files.deleteIfExists(p); - if (events.isEmpty()) { - throw new Exception("Could not locate CPUTimeStampCounter event"); - } - timeStampCounterEvent = events.get(0); - } - } - return timeStampCounterEvent; - } - - public static void waitForSystemCurrentMillisToChange() { - long t = System.currentTimeMillis(); - while (t == System.currentTimeMillis()) { - try { - Thread.sleep(2); - } catch (InterruptedException e) { - throw new Error("Sleep interupted", e); - } - } - } -} diff --git a/test/lib/jfr/EventField.java b/test/lib/jfr/EventField.java deleted file mode 100644 index 3b802e75586889b032139bf5b86a1db0daa5d749..0000000000000000000000000000000000000000 --- a/test/lib/jfr/EventField.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import jdk.jfr.ValueDescriptor; -import jdk.jfr.consumer.RecordedObject; -import jdk.test.lib.Asserts; - - -public final class EventField { - public final RecordedObject event; - public final ValueDescriptor desc; - - public EventField(RecordedObject event, ValueDescriptor valueDescriptor) { - this.event = event; - this.desc = valueDescriptor; - } - - @SuppressWarnings("unchecked") - public > boolean isEqual(T value) { - return value == (T)getValue(); - } - - @SuppressWarnings("unchecked") - public > EventField equal(T value) { - doAssert(()-> Asserts.assertEquals((T)getValue(), value, getErrMsg("Value not equal to " + value))); - return this; - } - - @SuppressWarnings("unchecked") - public > EventField notEqual(T value) { - doAssert(()-> Asserts.assertNotEquals((T)getValue(), value, getErrMsg("Value equal to " + value))); - return this; - } - - @SuppressWarnings("unchecked") - public > EventField above(T value) { - doAssert(()-> Asserts.assertGreaterThan((T)getValue(), value, getErrMsg("Value not above " + value))); - return this; - } - - @SuppressWarnings("unchecked") - public > EventField below(T value) { - doAssert(()-> Asserts.assertLessThan((T)getValue(), value, getErrMsg("Value not below " + value))); - return this; - } - - @SuppressWarnings("unchecked") - public > EventField atLeast(T value) { - doAssert(()-> Asserts.assertGreaterThanOrEqual((T)getValue(), value, getErrMsg("Value not atLeast" + value))); - return this; - } - - @SuppressWarnings("unchecked") - public > EventField atMost(T value) { - doAssert(()-> Asserts.assertLessThanOrEqual((T)getValue(), value, getErrMsg("Value not atMost " + value))); - return this; - } - - public > EventField instring(String part) { - final String value = getValue(); - doAssert(()-> Asserts.assertTrue(value.contains(part), getErrMsg("Value does not contain '" + part +"'"))); - return this; - } - - @SuppressWarnings("unchecked") - public T getValue() { - return (T)event.getValue(desc.getName()); - } - - public EventField notNull() { - doAssert(()-> Asserts.assertNotNull(getValue(), getErrMsg("Field is null"))); - return this; - } - - public EventField isNull() { - doAssert(()-> Asserts.assertNull(getValue(), getErrMsg("Field is not null"))); - return this; - } - - public EventField notEmpty() { - notNull(); - final String s = getValue(); - doAssert(()-> Asserts.assertFalse(s.isEmpty(), getErrMsg("Field is empty"))); - return this; - } - - private void doAssert(AssertFunction f) { - try { - f.doAssert(); - } catch (RuntimeException e) { - System.out.printf("Error: %s%nFailed event:%n%s%n", e.getMessage(), event.toString()); - throw e; - } - } - - public EventField containsAny(String... allowed) { - final String value = getValue(); - final List allowedValues = Arrays.asList(allowed); - boolean contains = false; - for(String allowedValue : allowed) { - if (value.contains(allowedValue)) { - contains = true; - } - } - if (!contains) { - doAssert(()-> Asserts.fail(getErrMsg(String.format("Value not in (%s)", - allowedValues.stream().collect(Collectors.joining(", ")))))); - } - return this; - } - - private String getErrMsg(String msg) { - final String name = desc.getName(); - final Object value = event.getValue(name); - return String.format("%s, field='%s', value='%s'", msg, name, value); - } - - @FunctionalInterface - public interface AssertFunction { - void doAssert(); - } -} diff --git a/test/lib/jfr/EventNames.java b/test/lib/jfr/EventNames.java deleted file mode 100644 index 0902c9e93a38707ebc146aae49b93e4ad125310f..0000000000000000000000000000000000000000 --- a/test/lib/jfr/EventNames.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2015, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import jdk.jfr.EventType; - -/** - * Contains id for events that are shipped with the JDK. - * - */ -public class EventNames { - - public final static String PREFIX = "jdk."; - private static final String GC_CATEGORY = "GC"; - - // JVM Configuration - public final static String JVMInformation = PREFIX + "JVMInformation"; - public final static String InitialSystemProperty = PREFIX + "InitialSystemProperty"; - public final static String IntFlag = PREFIX + "IntFlag"; - public final static String UnsignedIntFlag = PREFIX + "UnsignedIntFlag"; - public final static String LongFlag = PREFIX + "LongFlag"; - public final static String UnsignedLongFlag = PREFIX + "UnsignedLongFlag"; - public final static String DoubleFlag = PREFIX + "DoubleFlag"; - public final static String BooleanFlag = PREFIX + "BooleanFlag"; - public final static String StringFlag = PREFIX + "StringFlag"; - public final static String IntFlagChanged = PREFIX + "IntFlagChanged"; - public final static String UnsignedIntFlagChanged = PREFIX + "UnsignedIntFlagChanged"; - public final static String LongFlagChanged = PREFIX + "LongFlagChanged"; - public final static String UnsignedLongFlagChanged = PREFIX + "UnsignedLongFlagChanged"; - public final static String DoubleFlagChanged = PREFIX + "DoubleFlagChanged"; - public final static String BooleanFlagChanged = PREFIX + "BooleanFlagChanged"; - public final static String StringFlagChanged = PREFIX + "StringFlagChanged"; - - // Runtime - public final static String VMException = PREFIX + "JavaErrorThrow"; - public final static String ThreadStart = PREFIX + "ThreadStart"; - public final static String ThreadEnd = PREFIX + "ThreadEnd"; - public final static String ThreadSleep = PREFIX + "ThreadSleep"; - public final static String ThreadPark = PREFIX + "ThreadPark"; - public final static String JavaMonitorEnter = PREFIX + "JavaMonitorEnter"; - public final static String JavaMonitorWait = PREFIX + "JavaMonitorWait"; - public final static String JavaMonitorInflate = PREFIX + "JavaMonitorInflate"; - public final static String ClassLoad = PREFIX + "ClassLoad"; - public final static String ClassDefine = PREFIX + "ClassDefine"; - public final static String ClassUnload = PREFIX + "ClassUnload"; - public final static String SafepointBegin = PREFIX + "SafepointBegin"; - public final static String SafepointStateSyncronization = PREFIX + "SafepointStateSynchronization"; - public final static String SafepointWaitBlocked = PREFIX + "SafepointWaitBlocked"; - public final static String SafepointCleanup = PREFIX + "SafepointCleanup"; - public final static String SafepointCleanupTask = PREFIX + "SafepointCleanupTask"; - public final static String SafepointEnd = PREFIX + "SafepointEnd"; - public final static String ExecuteVMOperation = PREFIX + "ExecuteVMOperation"; - public final static String Shutdown = PREFIX + "Shutdown"; - public final static String VMError = PREFIX + "VMError"; - public final static String JavaThreadStatistics = PREFIX + "JavaThreadStatistics"; - public final static String ClassLoadingStatistics = PREFIX + "ClassLoadingStatistics"; - public final static String ClassLoaderStatistics = PREFIX + "ClassLoaderStatistics"; - public final static String ThreadAllocationStatistics = PREFIX + "ThreadAllocationStatistics"; - public final static String ExecutionSample = PREFIX + "ExecutionSample"; - public final static String NativeMethodSample = PREFIX + "NativeMethodSample"; - public final static String ExecutionSampling = PREFIX + "ExecutionSampling"; - public final static String ThreadDump = PREFIX + "ThreadDump"; - public final static String OldObjectSample = PREFIX + "OldObjectSample"; - public final static String BiasedLockRevocation = PREFIX + "BiasedLockRevocation"; - public final static String BiasedLockSelfRevocation = PREFIX + "BiasedLockSelfRevocation"; - public final static String BiasedLockClassRevocation = PREFIX + "BiasedLockClassRevocation"; - - // GC - public final static String GCHeapSummary = PREFIX + "GCHeapSummary"; - public final static String MetaspaceSummary = PREFIX + "MetaspaceSummary"; - public final static String MetaspaceGCThreshold = PREFIX + "MetaspaceGCThreshold"; - public final static String MetaspaceAllocationFailure = PREFIX + "MetaspaceAllocationFailure"; - public final static String MetaspaceOOM = PREFIX + "MetaspaceOOM"; - public final static String MetaspaceChunkFreeListSummary = PREFIX + "MetaspaceChunkFreeListSummary"; - public final static String PSHeapSummary = PREFIX + "PSHeapSummary"; - public final static String G1HeapSummary = PREFIX + "G1HeapSummary"; - public final static String G1HeapRegionInformation = PREFIX + "G1HeapRegionInformation"; - public final static String G1HeapRegionTypeChange = PREFIX + "G1HeapRegionTypeChange"; - public final static String TenuringDistribution = PREFIX + "TenuringDistribution"; - public final static String GarbageCollection = PREFIX + "GarbageCollection"; - public final static String ParallelOldCollection = PREFIX + "ParallelOldGarbageCollection"; - public final static String YoungGarbageCollection = PREFIX + "YoungGarbageCollection"; - public final static String OldGarbageCollection = PREFIX + "OldGarbageCollection"; - public final static String G1GarbageCollection = PREFIX + "G1GarbageCollection"; - public final static String G1MMU = PREFIX + "G1MMU"; - public final static String EvacuationInfo = PREFIX + "EvacuationInfo"; - public final static String GCReferenceStatistics = PREFIX + "GCReferenceStatistics"; - public final static String ObjectCountAfterGC = PREFIX + "ObjectCountAfterGC"; - public final static String PromoteObjectInNewPLAB = PREFIX + "PromoteObjectInNewPLAB"; - public final static String PromoteObjectOutsidePLAB = PREFIX + "PromoteObjectOutsidePLAB"; - public final static String PromotionFailed = PREFIX + "PromotionFailed"; - public final static String EvacuationFailed = PREFIX + "EvacuationFailed"; - public final static String ConcurrentModeFailure = PREFIX + "ConcurrentModeFailure"; - public final static String GCPhasePause = PREFIX + "GCPhasePause"; - public final static String GCPhasePauseLevel1 = PREFIX + "GCPhasePauseLevel1"; - public final static String GCPhasePauseLevel2 = PREFIX + "GCPhasePauseLevel2"; - public final static String GCPhasePauseLevel3 = PREFIX + "GCPhasePauseLevel3"; - public final static String ObjectCount = PREFIX + "ObjectCount"; - public final static String GCConfiguration = PREFIX + "GCConfiguration"; - public final static String GCSurvivorConfiguration = PREFIX + "GCSurvivorConfiguration"; - public final static String GCTLABConfiguration = PREFIX + "GCTLABConfiguration"; - public final static String GCHeapConfiguration = PREFIX + "GCHeapConfiguration"; - public final static String YoungGenerationConfiguration = PREFIX + "YoungGenerationConfiguration"; - public final static String G1AdaptiveIHOP = PREFIX + "G1AdaptiveIHOP"; - public final static String G1EvacuationYoungStatistics = PREFIX + "G1EvacuationYoungStatistics"; - public final static String G1EvacuationOldStatistics = PREFIX + "G1EvacuationOldStatistics"; - public final static String G1BasicIHOP = PREFIX + "G1BasicIHOP"; - public final static String AllocationRequiringGC = PREFIX + "AllocationRequiringGC"; - - // Compiler - public final static String Compilation = PREFIX + "Compilation"; - public final static String CompilerPhase = PREFIX + "CompilerPhase"; - public final static String CompilationFailure = PREFIX + "CompilationFailure"; - public final static String CompilerInlining = PREFIX + "CompilerInlining"; - public final static String CompilerStatistics = PREFIX + "CompilerStatistics"; - public final static String CompilerConfig = PREFIX + "CompilerConfiguration"; - public final static String CodeCacheStatistics = PREFIX + "CodeCacheStatistics"; - public final static String CodeCacheConfiguration = PREFIX + "CodeCacheConfiguration"; - public final static String CodeSweeperStatistics = PREFIX + "CodeSweeperStatistics"; - public final static String CodeSweeperConfiguration = PREFIX + "CodeSweeperConfiguration"; - public final static String SweepCodeCache = PREFIX + "SweepCodeCache"; - public final static String CodeCacheFull = PREFIX + "CodeCacheFull"; - public final static String ObjectAllocationInNewTLAB = PREFIX + "ObjectAllocationInNewTLAB"; - public final static String ObjectAllocationOutsideTLAB = PREFIX + "ObjectAllocationOutsideTLAB"; - - // OS - public final static String OSInformation = PREFIX + "OSInformation"; - public final static String CPUInformation = PREFIX + "CPUInformation"; - public final static String CPULoad = PREFIX + "CPULoad"; - public final static String ThreadCPULoad = PREFIX + "ThreadCPULoad"; - public final static String SystemProcess = PREFIX + "SystemProcess"; - public final static String ThreadContextSwitchRate = PREFIX + "ThreadContextSwitchRate"; - public final static String InitialEnvironmentVariable = PREFIX + "InitialEnvironmentVariable"; - public final static String NativeLibrary = PREFIX + "NativeLibrary"; - public final static String PhysicalMemory = PREFIX + "PhysicalMemory"; - public final static String NetworkUtilization = PREFIX + "NetworkUtilization"; - - // JDK - public static final String FileForce = PREFIX + "FileForce"; - public static final String FileRead = PREFIX + "FileRead"; - public static final String FileWrite = PREFIX + "FileWrite"; - public static final String SocketRead = PREFIX + "SocketRead"; - public static final String SocketWrite = PREFIX + "SocketWrite"; - public final static String ExceptionStatistics = PREFIX + "ExceptionStatistics"; - public final static String JavaExceptionThrow = PREFIX + "JavaExceptionThrow"; - public final static String JavaErrorThrow = PREFIX + "JavaErrorThrow"; - - // Flight Recorder - public final static String DumpReason = PREFIX + "DumpReason"; - public final static String DataLoss = PREFIX + "DataLoss"; - public final static String CPUTimeStampCounter = PREFIX + "CPUTimeStampCounter"; - public final static String ActiveRecording = PREFIX + "ActiveRecording"; - public final static String ActiveSetting = PREFIX + "ActiveSetting"; - - public static boolean isGcEvent(EventType et) { - return et.getCategoryNames().contains(GC_CATEGORY); - } - -} diff --git a/test/lib/jfr/EventTypePrototype.java b/test/lib/jfr/EventTypePrototype.java deleted file mode 100644 index d5afe85783181b2a434ed2916fdfb09f41844e55..0000000000000000000000000000000000000000 --- a/test/lib/jfr/EventTypePrototype.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.util.ArrayList; -import java.util.List; - -import jdk.jfr.AnnotationElement; -import jdk.jfr.Name; -import jdk.jfr.ValueDescriptor; - -public final class EventTypePrototype { - private final List fields; - private final List annotations; - private final String name; - - public EventTypePrototype(String name, List as, List fields) { - this.annotations = new ArrayList<>(as); - this.annotations.add(new AnnotationElement(Name.class, name)); - this.fields = fields; - this.name = name; - } - - public EventTypePrototype(String name) { - this(name, new ArrayList<>(), new ArrayList<>()); - } - - public int getFieldIndex(String key) { - int index = 0; - for (ValueDescriptor f : fields) { - if (f.getName().equals(key)) { - return index; - } - index++; - } - throw new NoSuchFieldError(key); - } - - public void addField(ValueDescriptor fieldDescriptor) { - fields.add(fieldDescriptor); - } - - public void addAnnotation(AnnotationElement annotation) { - annotations.add(annotation); - } - - public List getFields() { - return fields; - } - - public List getAnnotations() { - return annotations; - } - - public String getName() { - return name; - } -} diff --git a/test/lib/jfr/EventVerifier.java b/test/lib/jfr/EventVerifier.java deleted file mode 100644 index a72fb1c4ba65ba523c38d90b21bce3d408e331e6..0000000000000000000000000000000000000000 --- a/test/lib/jfr/EventVerifier.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import jdk.jfr.consumer.RecordedEvent; - -public abstract class EventVerifier { - protected final RecordedEvent event; - - public EventVerifier(RecordedEvent event) { - this.event = event; - } - - public > void verifyEquals(String name, T value) { - Events.assertField(event, name).equal(value); - } - - public void verifyContains(String name, String value) { - Events.assertField(event, name).containsAny(value); - } - - protected long gigabytes(int num) { - return num * 1024L * 1024L * 1024L; - } - - protected long megabytes(int num) { - return num * 1024L * 1024L; - } - - public abstract void verify() throws Exception; -} diff --git a/test/lib/jfr/Events.java b/test/lib/jfr/Events.java deleted file mode 100644 index 1b715b3ff1dacef81445d43040eeafb2f1b56355..0000000000000000000000000000000000000000 --- a/test/lib/jfr/Events.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import static jdk.test.lib.Asserts.assertEquals; -import static jdk.test.lib.Asserts.assertFalse; -import static jdk.test.lib.Asserts.assertNotNull; -import static jdk.test.lib.Asserts.assertTrue; -import static jdk.test.lib.Asserts.fail; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; - -import jdk.jfr.AnnotationElement; -import jdk.jfr.EventType; -import jdk.jfr.Recording; -import jdk.jfr.SettingDescriptor; -import jdk.jfr.ValueDescriptor; -import jdk.jfr.consumer.RecordingFile; -import jdk.test.lib.Asserts; -import jdk.jfr.consumer.RecordedClass; -import jdk.jfr.consumer.RecordedEvent; -import jdk.jfr.consumer.RecordedObject; -import jdk.jfr.consumer.RecordedThread; -import jdk.jfr.consumer.RecordedThreadGroup; - - -/** - * Helper class to verify RecordedEvent content - */ -public class Events { - - public static EventField assertField(RecordedEvent event, String name) { - String[] partNames = name.split("\\."); - RecordedObject struct = event; - try { - for (int i=0; i valueDescriptors = struct.getFields(); - for (ValueDescriptor d : valueDescriptors) { - if (name.equals(d.getName())) { - return d; - } - } - System.out.printf("Failed struct:%s", struct.toString()); - fail(String.format("Field %s not in struct", name)); - return null; - } - - public static void hasEvents(List events) { - assertFalse(events.isEmpty(), "No events"); - } - - public static void hasEvents(RecordingFile file) { - assertTrue(file.hasMoreEvents(), "No events"); - } - - public static void assertEventThread(RecordedEvent event) { - RecordedThread eventThread = event.getThread(); - if (eventThread == null) { - System.out.printf("Failed event:%n%s%n", event.toString()); - fail("No thread in event"); - } - } - - public static void assertJavaMethod(RecordedEvent event) { - assertField(event, "method.name").notEmpty(); - assertField(event, "method.descriptor").notEmpty(); - assertField(event, "method.modifiers").atLeast(0); - assertField(event, "method.hidden"); - assertField(event, "method.type.name").notEmpty(); - assertField(event, "method.type.modifiers").atLeast(0); - } - - public static void assertEventThread(RecordedEvent event, Thread thread) { - assertThread(event.getThread(), thread); - } - - public static void assertEventThread(RecordedEvent event, String structName, Thread thread) { - assertThread(assertField(event, structName).notNull().getValue(), thread); - } - - private static void assertThread(RecordedThread eventThread, Thread thread) { - assertNotNull(eventThread, "Thread in event was null"); - assertEquals(eventThread.getJavaThreadId(), thread.getId(), "Wrong thread id"); - assertEquals(eventThread.getJavaName(), thread.getName(), "Wrong thread name"); - - ThreadGroup threadGroup = thread.getThreadGroup(); - RecordedThreadGroup eventThreadGroup = eventThread.getThreadGroup(); - assertNotNull(eventThreadGroup, "eventThreadGroup was null"); - - // Iterate and check all threadGroups - while (eventThreadGroup != null) { - final String groupName = eventThreadGroup.getName(); - if (threadGroup != null) { - assertEquals(groupName, threadGroup.getName(), "Wrong threadGroup name"); - threadGroup = threadGroup.getParent(); - } else { - assertNotNull(groupName, "threadGroup name was null"); - assertFalse(groupName.isEmpty(), "threadGroup name was empty"); - } - eventThreadGroup = eventThreadGroup.getParent(); - } - } - - public static boolean hasField(RecordedEvent event, String name) { - return event.getFields().stream().map(vd -> vd.getName()).anyMatch(s -> s.equals(name)); - } - - public static boolean isEventType(RecordedEvent event, String typeName) { - return typeName.equals(event.getEventType().getName()); - } - - - /** - * Creates a list of events from a recording. - * - * @param recording recording, not {@code null} - * @return an a list, not null - * @throws IOException if an event set could not be created due to I/O - * errors. - */ - public static List fromRecording(Recording recording) throws IOException { - return RecordingFile.readAllEvents(makeCopy(recording)); - } - - public static RecordingFile copyTo(Recording r) throws IOException { - return new RecordingFile(makeCopy(r)); - } - - private static Path makeCopy(Recording recording) throws IOException { - Path p = recording.getDestination(); - if (p == null) { - File directory = new File("."); - // FIXME: Must come up with a way to give human-readable name - // this will at least not clash when running parallel. - ProcessHandle h = ProcessHandle.current(); - p = new File(directory.getAbsolutePath(), "recording-" + recording.getId() + "-pid" + h.pid() + ".jfr").toPath(); - recording.dump(p); - } - return p; - } - - public static void hasAnnotation(ValueDescriptor field, Class annotationClass) throws Exception { - AnnotationElement a = getAnnotation(field, annotationClass); - if (a == null) { - throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName()); - } - } - - public static void assertAnnotation(ValueDescriptor field, Class annotationClass, String value) throws Exception { - AnnotationElement a = getAnnotation(field, annotationClass); - Object v = a.getValue("value"); - if (!v.equals(value)) { - throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName() + " to have value " + value + ", but got " + v); - } - } - - // candidate for moving into API - public static AnnotationElement getAnnotation(ValueDescriptor v, Class clazz) throws Exception { - for (AnnotationElement a : v.getAnnotationElements()) { - if (a.getTypeName().equals(clazz.getName())) { - return a; - } - } - - throw new Exception("Could not find annotation " + clazz.getName()); - } - - // candidate for moving into API - public static AnnotationElement getAnnotationByName(EventType t, String name) throws Exception { - for (AnnotationElement a : t.getAnnotationElements()) { - if (a.getTypeName().equals(name)) { - return a; - } - } - throw new Exception("Could not find annotation '" + name + " in type " + t.getName()); - } - - // candidate for moving into API - public static SettingDescriptor getSetting(EventType type, String name) { - for (SettingDescriptor s : type.getSettingDescriptors()) { - if (s.getName().equals(name)) { - return s; - } - } - throw new IllegalArgumentException("Could not setting with name " + name); - } - - public static void hasEvent(Recording r, String name) throws IOException { - List events = fromRecording(r); - Events.hasEvents(events); - Events.hasEvent(events, name); - } - - public static void hasEvent(List events, String name) throws IOException { - if (!containsEvent(events, name)) { - Asserts.fail("Missing event " + name + " in recording " + events.toString()); - } - } - - public static void hasNotEvent(List events, String name) throws IOException { - if (containsEvent(events, name)) { - Asserts.fail("Rercording should not contain event " + name + " " + events.toString()); - } - } - - private static boolean containsEvent(List events, String name) { - for (RecordedEvent event : events) { - if (event.getEventType().getName().equals(name)) { - return true; - } - } - return false; - } -} diff --git a/test/lib/jfr/FileHelper.java b/test/lib/jfr/FileHelper.java deleted file mode 100644 index d84c47613f6437541113599655f66e513eca8315..0000000000000000000000000000000000000000 --- a/test/lib/jfr/FileHelper.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.io.File; -import java.io.IOException; -import java.nio.file.AccessDeniedException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; - -import jdk.jfr.consumer.RecordedEvent; -import jdk.jfr.consumer.RecordingFile; -import jdk.test.lib.Asserts; - -/** - * Common helper class. - */ -public class FileHelper { - - public static Path getDest(String subPath) throws IOException { - Path path = Paths.get(subPath + "/test.jfr"); - Path parent = path.getParent(); - if (parent == null) { - throw new IOException("No parent cound be found for path " + subPath); - } - Files.createDirectories(parent); - return path; - } - - public static Path createLongDir(Path root) throws IOException { - final int minPathLength = 400; - StringBuilder buff = new StringBuilder(); - buff.append(root.toString()); - while (buff.length() < minPathLength) { - buff.append("/veryLongPath012345678901234567890123456789"); - } - Path path = Paths.get(buff.toString()); - System.out.println("long dir=" + path); - Files.createDirectories(path); - return path; - } - - public static Path getDestReadOnly(String subPath) throws IOException { - final Path path = getDest(subPath); - Path parent = path.getParent(); - if (parent == null) { - throw new IOException("No parent cound be found for path " + subPath); - } - parent.toFile().setReadOnly(); - return path; - } - - public static Path createReadOnlyFile(Path path) throws IOException { - final Path createdPath = Files.createFile(path); - createdPath.toFile().setReadOnly(); - return createdPath; - } - - public static Path createReadOnlyDir(Path path) throws IOException { - final Path createdPath = Files.createDirectories(path); - createdPath.toFile().setReadOnly(); - return createdPath; - } - - public static Path getDestNotExist() { - return Paths.get(".", "thisDirDoesNotExist/test.jfr"); - } - - public static boolean isReadOnlyPath(Path path) throws IOException { - // Files.isWritable(path) can not really be trusted. At least not on Windows. - // If path is a directory, we try to create a new file in it. - if (Files.isDirectory(path)) { - try { - Path f = Files.createFile(Paths.get(path.toString(), "dummyFileToCheckReadOnly")); - System.out.printf("Dir is not read-only, created %s, exists=%b%n", f, Files.exists(f)); - return false; - } catch (AccessDeniedException e) { - System.out.printf("'%s' verified read-only by %s%n", path, e.toString()); - return true; - } - } else { - boolean isReadOnly = !Files.isWritable(path); - System.out.format("isReadOnly '%s': %b%n", path, isReadOnly); - return isReadOnly; - } - } - - public static void verifyRecording(File file) throws Exception { - Asserts.assertTrue(file.exists(), file.getAbsolutePath() + " does not exist"); - Asserts.assertTrue(file.isFile(), file.getAbsolutePath() + " is not a file"); - Asserts.assertGreaterThan(file.length(), 0L, "Size of recording is 0."); - List events = RecordingFile.readAllEvents(file.toPath()); - for (RecordedEvent event : events) { - System.out.printf("First event in recording '%s':%n%s", file.getName(), event); - return; - } - Asserts.fail("No events in file " + file.getName()); - } - -} diff --git a/test/lib/jfr/GCHelper.java b/test/lib/jfr/GCHelper.java deleted file mode 100644 index d8c275e3f4417216887a82121876d87702fb581d..0000000000000000000000000000000000000000 --- a/test/lib/jfr/GCHelper.java +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import static jdk.test.lib.Asserts.assertEquals; -import static jdk.test.lib.Asserts.assertNotEquals; -import static jdk.test.lib.Asserts.assertNotNull; -import static jdk.test.lib.Asserts.assertNull; -import static jdk.test.lib.Asserts.fail; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.lang.management.GarbageCollectorMXBean; -import java.lang.management.ManagementFactory; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Stack; - -import jdk.jfr.ValueDescriptor; -import jdk.jfr.consumer.RecordedEvent; - -/** - * Mixed helper classes to test GC events. - */ -public class GCHelper { - public static final String event_garbage_collection = EventNames.GarbageCollection; - public static final String event_young_garbage_collection = EventNames.YoungGarbageCollection; - public static final String event_old_garbage_collection = EventNames.OldGarbageCollection; - public static final String event_parold_garbage_collection = EventNames.ParallelOldCollection; - public static final String event_g1_garbage_collection = EventNames.G1GarbageCollection; - public static final String event_heap_summary = EventNames.GCHeapSummary; - public static final String event_heap_ps_summary = EventNames.PSHeapSummary; - public static final String event_heap_metaspace_summary = EventNames.MetaspaceSummary; - public static final String event_reference_statistics = EventNames.GCReferenceStatistics; - public static final String event_phases_pause = EventNames.GCPhasePause; - public static final String event_phases_level_1 = EventNames.GCPhasePauseLevel1; - public static final String event_phases_level_2 = EventNames.GCPhasePauseLevel2; - public static final String event_phases_level_3 = EventNames.GCPhasePauseLevel3; - - public static final String gcG1New = "G1New"; - public static final String gcParNew = "ParNew"; - public static final String gcDefNew = "DefNew"; - public static final String gcParallelScavenge = "ParallelScavenge"; - public static final String gcG1Old = "G1Old"; - public static final String gcG1Full = "G1Full"; - public static final String gcConcurrentMarkSweep = "ConcurrentMarkSweep"; - public static final String gcSerialOld = "SerialOld"; - public static final String gcPSMarkSweep = "PSMarkSweep"; - public static final String gcParallelOld = "ParallelOld"; - public static final String pauseLevelEvent = "GCPhasePauseLevel"; - - private static final List g1HeapRegionTypes; - private static PrintStream defaultErrorLog = null; - - public static int getGcId(RecordedEvent event) { - return Events.assertField(event, "gcId").getValue(); - } - - public static boolean isGcEvent(RecordedEvent event) { - for (ValueDescriptor v : event.getFields()) { - if ("gcId".equals(v.getName())) { - return true; - } - } - return false; - } - -// public static String getEventDesc(RecordedEvent event) { -// final String path = event.getEventType().getName(); -// if (!isGcEvent(event)) { -// return path; -// } -// if (event_garbage_collection.equals(path)) { -// String name = Events.assertField(event, "name").getValue(); -// String cause = Events.assertField(event, "cause").getValue(); -// return String.format("path=%s, gcId=%d, endTime=%d, name=%s, cause=%s, startTime=%d", -// path, getGcId(event), event.getEndTime(), name, cause, event.getStartTime()); -// } else { -// return String.format("path=%s, gcId=%d, endTime=%d", path, getGcId(event), event.getEndTime()); -// } -// } - - public static RecordedEvent getConfigEvent(List events) throws Exception { - for (RecordedEvent event : events) { - if (EventNames.GCConfiguration.equals(event.getEventType().getName())) { - return event; - } - } - fail("Could not find event " + EventNames.GCConfiguration); - return null; - } - - public static void callSystemGc(int num, boolean withGarbage) { - for (int i = 0; i < num; i++) { - if (withGarbage) { - makeGarbage(); - } - System.gc(); - } - } - - private static void makeGarbage() { - Object[] garbage = new Object[1024]; - for (int i = 0; i < 1024; i++) { - garbage[i] = new Object(); - } - } - - // Removes gcEvents with lowest and highest gcID. This is used to filter out - // any incomplete GCs if the recording started/stopped in the middle of a GC. - // We also filters out events without gcId. Those events are not needed. - public static List removeFirstAndLastGC(List events) { - int minGcId = Integer.MAX_VALUE; - int maxGcId = Integer.MIN_VALUE; - // Find min/max gcId - for (RecordedEvent event : events) { - if (Events.hasField(event, "gcId")) { - int gcId = Events.assertField(event, "gcId").getValue(); - minGcId = Math.min(gcId, minGcId); - maxGcId = Math.max(gcId, maxGcId); - } - } - - // Add all events except those with gcId = min/max gcId - List filteredEvents = new ArrayList<>(); - for (RecordedEvent event : events) { - if (Events.hasField(event, "gcId")) { - int gcId = Events.assertField(event, "gcId").getValue(); - if (gcId != minGcId && gcId != maxGcId) { - filteredEvents.add(event); - } - } - } - return filteredEvents; - } - - public static Map beanCollectorTypes = new HashMap<>(); - public static Set collectorOverrides = new HashSet<>(); - public static Map requiredEvents = new HashMap<>(); - - static { - // young GarbageCollectionMXBeans. - beanCollectorTypes.put("G1 Young Generation", true); - beanCollectorTypes.put("Copy", true); - beanCollectorTypes.put("PS Scavenge", true); - beanCollectorTypes.put("ParNew", true); - - // old GarbageCollectionMXBeans. - beanCollectorTypes.put("G1 Old Generation", false); - beanCollectorTypes.put("ConcurrentMarkSweep", false); - beanCollectorTypes.put("PS MarkSweep", false); - beanCollectorTypes.put("MarkSweepCompact", false); - - // List of expected collector overrides. "A.B" means that collector A may use collector B. - collectorOverrides.add("G1Old.G1Full"); - collectorOverrides.add("ConcurrentMarkSweep.SerialOld"); - collectorOverrides.add("SerialOld.PSMarkSweep"); - - requiredEvents.put(gcG1New, new String[] {event_heap_summary, event_young_garbage_collection}); - requiredEvents.put(gcParNew, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection}); - requiredEvents.put(gcDefNew, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection}); - requiredEvents.put(gcParallelScavenge, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_young_garbage_collection}); - requiredEvents.put(gcG1Old, new String[] {event_heap_summary, event_old_garbage_collection}); - requiredEvents.put(gcG1Full, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection}); - requiredEvents.put(gcConcurrentMarkSweep, new String[] {event_phases_pause, event_phases_level_1, event_old_garbage_collection}); - requiredEvents.put(gcSerialOld, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection}); - requiredEvents.put(gcParallelOld, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_old_garbage_collection, event_parold_garbage_collection}); - - String[] g1HeapRegionTypeLiterals = new String[] { - "Free", - "Eden", - "Survivor", - "Starts Humongous", - "Continues Humongous", - "Old", - "Archive" - }; - - g1HeapRegionTypes = Collections.unmodifiableList(Arrays.asList(g1HeapRegionTypeLiterals)); - } - - /** - * Contains all GC events belonging to the same GC (same gcId). - */ - public static class GcBatch { - private List events = new ArrayList<>(); - - public int getGcId() { - if (events.isEmpty()) { - return -1; - } - return GCHelper.getGcId(events.get(0)); - } - - public String getName() { - RecordedEvent endEvent = getEndEvent(); - String name = endEvent == null ? null : Events.assertField(endEvent, "name").getValue(); - return name == null ? "null" : name; - } - - public RecordedEvent getEndEvent() { - return getEvent(event_garbage_collection); - } - - public boolean addEvent(RecordedEvent event) { - if (!events.isEmpty()) { - assertEquals(getGcId(), GCHelper.getGcId(event), "Wrong gcId in event. Error in test code."); - } - boolean isEndEvent = event_garbage_collection.equals(event.getEventType().getName()); - if (isEndEvent) { - // Verify that we have not already got a garbage_collection event with this gcId. - assertNull(getEndEvent(), String.format("Multiple %s for gcId %d", event_garbage_collection, getGcId())); - } - events.add(event); - return isEndEvent; - } - - public boolean isYoungCollection() { - boolean isYoung = containsEvent(event_young_garbage_collection); - boolean isOld = containsEvent(event_old_garbage_collection); - assertNotEquals(isYoung, isOld, "isYoung and isOld was same for batch: " + toString()); - return isYoung; - } - - public int getEventCount() { - return events.size(); - } - - public RecordedEvent getEvent(int index) { - return events.get(index); - } - - public List getEvents() { - return events; - } - - public RecordedEvent getEvent(String eventPath) { - for (RecordedEvent event : events) { - if (eventPath.equals(event.getEventType().getName())) { - return event; - } - } - return null; - } - - public boolean containsEvent(String eventPath) { - return getEvent(eventPath) != null; - } - - public String toString() { - RecordedEvent endEvent = getEndEvent(); - Instant startTime = Instant.EPOCH; - String cause = "?"; - String name = "?"; - if (endEvent != null) { - name = getName(); - startTime = endEvent.getStartTime(); - cause = Events.assertField(endEvent, "cause").getValue(); - } - return String.format("GcEvent: gcId=%d, method=%s, cause=%s, startTime=%s", - getGcId(), name, cause, startTime); - } - - public String getLog() { - StringBuilder sb = new StringBuilder(); - sb.append(this.toString() + System.getProperty("line.separator")); - for (RecordedEvent event : events) { - sb.append(String.format("event: %s%n", event)); - } - return sb.toString(); - } - - // Group all events info batches. - public static List createFromEvents(List events) throws Exception { - Stack openGcIds = new Stack<>(); - List batches = new ArrayList<>(); - GcBatch currBatch = null; - - for (RecordedEvent event : events) { - if (!isGcEvent(event)) { - continue; - } - int gcId = GCHelper.getGcId(event); - if (currBatch == null || currBatch.getGcId() != gcId) { - currBatch = null; - // Search for existing batch - for (GcBatch loopBatch : batches) { - if (gcId == loopBatch.getGcId()) { - currBatch = loopBatch; - break; - } - } - if (currBatch == null) { - // No existing batch. Create new. - currBatch = new GcBatch(); - batches.add(currBatch); - openGcIds.push(new Integer(gcId)); - } - } - boolean isEndEvent = currBatch.addEvent(event); - if (isEndEvent) { - openGcIds.pop(); - } - } - // Verify that all start_garbage_collection events have received a corresponding "garbage_collection" event. - for (GcBatch batch : batches) { - if (batch.getEndEvent() == null) { - System.out.println(batch.getLog()); - } - assertNotNull(batch.getEndEvent(), "GcBatch has no end event"); - } - return batches; - } - } - - /** - * Contains number of collections and sum pause time for young and old collections. - */ - public static class CollectionSummary { - public long collectionCountOld; - public long collectionCountYoung; - public long collectionTimeOld; - public long collectionTimeYoung; - private Set names = new HashSet<>(); - - public void add(String collectorName, boolean isYoung, long count, long time) { - if (isYoung) { - collectionCountYoung += count; - collectionTimeYoung += time; - } else { - collectionCountOld += count; - collectionTimeOld += time; - } - if (!names.contains(collectorName)) { - names.add(collectorName); - } - } - - public long sum() { - return collectionCountOld + collectionCountYoung; - } - - public CollectionSummary calcDelta(CollectionSummary prev) { - CollectionSummary delta = new CollectionSummary(); - delta.collectionCountOld = this.collectionCountOld - prev.collectionCountOld; - delta.collectionTimeOld = this.collectionTimeOld - prev.collectionTimeOld; - delta.collectionCountYoung = this.collectionCountYoung - prev.collectionCountYoung; - delta.collectionTimeYoung = this.collectionTimeYoung - prev.collectionTimeYoung; - delta.names.addAll(this.names); - delta.names.addAll(prev.names); - return delta; - } - - public static CollectionSummary createFromMxBeans() { - CollectionSummary summary = new CollectionSummary(); - List gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); - for (int c=0; c batches) { - CollectionSummary summary = new CollectionSummary(); - for (GcBatch batch : batches) { - RecordedEvent endEvent = batch.getEndEvent(); - assertNotNull(endEvent, "No end event in batch with gcId " + batch.getGcId()); - String name = batch.getName(); - summary.add(name, batch.isYoungCollection(), 1, Events.assertField(endEvent, "sumOfPauses").getValue()); - } - return summary; - } - - public String toString() { - StringBuilder collectorNames = new StringBuilder(); - for (String s : names) { - if (collectorNames.length() > 0) { - collectorNames.append(", "); - } - collectorNames.append(s); - } - return String.format("CollectionSummary: young.collections=%d, young.time=%d, old.collections=%d, old.time=%d, collectors=(%s)", - collectionCountYoung, collectionTimeYoung, collectionCountOld, collectionTimeOld, collectorNames); - } - } - - public static PrintStream getDefaultErrorLog() { - if (defaultErrorLog == null) { - try { - defaultErrorLog = new PrintStream(new FileOutputStream("error.log", true)); - } catch (IOException e) { - e.printStackTrace(); - defaultErrorLog = System.err; - } - } - return defaultErrorLog; - } - - public static void log(Object msg) { - log(msg, System.err); - log(msg, getDefaultErrorLog()); - } - - public static void log(Object msg, PrintStream ps) { - ps.println(msg); - } - - public static boolean isValidG1HeapRegionType(final String type) { - return g1HeapRegionTypes.contains(type); - } - - /** - * Helper function to align heap size up. - * - * @param value - * @param alignment - * @return aligned value - */ - public static long alignUp(long value, long alignment) { - return (value + alignment - 1) & ~(alignment - 1); - } - - /** - * Helper function to align heap size down. - * - * @param value - * @param alignment - * @return aligned value - */ - public static long alignDown(long value, long alignment) { - return value & ~(alignment - 1); - } -} diff --git a/test/lib/jfr/RecurseThread.java b/test/lib/jfr/RecurseThread.java deleted file mode 100644 index 479af0996410fffbd9b730be03bd60ec435fea73..0000000000000000000000000000000000000000 --- a/test/lib/jfr/RecurseThread.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import jdk.test.lib.Asserts; - -public class RecurseThread extends Thread { - - public int totalDepth; - public long dummy = 0; // Just to make sure the optimizer does not remove the test code. - private volatile boolean timeToQuit = false; - private volatile boolean isInRunLoop = false; - - public RecurseThread(int totalDepth) { - this.totalDepth = totalDepth; - } - - @Override - public void run() { - // totalDepth includes functions run() and recurse() and runloop(). - // Remove 3 from totalDepth when recursing. - final int minDepth = 3; - Asserts.assertGreaterThanOrEqual(totalDepth, minDepth, "totalDepth too small"); - int recurseDepth = totalDepth - minDepth; - - // We want the last function before runloop() to be recurseA(). - boolean startWithRecurseA = (totalDepth % 2) != 0; - dummy = startWithRecurseA ? recurseA(recurseDepth) : recurseB(recurseDepth); - } - - public void quit() { - timeToQuit = true; - } - - public boolean isInRunLoop() { - return isInRunLoop; - } - - private long recurseA(int depth) { - if (depth == 0) { - return recurseEnd(); - } else { - return recurseB(depth - 1); - } - } - - private long recurseB(int depth) { - if (depth == 0) { - return recurseEnd(); - } else { - return recurseA(depth - 1); - } - } - - // Test expects this function to be at the top of the stack. - // We should not call other functions from here. - private long recurseEnd() { - isInRunLoop = true; - long[] dummyTable = new long[] { 0, 2, 4, 8, 16 }; - long dummyTotal = 0; - while (!timeToQuit) { - dummyTotal = 0; - for (int i = 0; i < 5; ++i) { - dummyTotal += dummyTable[i]; - } - } - return dummyTotal; - } - -} diff --git a/test/lib/jfr/SimpleEvent.java b/test/lib/jfr/SimpleEvent.java deleted file mode 100644 index 8476b0011b5be498f271484c811486ec43af6f10..0000000000000000000000000000000000000000 --- a/test/lib/jfr/SimpleEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import jdk.jfr.Event; - -public class SimpleEvent extends Event { - public int id; -} diff --git a/test/lib/jfr/SimpleEventHelper.java b/test/lib/jfr/SimpleEventHelper.java deleted file mode 100644 index f319cad7d710777a557eef193d7037daaa994885..0000000000000000000000000000000000000000 --- a/test/lib/jfr/SimpleEventHelper.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import jdk.jfr.Recording; -import jdk.jfr.consumer.RecordedEvent; -import jdk.test.lib.Asserts; - -public class SimpleEventHelper { - - public static void enable(Recording r, boolean isEnabled) { - if (isEnabled) { - r.enable(SimpleEvent.class).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); - } else { - r.disable(SimpleEvent.class); - } - } - - public static SimpleEvent createEvent(int id) { - SimpleEvent event = new SimpleEvent(); - event.begin(); - event.id = id; - event.end(); - event.commit(); - return event; - } - - public static void verifyEvents(Recording r, int ... ids) throws Exception { - List eventIds = new ArrayList<>(); - for (RecordedEvent event : Events.fromRecording(r)) { - if (Events.isEventType(event, SimpleEvent.class.getName())) { - int id = Events.assertField(event, "id").getValue(); - System.out.printf("recording %s: event.id=%d%n", r.getName(), id); - eventIds.add(id); - } - } - Asserts.assertEquals(eventIds.size(), ids.length, "Wrong number of events"); - for (int i = 0; i < ids.length; ++i) { - Asserts.assertEquals(eventIds.get(i).intValue(), ids[i], "Wrong id in event"); - } - } - - public static void verifyContains(List events, int ... ids) throws Exception { - Set missingIds = new HashSet<>(); - for (int id : ids) { - missingIds.add(id); - } - for (RecordedEvent event : getSimpleEvents(events)) { - int id = Events.assertField(event, "id").getValue(); - System.out.printf("event.id=%d%n", id); - missingIds.remove(new Integer(id)); - } - if (!missingIds.isEmpty()) { - missingIds.forEach(id -> System.out.println("Missing MyEvent with id " + id)); - Asserts.fail("Missing some MyEvent events"); - } - } - - public static void verifyNotContains(List events, int ... ids) throws Exception { - for (RecordedEvent event : getSimpleEvents(events)) { - int eventId = Events.assertField(event, "id").getValue(); - System.out.printf("event.id=%d%n", eventId); - for (int id : ids) { - Events.assertField(event, "id").notEqual(id); - } - } - } - - public static List getSimpleEvents(List events) { - List myEvents = new ArrayList<>(); - for (RecordedEvent event : events) { - if (Events.isEventType(event, SimpleEvent.class.getName())) { - myEvents.add(event); - } - } - return myEvents; - } -} diff --git a/test/lib/jfr/SimpleSetting.java b/test/lib/jfr/SimpleSetting.java deleted file mode 100644 index 25c1db9d0f4f93191c0301f1a0d9db424993a271..0000000000000000000000000000000000000000 --- a/test/lib/jfr/SimpleSetting.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.util.Set; - -import jdk.jfr.SettingControl; - -public class SimpleSetting extends SettingControl { - - @Override - public String combine(Set settingValue) { - return "none"; - } - - @Override - public void setValue(String value) { - } - - @Override - public String getValue() { - return "none"; - } -} diff --git a/test/lib/jfr/Stressor.java b/test/lib/jfr/Stressor.java deleted file mode 100644 index 4d525d1965a7f502a0a98141219214dff3ea5712..0000000000000000000000000000000000000000 --- a/test/lib/jfr/Stressor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.util.ArrayList; -import java.util.List; - -/** - * Class to help run multiple threads executing some task - * - * - * @since 1.9 - */ -public class Stressor { - public static void execute(int numberOfThreads, Thread.UncaughtExceptionHandler eh, Runnable task) throws Exception { - List threads = new ArrayList<>(); - for (int n = 0; n < numberOfThreads; ++n) { - Thread t = new Thread(task); - t.setUncaughtExceptionHandler(eh); - threads.add(t); - t.start(); - } - for (Thread t : threads) { - t.join(); - } - } -} diff --git a/test/lib/jfr/TestClassLoader.java b/test/lib/jfr/TestClassLoader.java deleted file mode 100644 index fe9e25d26a925472572f72c594fa2cb68e14f5f6..0000000000000000000000000000000000000000 --- a/test/lib/jfr/TestClassLoader.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * Custom class loader which will try to load the class via getResourceAsStream(). - * If there are any errors, the parent class loader will be used instead. - */ -public class TestClassLoader extends ClassLoader { - static public final String CLASS_LOADER_NAME = "JFR TestClassLoader"; - - public TestClassLoader() { - super(CLASS_LOADER_NAME, ClassLoader.getSystemClassLoader()); - } - - public Class loadClass(String name) throws ClassNotFoundException { - - InputStream is = null; - DataInputStream dis = null; - try { - String resourceName = name.replace('.', '/') + ".class"; - is = getResourceAsStream(resourceName); - if (is != null) { - int i = is.available(); - byte buf[] = new byte[i]; - dis = new DataInputStream(is); - dis.readFully(buf); - dis.close(); - return defineClass(name, buf, 0, buf.length); - } - } catch (SecurityException e) { - // This error will happen quite often (for example when loading - // "java.lang..."). - // Ignore this error and use parent class loader. - } catch (IOException e) { - // Unexpected error. Use parent class loader. - e.printStackTrace(); - } finally { - if (dis != null) { - try { - dis.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return super.loadClass(name); - } - -} diff --git a/test/lib/jfr/VoidFunction.java b/test/lib/jfr/VoidFunction.java deleted file mode 100644 index 22bd1d328a77443de6170964da8ea1e7aa048f99..0000000000000000000000000000000000000000 --- a/test/lib/jfr/VoidFunction.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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 jdk.test.lib.jfr; - -@FunctionalInterface -public interface VoidFunction { - void run() throws Throwable; -} diff --git a/test/lib/sun/hotspot/WhiteBox.java b/test/lib/sun/hotspot/WhiteBox.java index 5c1a009e43f29e1016738adeb9ee328ec29843a6..9497c953057bdb51f42789d3fefcda8406d09bd8 100644 --- a/test/lib/sun/hotspot/WhiteBox.java +++ b/test/lib/sun/hotspot/WhiteBox.java @@ -240,9 +240,18 @@ public class WhiteBox { public boolean enqueueMethodForCompilation(Executable method, int compLevel) { return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/); } - public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci); - public native boolean enqueueInitializerForCompilation(Class aClass, int compLevel); + private native boolean enqueueMethodForCompilation0(Executable method, int compLevel, int entry_bci); + public boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci) { + Objects.requireNonNull(method); + return enqueueMethodForCompilation0(method, compLevel, entry_bci); + } + private native boolean enqueueInitializerForCompilation0(Class aClass, int compLevel); + public boolean enqueueInitializerForCompilation(Class aClass, int compLevel) { + Objects.requireNonNull(aClass); + return enqueueInitializerForCompilation0(aClass, compLevel); + } public native void clearMethodState(Executable method); + public native void markMethodProfiled(Executable method); public native void lockCompilation(); public native void unlockCompilation(); public native int getMethodEntryBci(Executable method); @@ -257,7 +266,6 @@ public class WhiteBox { return allocateCodeBlob( intSize, type); } public native void freeCodeBlob(long addr); - public native void forceNMethodSweep(); public native Object[] getCodeHeapEntries(int type); public native int getCompilationActivityMode(); private native long getMethodData0(Executable method); @@ -427,10 +435,6 @@ public class WhiteBox { public native Object getResolvedReferences(Class c); public native boolean areOpenArchiveHeapObjectsMapped(); - // Compiler Directive - public native int addCompilerDirective(String compDirect); - public native void removeCompilerDirective(int count); - // Handshakes public native int handshakeWalkStack(Thread t, boolean all_threads);