提交 e9641939 编写于 作者: J jbachorik

8230707: JFR related tests are failing

Reviewed-by: neugens
上级 bf3ca964
......@@ -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 {
......
/*
* 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<RecordedEvent> 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);
}
}
}
......@@ -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 */);
}
......
......@@ -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);
}
......
......@@ -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");
}
......
......@@ -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);
}
......
......@@ -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);
}
......
/*
* 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<RecordedEvent> all = Events.fromRecording(recording);
Events.hasEvents(all);
for (RecordedEvent e : all) {
Events.assertField(e, "gcId").above(0);
}
recording.close();
}
}
/*
* 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<RecordedEvent> all = Events.fromRecording(recording);
Events.hasEvents(all);
for (RecordedEvent e : all) {
Events.assertField(e, "gcId").above(0);
}
recording.close();
}
}
......@@ -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);
}
}
......@@ -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<String> 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()) {
......
......@@ -102,7 +102,6 @@ public class TestJavaMonitorInflateEvent {
continue;
}
Events.assertField(event, FIELD_ADDRESS).notEqual(0L);
Events.assertField(event, FIELD_CAUSE).notNull();
isAnyFound = true;
break;
}
......
/*
* 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 = "<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<RecordedEvent> 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<RecordedEvent> 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<String, String> edges = new HashMap<>();
List<RecordedEvent> 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 -> <unnamed> (because we use the package)
// 2) java.util -> <unnamed> (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;
}
}
}
/*
* 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<String> 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");
}
}
/*
* 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);
}
}
}
/*
* 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 List<String>findWhat = new ArrayList<>();
findWhat.add("Starting a recording");
findWhat.add("Flight Recorder initialized");
boolean passed = false;
List<String> matches = new ArrayList<String>(findWhat);
do {
List<String> 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");
}
}
......@@ -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");
......
/*
* 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<String> 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);
}
}
/*
* 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<? extends Throwable> 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<Recording> 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<RecordedEvent> 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);
}
}
}
}
/*
* 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 <T extends Comparable<T>> boolean isEqual(T value) {
return value == (T)getValue();
}
@SuppressWarnings("unchecked")
public <T extends Comparable<T>> EventField equal(T value) {
doAssert(()-> Asserts.assertEquals((T)getValue(), value, getErrMsg("Value not equal to " + value)));
return this;
}
@SuppressWarnings("unchecked")
public <T extends Comparable<T>> EventField notEqual(T value) {
doAssert(()-> Asserts.assertNotEquals((T)getValue(), value, getErrMsg("Value equal to " + value)));
return this;
}
@SuppressWarnings("unchecked")
public <T extends Comparable<T>> EventField above(T value) {
doAssert(()-> Asserts.assertGreaterThan((T)getValue(), value, getErrMsg("Value not above " + value)));
return this;
}
@SuppressWarnings("unchecked")
public <T extends Comparable<T>> EventField below(T value) {
doAssert(()-> Asserts.assertLessThan((T)getValue(), value, getErrMsg("Value not below " + value)));
return this;
}
@SuppressWarnings("unchecked")
public <T extends Comparable<T>> EventField atLeast(T value) {
doAssert(()-> Asserts.assertGreaterThanOrEqual((T)getValue(), value, getErrMsg("Value not atLeast" + value)));
return this;
}
@SuppressWarnings("unchecked")
public <T extends Comparable<T>> EventField atMost(T value) {
doAssert(()-> Asserts.assertLessThanOrEqual((T)getValue(), value, getErrMsg("Value not atMost " + value)));
return this;
}
public <T extends Comparable<T>> 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> 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<String> 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();
}
}
/*
* 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);
}
}
/*
* 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<ValueDescriptor> fields;
private final List<AnnotationElement> annotations;
private final String name;
public EventTypePrototype(String name, List<AnnotationElement> as, List<ValueDescriptor> 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<ValueDescriptor> getFields() {
return fields;
}
public List<AnnotationElement> getAnnotations() {
return annotations;
}
public String getName() {
return name;
}
}
/*
* 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 <T extends Comparable<T>> 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;
}
/*
* 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<partNames.length; ++i) {
final String partName = partNames[i];
final boolean isLastPart = i == partNames.length - 1;
ValueDescriptor d = getValueDescriptor(struct, partName);
if (isLastPart) {
return new EventField(struct, d);
} else {
assertTrue(struct.getValue(partName) instanceof RecordedObject, "Expected '" + partName + "' to be a struct");
struct = struct.getValue(partName);
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.printf("Failed event:%n%s%n", event.toString());
fail(String.format("Field %s not in event", name));
return null;
}
private static RecordedObject getRecordedPackage(final RecordedClass rc) {
if (rc == null) {
throw new RuntimeException("RecordedClass must not be null!");
}
return rc.getValue("package");
}
private static RecordedObject getRecordedModule(final RecordedObject pkg) {
if (pkg == null) {
// null package is an unnamed module (null)
return null;
}
return pkg.getValue("module");
}
/**
* Validates the recored name field
*
* @param ro should be a Package or a Module
* @param targetName name to match
*/
private static boolean isMatchingTargetName(final RecordedObject ro, final String targetName) {
if (ro == null) {
return targetName == null;
}
final String recordedName = ro.getValue("name");
if (recordedName == null) {
return targetName == null;
}
return recordedName.equals(targetName);
}
public static void assertClassPackage(final RecordedClass rc, final String packageNameTarget) {
final RecordedObject recordedPackage = getRecordedPackage(rc);
if (recordedPackage == null) {
if (packageNameTarget != null) {
throw new RuntimeException("RecordedClass package is null!");
}
return;
}
assertTrue(isMatchingTargetName(recordedPackage, packageNameTarget), "mismatched package name! Target is " + packageNameTarget);
}
public static void assertClassModule(final RecordedClass rc, final String moduleNameTarget) {
final RecordedObject recordedPackage = getRecordedPackage(rc);
final RecordedObject recordedModule = getRecordedModule(recordedPackage);
if (recordedModule == null) {
if (moduleNameTarget != null) {
throw new RuntimeException("RecordedClass module is null!");
}
return;
}
assertTrue(isMatchingTargetName(recordedModule, moduleNameTarget), "mismatched module name! Target is " + moduleNameTarget);
}
private static ValueDescriptor getValueDescriptor(RecordedObject struct, String name) throws Exception {
List<ValueDescriptor> 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<RecordedEvent> 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<RecordedEvent> 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<? extends java.lang.annotation.Annotation> 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<? extends java.lang.annotation.Annotation> 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<RecordedEvent> events = fromRecording(r);
Events.hasEvents(events);
Events.hasEvent(events, name);
}
public static void hasEvent(List<RecordedEvent> events, String name) throws IOException {
if (!containsEvent(events, name)) {
Asserts.fail("Missing event " + name + " in recording " + events.toString());
}
}
public static void hasNotEvent(List<RecordedEvent> events, String name) throws IOException {
if (containsEvent(events, name)) {
Asserts.fail("Rercording should not contain event " + name + " " + events.toString());
}
}
private static boolean containsEvent(List<RecordedEvent> events, String name) {
for (RecordedEvent event : events) {
if (event.getEventType().getName().equals(name)) {
return true;
}
}
return false;
}
}
/*
* 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<RecordedEvent> 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());
}
}
此差异已折叠。
/*
* 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;
}
}
/*
* 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;
}
/*
* 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<Integer> 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<RecordedEvent> events, int ... ids) throws Exception {
Set<Integer> 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<RecordedEvent> 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<RecordedEvent> getSimpleEvents(List<RecordedEvent> events) {
List<RecordedEvent> myEvents = new ArrayList<>();
for (RecordedEvent event : events) {
if (Events.isEventType(event, SimpleEvent.class.getName())) {
myEvents.add(event);
}
}
return myEvents;
}
}
/*
* 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<String> settingValue) {
return "none";
}
@Override
public void setValue(String value) {
}
@Override
public String getValue() {
return "none";
}
}
/*
* 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<Thread> 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();
}
}
}
/*
* 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);
}
}
/*
* 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;
}
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册