/* * 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. * * 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.oldobject;
/** * Utility class to perform Old Object provocation/detection and * stack trace/object verification for the Old Object Sample JFR event
*/ finalpublicclass OldObjects {
publicstaticfinalint MIN_SIZE = 99901; // prime number publicfinalstaticint LEAK_CONTEXT = 100; // length of chain assiociated with the object sample publicfinalstaticint ROOT_CONTEXT = 100; // length of chain assoicated with the root publicfinalstaticint MAX_CHAIN_LENGTH = LEAK_CONTEXT + ROOT_CONTEXT; // the VM should not construct chains longer than this
/** * * @param r * A recording * @param expectedFrame * A frame that must be found on the stack. Null if no check is required. * @param fieldType * The object type (of the field). Null if no check is required. * @param fieldName * The field name. Null if no check is required. * @param referrerType * The class name. Null if no check is required. * @param minDuration * The minimum duration of the event, -1 if not applicable. * @return The count of matching events * @throws IOException
*/ publicstaticlong countMatchingEvents(Recording r, String expectedFrame, Class<?> fieldType, String fieldName, Class<?> referrerType, long minDuration) throws IOException { return countMatchingEvents(r, getFrames(expectedFrame), fieldType, fieldName, referrerType, minDuration);
}
/** * Gets the OldObjectSample events from the provided recording through a dump * and counts how many events matches the provided parameters. * * @param r * A recording * @param expectedStack * Some frames that must be found on the stack. Null if no check is required. * @param fieldType * The object type (of the field). Null if no check is required. * @param fieldName * The field name. Null if no check is required. * @param referrerType * The class name. Null if no check is required. * @param minDuration * The minimum duration of the event, -1 if not applicable. * @return The count of matching events * @throws IOException
*/ publicstaticlong countMatchingEvents(Recording r, String[] expectedStack, Class<?> fieldType, String fieldName, Class<?> referrerType, long minDuration) throws IOException { return countMatchingEvents(Events.fromRecording(r), fieldType, fieldName, referrerType, minDuration, expectedStack);
}
/** * * @param events * A list of RecordedEvent. * @param expectedFrame * A frame that must be found on the stack. Null if no check is required. * @param fieldType * The object type (of the field). Null if no check is required. * @param fieldName * The field name. Null if no check is required. * @param referrerType * The class name. Null if no check is required. * @param minDuration * The minimum duration of the event, -1 if not applicable. * @return The count of matching events * @throws IOException
*/ publicstaticlong countMatchingEvents(List<RecordedEvent> events, String expectedFrame, Class<?> fieldType, String fieldName, Class<?> referrerType, long minDuration) throws IOException { return countMatchingEvents(events, fieldType, fieldName, referrerType, minDuration, getFrames(expectedFrame));
}
/** * * @param events * The list of events to find matching events in * @param expectedStack * Some frames that must be found on the stack. Null if no check is required. * @param fieldType * The object type (of the field). Null if no check is required. * @param fieldName * The field name. Null if no check is required. * @param referrerType * The class name. Null if no check is required. * @param minDuration * The minimum duration of the event, -1 if not applicable. * @return The count of matching events * @throws IOException
*/ publicstaticlong countMatchingEvents(List<RecordedEvent> events, Class<?> fieldType, String fieldName, Class<?> referrerType, long minDuration, String... expectedStack) throws IOException {
String currentThread = Thread.currentThread().getName(); return events.stream()
.filter(hasJavaThread(currentThread))
.filter(fieldIsType(fieldType))
.filter(hasFieldName(fieldName))
.filter(isReferrerType(referrerType))
.filter(durationAtLeast(minDuration))
.filter(hasStackTrace(expectedStack))
.count();
}
privatestatic Predicate<RecordedEvent> hasJavaThread(String expectedThread) { if (expectedThread != null) { return e -> e.getThread() != null && expectedThread.equals(e.getThread().getJavaName());
} else { return e -> true;
}
}
privatestatic Predicate<RecordedEvent> hasStackTrace(String[] expectedStack) { if (expectedStack != null) { return e -> matchingStackTrace(e.getStackTrace(), expectedStack);
} else { return e -> true;
}
}
privatestatic Predicate<RecordedEvent> fieldIsType(Class<?> fieldType) { if (fieldType != null) { return e -> e.hasField("object.type") && ((RecordedClass) e.getValue("object.type")).getName().equals(fieldType.getName());
} else { return e -> true;
}
}
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.