/* * Copyright (c) 2013, 2021, 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;
publicstatic RecordedEvent getConfigEvent(List<RecordedEvent> events) throws Exception { for (RecordedEvent event : events) { if (EventNames.GCConfiguration.equals(event.getEventType().getName())) { return event;
}
}
fail("Could not find event " + EventNames.GCConfiguration); returnnull;
}
publicstaticvoid callSystemGc(int num, boolean withGarbage) { for (int i = 0; i < num; i++) { if (withGarbage) {
makeGarbage();
}
System.gc();
}
}
privatestaticvoid makeGarbage() {
Object[] garbage = new Object[1024]; for (int i = 0; i < 1024; i++) {
garbage[i] = new Object();
}
}
// Removes gcEvents with lowest and highest gcID. This is used to filter out // any incomplete GCs if the recording started/stopped in the middle of a GC. // We also filters out events without gcId. Those events are not needed. publicstatic List<RecordedEvent> removeFirstAndLastGC(List<RecordedEvent> events) { int minGcId = Integer.MAX_VALUE; int maxGcId = Integer.MIN_VALUE; // Find min/max gcId for (RecordedEvent event : events) { if (Events.hasField(event, "gcId")) { int gcId = Events.assertField(event, "gcId").getValue();
minGcId = Math.min(gcId, minGcId);
maxGcId = Math.max(gcId, maxGcId);
}
}
// Add all events except those with gcId = min/max gcId
List<RecordedEvent> filteredEvents = new ArrayList<>(); for (RecordedEvent event : events) { if (Events.hasField(event, "gcId")) { int gcId = Events.assertField(event, "gcId").getValue(); if (gcId != minGcId && gcId != maxGcId) {
filteredEvents.add(event);
}
}
} return filteredEvents;
}
publicstatic Map<String, Boolean> beanCollectorTypes = new HashMap<>(); publicstatic Set<String> collectorOverrides = new HashSet<>(); publicstatic Map<String, String[]> requiredEvents = new HashMap<>();
static { // young GarbageCollectionMXBeans.
beanCollectorTypes.put("G1 Young Generation", true);
beanCollectorTypes.put("Copy", true);
beanCollectorTypes.put("PS Scavenge", true);
// old GarbageCollectionMXBeans.
beanCollectorTypes.put("G1 Old Generation", false);
beanCollectorTypes.put("G1 Concurrent GC", false);
beanCollectorTypes.put("PS MarkSweep", false);
beanCollectorTypes.put("MarkSweepCompact", false);
// List of expected collector overrides. "A.B" means that collector A may use collector B.
collectorOverrides.add("G1Old.G1Full");
collectorOverrides.add("SerialOld.PSMarkSweep");
requiredEvents.put(gcG1New, new String[] {event_heap_summary, event_young_garbage_collection});
requiredEvents.put(gcDefNew, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
requiredEvents.put(gcParallelScavenge, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
requiredEvents.put(gcG1Old, new String[] {event_heap_summary, event_old_garbage_collection});
requiredEvents.put(gcG1Full, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
requiredEvents.put(gcSerialOld, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
requiredEvents.put(gcParallelOld, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_old_garbage_collection, event_parold_garbage_collection});
/** * Contains all GC events belonging to the same GC (same gcId).
*/ publicstaticclass GcBatch { private List<RecordedEvent> events = new ArrayList<>();
public String getName() {
RecordedEvent endEvent = getEndEvent();
String name = endEvent == null ? null : Events.assertField(endEvent, "name").getValue(); return name == null ? "null" : name;
}
public RecordedEvent getEndEvent() { return getEvent(event_garbage_collection);
}
publicboolean addEvent(RecordedEvent event) { if (!events.isEmpty()) {
assertEquals(getGcId(), GCHelper.getGcId(event), "Wrong gcId in event. Error in test code.");
} boolean isEndEvent = event_garbage_collection.equals(event.getEventType().getName()); if (isEndEvent) { // Verify that we have not already got a garbage_collection event with this gcId.
assertNull(getEndEvent(), String.format("Multiple %s for gcId %d", event_garbage_collection, getGcId()));
}
events.add(event); return isEndEvent;
}
publicboolean isYoungCollection() { boolean isYoung = containsEvent(event_young_garbage_collection); boolean isOld = containsEvent(event_old_garbage_collection);
assertNotEquals(isYoung, isOld, "isYoung and isOld was same for batch: " + toString()); return isYoung;
}
public String toString() {
RecordedEvent endEvent = getEndEvent();
Instant startTime = Instant.EPOCH;
String cause = "?";
String name = "?"; if (endEvent != null) {
name = getName();
startTime = endEvent.getStartTime();
cause = Events.assertField(endEvent, "cause").getValue();
} return String.format("GcEvent: gcId=%d, method=%s, cause=%s, startTime=%s",
getGcId(), name, cause, startTime);
}
public String getLog() {
StringBuilder sb = new StringBuilder();
sb.append(this.toString() + System.getProperty("line.separator")); for (RecordedEvent event : events) {
sb.append(String.format("event: %s%n", event));
} return sb.toString();
}
// Group all events info batches. publicstatic List<GcBatch> createFromEvents(List<RecordedEvent> events) throws Exception {
Stack<Integer> openGcIds = new Stack<>();
List<GcBatch> batches = new ArrayList<>();
GcBatch currBatch = null;
for (RecordedEvent event : events) { if (!isGcEvent(event)) { continue;
} int gcId = GCHelper.getGcId(event); if (currBatch == null || currBatch.getGcId() != gcId) {
currBatch = null; // Search for existing batch for (GcBatch loopBatch : batches) { if (gcId == loopBatch.getGcId()) {
currBatch = loopBatch; break;
}
} if (currBatch == null) { // No existing batch. Create new.
currBatch = new GcBatch();
batches.add(currBatch);
openGcIds.push(Integer.valueOf(gcId));
}
} boolean isEndEvent = currBatch.addEvent(event); if (isEndEvent) {
openGcIds.pop();
}
} // Verify that all start_garbage_collection events have received a corresponding "garbage_collection" event. for (GcBatch batch : batches) { if (batch.getEndEvent() == null) {
System.out.println(batch.getLog());
}
assertNotNull(batch.getEndEvent(), "GcBatch has no end event");
} return batches;
}
}
/** * Contains number of collections and sum pause time for young and old collections.
*/ publicstaticclass CollectionSummary { publiclong collectionCountOld; publiclong collectionCountYoung; publiclong collectionTimeOld; publiclong collectionTimeYoung; private Set<String> names = new HashSet<>();
publicvoid add(String collectorName, boolean isYoung, long count, long time) { if (isYoung) {
collectionCountYoung += count;
collectionTimeYoung += time;
} else {
collectionCountOld += count;
collectionTimeOld += time;
} if (!names.contains(collectorName)) {
names.add(collectorName);
}
}
publicstaticboolean assertIsValidShenandoahHeapRegionState(final String state) { if (!shenandoahHeapRegionStates.contains(state)) { thrownew AssertionError("Unknown state '" + state + "', valid heap region states are " + shenandoahHeapRegionStates);
} returntrue;
}
/** * Helper function to align heap size up. * * @param value * @param alignment * @return aligned value
*/ publicstaticlong alignUp(long value, long alignment) { return (value + alignment - 1) & ~(alignment - 1);
}
/** * Helper function to align heap size down. * * @param value * @param alignment * @return aligned value
*/ publicstaticlong alignDown(long value, long alignment) { return value & ~(alignment - 1);
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.18 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.