/* * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ package jdk.jfr.jvm;
@Label("My Event")
@Description("My fine event") staticclass MyEvent extends Event { int myValue;
}
publicstaticvoid main(String... args) throws Exception { if (Boolean.getBoolean("prepare-recording")) {
Recording r = new Recording(Configuration.getConfiguration("default"));
r.start();
r.stop();
r.dump(RECORDING_FILE);
r.close(); return;
}
System.out.println("jfr.unsupported.vm=" + System.getProperty("jfr.unsupported.vm")); // Class FlightRecorder if (FlightRecorder.isAvailable()) { thrownew AssertionError("JFR should not be available on an unsupported VM");
}
if (FlightRecorder.isInitialized()) { thrownew AssertionError("JFR should not be initialized on an unsupported VM");
}
// Class Configuration if (!Configuration.getConfigurations().isEmpty()) { thrownew AssertionError("Configuration files should not exist on an unsupported VM");
}
Path jfcFile = Utils.createTempFile("empty", ".jfr");
assertIOException(() -> Configuration.getConfiguration("default"));
assertIOException(() -> Configuration.create(jfcFile));
assertIOException(() -> Configuration.create(new FileReader(jfcFile.toFile())));
// Class EventType
assertInternalError(() -> EventType.getEventType(MyEvent.class));
// Class EventFactory
assertInternalError(() -> EventFactory.create(new ArrayList<>(), new ArrayList<>()));
// Create a static event
MyEvent myEvent = new MyEvent();
myEvent.begin();
myEvent.end();
myEvent.shouldCommit();
myEvent.commit();
// Trigger class initialization failure for (Class<?> c : APIClasses) {
assertNoClassInitFailure(c);
}
// jdk.jfr.consumer.* // Only run this part of tests if we are on VM // that can produce a recording file if (Files.exists(RECORDING_FILE)) { boolean firstFileEvent = true; for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) { // Print one event if (firstFileEvent) {
System.out.println(re);
firstFileEvent = false;
}
}
AtomicBoolean firstStreamEvent = new AtomicBoolean(true); try (EventStream es = EventStream.openFile(RECORDING_FILE)) {
es.onEvent(e -> { // Print one event if (firstStreamEvent.get()) { try {
System.out.println(e);
firstStreamEvent.set(false);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
es.start(); if (firstStreamEvent.get()) { thrownew AssertionError("Didn't print streaming event");
}
}
privatestaticvoid assertNoClassInitFailure(Class<?> clazz) { try { Class.forName(clazz.getName(), true, clazz.getClassLoader());
} catch (ClassNotFoundException e) { thrownew AssertionError("Could not find public API class on unsupported VM");
}
}
privatestaticvoid assertInternalError(Runnable r) { try {
r.run();
} catch (InternalError e) { // OK, as expected return;
} thrownew AssertionError("Expected InternalError on an unsupported JVM");
}
privatestaticvoid assertIOException(Callable<?> c) { try {
c.call();
} catch (Exception e) { if (e.getClass() == IOException.class) { return;
}
} thrownew AssertionError("Expected IOException on an unsupported JVM");
}
privatestaticvoid assertIllegalStateException(Runnable r) throws Exception { try {
r.run();
} catch (IllegalStateException ise) { if (!ise.getMessage().equals("Flight Recorder is not supported on this VM")) { thrownew AssertionError("Expected 'Flight Recorder is not supported on this VM'");
}
}
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.13Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.