/* * Copyright (c) 2020, 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.
*/
privatestaticvoid test(Class<?> crasher, String reason) throws Exception { // The JVM may be in a state it can't recover from, so try three times // before concluding functionality is not working. for (int attempt = 0; attempt < ATTEMPTS; attempt++) { try {
verify(runProcess(crasher), reason); return;
} catch (Exception e) {
System.out.println("Attempt " + attempt + ". Verification failed:");
System.out.println(e.getMessage());
System.out.println("Retrying...");
System.out.println();
} catch (OutOfMemoryError | StackOverflowError e) { // Could happen if file is corrupt and parser loops or // tries to allocate more memory than what is available return;
}
} thrownew Exception(ATTEMPTS + " attempts with failure!");
}
privatestaticlong runProcess(Class<?> crasher) throws Exception {
System.out.println("Test case for " + crasher.getName());
Process p = ProcessTools.createTestJvm( "-Xmx64m", "-XX:-CreateCoredumpOnCrash", "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
crasher.getName(), ""
).start();
OutputAnalyzer output = new OutputAnalyzer(p);
System.out.println("========== Crasher process output:");
System.out.println(output.getOutput());
System.out.println("==================================");
return p.pid();
}
privatestaticvoid verify(long pid, String reason) throws Exception {
String fileName = "hs_err_pid" + pid + ".jfr";
Path file = Paths.get(fileName).toAbsolutePath().normalize(); try {
Asserts.assertTrue(Files.exists(file), "No emergency jfr recording file " + file + " exists");
Asserts.assertNotEquals(Files.size(file), 0L, "File length 0. Should at least be some bytes");
System.out.printf("File size=%d%n", Files.size(file));
List<RecordedEvent> events = RecordingFile.readAllEvents(file);
System.out.println(events);
Asserts.assertTrue(events.size() == 1, "Expected one event");
RecordedEvent e = events.get(0); if (reason.equals(e.getString("reason"))) { return;
} thrownew Exception("Could not find vaild DumpReason event");
} finally {
Files.delete(file);
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(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.